src/Tools/jEdit/src/plugin.scala
author wenzelm
Tue Mar 14 21:24:33 2017 +0100 (2017-03-14)
changeset 65242 63a64779d586
parent 65241 6f00727f0d41
child 65243 ba5ce07e06a7
permissions -rw-r--r--
tuned;
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@60835
    39
  @volatile var session: Session = new Session(JEdit_Resources.empty)
wenzelm@49101
    40
wenzelm@62068
    41
  def options_changed() { if (plugin != null) plugin.options_changed() }
wenzelm@62068
    42
  def deps_changed() { if (plugin != null) plugin.deps_changed() }
wenzelm@52815
    43
wenzelm@56208
    44
  def resources(): JEdit_Resources =
wenzelm@56208
    45
    session.resources.asInstanceOf[JEdit_Resources]
wenzelm@44955
    46
wenzelm@65222
    47
  def debugger: Debugger = session.debugger
wenzelm@65213
    48
wenzelm@64858
    49
  def file_watcher(): File_Watcher =
wenzelm@64858
    50
    if (plugin == null) File_Watcher.none else plugin.file_watcher
wenzelm@64858
    51
wenzelm@52971
    52
  lazy val editor = new JEdit_Editor
wenzelm@52971
    53
wenzelm@34784
    54
wenzelm@43449
    55
  /* document model and view */
wenzelm@43449
    56
wenzelm@50344
    57
  def exit_models(buffers: List[Buffer])
wenzelm@47058
    58
  {
wenzelm@57612
    59
    GUI_Thread.now {
wenzelm@50344
    60
      buffers.foreach(buffer =>
wenzelm@50344
    61
        JEdit_Lib.buffer_lock(buffer) {
wenzelm@50344
    62
          JEdit_Lib.jedit_text_areas(buffer).foreach(Document_View.exit)
wenzelm@50344
    63
          Document_Model.exit(buffer)
wenzelm@50344
    64
        })
wenzelm@50344
    65
      }
wenzelm@47058
    66
  }
wenzelm@47058
    67
wenzelm@55791
    68
  def init_models()
wenzelm@43510
    69
  {
wenzelm@57612
    70
    GUI_Thread.now {
wenzelm@54461
    71
      PIDE.editor.flush()
wenzelm@55791
    72
wenzelm@55791
    73
      for {
wenzelm@55791
    74
        buffer <- JEdit_Lib.jedit_buffers()
wenzelm@62068
    75
        if buffer != null && !buffer.getBooleanProperty(Buffer.GZIPPED)
wenzelm@55791
    76
      } {
wenzelm@62068
    77
        if (buffer.isLoaded) {
wenzelm@62068
    78
          JEdit_Lib.buffer_lock(buffer) {
wenzelm@62068
    79
            val node_name = resources.node_name(buffer)
wenzelm@64817
    80
            val model = Document_Model.init(session, node_name, buffer)
wenzelm@62068
    81
            for {
wenzelm@62068
    82
              text_area <- JEdit_Lib.jedit_text_areas(buffer)
wenzelm@64882
    83
              if Document_View.get(text_area).map(_.model) != Some(model)
wenzelm@62068
    84
            } Document_View.init(model, text_area)
wenzelm@62068
    85
          }
wenzelm@43510
    86
        }
wenzelm@62068
    87
        else if (plugin != null) plugin.delay_init.invoke()
wenzelm@55791
    88
      }
wenzelm@55791
    89
wenzelm@64524
    90
      PIDE.editor.invoke_generated()
wenzelm@43510
    91
    }
wenzelm@43510
    92
  }
wenzelm@43510
    93
wenzelm@56774
    94
  def init_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@57612
    95
    GUI_Thread.now {
wenzelm@56774
    96
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@64813
    97
        Document_Model.get(buffer) match {
wenzelm@56774
    98
          case Some(model) => Document_View.init(model, text_area)
wenzelm@56774
    99
          case None =>
wenzelm@56774
   100
        }
wenzelm@43510
   101
      }
wenzelm@43510
   102
    }
