src/Tools/jEdit/src/plugin.scala
author wenzelm
Mon Jun 05 23:55:58 2017 +0200 (2017-06-05)
changeset 66019 69b5ef78fb07
parent 65571 923e32ad0976
child 66082 2d12a730a380
permissions -rw-r--r--
HTML preview via builtin HTTP server;
wenzelm@43282
     1
/*  Title:      Tools/jEdit/src/plugin.scala
wenzelm@36760
     2
    Author:     Makarius
wenzelm@36760
     3
wenzelm@50362
     4
Main plumbing for PIDE infrastructure as jEdit plugin.
wenzelm@36760
     5
*/
wenzelm@34407
     6
wenzelm@34318
     7
package isabelle.jedit
wenzelm@34318
     8
wenzelm@34429
     9
wenzelm@36015
    10
import isabelle._
wenzelm@36015
    11
wenzelm@44573
    12
import javax.swing.JOptionPane
wenzelm@34318
    13
wenzelm@64858
    14
import java.io.{File => JFile}
wenzelm@66019
    15
import java.util.UUID
wenzelm@64858
    16
wenzelm@60205
    17
import org.gjt.sp.jedit.{jEdit, EBMessage, EBPlugin, Buffer, View, Debug, PerspectiveManager}
wenzelm@65248
    18
import org.gjt.sp.jedit.textarea.JEditTextArea
wenzelm@50362
    19
import org.gjt.sp.jedit.syntax.ModeProvider
wenzelm@49100
    20
import org.gjt.sp.jedit.msg.{EditorStarted, BufferUpdate, EditPaneUpdate, PropertiesChanged}
wenzelm@43443
    21
import org.gjt.sp.util.SyntaxUtilities
wenzelm@62228
    22
import org.gjt.sp.util.Log
wenzelm@39241
    23
wenzelm@34318
    24
wenzelm@50205
    25
object PIDE
wenzelm@34618
    26
{
wenzelm@65248
    27
  /* semantic document content */
wenzelm@55621
    28
wenzelm@62062
    29
  def snapshot(view: View): Document.Snapshot = GUI_Thread.now
wenzelm@55621
    30
  {
wenzelm@64813
    31
    Document_Model.get(view.getBuffer) match {
wenzelm@55621
    32
      case Some(model) => model.snapshot
wenzelm@55621
    33
      case None => error("No document model for current buffer")
wenzelm@55621
    34
    }
wenzelm@55621
    35
  }
wenzelm@55621
    36
wenzelm@64621
    37
  def rendering(view: View): JEdit_Rendering = GUI_Thread.now
wenzelm@55621
    38
  {
wenzelm@55621
    39
    val text_area = view.getTextArea
wenzelm@64882
    40
    Document_View.get(text_area) match {
wenzelm@55621
    41
      case Some(doc_view) => doc_view.get_rendering()
wenzelm@55621
    42
      case None => error("No document view for current text area")
wenzelm@55621
    43
    }
wenzelm@55621
    44
  }
wenzelm@65277
    45
wenzelm@65277
    46
wenzelm@65277
    47
  /* plugin instance */
wenzelm@65277
    48
wenzelm@65277
    49
  @volatile var _plugin: Plugin = null
wenzelm@65277
    50
wenzelm@65277
    51
  def plugin: Plugin =
wenzelm@65277
    52
    if (_plugin == null) error("Uninitialized Isabelle/jEdit plugin")
wenzelm@65277
    53
    else _plugin
wenzelm@65277
    54
wenzelm@65277
    55
  def options: JEdit_Options = plugin.options
wenzelm@65277
    56
  def resources: JEdit_Resources = plugin.resources
wenzelm@65277
    57
  def session: Session = plugin.session
wenzelm@34318
    58
}
wenzelm@34318
    59
wenzelm@34618
    60
