Admin/MacOS/App1/script
author wenzelm
Thu, 29 Aug 2013 12:38:33 +0200
changeset 53274 1760c01f1c78
parent 50805 69439c9defec
child 53498 05313b45a5ae
permissions -rw-r--r--
maintain Completion_Popup.Text_Area as client property like Document_View; global Completion_Popup.Text_Area init/exit like SideKickPlugin; eliminated old SideKick completion -- cover all Isabelle modes uniformly; dynamic lookup of Isabelle.mode_syntax -- NB: buffer mode might be undefined in intermediate stages;

#!/bin/bash
#
# Author: Makarius
#
# Isabelle application wrapper

THIS="$(cd "$(dirname "$0")"; pwd)"
THIS_APP="$(cd "$THIS/../.."; pwd)"
SUPER_APP="$(cd "$THIS/../../.."; pwd)"


# global defaults

ISABELLE_TOOL="$THIS/Isabelle/bin/isabelle"
PROOFGENERAL_EMACS="$THIS/Aquamacs.app/Contents/MacOS/Aquamacs"


# environment

cd "$HOME"
if [ -x /usr/libexec/path_helper ]; then
  eval $(/usr/libexec/path_helper -s)
fi

[ -z "$LANG" ] && export LANG=en_US.UTF-8


# run interface with error feedback

ISABELLE_INTERFACE_CHOICE="$("$ISABELLE_TOOL" getenv -b ISABELLE_INTERFACE_CHOICE)"
if [ "$ISABELLE_INTERFACE_CHOICE" != emacs -a "$ISABELLE_INTERFACE_CHOICE" != jedit ]
then
  declare -a CHOICE
  CHOICE=($("$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" dropdown \
    --title Isabelle \
    --text "Which Isabelle interface?" \
    --items "Isabelle/jEdit PIDE" "Emacs / Proof General" \
    --button2 "OK, do not ask again" --button1 "OK"))
  if [ "${CHOICE[1]}" = 0 ]; then
    ISABELLE_INTERFACE_CHOICE=jedit
  else
    ISABELLE_INTERFACE_CHOICE=emacs
  fi
  if [ "${CHOICE[0]}" = 2 ]; then
    ISABELLE_HOME_USER="$("$ISABELLE_TOOL" getenv -b ISABELLE_HOME_USER)"
    mkdir -p "$ISABELLE_HOME_USER/etc"
    ( echo; echo "ISABELLE_INTERFACE_CHOICE=$ISABELLE_INTERFACE_CHOICE"; ) \
      >> "$ISABELLE_HOME_USER/etc/settings"
    "$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" ok-msgbox \
      --title Isabelle \
      --text Note \
      --informative-text "ISABELLE_INTERFACE_CHOICE stored in $ISABELLE_HOME_USER/etc/settings" \
      --no-cancel
  fi
fi

OUTPUT="/tmp/isabelle$$.out"

if [ "$ISABELLE_INTERFACE_CHOICE" = emacs ]; then
  ( "$ISABELLE_TOOL" emacs -p "$PROOFGENERAL_EMACS" "$@" ) > "$OUTPUT" 2>&1
  RC=$?
else
  ( "$ISABELLE_TOOL" jedit -s "$@" ) > "$OUTPUT" 2>&1
  RC=$?
fi

if [ "$RC" != 0 ]; then
  echo >> "$OUTPUT"
  echo "Return code: $RC" >> "$OUTPUT"
fi

if [ $(stat -f "%z" "$OUTPUT") != 0 ]; then
  "$THIS/CocoaDialog.app/Contents/MacOS/CocoaDialog" textbox \
    --title "Isabelle" \
    --informative-text "Isabelle output" \
    --text-from-file "$OUTPUT" \
    --button1 "OK"
fi

rm -f "$OUTPUT"

exit "$RC"