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