src/Tools/jEdit/src/plugin.scala
author wenzelm
Wed Mar 15 15:50:28 2017 +0100 (2017-03-15)
changeset 65264 7e6ecd04b5fe
parent 65263 c97abf0fa0c1
child 65265 f994a61376eb
permissions -rw-r--r--
dynamic session_options for tuning parameters and initial prover options;
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@65263
    36
  def session: Session = plugin.session
wenzelm@49101
    37
wenzelm@34784
    38
wenzelm@65248
    39
  /* semantic document content */
wenzelm@55621
    40
wenzelm@62062
    41
  def snapshot(view: View): Document.Snapshot = GUI_Thread.now
wenzelm@55621
    42
  {
wenzelm@64813
    43
    Document_Model.get(view.getBuffer) match {
wenzelm@55621
    44
      case Some(model) => model.snapshot
wenzelm@55621
    45
      case None => error("No document model for current buffer")
wenzelm@55621
    46
    }
wenzelm@55621
    47
  }
wenzelm@55621
    48
wenzelm@64621
    49
  def rendering(view: View): JEdit_Rendering = GUI_Thread.now
wenzelm@55621
    50
  {
wenzelm@55621
    51
    val text_area = view.getTextArea
wenzelm@64882
    52
    Document_View.get(text_area) match {
wenzelm@55621
    53
      case Some(doc_view) => doc_view.get_rendering()
wenzelm@55621
    54
      case None => error("No document view for current text area")
wenzelm@55621
    55
    }
wenzelm@55621
    56
  }
wenzelm@34318
    57
}
wenzelm@34318
    58
wenzelm@34429
    59
wenzelm@34618
    60
