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