src/Tools/jEdit/lib/Tools/jedit
author wenzelm
Sun Oct 05 17:58:36 2014 +0200 (2014-10-05 ago)
changeset 58545 30b75b7958d6
parent 58529 cd4439d8799c
child 58546 72e2b2a609c4
permissions -rwxr-xr-x
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm@34333
     1
#!/usr/bin/env bash
wenzelm@34333
     2
#
wenzelm@34664
     3
# Author: Makarius
wenzelm@34664
     4
#
wenzelm@34664
     5
# DESCRIPTION: Isabelle/jEdit interface wrapper
wenzelm@34664
     6
wenzelm@34333
     7
wenzelm@43285
     8
## sources
wenzelm@43285
     9
wenzelm@43320
    10
declare -a SOURCES=(
wenzelm@50450
    11
  "src/active.scala"
wenzelm@58545
    12
  "src/bibtex_jedit.scala"
wenzelm@58529
    13
  "src/bibtex_token_markup.scala"
wenzelm@53023
    14
  "src/completion_popup.scala"
wenzelm@56585
    15
  "src/context_menu.scala"
wenzelm@43285
    16
  "src/dockable.scala"
wenzelm@43285
    17
  "src/document_model.scala"
wenzelm@43285
    18
  "src/document_view.scala"
wenzelm@52445
    19
  "src/documentation_dockable.scala"
wenzelm@50542
    20
  "src/fold_handling.scala"
wenzelm@55825
    21
  "src/font_info.scala"
wenzelm@49570
    22
  "src/graphview_dockable.scala"
wenzelm@49726
    23
  "src/info_dockable.scala"
wenzelm@50208
    24
  "src/isabelle.scala"
wenzelm@43285
    25
  "src/isabelle_encoding.scala"
wenzelm@49246
    26
  "src/isabelle_logic.scala"
wenzelm@43285
    27
  "src/isabelle_options.scala"
wenzelm@43285
    28
  "src/isabelle_sidekick.scala"
wenzelm@52971
    29
  "src/jedit_editor.scala"
wenzelm@49406
    30
  "src/jedit_lib.scala"
wenzelm@50202
    31
  "src/jedit_options.scala"
wenzelm@56208
    32
  "src/jedit_resources.scala"
wenzelm@50433
    33
  "src/monitor_dockable.scala"
wenzelm@43285
    34
  "src/output_dockable.scala"
wenzelm@56906
    35
  "src/pide_docking_framework.scala"
wenzelm@43285
    36
  "src/plugin.scala"
wenzelm@49398
    37
  "src/pretty_text_area.scala"
wenzelm@49702
    38
  "src/pretty_tooltip.scala"
wenzelm@52934
    39
  "src/process_indicator.scala"
wenzelm@43285
    40
  "src/protocol_dockable.scala"
wenzelm@56879
    41
  "src/query_dockable.scala"
wenzelm@43285
    42
  "src/raw_output_dockable.scala"
wenzelm@50202
    43
  "src/rendering.scala"
wenzelm@49411
    44
  "src/rich_text_area.scala"
wenzelm@43285
    45
  "src/scala_console.scala"
lars@55316
    46
  "src/simplifier_trace_dockable.scala"
lars@55316
    47
  "src/simplifier_trace_window.scala"
wenzelm@58529
    48
  "src/sledgehammer_dockable.scala"
wenzelm@56547
    49
  "src/spell_checker.scala"
immler@50143
    50
  "src/symbols_dockable.scala"
wenzelm@48021
    51
  "src/syslog_dockable.scala"
wenzelm@46572
    52
  "src/text_overview.scala"
wenzelm@50299
    53
  "src/theories_dockable.scala"
wenzelm@51533
    54
  "src/timing_dockable.scala"
wenzelm@43414
    55
  "src/token_markup.scala"
wenzelm@43285
    56
)
wenzelm@43285
    57
wenzelm@43320
    58
declare -a RESOURCES=(
wenzelm@43286
    59
  "src/actions.xml"
wenzelm@43286
    60
  "src/dockables.xml"
wenzelm@43286
    61
  "src/Isabelle.props"
wenzelm@50306
    62
  "src/jEdit.props"
wenzelm@43286
    63
  "src/services.xml"
wenzelm@55500
    64
  "src/modes/isabelle-ml.xml"
wenzelm@52540
    65
  "src/modes/isabelle-news.xml"
wenzelm@52540
    66
  "src/modes/isabelle-options.xml"
wenzelm@52540
    67
  "src/modes/isabelle-root.xml"
wenzelm@52540
    68
  "src/modes/isabelle.xml"
wenzelm@56277
    69
  "src/modes/sml.xml"
wenzelm@43285
    70
)
wenzelm@43285
    71