wenzelm@43510
   103
wenzelm@56774
   104
  def exit_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@57612
   105
    GUI_Thread.now {
wenzelm@56774
   106
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@56774
   107
        Document_View.exit(text_area)
wenzelm@56774
   108
      }
wenzelm@43510
   109
    }
wenzelm@55621
   110
wenzelm@55621
   111
wenzelm@55621
   112
  /* current document content */
wenzelm@55621
   113
wenzelm@62062
   114
  def snapshot(view: View): Document.Snapshot = GUI_Thread.now
wenzelm@55621
   115
  {
wenzelm@64813
   116
    Document_Model.get(view.getBuffer) match {
wenzelm@55621
   117
      case Some(model) => model.snapshot
wenzelm@55621
   118
      case None => error("No document model for current buffer")
wenzelm@55621
   119
    }
wenzelm@55621
   120
  }
wenzelm@55621
   121
wenzelm@64621
   122
  def rendering(view: View): JEdit_Rendering = GUI_Thread.now
wenzelm@55621
   123
  {
wenzelm@55621
   124
    val text_area = view.getTextArea
wenzelm@64882
   125
    Document_View.get(text_area) match {
wenzelm@55621
   126
      case Some(doc_view) => doc_view.get_rendering()
wenzelm@55621
   127
      case None => error("No document view for current text area")
wenzelm@55621
   128
    }
wenzelm@55621
   129
  }
wenzelm@34318
   130
}
wenzelm@34318
   131
wenzelm@34429
   132
wenzelm@34618
   133