class Plugin extends EBPlugin
wenzelm@34618
    61
{
wenzelm@65262
    62
  /* options */
wenzelm@65238
    63
wenzelm@65257
    64
  private var _options: JEdit_Options = null
wenzelm@65262
    65
  private def init_options(): Unit = _options = new JEdit_Options(Options.init())
wenzelm@65257
    66
  def options: JEdit_Options = _options
wenzelm@65239
    67
wenzelm@65262
    68
wenzelm@65262
    69
  /* resources */
wenzelm@65262
    70
wenzelm@65262
    71
  private var _resources: JEdit_Resources = null
wenzelm@65571
    72
  private def init_resources(): Unit =
wenzelm@65571
    73
    _resources = new JEdit_Resources(JEdit_Sessions.session_base(options.value))
wenzelm@65262
    74
  def resources: JEdit_Resources = _resources
wenzelm@65262
    75
wenzelm@65262
    76
wenzelm@65263
    77
  /* session */
wenzelm@65263
    78
wenzelm@65263
    79
  private var _session: Session = null
wenzelm@65264
    80
  private def init_session(): Unit = _session = new Session(options.value, resources)
wenzelm@65263
    81
  def session: Session = _session
wenzelm@65263
    82
wenzelm@65263
    83
wenzelm@65262
    84
  /* misc support */
wenzelm@65262
    85
wenzelm@65239
    86
  val completion_history = new Completion.History_Variable
wenzelm@65239
    87
  val spell_checker = new Spell_Checker_Variable
wenzelm@65239
    88
wenzelm@65238
    89
wenzelm@56316
    90
  /* global changes */
wenzelm@55791
    91
wenzelm@56316
    92
  def options_changed()
wenzelm@56316
    93
  {
wenzelm@65263
    94
    session.global_options.post(Session.Global_Options(options.value))
wenzelm@56770
    95
    delay_load.invoke()
wenzelm@55791
    96
  }
wenzelm@55791
    97
wenzelm@56316
    98
  def deps_changed()
wenzelm@56316
    99
  {
wenzelm@56770
   100
    delay_load.invoke()
wenzelm@56316
   101
  }
wenzelm@56316
   102
wenzelm@55791
   103
wenzelm@44577
   104
  /* theory files */
wenzelm@44574
   105
wenzelm@62068
   106
  lazy val delay_init =
wenzelm@65249
   107
    GUI_Thread.delay_last(options.seconds("editor_load_delay"))
wenzelm@50344
   108
    {
wenzelm@65244
   109
      init_models()
wenzelm@50344
   110
    }
wenzelm@50344
   111
wenzelm@57582
   112
  private val delay_load_active = Synchronized(false)
wenzelm@57582
   113
  private def delay_load_activated(): Boolean =
wenzelm@57582
   114
    delay_load_active.guarded_access(a => Some((!a, true)))
wenzelm@62068
   115
  private def delay_load_action()
wenzelm@62068
   116
  {
wenzelm@62068
   117
    if (Isabelle.continuous_checking && delay_load_activated() &&
wenzelm@62068
   118
        PerspectiveManager.isPerspectiveEnabled)
wenzelm@44574
   119
    {
wenzelm@64835
   120
      if (JEdit_Lib.jedit_buffers().exists(_.isLoading)) delay_load.invoke()
wenzelm@64835
   121
      else {
wenzelm@64835
   122
        val required_files =
wenzelm@64835
   123
        {
wenzelm@64835
   124
          val models = Document_Model.get_models()
wenzelm@44574
   125
wenzelm@62068
   126
          val thys =
wenzelm@64835
   127
            (for ((node_name, model) <- models.iterator if model.is_theory)
wenzelm@64835
   128
              yield (node_name, Position.none)).toList
wenzelm@65359
   129
          val thy_files = resources.thy_info.dependencies(thys).deps.map(_.name)
wenzelm@46761
   130
wenzelm@64839
   131
          val aux_files =
wenzelm@65249
   132
            if (options.bool("jedit_auto_resolve")) {
wenzelm@64835
   133
              val stable_tip_version =
wenzelm@64835
   134
                if (models.forall(p => p._2.is_stable))
wenzelm@65263
   135
                  session.current_state().stable_tip_version
wenzelm@64835
   136
                else None
wenzelm@64835
   137
              stable_tip_version match {
wenzelm@65262
   138
                case Some(version) => resources.undefined_blobs(version.nodes)
wenzelm@64478
   139
                case None => delay_load.invoke(); Nil
wenzelm@57582
   140
              }
wenzelm@62068
   141
            }
wenzelm@62068
   142
            else Nil
wenzelm@62068
   143
wenzelm@64835
   144
          (thy_files ::: aux_files).filterNot(models.isDefinedAt(_))
wenzelm@64835
   145
        }
wenzelm@64835
   146
        if (required_files.nonEmpty) {
wenzelm@64835
   147
          try {
wenzelm@64835
   148
            Standard_Thread.fork("resolve_dependencies") {
wenzelm@64835
   149
              val loaded_files =
wenzelm@64835
   150
                for {
wenzelm@64835
   151
                  name <- required_files
wenzelm@65262
   152
                  text <- resources.read_file_content(name)
wenzelm@64835
   153
                } yield (name, text)
wenzelm@62068
   154
wenzelm@64835
   155
              GUI_Thread.later {
wenzelm@64835
   156
                try {
wenzelm@65263
   157
                  Document_Model.provide_files(session, loaded_files)
wenzelm@64835
   158
                  delay_init.invoke()
wenzelm@64835
   159
                }
wenzelm@64835
   160
                finally { delay_load_active.change(_ => false) }
wenzelm@53715
   161
              }
wenzelm@53074
   162
            }
wenzelm@46761
   163
          }
wenzelm@64835
   164
          catch { case _: Throwable => delay_load_active.change(_ => false) }
wenzelm@46761
   165
        }
wenzelm@64835
   166
        else delay_load_active.change(_ => false)
wenzelm@44606
   167
      }
wenzelm@44574
   168
    }
wenzelm@62068
   169
  }
wenzelm@62068
   170
wenzelm@64478
   171
  private lazy val delay_load =
wenzelm@65249
   172
    GUI_Thread.delay_last(options.seconds("editor_load_delay")) { delay_load_action() }
wenzelm@44573
   173
wenzelm@64858
   174
  private def file_watcher_action(changed: Set[JFile]): Unit =
wenzelm@65246
   175
    if (Document_Model.sync_files(changed)) JEdit_Editor.invoke_generated()
wenzelm@64858
   176
wenzelm@64858
   177
  lazy val file_watcher: File_Watcher =
wenzelm@65249
   178
    File_Watcher(file_watcher_action _, options.seconds("editor_load_delay"))
wenzelm@64858
   179
wenzelm@44574
   180
wenzelm@56715
   181
  /* session phase */
wenzelm@44573
   182
wenzelm@65226
   183
  val session_phase_changed: Session.Phase => Unit =
wenzelm@65226
   184
  {
wenzelm@65317
   185
    case Session.Terminated(result) if !result.ok =>
wenzelm@65226
   186
      GUI_Thread.later {
wenzelm@65267
   187
        GUI.error_dialog(jEdit.getActiveView, "Prover process terminated with error",
wenzelm@65263
   188
          "Isabelle Syslog", GUI.scrollable_text(session.syslog_content()))
wenzelm@65226
   189
      }
wenzelm@39735
   190
wenzelm@65226
   191
    case Session.Ready =>
wenzelm@65244
   192
      init_models()
wenzelm@57640
   193
wenzelm@65226
   194
      if (!Isabelle.continuous_checking) {
wenzelm@65226
   195
        GUI_Thread.later {
wenzelm@65226
   196
          val answer =
wenzelm@65226
   197
            GUI.confirm_dialog(jEdit.getActiveView,
wenzelm@65226
   198
              "Continuous checking of PIDE document",
wenzelm@65226
   199
              JOptionPane.YES_NO_OPTION,
wenzelm@65226
   200
              "Continuous checking is presently disabled:",
wenzelm@65226
   201
              "editor buffers will remain inactive!",
wenzelm@65226
   202
              "Enable continuous checking now?")
wenzelm@65226
   203
          if (answer == 0) Isabelle.continuous_checking = true
wenzelm@57640
   204
        }
wenzelm@65226
   205
      }
wenzelm@57640
   206
wenzelm@65226
   207
      delay_load.invoke()
wenzelm@44573
   208
wenzelm@65226
   209
    case Session.Shutdown =>
wenzelm@65226
   210
      GUI_Thread.later {
wenzelm@65226
   211
        delay_load.revoke()
wenzelm@65226
   212
        delay_init.revoke()
wenzelm@65246
   213
        JEdit_Editor.flush()
wenzelm@65244
   214
        exit_models(JEdit_Lib.jedit_buffers().toList)
wenzelm@65226
   215
      }
wenzelm@46740
   216
wenzelm@65226
   217
    case _ =>
wenzelm@65226
   218
  }
wenzelm@39630
   219
wenzelm@39630
   220
wenzelm@65244
   221
  /* document model and view */
wenzelm@65244
   222
wenzelm@65244
   223
  def exit_models(buffers: List[Buffer])
wenzelm@65244
   224
  {
wenzelm@65244
   225
    GUI_Thread.now {
wenzelm@65244
   226
      buffers.foreach(buffer =>
wenzelm@65244
   227
        JEdit_Lib.buffer_lock(buffer) {
wenzelm@65244
   228
          JEdit_Lib.jedit_text_areas(buffer).foreach(Document_View.exit)
wenzelm@65244
   229
          Document_Model.exit(buffer)
wenzelm@65244
   230
        })
wenzelm@65244
   231
      }
wenzelm@65244
   232
  }
wenzelm@65244
   233
wenzelm@65244
   234
  def init_models()
wenzelm@65244
   235
  {
wenzelm@65244
   236
    GUI_Thread.now {
wenzelm@65246
   237
      JEdit_Editor.flush()
wenzelm@65244
   238
wenzelm@65244
   239
      for {
wenzelm@65244
   240
        buffer <- JEdit_Lib.jedit_buffers()
wenzelm@65244
   241
        if buffer != null && !buffer.getBooleanProperty(Buffer.GZIPPED)
wenzelm@65244
   242
      } {
wenzelm@65244
   243
        if (buffer.isLoaded) {
wenzelm@65244
   244
          JEdit_Lib.buffer_lock(buffer) {
wenzelm@65262
   245
            val node_name = resources.node_name(buffer)
wenzelm@65263
   246
            val model = Document_Model.init(session, node_name, buffer)
wenzelm@65244
   247
            for {
wenzelm@65244
   248
              text_area <- JEdit_Lib.jedit_text_areas(buffer)
wenzelm@65244
   249
              if Document_View.get(text_area).map(_.model) != Some(model)
wenzelm@65244
   250
            } Document_View.init(model, text_area)
wenzelm@65244
   251
          }
wenzelm@65244
   252
        }
wenzelm@65244
   253
        else delay_init.invoke()
wenzelm@65244
   254
      }
wenzelm@65244
   255
wenzelm@65246
   256
      JEdit_Editor.invoke_generated()
wenzelm@65244
   257
    }
wenzelm@65244
   258
  }
wenzelm@65244
   259
wenzelm@65244
   260
  def init_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@65244
   261
    GUI_Thread.now {
wenzelm@65244
   262
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@65244
   263
        Document_Model.get(buffer) match {
wenzelm@65244
   264
          case Some(model) => Document_View.init(model, text_area)
wenzelm@65244
   265
          case None =>
wenzelm@65244
   266
        }
wenzelm@65244
   267
      }
wenzelm@65244
   268
    }
