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