class Plugin extends EBPlugin
wenzelm@34618
    61
{
wenzelm@65262
    62
  /* options */
wenzelm@65238
    63
wenzelm@65257
    64
  private var _options: JEdit_Options = null
wenzelm@65262
    65
  private def init_options(): Unit = _options = new JEdit_Options(Options.init())
wenzelm@65257
    66
  def options: JEdit_Options = _options
wenzelm@65239
    67
wenzelm@65262
    68
wenzelm@65262
    69
  /* resources */
wenzelm@65262
    70
wenzelm@65262
    71
  private var _resources: JEdit_Resources = null
wenzelm@65262
    72
  private def init_resources()
wenzelm@65262
    73
  {
wenzelm@65262
    74
    val options = this.options.value
wenzelm@65262
    75
    val session_name = JEdit_Sessions.session_name(options)
wenzelm@65262
    76
    val session_base =
wenzelm@65262
    77
      try { Sessions.session_base(options, session_name, JEdit_Sessions.session_dirs()) }
wenzelm@65262
    78
      catch { case ERROR(_) => Sessions.pure_base(options) }
wenzelm@65262
    79
wenzelm@65262
    80
    _resources =
wenzelm@65262
    81
      new JEdit_Resources(session_base.copy(known_theories =
wenzelm@65262
    82
        for ((a, b) <- session_base.known_theories) yield (a, b.map(File.platform_path(_)))))
wenzelm@65262
    83
  }
wenzelm@65262
    84
  def resources: JEdit_Resources = _resources
wenzelm@65262
    85
wenzelm@65262
    86
wenzelm@65263
    87
  /* session */
wenzelm@65263
    88
wenzelm@65263
    89
  private var _session: Session = null
wenzelm@65264
    90
  private def init_session(): Unit = _session = new Session(options.value, resources)
wenzelm@65263
    91
  def session: Session = _session
wenzelm@65263
    92
wenzelm@65263
    93
wenzelm@65262
    94
  /* misc support */
wenzelm@65262
    95
wenzelm@65239
    96
  val completion_history = new Completion.History_Variable
wenzelm@65239
    97
  val spell_checker = new Spell_Checker_Variable
wenzelm@65239
    98
wenzelm@65238
    99
wenzelm@56316
   100
  /* global changes */
wenzelm@55791
   101
wenzelm@56316
   102
  def options_changed()
wenzelm@56316
   103
  {
wenzelm@65263
   104
    session.global_options.post(Session.Global_Options(options.value))
wenzelm@56770
   105
    delay_load.invoke()
wenzelm@55791
   106
  }
wenzelm@55791
   107
wenzelm@56316
   108
  def deps_changed()
wenzelm@56316
   109
  {
wenzelm@56770
   110
    delay_load.invoke()
wenzelm@56316
   111
  }
wenzelm@56316
   112
wenzelm@55791
   113
wenzelm@44577
   114
  /* theory files */
wenzelm@44574
   115
wenzelm@62068
   116
  lazy val delay_init =
wenzelm@65249
   117
    GUI_Thread.delay_last(options.seconds("editor_load_delay"))
wenzelm@50344
   118
    {
wenzelm@65244
   119
      init_models()
wenzelm@50344
   120
    }
wenzelm@50344
   121
wenzelm@57582
   122
  private val delay_load_active = Synchronized(false)
wenzelm@57582
   123
  private def delay_load_activated(): Boolean =
wenzelm@57582
   124
    delay_load_active.guarded_access(a => Some((!a, true)))
wenzelm@62068
   125
  private def delay_load_action()
wenzelm@62068
   126
  {
wenzelm@62068
   127
    if (Isabelle.continuous_checking && delay_load_activated() &&
wenzelm@62068
   128
        PerspectiveManager.isPerspectiveEnabled)
wenzelm@44574
   129
    {
wenzelm@64835
   130
      if (JEdit_Lib.jedit_buffers().exists(_.isLoading)) delay_load.invoke()
wenzelm@64835
   131
      else {
wenzelm@64835
   132
        val required_files =
wenzelm@64835
   133
        {
wenzelm@64835
   134
          val models = Document_Model.get_models()
wenzelm@44574
   135
wenzelm@62068
   136
          val thys =
wenzelm@64835
   137
            (for ((node_name, model) <- models.iterator if model.is_theory)
wenzelm@64835
   138
              yield (node_name, Position.none)).toList
wenzelm@65262
   139
          val thy_files = resources.thy_info.dependencies("", thys).deps.map(_.name)
wenzelm@46761
   140
wenzelm@64839
   141
          val aux_files =
wenzelm@65249
   142
            if (options.bool("jedit_auto_resolve")) {
wenzelm@64835
   143
              val stable_tip_version =
wenzelm@64835
   144
                if (models.forall(p => p._2.is_stable))
wenzelm@65263
   145
                  session.current_state().stable_tip_version
wenzelm@64835
   146
                else None
wenzelm@64835
   147
              stable_tip_version match {
wenzelm@65262
   148
                case Some(version) => resources.undefined_blobs(version.nodes)
wenzelm@64478
   149
                case None => delay_load.invoke(); Nil
wenzelm@57582
   150
              }
wenzelm@62068
   151
            }
wenzelm@62068
   152
            else Nil
wenzelm@62068
   153
wenzelm@64835
   154
          (thy_files ::: aux_files).filterNot(models.isDefinedAt(_))
wenzelm@64835
   155
        }
wenzelm@64835
   156
        if (required_files.nonEmpty) {
wenzelm@64835
   157
          try {
wenzelm@64835
   158
            Standard_Thread.fork("resolve_dependencies") {
wenzelm@64835
   159
              val loaded_files =
wenzelm@64835
   160
                for {
wenzelm@64835
   161
                  name <- required_files
wenzelm@65262
   162
                  text <- resources.read_file_content(name)
wenzelm@64835
   163
                } yield (name, text)
wenzelm@62068
   164
wenzelm@64835
   165
              GUI_Thread.later {
wenzelm@64835
   166
                try {
wenzelm@65263
   167
                  Document_Model.provide_files(session, loaded_files)
wenzelm@64835
   168
                  delay_init.invoke()
wenzelm@64835
   169
                }
wenzelm@64835
   170
                finally { delay_load_active.change(_ => false) }
wenzelm@53715
   171
              }
wenzelm@53074
   172
            }
wenzelm@46761
   173
          }
wenzelm@64835
   174
          catch { case _: Throwable => delay_load_active.change(_ => false) }
wenzelm@46761
   175
        }
wenzelm@64835
   176
        else delay_load_active.change(_ => false)
wenzelm@44606
   177
      }
wenzelm@44574
   178
    }
wenzelm@62068
   179
  }
wenzelm@62068
   180
wenzelm@64478
   181
  private lazy val delay_load =
wenzelm@65249
   182
    GUI_Thread.delay_last(options.seconds("editor_load_delay")) { delay_load_action() }
wenzelm@44573
   183
wenzelm@64858
   184
  private def file_watcher_action(changed: Set[JFile]): Unit =
wenzelm@65246
   185
    if (Document_Model.sync_files(changed)) JEdit_Editor.invoke_generated()
wenzelm@64858
   186
wenzelm@64858
   187
  lazy val file_watcher: File_Watcher =
wenzelm@65249
   188
    File_Watcher(file_watcher_action _, options.seconds("editor_load_delay"))
wenzelm@64858
   189
wenzelm@44574
   190
wenzelm@56715
   191
  /* session phase */
wenzelm@44573
   192
wenzelm@65226
   193
  val session_phase_changed: Session.Phase => Unit =
wenzelm@65226
   194
  {
wenzelm@65226
   195
    case Session.Terminated(_) =>
wenzelm@65226
   196
      GUI_Thread.later {
wenzelm@65226
   197
        GUI.error_dialog(jEdit.getActiveView, "Prover process terminated",
wenzelm@65263
   198
          "Isabelle Syslog", GUI.scrollable_text(session.syslog_content()))
wenzelm@65226
   199
      }
wenzelm@39735
   200
wenzelm@65226
   201
    case Session.Ready =>
wenzelm@65244
   202
      init_models()
wenzelm@57640
   203
wenzelm@65226
   204
      if (!Isabelle.continuous_checking) {
wenzelm@65226
   205
        GUI_Thread.later {
wenzelm@65226
   206
          val answer =
wenzelm@65226
   207
            GUI.confirm_dialog(jEdit.getActiveView,
wenzelm@65226
   208
              "Continuous checking of PIDE document",
wenzelm@65226
   209
              JOptionPane.YES_NO_OPTION,
wenzelm@65226
   210
              "Continuous checking is presently disabled:",
wenzelm@65226
   211
              "editor buffers will remain inactive!",
wenzelm@65226
   212
              "Enable continuous checking now?")
wenzelm@65226
   213
          if (answer == 0) Isabelle.continuous_checking = true
wenzelm@57640
   214
        }
wenzelm@65226
   215
      }
wenzelm@57640
   216
wenzelm@65226
   217
      delay_load.invoke()
wenzelm@44573
   218
wenzelm@65226
   219
    case Session.Shutdown =>
wenzelm@65226
   220
      GUI_Thread.later {
wenzelm@65226
   221
        delay_load.revoke()
wenzelm@65226
   222
        delay_init.revoke()
wenzelm@65246
   223
        JEdit_Editor.flush()
wenzelm@65244
   224
        exit_models(JEdit_Lib.jedit_buffers().toList)
wenzelm@65226
   225
      }
wenzelm@46740
   226
wenzelm@65226
   227
    case _ =>
wenzelm@65226
   228
  }
wenzelm@39630
   229
wenzelm@39630
   230
wenzelm@65244
   231
  /* document model and view */
wenzelm@65244
   232
wenzelm@65244
   233
  def exit_models(buffers: List[Buffer])
wenzelm@65244
   234
  {
wenzelm@65244
   235
    GUI_Thread.now {
wenzelm@65244
   236
      buffers.foreach(buffer =>
wenzelm@65244
   237
        JEdit_Lib.buffer_lock(buffer) {
wenzelm@65244
   238
          JEdit_Lib.jedit_text_areas(buffer).foreach(Document_View.exit)
wenzelm@65244
   239
          Document_Model.exit(buffer)
wenzelm@65244
   240
        })
wenzelm@65244
   241
      }
wenzelm@65244
   242
  }
wenzelm@65244
   243
wenzelm@65244
   244
  def init_models()
wenzelm@65244
   245
  {
wenzelm@65244
   246
    GUI_Thread.now {
wenzelm@65246
   247
      JEdit_Editor.flush()
wenzelm@65244
   248
wenzelm@65244
   249
      for {
wenzelm@65244
   250
        buffer <- JEdit_Lib.jedit_buffers()
wenzelm@65244
   251
        if buffer != null && !buffer.getBooleanProperty(Buffer.GZIPPED)
wenzelm@65244
   252
      } {
wenzelm@65244
   253
        if (buffer.isLoaded) {
wenzelm@65244
   254
          JEdit_Lib.buffer_lock(buffer) {
wenzelm@65262
   255
            val node_name = resources.node_name(buffer)
wenzelm@65263
   256
            val model = Document_Model.init(session, node_name, buffer)
wenzelm@65244
   257
            for {
wenzelm@65244
   258
              text_area <- JEdit_Lib.jedit_text_areas(buffer)
wenzelm@65244
   259
              if Document_View.get(text_area).map(_.model) != Some(model)
wenzelm@65244
   260
            } Document_View.init(model, text_area)
wenzelm@65244
   261
          }
wenzelm@65244
   262
        }
wenzelm@65244
   263
        else delay_init.invoke()
wenzelm@65244
   264
      }
wenzelm@65244
   265
wenzelm@65246
   266
      JEdit_Editor.invoke_generated()
wenzelm@65244
   267
    }
wenzelm@65244
   268
  }
wenzelm@65244
   269
wenzelm@65244
   270
  def init_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@65244
   271
    GUI_Thread.now {
wenzelm@65244
   272
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@65244
   273
        Document_Model.get(buffer) match {
wenzelm@65244
   274
          case Some(model) => Document_View.init(model, text_area)
wenzelm@65244
   275
          case None =>
wenzelm@65244
   276
        }
wenzelm@65244
   277
      }
wenzelm@65244
   278
    }