wenzelm@65244
   269
wenzelm@65244
   270
  def exit_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@65244
   271
    GUI_Thread.now {
wenzelm@65244
   272
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@65244
   273
        Document_View.exit(text_area)
wenzelm@65244
   274
      }
wenzelm@65244
   275
    }
wenzelm@65244
   276
wenzelm@65244
   277
wenzelm@34618
   278
  /* main plugin plumbing */
wenzelm@34433
   279
wenzelm@65241
   280
  @volatile private var startup_failure: Option[Throwable] = None
wenzelm@65241
   281
  @volatile private var startup_notified = false
wenzelm@65241
   282
wenzelm@34767
   283
  override def handleMessage(message: EBMessage)
wenzelm@34618
   284
  {
wenzelm@57612
   285
    GUI_Thread.assert {}
wenzelm@39630
   286
wenzelm@65241
   287
    if (startup_failure.isDefined && !startup_notified) {
wenzelm@49099
   288
      message match {
wenzelm@49100
   289
        case msg: EditorStarted =>
wenzelm@51616
   290
          GUI.error_dialog(null, "Isabelle plugin startup failure",
wenzelm@65241
   291
            GUI.scrollable_text(Exn.message(startup_failure.get)),
wenzelm@49099
   292
            "Prover IDE inactive!")
wenzelm@65241
   293
          startup_notified = true
wenzelm@49099
   294
        case _ =>
wenzelm@49099
   295
      }
wenzelm@49099
   296
    }
wenzelm@49099
   297
wenzelm@65241
   298
    if (startup_failure.isEmpty) {
wenzelm@49099
   299
      message match {
wenzelm@49099
   300
        case msg: EditorStarted =>
wenzelm@57649
   301
          if (Distribution.is_identified && !Distribution.is_official) {
wenzelm@57680
   302
            GUI.warning_dialog(jEdit.getActiveView, "Isabelle version for testing",
wenzelm@60206
   303
              "This is " + Distribution.version + ".",
wenzelm@57649
   304
              "It is for testing only, not for production use.")
wenzelm@57649
   305
          }
wenzelm@57649
   306
wenzelm@64602
   307
          val view = jEdit.getActiveView()
wenzelm@64602
   308
wenzelm@65256
   309
          Session_Build.check_dialog(view)
wenzelm@63747
   310
wenzelm@64602
   311
          Keymap_Merge.check_dialog(view)
wenzelm@64602
   312
wenzelm@65246
   313
          JEdit_Editor.hyperlink_position(true, Document.Snapshot.init,
wenzelm@65256
   314
            JEdit_Sessions.session_info(options.value).open_root).foreach(_.follow(view))
wenzelm@61277
   315
wenzelm@49099
   316
        case msg: BufferUpdate
wenzelm@64818
   317
        if msg.getWhat == BufferUpdate.LOAD_STARTED || msg.getWhat == BufferUpdate.CLOSING =>
wenzelm@64838
   318
          if (msg.getBuffer != null) {
wenzelm@65244
   319
            exit_models(List(msg.getBuffer))
wenzelm@65246
   320
            JEdit_Editor.invoke_generated()
wenzelm@64838
   321
          }
wenzelm@57611
   322
wenzelm@64818
   323
        case msg: BufferUpdate
wenzelm@64818
   324
        if msg.getWhat == BufferUpdate.PROPERTIES_CHANGED || msg.getWhat == BufferUpdate.LOADED =>
wenzelm@65263
   325
          if (session.is_ready) {
wenzelm@55791
   326
            delay_init.invoke()
wenzelm@55791
   327
            delay_load.invoke()
wenzelm@49099
   328
          }
wenzelm@34784
   329
wenzelm@49099
   330
        case msg: EditPaneUpdate
wenzelm@60215
   331
        if msg.getWhat == EditPaneUpdate.BUFFER_CHANGING ||
wenzelm@49099
   332
            msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
wenzelm@49099
   333
            msg.getWhat == EditPaneUpdate.CREATED ||
wenzelm@60215
   334
            msg.getWhat == EditPaneUpdate.DESTROYED =>
wenzelm@49099
   335
          val edit_pane = msg.getEditPane
wenzelm@49099
   336
          val buffer = edit_pane.getBuffer
wenzelm@49099
   337
          val text_area = edit_pane.getTextArea
wenzelm@49099
   338
wenzelm@49099
   339
          if (buffer != null && text_area != null) {
wenzelm@49099
   340
            if (msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
wenzelm@49099
   341
                msg.getWhat == EditPaneUpdate.CREATED) {
wenzelm@65263
   342
              if (session.is_ready)
wenzelm@65244
   343
                init_view(buffer, text_area)
wenzelm@49099
   344
            }
wenzelm@52867
   345
            else {
wenzelm@65240
   346
              Isabelle.dismissed_popups(text_area.getView)
wenzelm@65244
   347
              exit_view(buffer, text_area)
wenzelm@52867
   348
            }
wenzelm@53274
   349
wenzelm@53274
   350
            if (msg.getWhat == EditPaneUpdate.CREATED)
wenzelm@53274
   351
              Completion_Popup.Text_Area.init(text_area)
wenzelm@53274
   352
wenzelm@53274
   353
            if (msg.getWhat == EditPaneUpdate.DESTROYED)
wenzelm@53274
   354
              Completion_Popup.Text_Area.exit(text_area)
wenzelm@43510
   355
          }
wenzelm@34784
   356
wenzelm@49099
   357
        case msg: PropertiesChanged =>
wenzelm@62264
   358
          for {
wenzelm@62264
   359
            view <- JEdit_Lib.jedit_views
wenzelm@62264
   360
            edit_pane <- JEdit_Lib.jedit_edit_panes(view)
wenzelm@62264
   361
          } {
wenzelm@62264
   362
            val buffer = edit_pane.getBuffer
wenzelm@62264
   363
            val text_area = edit_pane.getTextArea
wenzelm@65244
   364
            if (buffer != null && text_area != null) init_view(buffer, text_area)
wenzelm@62264
   365
          }
wenzelm@62264
   366
wenzelm@65249
   367
          spell_checker.update(options.value)
wenzelm@65263
   368
          session.update_options(options.value)
wenzelm@34784
   369
wenzelm@49099
   370
        case _ =>
wenzelm@49099
   371
      }
wenzelm@34318
   372
    }
wenzelm@34318
   373
  }
