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