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