wenzelm@34318
   374
wenzelm@65260
   375
wenzelm@65260
   376
  /* mode provider */
wenzelm@65260
   377
wenzelm@65260
   378
  private var orig_mode_provider: ModeProvider = null
wenzelm@65260
   379
  private var pide_mode_provider: ModeProvider = null
wenzelm@65260
   380
wenzelm@65260
   381
  def init_mode_provider()
wenzelm@65260
   382
  {
wenzelm@65260
   383
    orig_mode_provider = ModeProvider.instance
wenzelm@65260
   384
    if (orig_mode_provider.isInstanceOf[ModeProvider]) {
wenzelm@65260
   385
      pide_mode_provider = new Token_Markup.Mode_Provider(orig_mode_provider)
wenzelm@65260
   386
      ModeProvider.instance = pide_mode_provider
wenzelm@65260
   387
    }
wenzelm@65260
   388
  }
wenzelm@65260
   389
wenzelm@65260
   390
  def exit_mode_provider()
wenzelm@65260
   391
  {
wenzelm@65260
   392
    if (ModeProvider.instance == pide_mode_provider)
wenzelm@65260
   393
      ModeProvider.instance = orig_mode_provider
wenzelm@65260
   394
  }
wenzelm@65260
   395
wenzelm@65260
   396