wenzelm@43285
    72
wenzelm@34333
    73
## diagnostics
wenzelm@34333
    74
wenzelm@34664
    75
PRG="$(basename "$0")"
wenzelm@34664
    76
wenzelm@43284
    77
function usage()
wenzelm@34333
    78
{
wenzelm@34333
    79
  echo
wenzelm@34664
    80
  echo "Usage: isabelle $PRG [OPTIONS] [FILES ...]"
wenzelm@34333
    81
  echo
wenzelm@34333
    82
  echo "  Options are:"
wenzelm@34333
    83
  echo "    -J OPTION    add JVM runtime option"
wenzelm@34409
    84
  echo "                 (default JEDIT_JAVA_OPTIONS=$JEDIT_JAVA_OPTIONS)"
wenzelm@43285
    85
  echo "    -b           build only"
wenzelm@48791
    86
  echo "    -d DIR       include session directory"
wenzelm@43285
    87
  echo "    -f           fresh build"
wenzelm@34333
    88
  echo "    -j OPTION    add jEdit runtime option"
wenzelm@34333
    89
  echo "                 (default JEDIT_OPTIONS=$JEDIT_OPTIONS)"
wenzelm@50403
    90
  echo "    -l NAME      logic session name"
wenzelm@34333
    91
  echo "    -m MODE      add print mode for output"
wenzelm@57086
    92
  echo "    -n           no build of session image on startup"
wenzelm@50373
    93
  echo "    -s           system build mode for session image"
wenzelm@34333
    94
  echo
wenzelm@54682
    95
  echo "  Start jEdit with Isabelle plugin setup and open theory FILES"
wenzelm@54682
    96
  echo "  (default \"$USER_HOME/Scratch.thy\")."
wenzelm@34333
    97
  echo
wenzelm@34333
    98
  exit 1
wenzelm@34333
    99
}
wenzelm@34333
   100
wenzelm@43284
   101
function fail()
wenzelm@34333
   102
{
wenzelm@34333
   103
  echo "$1" >&2
wenzelm@34333
   104
  exit 2
wenzelm@34333
   105
}
wenzelm@34333
   106
wenzelm@43284
   107
function failed()
wenzelm@43284
   108
{
wenzelm@43284
   109
  fail "Failed!"
wenzelm@43284
   110
}
wenzelm@43284
   111
wenzelm@34333
   112
wenzelm@34333
   113
## process command line
wenzelm@34333
   114
wenzelm@34333
   115
# options
wenzelm@34333
   116
wenzelm@43285
   117
BUILD_ONLY=false
wenzelm@43285
   118
BUILD_JARS="jars"
wenzelm@48791
   119
JEDIT_SESSION_DIRS=""
wenzelm@50403
   120
JEDIT_LOGIC=""
wenzelm@34333
   121
JEDIT_PRINT_MODE=""
wenzelm@53449
   122
JEDIT_BUILD_MODE="normal"
wenzelm@34333
   123
wenzelm@43284
   124
function getoptions()
wenzelm@34780
   125
{
wenzelm@34780
   126
  OPTIND=1
wenzelm@50405
   127
  while getopts "J:bd:fj:l:m:ns" OPT
wenzelm@34780
   128
  do
wenzelm@34780
   129
    case "$OPT" in
wenzelm@34780
   130
      J)
wenzelm@34780
   131
        JAVA_ARGS["${#JAVA_ARGS[@]}"]="$OPTARG"
wenzelm@34780
   132
        ;;
wenzelm@43285
   133
      b)
wenzelm@43285
   134
        BUILD_ONLY=true
wenzelm@43285
   135
        ;;
wenzelm@48791
   136
      d)
wenzelm@48791
   137
        if [ -z "$JEDIT_SESSION_DIRS" ]; then
wenzelm@48791
   138
          JEDIT_SESSION_DIRS="$OPTARG"
wenzelm@48791
   139
        else
wenzelm@48791
   140
          JEDIT_SESSION_DIRS="$JEDIT_SESSION_DIRS:$OPTARG"
wenzelm@48791
   141
        fi
wenzelm@48791
   142
        ;;
wenzelm@43285
   143
      f)
wenzelm@43285
   144
        BUILD_JARS="jars_fresh"
wenzelm@43285
   145
        ;;
wenzelm@34780
   146
      j)
wenzelm@34780
   147
        ARGS["${#ARGS[@]}"]="$OPTARG"
wenzelm@34780
   148
        ;;
wenzelm@34780
   149
      l)
