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