wenzelm@66019
   397
  /* HTTP server */
wenzelm@66019
   398
wenzelm@66019
   399
  val http_root: String = "/" + UUID.randomUUID().toString
wenzelm@66019
   400
wenzelm@66019
   401
  val http_server: HTTP.Server = HTTP.server(Document_Model.http_handlers(http_root))
wenzelm@66019
   402
wenzelm@66019
   403
wenzelm@65260
   404
  /* start and stop */
wenzelm@65260
   405
wenzelm@34618
   406
  override def start()
wenzelm@49099
   407
  {
wenzelm@65262
   408
    Debug.DISABLE_SEARCH_DIALOG_POOL = true
wenzelm@65262
   409
wenzelm@65262
   410
wenzelm@65257
   411
    /* strict initialization */
wenzelm@65257
   412
wenzelm@65262
   413
    init_options()
wenzelm@65262
   414
    init_resources()
wenzelm@65263
   415
    init_session()
wenzelm@65262
   416
    PIDE._plugin = this
wenzelm@65257
   417
wenzelm@65257
   418
wenzelm@65257
   419
    /* non-strict initialization */
wenzelm@65257
   420
wenzelm@49099
   421
    try {
wenzelm@65242
   422
      completion_history.load()
wenzelm@65249
   423
      spell_checker.update(options.value)
wenzelm@49245
   424
wenzelm@65261
   425
      SyntaxUtilities.setStyleExtender(Syntax_Style.Extender)
wenzelm@65260
   426
      init_mode_provider()
wenzelm@53274
   427
      JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.init _)
wenzelm@53274
   428
wenzelm@66019
   429
      http_server.start
wenzelm@66019
   430
wenzelm@65241
   431
      startup_failure = None
wenzelm@49099
   432
    }
wenzelm@49099
   433
    catch {
wenzelm@49099
   434
      case exn: Throwable =>
wenzelm@65241
   435
        startup_failure = Some(exn)
wenzelm@65241
   436
        startup_notified = false
wenzelm@62228
   437
        Log.log(Log.ERROR, this, exn)
wenzelm@49099
   438
    }
wenzelm@34318
   439
  }
wenzelm@34618
   440
wenzelm@39628
   441
  override def stop()
wenzelm@34618
   442
  {
wenzelm@66019
   443
    http_server.stop
wenzelm@66019
   444
wenzelm@65261
   445
    exit_mode_provider()
wenzelm@53274
   446
    JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.exit _)
wenzelm@53274
   447
wenzelm@65241
   448
    if (startup_failure.isEmpty) {
wenzelm@65249
   449
      options.value.save_prefs()
wenzelm@65242
   450
      completion_history.value.save()
wenzelm@53337
   451
    }
wenzelm@49245
   452
wenzelm@65244
   453
    exit_models(JEdit_Lib.jedit_buffers().toList)
wenzelm@65263
   454
    session.stop()
wenzelm@65245
   455
    file_watcher.shutdown()
wenzelm@34318
   456
  }
wenzelm@34318
   457
}