wenzelm@65244
   279
wenzelm@65244
   280
  def exit_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@65244
   281
    GUI_Thread.now {
wenzelm@65244
   282
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@65244
   283
        Document_View.exit(text_area)
wenzelm@65244
   284
      }
wenzelm@65244
   285
    }
wenzelm@65244
   286
wenzelm@65244
   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@65256
   319
          Session_Build.check_dialog(view)
wenzelm@63747
   320
wenzelm@64602
   321
          Keymap_Merge.check_dialog(view)
wenzelm@64602
   322
wenzelm@65246
   323
          JEdit_Editor.hyperlink_position(true, Document.Snapshot.init,
wenzelm@65256
   324
            JEdit_Sessions.session_info(options.value).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@65244
   329
            exit_models(List(msg.getBuffer))
wenzelm@65246
   330
            JEdit_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@65263
   335
          if (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@65263
   352
              if (session.is_ready)
wenzelm@65244
   353
                init_view(buffer, text_area)
wenzelm@49099
   354
            }
wenzelm@52867
   355
            else {
wenzelm@65240
   356
              Isabelle.dismissed_popups(text_area.getView)
wenzelm@65244
   357
              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@65244
   374
            if (buffer != null && text_area != null) init_view(buffer, text_area)
wenzelm@62264
   375
          }
wenzelm@62264
   376
wenzelm@65249
   377
          spell_checker.update(options.value)
wenzelm@65263
   378
          session.update_options(options.value)
wenzelm@34784
   379
wenzelm@49099
   380
        case _ =>
wenzelm@49099
   381
      }