wenzelm@34780
   150
        JEDIT_LOGIC="$OPTARG"
wenzelm@34780
   151
        ;;
wenzelm@34780
   152
      m)
wenzelm@34780
   153
        if [ -z "$JEDIT_PRINT_MODE" ]; then
wenzelm@34780
   154
          JEDIT_PRINT_MODE="$OPTARG"
wenzelm@34780
   155
        else
wenzelm@34780
   156
          JEDIT_PRINT_MODE="$JEDIT_PRINT_MODE,$OPTARG"
wenzelm@34780
   157
        fi
wenzelm@34780
   158
        ;;
wenzelm@50405
   159
      n)
wenzelm@53449
   160
        JEDIT_BUILD_MODE="none"
wenzelm@50405
   161
        ;;
wenzelm@50373
   162
      s)
wenzelm@53449
   163
        JEDIT_BUILD_MODE="system"
wenzelm@50373
   164
        ;;
wenzelm@34780
   165
      \?)
wenzelm@34780
   166
        usage
wenzelm@34780
   167
        ;;
wenzelm@34780
   168
    esac
wenzelm@34780
   169
  done
wenzelm@34780
   170
}
wenzelm@34581
   171
wenzelm@38257
   172
declare -a JAVA_ARGS; eval "JAVA_ARGS=($JEDIT_JAVA_OPTIONS $JEDIT_SYSTEM_OPTIONS)"
wenzelm@34843
   173
wenzelm@53446
   174
declare -a ARGS=()
wenzelm@34333
   175
wenzelm@34780
   176
declare -a OPTIONS; eval "OPTIONS=($ISABELLE_JEDIT_OPTIONS)"
wenzelm@34780
   177
getoptions "${OPTIONS[@]}"
wenzelm@34780
   178
wenzelm@34780
   179
getoptions "$@"
wenzelm@34333
   180
shift $(($OPTIND - 1))
wenzelm@34333
   181
wenzelm@34333
   182
wenzelm@34333
   183
# args
wenzelm@34333
   184
wenzelm@44485
   185
if [ "$#" -eq 0 ]; then
wenzelm@50120
   186
  ARGS["${#ARGS[@]}"]="$(jvmpath "$USER_HOME/Scratch.thy")"
wenzelm@44485
   187
else
wenzelm@44485
   188
  while [ "$#" -gt 0 ]; do
wenzelm@44485
   189
    ARGS["${#ARGS[@]}"]="$(jvmpath "$1")"
wenzelm@44485
   190
    shift
wenzelm@44485
   191
  done
wenzelm@44485
   192
fi
wenzelm@34333
   193
wenzelm@34333
   194
wenzelm@43284
   195
## dependencies
wenzelm@43284
   196
wenzelm@49953
   197
if [ -e "$ISABELLE_HOME/Admin/build" ]; then
wenzelm@50782
   198
  "$ISABELLE_TOOL" browser -b || exit $?
wenzelm@57032
   199
  "$ISABELLE_HOME/Admin/build" "$BUILD_JARS" || exit $?
wenzelm@49953
   200
fi
wenzelm@43413
   201
wenzelm@53577
   202
PURE_JAR="$ISABELLE_HOME/lib/classes/Pure.jar"
wenzelm@43413
   203
wenzelm@43285
   204
pushd "$JEDIT_HOME" >/dev/null || failed
wenzelm@43284
   205
wenzelm@43284
   206
JEDIT_JAR="$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/jedit.jar"
wenzelm@43284
   207
wenzelm@43284
   208
JEDIT_JARS=(
wenzelm@56421
   209
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/Code2HTML.jar"
wenzelm@56421
   210
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/CommonControls.jar"
wenzelm@53445
   211
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/Console.jar"
wenzelm@53445
   212
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/ErrorList.jar"
wenzelm@53445
   213
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/Highlight.jar"
wenzelm@56421
   214
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/kappalayout.jar"
wenzelm@53883
   215
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/MacOSX.jar"
wenzelm@56421
   216
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/Navigator.jar"
wenzelm@53445
   217
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/SideKick.jar"
wenzelm@53445
   218
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/idea-icons.jar"
wenzelm@53445
   219
  "$ISABELLE_JEDIT_BUILD_HOME/contrib/jsr305-2.0.0.jar"
wenzelm@43284
   220
)
wenzelm@43284
   221
wenzelm@43284
   222
wenzelm@43284
   223
# target
wenzelm@43284
   224
wenzelm@43284
   225
TARGET="dist/jars/Isabelle-jEdit.jar"
wenzelm@43284
   226
wenzelm@43384
   227
