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