wenzelm@34318
   382
    }
wenzelm@34318
   383
  }
wenzelm@34318
   384
wenzelm@65260
   385
wenzelm@65260
   386
  /* mode provider */
wenzelm@65260
   387
wenzelm@65260
   388
  private var orig_mode_provider: ModeProvider = null
wenzelm@65260
   389
  private var pide_mode_provider: ModeProvider = null
wenzelm@65260
   390
wenzelm@65260
   391
  def init_mode_provider()
wenzelm@65260
   392
  {
wenzelm@65260
   393
    orig_mode_provider = ModeProvider.instance
wenzelm@65260
   394
    if (orig_mode_provider.isInstanceOf[ModeProvider]) {
wenzelm@65260
   395
      pide_mode_provider = new Token_Markup.Mode_Provider(orig_mode_provider)
wenzelm@65260
   396
      ModeProvider.instance = pide_mode_provider
wenzelm@65260
   397
    }
wenzelm@65260
   398
  }
wenzelm@65260
   399
wenzelm@65260
   400
  def exit_mode_provider()
wenzelm@65260
   401
  {
wenzelm@65260
   402
    if (ModeProvider.instance == pide_mode_provider)
wenzelm@65260
   403
      ModeProvider.instance = orig_mode_provider
wenzelm@65260
   404
  }