declare -a UPDATED=()
wenzelm@43384
   228
wenzelm@43285
   229
if [ "$BUILD_JARS" = jars_fresh ]; then
wenzelm@43285
   230
  OUTDATED=true
wenzelm@43285
   231
else
wenzelm@43285
   232
  OUTDATED=false
wenzelm@43368
   233
  if [ ! -e "$TARGET" ]; then
wenzelm@43368
   234
    OUTDATED=true
wenzelm@43384
   235
  else
wenzelm@43384
   236
    if [ -n "$ISABELLE_JEDIT_BUILD_HOME" ]; then
wenzelm@49566
   237
      declare -a DEPS=(
wenzelm@57032
   238
        "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR"
wenzelm@53576
   239
        "${SOURCES[@]}" "${RESOURCES[@]}"
wenzelm@49566
   240
      )
wenzelm@47666
   241
    elif [ -e "$ISABELLE_HOME/Admin/build" ]; then
wenzelm@57032
   242
      declare -a DEPS=("$PURE_JAR" "${SOURCES[@]}" "${RESOURCES[@]}")
wenzelm@43384
   243
    else
wenzelm@47666
   244
      declare -a DEPS=()
wenzelm@43384
   245
    fi
wenzelm@43384
   246
    for DEP in "${DEPS[@]}"
wenzelm@43368
   247
    do
wenzelm@43384
   248
      [ ! -e "$DEP" ] && fail "Missing file: $DEP"
wenzelm@43384
   249
      [ "$DEP" -nt "$TARGET" ] && {
wenzelm@43384
   250
        OUTDATED=true
wenzelm@43384
   251
        UPDATED["${#UPDATED[@]}"]="$DEP"
wenzelm@43384
   252
      }
wenzelm@43368
   253
    done
wenzelm@43368
   254
  fi
wenzelm@43285
   255
fi
wenzelm@43284
   256
wenzelm@43284
   257
wenzelm@43284
   258
# build
wenzelm@43284
   259
wenzelm@43284
   260
if [ "$OUTDATED" = true ]
wenzelm@43284
   261
then
wenzelm@43405
   262
  echo "### Building Isabelle/jEdit ..."
wenzelm@43405
   263
wenzelm@43384
   264
  [ "${#UPDATED[@]}" -gt 0 ] && {
wenzelm@43405
   265
    echo "Changed files:"
wenzelm@43384
   266
    for FILE in "${UPDATED[@]}"
wenzelm@43384
   267
    do
wenzelm@43384
   268
      echo "  $FILE"
wenzelm@43384
   269
    done
wenzelm@43384
   270
  }
wenzelm@43384
   271
wenzelm@43284
   272
  [ -z "$ISABELLE_JEDIT_BUILD_HOME" ] && \
wenzelm@43284
   273
    fail "Unknown ISABELLE_JEDIT_BUILD_HOME -- missing auxiliary component"
wenzelm@43284
   274
wenzelm@43284
   275
  rm -rf dist || failed
wenzelm@43284
   276
  mkdir -p dist dist/classes || failed
wenzelm@43287
   277
wenzelm@46502
   278
  cp -p -R -f "$ISABELLE_JEDIT_BUILD_HOME/contrib/$ISABELLE_JEDIT_BUILD_VERSION/." dist/.
wenzelm@46502
   279
  cp -p -R -f "${RESOURCES[@]}" dist/classes/.
wenzelm@43287
   280
  cp src/jEdit.props dist/properties/.
wenzelm@46502
   281
  cp -p -R -f src/modes/. dist/modes/.
wenzelm@43284
   282
wenzelm@43391
   283
  perl -i -e 'while (<>) {
wenzelm@56277
   284
    if (m/FILE="ml.xml"/ or m/FILE_NAME_GLOB="\*\.{sml,ml}"/) { }
wenzelm@55500
   285
    elsif (m/NAME="javacc"/) {
wenzelm@43391
   286
      print qq,<MODE NAME="isabelle" FILE="isabelle.xml" FILE_NAME_GLOB="*.thy"/>\n\n,;
wenzelm@55500
   287
      print qq,<MODE NAME="isabelle-ml" FILE="isabelle-ml.xml" FILE_NAME_GLOB="*.ML"/>\n\n,;
wenzelm@52539
   288
      print qq,<MODE NAME="isabelle-news" FILE="isabelle-news.xml"/>\n\n,;
wenzelm@48366
   289
      print qq,<MODE NAME="isabelle-options" FILE="isabelle-options.xml"/>\n\n,;
wenzelm@55500
   290
      print qq,<MODE NAME="isabelle-root" FILE="isabelle-root.xml" FILE_NAME_GLOB="ROOT"/>\n\n,;
wenzelm@55500
   291
      print;
wenzelm@55500
   292
    }
