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