wenzelm@65260
   405
wenzelm@65260
   406
wenzelm@65260
   407
  /* start and stop */
wenzelm@65260
   408
wenzelm@34618
   409
  override def start()
wenzelm@49099
   410
  {
wenzelm@65262
   411
    Debug.DISABLE_SEARCH_DIALOG_POOL = true
wenzelm@65262
   412
wenzelm@65262
   413
wenzelm@65257
   414
    /* strict initialization */
wenzelm@65257
   415
wenzelm@65257
   416
    // adhoc patch of confusing message
wenzelm@65257
   417
    val orig_plugin_error = jEdit.getProperty("plugin-error.start-error")
wenzelm@65257
   418
    jEdit.setProperty("plugin-error.start-error", "Cannot start plugin:\n{0}")
wenzelm@65257
   419
wenzelm@65262
   420
    init_options()
wenzelm@65262
   421
    init_resources()
wenzelm@65263
   422
    init_session()
wenzelm@65262
   423
    PIDE._plugin = this
wenzelm@65257
   424
wenzelm@65257
   425
    jEdit.setProperty("plugin-error.start-error", orig_plugin_error)
wenzelm@65257
   426
wenzelm@65257
   427
wenzelm@65257
   428
    /* non-strict initialization */
wenzelm@65257
   429
wenzelm@49099
   430
    try {
wenzelm@65242
   431
      completion_history.load()
wenzelm@65249
   432
      spell_checker.update(options.value)
wenzelm@49245
   433
wenzelm@65261
   434
      SyntaxUtilities.setStyleExtender(Syntax_Style.Extender)
wenzelm@65260
   435
      init_mode_provider()
wenzelm@53274
   436
      JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.init _)
wenzelm@53274
   437
wenzelm@65241
   438
      startup_failure = None
wenzelm@49099
   439
    }
wenzelm@49099
   440
    catch {
wenzelm@49099
   441
      case exn: Throwable =>
wenzelm@65241
   442
        startup_failure = Some(exn)
wenzelm@65241
   443
        startup_notified = false
wenzelm@62228
   444
        Log.log(Log.ERROR, this, exn)
wenzelm@49099
   445
    }
wenzelm@34318
   446
  }
wenzelm@34618
   447
wenzelm@39628
   448
  override def stop()
wenzelm@34618
   449
  {
wenzelm@65261
   450
    SyntaxUtilities.setStyleExtender(Syntax_Style.No_Extender)
wenzelm@65261
   451
    exit_mode_provider()
wenzelm@53274
   452
    JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.exit _)
wenzelm@53274
   453
wenzelm@65241
   454
    if (startup_failure.isEmpty) {
wenzelm@65249
   455
      options.value.save_prefs()
wenzelm@65242
   456
      completion_history.value.save()
wenzelm@53337
   457
    }
wenzelm@49245
   458
wenzelm@65244
   459
    exit_models(JEdit_Lib.jedit_buffers().toList)
wenzelm@65263
   460
    session.stop()
wenzelm@65245
   461
    file_watcher.shutdown()
wenzelm@65262
   462
wenzelm@65262
   463
    PIDE._plugin = null
wenzelm@34318
   464
  }
wenzelm@34318
   465
}