wenzelm@56277
   293
    elsif (m/NAME="sqr"/) {
wenzelm@56277
   294
      print qq!<MODE NAME="sml" FILE="sml.xml" FILE_NAME_GLOB="*.{sml,sig}"/>\n\n!;
wenzelm@56277
   295
      print;
wenzelm@56277
   296
    }
wenzelm@55500
   297
    else { print; }
wenzelm@55500
   298
  }' dist/modes/catalog
wenzelm@43284
   299
wenzelm@54660
   300
  cd dist
wenzelm@54660
   301
  isabelle_jdk jar xf jedit.jar
wenzelm@54676
   302
  cp "$ISABELLE_HOME/lib/logo/isabelle_transparent-32.gif" \
wenzelm@54660
   303
    "org/gjt/sp/jedit/icons/themes/classic/32x32/apps/isabelle.gif" || failed
wenzelm@54676
   304
  cp "$ISABELLE_HOME/lib/logo/isabelle_transparent-32.gif" \
wenzelm@54660
   305
    "org/gjt/sp/jedit/icons/themes/tango/32x32/apps/isabelle.gif" || failed
wenzelm@54666
   306
  isabelle_jdk jar cfe jedit.jar org.gjt.sp.jedit.jEdit org || failed
wenzelm@54667
   307
  rm -rf META-INF org
wenzelm@54660
   308
  cd ..
wenzelm@54660
   309
wenzelm@53445
   310
  cp -p -R -f "${JEDIT_JARS[@]}" dist/jars/. || failed
wenzelm@43284
   311
  (
wenzelm@57618
   312
    #FIXME workarounds for scalac 2.11.0
wenzelm@57618
   313
    export CYGWIN="nodosfilewarning"
wenzelm@53451
   314
    function stty() { :; }
wenzelm@53451
   315
    export -f stty
wenzelm@53451
   316
wenzelm@57032
   317
    for JAR in "$JEDIT_JAR" "${JEDIT_JARS[@]}" "$PURE_JAR"
wenzelm@43284
   318
    do
wenzelm@53576
   319
      classpath "$JAR"
wenzelm@43284
   320
    done
wenzelm@53576
   321
    export CLASSPATH="$(jvmpath "$ISABELLE_CLASSPATH")"
wenzelm@47009
   322
    exec "$SCALA_HOME/bin/scalac" $ISABELLE_SCALA_BUILD_OPTIONS -d dist/classes "${SOURCES[@]}"
wenzelm@43284
   323
  ) || fail "Failed to compile sources"
wenzelm@43284
   324
wenzelm@43284
   325
  cd dist/classes
wenzelm@47115
   326
  isabelle_jdk jar cf "../jars/Isabelle-jEdit.jar" * || failed
wenzelm@43284
   327
  cd ../..
wenzelm@43284
   328
  rm -rf dist/classes
wenzelm@56422
   329
wenzelm@56422
   330
  cp "$ISABELLE_JEDIT_BUILD_HOME/doc/jedit5.1.0manual-a4.pdf" dist/doc/jedit-manual.pdf
wenzelm@56422
   331
  cp dist/doc/CHANGES.txt dist/doc/jedit-changes
wenzelm@56422
   332
  cat > dist/doc/Contents <<EOF
wenzelm@57338
   333
Original jEdit Documentation
wenzelm@56422
   334
  jedit-manual    jEdit 5.1 User's Guide
wenzelm@56422
   335
  jedit-changes   jEdit 5.1 Version History
wenzelm@56422
   336
wenzelm@56422
   337
EOF
wenzelm@56422
   338
wenzelm@43284
   339
fi
wenzelm@43284
   340
wenzelm@43284
   341
popd >/dev/null
wenzelm@43284
   342
wenzelm@43284
   343
wenzelm@43284
   344
## main
wenzelm@43284
   345
wenzelm@53576
   346
if [ "$BUILD_ONLY" = false ]
wenzelm@53576
   347
then
wenzelm@53449
   348
  export JEDIT_SESSION_DIRS JEDIT_LOGIC JEDIT_PRINT_MODE JEDIT_BUILD_MODE
wenzelm@53576
   349
  classpath "$JEDIT_HOME/dist/jedit.jar"
wenzelm@53576
   350
  exec "$ISABELLE_TOOL" java "${JAVA_ARGS[@]}" isabelle.Main "${ARGS[@]}"
wenzelm@50416
   351
fi