class Plugin extends EBPlugin
wenzelm@34618
   134
{
wenzelm@65238
   135
  /* early initialization */
wenzelm@65238
   136
wenzelm@65238
   137
  val options: JEdit_Options =
wenzelm@65238
   138
  {
wenzelm@65238
   139
    // adhoc patch of confusing message
wenzelm@65238
   140
    val plugin_error = jEdit.getProperty("plugin-error.start-error")
wenzelm@65238
   141
    jEdit.setProperty("plugin-error.start-error", "Cannot start plugin:\n{0}")
wenzelm@65238
   142
wenzelm@65238
   143
    val options = new JEdit_Options(Options.init())
wenzelm@65238
   144
wenzelm@65238
   145
    jEdit.setProperty("plugin-error.start-error", plugin_error)
wenzelm@65238
   146
wenzelm@65238
   147
    options
wenzelm@65238
   148
  }
wenzelm@65239
   149
wenzelm@65239
   150
  val completion_history = new Completion.History_Variable
wenzelm@65239
   151
  val spell_checker = new Spell_Checker_Variable
wenzelm@65239
   152
wenzelm@65238
   153
  PIDE._plugin = this
wenzelm@65238
   154
wenzelm@65238
   155
wenzelm@56316
   156
  /* global changes */
wenzelm@55791
   157
wenzelm@56316
   158
  def options_changed()
wenzelm@56316
   159
  {
wenzelm@56715
   160
    PIDE.session.global_options.post(Session.Global_Options(PIDE.options.value))
wenzelm@56770
   161
    delay_load.invoke()
wenzelm@55791
   162
  }
wenzelm@55791
   163
wenzelm@56316
   164
  def deps_changed()
wenzelm@56316
   165
  {
wenzelm@56770
   166
    delay_load.invoke()
wenzelm@56316
   167
  }
wenzelm@56316
   168
wenzelm@55791
   169
wenzelm@44577
   170
  /* theory files */
wenzelm@44574
   171
wenzelm@62068
   172
  lazy val delay_init =
wenzelm@57612
   173
    GUI_Thread.delay_last(PIDE.options.seconds("editor_load_delay"))
wenzelm@50344
   174
    {
wenzelm@55791
   175
      PIDE.init_models()
wenzelm@50344
   176
    }
wenzelm@50344
   177
wenzelm@57582
   178
  private val delay_load_active = Synchronized(false)
wenzelm@57582
   179
  private def delay_load_activated(): Boolean =
wenzelm@57582
   180
    delay_load_active.guarded_access(a => Some((!a, true)))
wenzelm@62068
   181
  private def delay_load_action()
wenzelm@62068
   182
  {
wenzelm@62068
   183
    if (Isabelle.continuous_checking && delay_load_activated() &&
wenzelm@62068
   184
        PerspectiveManager.isPerspectiveEnabled)
wenzelm@44574
   185
    {
wenzelm@64835
   186
      if (JEdit_Lib.jedit_buffers().exists(_.isLoading)) delay_load.invoke()
wenzelm@64835
   187
      else {
wenzelm@64835
   188
        val required_files =
wenzelm@64835
   189
        {
wenzelm@64835
   190
          val models = Document_Model.get_models()
wenzelm@44574
   191
wenzelm@62068
   192
          val thys =
wenzelm@64835
   193
            (for ((node_name, model) <- models.iterator if model.is_theory)
wenzelm@64835
   194
              yield (node_name, Position.none)).toList
wenzelm@64839
   195
          val thy_files = PIDE.resources.thy_info.dependencies("", thys).deps.map(_.name)
wenzelm@46761
   196
wenzelm@64839
   197
          val aux_files =
wenzelm@62068
   198
            if (PIDE.options.bool("jedit_auto_resolve")) {
wenzelm@64835
   199
              val stable_tip_version =
wenzelm@64835
   200
                if (models.forall(p => p._2.is_stable))
wenzelm@64835
   201
                  PIDE.session.current_state().stable_tip_version
wenzelm@64835
   202
                else None
wenzelm@64835
   203
              stable_tip_version match {
wenzelm@64835
   204
                case Some(version) => PIDE.resources.undefined_blobs(version.nodes)
wenzelm@64478
   205
                case None => delay_load.invoke(); Nil
wenzelm@57582
   206
              }
wenzelm@62068
   207
            }
wenzelm@62068
   208
            else Nil
wenzelm@62068
   209
wenzelm@64835
   210
          (thy_files ::: aux_files).filterNot(models.isDefinedAt(_))
wenzelm@64835
   211
        }
wenzelm@64835
   212
        if (required_files.nonEmpty) {
wenzelm@64835
   213
          try {
wenzelm@64835
   214
            Standard_Thread.fork("resolve_dependencies") {
wenzelm@64835
   215
              val loaded_files =
wenzelm@64835
   216
                for {
wenzelm@64835
   217
                  name <- required_files
wenzelm@64835
   218
                  text <- PIDE.resources.read_file_content(name)
wenzelm@64835
   219
                } yield (name, text)
wenzelm@62068
   220
wenzelm@64835
   221
              GUI_Thread.later {
wenzelm@64835
   222
                try {
wenzelm@64835
   223
                  Document_Model.provide_files(PIDE.session, loaded_files)
wenzelm@64835
   224
                  delay_init.invoke()
wenzelm@64835
   225
                }
wenzelm@64835
   226
                finally { delay_load_active.change(_ => false) }
wenzelm@53715
   227
              }
wenzelm@53074
   228
            }
wenzelm@46761
   229
          }
wenzelm@64835
   230
          catch { case _: Throwable => delay_load_active.change(_ => false) }
wenzelm@46761
   231
        }
wenzelm@64835
   232
        else delay_load_active.change(_ => false)
wenzelm@44606
   233
      }
wenzelm@44574
   234
    }
wenzelm@62068
   235
  }
wenzelm@62068
   236
wenzelm@64478
   237
  private lazy val delay_load =
wenzelm@62068
   238
    GUI_Thread.delay_last(PIDE.options.seconds("editor_load_delay")) { delay_load_action() }
wenzelm@44573
   239
wenzelm@64858
   240
  private def file_watcher_action(changed: Set[JFile]): Unit =
wenzelm@64858
   241
    if (Document_Model.sync_files(changed)) PIDE.editor.invoke_generated()
wenzelm@64858
   242
wenzelm@64858
   243
  lazy val file_watcher: File_Watcher =
wenzelm@64858
   244
    File_Watcher(file_watcher_action _, PIDE.options.seconds("editor_load_delay"))
wenzelm@64858
   245
wenzelm@44574
   246
wenzelm@56715
   247
  /* session phase */
wenzelm@44573
   248
wenzelm@65226
   249
  val session_phase_changed: Session.Phase => Unit =
wenzelm@65226
   250
  {
wenzelm@65226
   251
    case Session.Terminated(_) =>
wenzelm@65226
   252
      GUI_Thread.later {
wenzelm@65226
   253
        GUI.error_dialog(jEdit.getActiveView, "Prover process terminated",
wenzelm@65226
   254
          "Isabelle Syslog", GUI.scrollable_text(PIDE.session.syslog_content()))
wenzelm@65226
   255
      }
wenzelm@39735
   256
wenzelm@65226
   257
    case Session.Ready =>
wenzelm@65226
   258
      PIDE.session.update_options(PIDE.options.value)
wenzelm@65226
   259
      PIDE.init_models()
wenzelm@57640
   260
wenzelm@65226
   261
      if (!Isabelle.continuous_checking) {
wenzelm@65226
   262
        GUI_Thread.later {
wenzelm@65226
   263
          val answer =
wenzelm@65226
   264
            GUI.confirm_dialog(jEdit.getActiveView,
wenzelm@65226
   265
              "Continuous checking of PIDE document",
wenzelm@65226
   266
              JOptionPane.YES_NO_OPTION,
wenzelm@65226
   267
              "Continuous checking is presently disabled:",
wenzelm@65226
   268
              "editor buffers will remain inactive!",
wenzelm@65226
   269
              "Enable continuous checking now?")
wenzelm@65226
   270
          if (answer == 0) Isabelle.continuous_checking = true
wenzelm@57640
   271
        }
wenzelm@65226
   272
      }
wenzelm@57640
   273
wenzelm@65226
   274
      delay_load.invoke()
wenzelm@44573
   275
wenzelm@65226
   276
    case Session.Shutdown =>
wenzelm@65226
   277
      GUI_Thread.later {
wenzelm@65226
   278
        delay_load.revoke()
wenzelm@65226
   279
        delay_init.revoke()
wenzelm@65226
   280
        PIDE.editor.flush()
wenzelm@65226
   281
        PIDE.exit_models(JEdit_Lib.jedit_buffers().toList)
wenzelm@65226
   282
      }
wenzelm@46740
   283
wenzelm@65226
   284
    case _ =>
wenzelm@65226
   285
  }
wenzelm@39630
   286
wenzelm@39630
   287
wenzelm@34618
   288
  /* main plugin plumbing */
wenzelm@34433
   289
wenzelm@65241
   290
  @volatile private var startup_failure: Option[Throwable] = None
wenzelm@65241
   291
  @volatile private var startup_notified = false
wenzelm@65241
   292
wenzelm@34767
   293
  override def handleMessage(message: EBMessage)
wenzelm@34618
   294
  {
wenzelm@57612
   295
    GUI_Thread.assert {}
wenzelm@39630
   296
wenzelm@65241
   297
    if (startup_failure.isDefined && !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@65241
   301
            GUI.scrollable_text(Exn.message(startup_failure.get)),
wenzelm@49099
   302
            "Prover IDE inactive!")
wenzelm@65241
   303
          startup_notified = true
wenzelm@49099
   304
        case _ =>
wenzelm@49099
   305
      }
wenzelm@49099
   306
    }
wenzelm@49099
   307
wenzelm@65241
   308
    if (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@65242
   377
          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@65242
   390
      completion_history.load()
wenzelm@65242
   391
      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@65241
   409
      startup_failure = None
wenzelm@49099
   410
    }
wenzelm@49099
   411
    catch {
wenzelm@49099
   412
      case exn: Throwable =>
wenzelm@65241
   413
        startup_failure = Some(exn)
wenzelm@65241
   414
        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@65241
   423
    if (startup_failure.isEmpty) {
wenzelm@50205
   424
      PIDE.options.value.save_prefs()
wenzelm@65242
   425
      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
}