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