src/Tools/jEdit/src/plugin.scala
author wenzelm
Fri Jan 06 13:27:18 2017 +0100 (2017-01-06)
changeset 64813 7283f41d05ab
parent 64621 7116f2634e32
child 64817 0bb6b582bb4f
permissions -rw-r--r--
manage buffer models as explicit global state;
tuned signature;
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@49246
    14
import scala.swing.{ListView, ScrollPane}
immler@34406
    15
wenzelm@60205
    16
import org.gjt.sp.jedit.{jEdit, EBMessage, EBPlugin, Buffer, View, Debug, PerspectiveManager}
wenzelm@53487
    17
import org.gjt.sp.jedit.gui.AboutDialog
wenzelm@39043
    18
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea}
wenzelm@59077
    19
import org.gjt.sp.jedit.buffer.JEditBuffer
wenzelm@50362
    20
import org.gjt.sp.jedit.syntax.ModeProvider
wenzelm@49100
    21
import org.gjt.sp.jedit.msg.{EditorStarted, BufferUpdate, EditPaneUpdate, PropertiesChanged}
wenzelm@43443
    22
import org.gjt.sp.util.SyntaxUtilities
wenzelm@62228
    23
import org.gjt.sp.util.Log
wenzelm@39241
    24
wenzelm@34318
    25
wenzelm@50205
    26
object PIDE
wenzelm@34618
    27
{
wenzelm@34784
    28
  /* plugin instance */
wenzelm@34784
    29
wenzelm@49245
    30
  val options = new JEdit_Options
wenzelm@53337
    31
  val completion_history = new Completion.History_Variable
wenzelm@56558
    32
  val spell_checker = new Spell_Checker_Variable
wenzelm@49245
    33
wenzelm@49099
    34
  @volatile var startup_failure: Option[Throwable] = None
wenzelm@49099
    35
  @volatile var startup_notified = false
wenzelm@34784
    36
wenzelm@49101
    37
  @volatile var plugin: Plugin = null
wenzelm@60835
    38
  @volatile var session: Session = new Session(JEdit_Resources.empty)
wenzelm@49101
    39
wenzelm@62068
    40
  def options_changed() { if (plugin != null) plugin.options_changed() }
wenzelm@62068
    41
  def deps_changed() { if (plugin != null) plugin.deps_changed() }
wenzelm@52815
    42
wenzelm@56208
    43
  def resources(): JEdit_Resources =
wenzelm@56208
    44
    session.resources.asInstanceOf[JEdit_Resources]
wenzelm@44955
    45
wenzelm@52971
    46
  lazy val editor = new JEdit_Editor
wenzelm@52971
    47
wenzelm@34784
    48
wenzelm@53244
    49
  /* popups */
wenzelm@53244
    50
wenzelm@53244
    51
  def dismissed_popups(view: View): Boolean =
wenzelm@53244
    52
  {
wenzelm@53272
    53
    var dismissed = false
wenzelm@53272
    54
wenzelm@53274
    55
    JEdit_Lib.jedit_text_areas(view).foreach(text_area =>
wenzelm@53274
    56
      if (Completion_Popup.Text_Area.dismissed(text_area)) dismissed = true)
wenzelm@53272
    57
wenzelm@53272
    58
    if (Pretty_Tooltip.dismissed_all()) dismissed = true
wenzelm@53272
    59
wenzelm@53272
    60
    dismissed
wenzelm@53244
    61
  }
wenzelm@53244
    62
wenzelm@53244
    63
wenzelm@43449
    64
  /* document model and view */
wenzelm@43449
    65
wenzelm@55712
    66
  def document_view(text_area: TextArea): Option[Document_View] = Document_View(text_area)
wenzelm@43449
    67
wenzelm@44379
    68
  def document_views(buffer: Buffer): List[Document_View] =
wenzelm@44379
    69
    for {
wenzelm@49406
    70
      text_area <- JEdit_Lib.jedit_text_areas(buffer).toList
wenzelm@54529
    71
      doc_view <- document_view(text_area)
wenzelm@54529
    72
    } yield doc_view
wenzelm@44379
    73
wenzelm@54522
    74
  def document_models(): List[Document_Model] =
wenzelm@54522
    75
    for {
wenzelm@54522
    76
      buffer <- JEdit_Lib.jedit_buffers().toList
wenzelm@64813
    77
      model <- Document_Model.get(buffer)
wenzelm@54522
    78
    } yield model
wenzelm@54522
    79
wenzelm@54522
    80
  def document_blobs(): Document.Blobs =
wenzelm@55783
    81
    Document.Blobs(
wenzelm@55783
    82
      (for {
wenzelm@55783
    83
        buffer <- JEdit_Lib.jedit_buffers()
wenzelm@64813
    84
        model <- Document_Model.get(buffer)
wenzelm@64813
    85
        blob <- model.get_blob
wenzelm@55783
    86
      } yield (model.node_name -> blob)).toMap)
wenzelm@54522
    87
wenzelm@50344
    88
  def exit_models(buffers: List[Buffer])
wenzelm@47058
    89
  {
wenzelm@57612
    90
    GUI_Thread.now {
wenzelm@54461
    91
      PIDE.editor.flush()
wenzelm@50344
    92
      buffers.foreach(buffer =>
wenzelm@50344
    93
        JEdit_Lib.buffer_lock(buffer) {
wenzelm@50344
    94
          JEdit_Lib.jedit_text_areas(buffer).foreach(Document_View.exit)
wenzelm@50344
    95
          Document_Model.exit(buffer)
wenzelm@50344
    96
        })
wenzelm@50344
    97
      }
wenzelm@47058
    98
  }
wenzelm@47058
    99
wenzelm@55791
   100
  def init_models()
wenzelm@43510
   101
  {
wenzelm@57612
   102
    GUI_Thread.now {
wenzelm@54461
   103
      PIDE.editor.flush()
wenzelm@55791
   104
wenzelm@55791
   105
      for {
wenzelm@55791
   106
        buffer <- JEdit_Lib.jedit_buffers()
wenzelm@62068
   107
        if buffer != null && !buffer.getBooleanProperty(Buffer.GZIPPED)
wenzelm@55791
   108
      } {
wenzelm@62068
   109
        if (buffer.isLoaded) {
wenzelm@62068
   110
          JEdit_Lib.buffer_lock(buffer) {
wenzelm@62068
   111
            val node_name = resources.node_name(buffer)
wenzelm@64813
   112
            val model = Document_Model.init(session, buffer, node_name)
wenzelm@62068
   113
            for {
wenzelm@62068
   114
              text_area <- JEdit_Lib.jedit_text_areas(buffer)
wenzelm@62068
   115
              if document_view(text_area).map(_.model) != Some(model)
wenzelm@62068
   116
            } Document_View.init(model, text_area)
wenzelm@62068
   117
          }
wenzelm@43510
   118
        }
wenzelm@62068
   119
        else if (plugin != null) plugin.delay_init.invoke()
wenzelm@55791
   120
      }
wenzelm@55791
   121
wenzelm@64524
   122
      PIDE.editor.invoke_generated()
wenzelm@43510
   123
    }
wenzelm@43510
   124
  }
wenzelm@43510
   125
wenzelm@56774
   126
  def init_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@57612
   127
    GUI_Thread.now {
wenzelm@56774
   128
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@64813
   129
        Document_Model.get(buffer) match {
wenzelm@56774
   130
          case Some(model) => Document_View.init(model, text_area)
wenzelm@56774
   131
          case None =>
wenzelm@56774
   132
        }
wenzelm@43510
   133
      }
wenzelm@43510
   134
    }
wenzelm@43510
   135
wenzelm@56774
   136
  def exit_view(buffer: Buffer, text_area: JEditTextArea): Unit =
wenzelm@57612
   137
    GUI_Thread.now {
wenzelm@56774
   138
      JEdit_Lib.buffer_lock(buffer) {
wenzelm@56774
   139
        Document_View.exit(text_area)
wenzelm@56774
   140
      }
wenzelm@43510
   141
    }
wenzelm@55621
   142
wenzelm@55621
   143
wenzelm@55621
   144
  /* current document content */
wenzelm@55621
   145
wenzelm@62062
   146
  def snapshot(view: View): Document.Snapshot = GUI_Thread.now
wenzelm@55621
   147
  {
wenzelm@64813
   148
    Document_Model.get(view.getBuffer) match {
wenzelm@55621
   149
      case Some(model) => model.snapshot
wenzelm@55621
   150
      case None => error("No document model for current buffer")
wenzelm@55621
   151
    }
wenzelm@55621
   152
  }
wenzelm@55621
   153
wenzelm@64621
   154
  def rendering(view: View): JEdit_Rendering = GUI_Thread.now
wenzelm@55621
   155
  {
wenzelm@55621
   156
    val text_area = view.getTextArea
wenzelm@55621
   157
    document_view(text_area) match {
wenzelm@55621
   158
      case Some(doc_view) => doc_view.get_rendering()
wenzelm@55621
   159
      case None => error("No document view for current text area")
wenzelm@55621
   160
    }
wenzelm@55621
   161
  }
wenzelm@34318
   162
}
wenzelm@34318
   163
wenzelm@34429
   164
wenzelm@34618
   165
class Plugin extends EBPlugin
wenzelm@34618
   166
{
wenzelm@56316
   167
  /* global changes */
wenzelm@55791
   168
wenzelm@56316
   169
  def options_changed()
wenzelm@56316
   170
  {
wenzelm@56715
   171
    PIDE.session.global_options.post(Session.Global_Options(PIDE.options.value))
wenzelm@56770
   172
    delay_load.invoke()
wenzelm@55791
   173
  }
wenzelm@55791
   174
wenzelm@56316
   175
  def deps_changed()
wenzelm@56316
   176
  {
wenzelm@56770
   177
    delay_load.invoke()
wenzelm@56316
   178
  }
wenzelm@56316
   179
wenzelm@55791
   180
wenzelm@44577
   181
  /* theory files */
wenzelm@44574
   182
wenzelm@62068
   183
  lazy val delay_init =
wenzelm@57612
   184
    GUI_Thread.delay_last(PIDE.options.seconds("editor_load_delay"))
wenzelm@50344
   185
    {
wenzelm@55791
   186
      PIDE.init_models()
wenzelm@50344
   187
    }
wenzelm@50344
   188
wenzelm@57582
   189
  private val delay_load_active = Synchronized(false)
wenzelm@57582
   190
  private def delay_load_activated(): Boolean =
wenzelm@57582
   191
    delay_load_active.guarded_access(a => Some((!a, true)))
wenzelm@62068
   192
  private def delay_load_action()
wenzelm@62068
   193
  {
wenzelm@62068
   194
    if (Isabelle.continuous_checking && delay_load_activated() &&
wenzelm@62068
   195
        PerspectiveManager.isPerspectiveEnabled)
wenzelm@44574
   196
    {
wenzelm@62068
   197
      try {
wenzelm@62068
   198
        val view = jEdit.getActiveView()
wenzelm@44963
   199
wenzelm@62068
   200
        val buffers = JEdit_Lib.jedit_buffers().toList
wenzelm@62068
   201
        if (buffers.forall(_.isLoaded)) {
wenzelm@62068
   202
          def loaded_buffer(name: String): Boolean =
wenzelm@62068
   203
            buffers.exists(buffer => JEdit_Lib.buffer_name(buffer) == name)
wenzelm@44574
   204
wenzelm@62068
   205
          val thys =
wenzelm@62068
   206
            for {
wenzelm@62068
   207
              buffer <- buffers
wenzelm@64813
   208
              model <- Document_Model.get(buffer)
wenzelm@62068
   209
              if model.is_theory
wenzelm@62068
   210
            } yield (model.node_name, Position.none)
wenzelm@46761
   211
wenzelm@62068
   212
          val thy_info = new Thy_Info(PIDE.resources)
wenzelm@62068
   213
          val thy_files = thy_info.dependencies("", thys).deps.map(_.name.node)
wenzelm@60916
   214
wenzelm@62068
   215
          val aux_files =
wenzelm@62068
   216
            if (PIDE.options.bool("jedit_auto_resolve")) {
wenzelm@62068
   217
              PIDE.editor.stable_tip_version() match {
wenzelm@62068
   218
                case Some(version) => PIDE.resources.undefined_blobs(version.nodes).map(_.node)
wenzelm@64478
   219
                case None => delay_load.invoke(); Nil
wenzelm@57582
   220
              }
wenzelm@62068
   221
            }
wenzelm@62068
   222
            else Nil
wenzelm@62068
   223
wenzelm@62068
   224
          val files =
wenzelm@62068
   225
            (thy_files ::: aux_files).filter(file =>
wenzelm@62068
   226
              !loaded_buffer(file) && PIDE.resources.check_file(file))
wenzelm@44606
   227
wenzelm@62068
   228
          if (files.nonEmpty) {
wenzelm@62068
   229
            if (PIDE.options.bool("jedit_auto_load")) {
wenzelm@62068
   230
              files.foreach(file => jEdit.openFile(null: View, file))
wenzelm@62068
   231
            }
wenzelm@62068
   232
            else {
wenzelm@62068
   233
              val files_list = new ListView(files.sorted)
wenzelm@62068
   234
              for (i <- 0 until files.length)
wenzelm@62068
   235
                files_list.selection.indices += i
wenzelm@62068
   236
wenzelm@62068
   237
              val answer =
wenzelm@62068
   238
                GUI.confirm_dialog(view,
wenzelm@62068
   239
                  "Auto loading of required files",
wenzelm@62068
   240
                  JOptionPane.YES_NO_OPTION,
wenzelm@62068
   241
                  "The following files are required to resolve theory imports.",
wenzelm@62068
   242
                  "Reload selected files now?",
wenzelm@62068
   243
                  new ScrollPane(files_list),
wenzelm@62068
   244
                  new Isabelle.Continuous_Checking)
wenzelm@62068
   245
              if (answer == 0) {
wenzelm@62068
   246
                files.foreach(file =>
wenzelm@62068
   247
                  if (files_list.selection.items.contains(file))
wenzelm@62068
   248
                    jEdit.openFile(null: View, file))
wenzelm@53715
   249
              }
wenzelm@53074
   250
            }
wenzelm@46761
   251
          }
wenzelm@46761
   252
        }
wenzelm@62068
   253
        else delay_load.invoke()
wenzelm@44606
   254
      }
wenzelm@62068
   255
      finally { delay_load_active.change(_ => false) }
wenzelm@44574
   256
    }
wenzelm@62068
   257
  }
wenzelm@62068
   258
wenzelm@64478
   259
  private lazy val delay_load =
wenzelm@62068
   260
    GUI_Thread.delay_last(PIDE.options.seconds("editor_load_delay")) { delay_load_action() }
wenzelm@44573
   261
wenzelm@44574
   262
wenzelm@56715
   263
  /* session phase */
wenzelm@44573
   264
wenzelm@56715
   265
  private val session_phase =
wenzelm@56715
   266
    Session.Consumer[Session.Phase](getClass.getName) {
wenzelm@56715
   267
      case Session.Inactive | Session.Failed =>
wenzelm@57612
   268
        GUI_Thread.later {
wenzelm@56715
   269
          GUI.error_dialog(jEdit.getActiveView, "Prover process terminated",
wenzelm@56775
   270
            "Isabelle Syslog", GUI.scrollable_text(PIDE.session.syslog_content()))
wenzelm@56715
   271
        }
wenzelm@39735
   272
wenzelm@56715
   273
      case Session.Ready =>
wenzelm@60910
   274
        Debugger.init_session(PIDE.session)
wenzelm@60075
   275
        PIDE.session.update_options(PIDE.options.value)
wenzelm@56715
   276
        PIDE.init_models()
wenzelm@57640
   277
wenzelm@57640
   278
        if (!Isabelle.continuous_checking) {
wenzelm@57640
   279
          GUI_Thread.later {
wenzelm@57640
   280
            val answer =
wenzelm@57640
   281
              GUI.confirm_dialog(jEdit.getActiveView,
wenzelm@57640
   282
                "Continuous checking of PIDE document",
wenzelm@57640
   283
                JOptionPane.YES_NO_OPTION,
wenzelm@57640
   284
                "Continuous checking is presently disabled:",
wenzelm@57640
   285
                "editor buffers will remain inactive!",
wenzelm@57640
   286
                "Enable continuous checking now?")
wenzelm@57640
   287
            if (answer == 0) Isabelle.continuous_checking = true
wenzelm@57640
   288
          }
wenzelm@57640
   289
        }
wenzelm@57640
   290
wenzelm@56770
   291
        delay_load.invoke()
wenzelm@44573
   292
wenzelm@56715
   293
      case Session.Shutdown =>
wenzelm@62062
   294
        GUI_Thread.later {
wenzelm@62062
   295
          delay_load.revoke()
wenzelm@62062
   296
          PIDE.exit_models(JEdit_Lib.jedit_buffers().toList)
wenzelm@62062
   297
        }
wenzelm@46740
   298
wenzelm@56715
   299
      case _ =>
wenzelm@39630
   300
    }
wenzelm@39630
   301
wenzelm@39630
   302
wenzelm@34618
   303
  /* main plugin plumbing */
wenzelm@34433
   304
wenzelm@34767
   305
  override def handleMessage(message: EBMessage)
wenzelm@34618
   306
  {
wenzelm@57612
   307
    GUI_Thread.assert {}
wenzelm@39630
   308
wenzelm@50205
   309
    if (PIDE.startup_failure.isDefined && !PIDE.startup_notified) {
wenzelm@49099
   310
      message match {
wenzelm@49100
   311
        case msg: EditorStarted =>
wenzelm@51616
   312
          GUI.error_dialog(null, "Isabelle plugin startup failure",
wenzelm@51616
   313
            GUI.scrollable_text(Exn.message(PIDE.startup_failure.get)),
wenzelm@49099
   314
            "Prover IDE inactive!")
wenzelm@50205
   315
          PIDE.startup_notified = true
wenzelm@49099
   316
        case _ =>
wenzelm@49099
   317
      }
wenzelm@49099
   318
    }
wenzelm@49099
   319
wenzelm@50205
   320
    if (PIDE.startup_failure.isEmpty) {
wenzelm@49099
   321
      message match {
wenzelm@49099
   322
        case msg: EditorStarted =>
wenzelm@57649
   323
          if (Distribution.is_identified && !Distribution.is_official) {
wenzelm@57680
   324
            GUI.warning_dialog(jEdit.getActiveView, "Isabelle version for testing",
wenzelm@60206
   325
              "This is " + Distribution.version + ".",
wenzelm@57649
   326
              "It is for testing only, not for production use.")
wenzelm@57649
   327
          }
wenzelm@57649
   328
wenzelm@64602
   329
          val view = jEdit.getActiveView()
wenzelm@64602
   330
wenzelm@64602
   331
          Session_Build.session_build(view)
wenzelm@63747
   332
wenzelm@64602
   333
          Keymap_Merge.check_dialog(view)
wenzelm@64602
   334
wenzelm@64602
   335
          PIDE.editor.hyperlink_position(true, Document.Snapshot.init,
wenzelm@64602
   336
            JEdit_Sessions.session_info().open_root).foreach(_.follow(view))
wenzelm@61277
   337
wenzelm@49099
   338
        case msg: BufferUpdate
wenzelm@57611
   339
        if msg.getWhat == BufferUpdate.LOADED ||
wenzelm@57611
   340
          msg.getWhat == BufferUpdate.PROPERTIES_CHANGED ||
wenzelm@57611
   341
          msg.getWhat == BufferUpdate.CLOSING =>
wenzelm@57611
   342
wenzelm@57611
   343
          if (msg.getWhat == BufferUpdate.CLOSING) {
wenzelm@57611
   344
            val buffer = msg.getBuffer
wenzelm@57611
   345
            if (buffer != null) PIDE.editor.remove_node(PIDE.resources.node_name(msg.getBuffer))
wenzelm@57611
   346
          }
wenzelm@50205
   347
          if (PIDE.session.is_ready) {
wenzelm@55791
   348
            delay_init.invoke()
wenzelm@55791
   349
            delay_load.invoke()
wenzelm@49099
   350
          }
wenzelm@34784
   351
wenzelm@49099
   352
        case msg: EditPaneUpdate
wenzelm@60215
   353
        if msg.getWhat == EditPaneUpdate.BUFFER_CHANGING ||
wenzelm@49099
   354
            msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
wenzelm@49099
   355
            msg.getWhat == EditPaneUpdate.CREATED ||
wenzelm@60215
   356
            msg.getWhat == EditPaneUpdate.DESTROYED =>
wenzelm@49099
   357
          val edit_pane = msg.getEditPane
wenzelm@49099
   358
          val buffer = edit_pane.getBuffer
wenzelm@49099
   359
          val text_area = edit_pane.getTextArea
wenzelm@49099
   360
wenzelm@49099
   361
          if (buffer != null && text_area != null) {
wenzelm@49099
   362
            if (msg.getWhat == EditPaneUpdate.BUFFER_CHANGED ||
wenzelm@49099
   363
                msg.getWhat == EditPaneUpdate.CREATED) {
wenzelm@50205
   364
              if (PIDE.session.is_ready)
wenzelm@50205
   365
                PIDE.init_view(buffer, text_area)
wenzelm@49099
   366
            }
wenzelm@52867
   367
            else {
wenzelm@53244
   368
              PIDE.dismissed_popups(text_area.getView)
wenzelm@52867
   369
              PIDE.exit_view(buffer, text_area)
wenzelm@52867
   370
            }
wenzelm@53274
   371
wenzelm@53274
   372
            if (msg.getWhat == EditPaneUpdate.CREATED)
wenzelm@53274
   373
              Completion_Popup.Text_Area.init(text_area)
wenzelm@53274
   374
wenzelm@53274
   375
            if (msg.getWhat == EditPaneUpdate.DESTROYED)
wenzelm@53274
   376
              Completion_Popup.Text_Area.exit(text_area)
wenzelm@43510
   377
          }
wenzelm@34784
   378
wenzelm@49099
   379
        case msg: PropertiesChanged =>
wenzelm@62264
   380
          for {
wenzelm@62264
   381
            view <- JEdit_Lib.jedit_views
wenzelm@62264
   382
            edit_pane <- JEdit_Lib.jedit_edit_panes(view)
wenzelm@62264
   383
          } {
wenzelm@62264
   384
            val buffer = edit_pane.getBuffer
wenzelm@62264
   385
            val text_area = edit_pane.getTextArea
wenzelm@62264
   386
            if (buffer != null && text_area != null) PIDE.init_view(buffer, text_area)
wenzelm@62264
   387
          }
wenzelm@62264
   388
wenzelm@56558
   389
          PIDE.spell_checker.update(PIDE.options.value)
wenzelm@52084
   390
          PIDE.session.update_options(PIDE.options.value)
wenzelm@34784
   391
wenzelm@49099
   392
        case _ =>
wenzelm@49099
   393
      }
wenzelm@34318
   394
    }
wenzelm@34318
   395
  }
wenzelm@34318
   396
wenzelm@34618
   397
  override def start()
wenzelm@49099
   398
  {
wenzelm@49099
   399
    try {
wenzelm@50709
   400
      Debug.DISABLE_SEARCH_DIALOG_POOL = true
wenzelm@50709
   401
wenzelm@50205
   402
      PIDE.plugin = this
wenzelm@62917
   403
      PIDE.options.store(Options.init())
wenzelm@53337
   404
      PIDE.completion_history.load()
wenzelm@56558
   405
      PIDE.spell_checker.update(PIDE.options.value)
wenzelm@49245
   406
wenzelm@49099
   407
      SyntaxUtilities.setStyleExtender(new Token_Markup.Style_Extender)
wenzelm@49099
   408
      if (ModeProvider.instance.isInstanceOf[ModeProvider])
wenzelm@49099
   409
        ModeProvider.instance = new Token_Markup.Mode_Provider(ModeProvider.instance)
wenzelm@48870
   410
wenzelm@53274
   411
      JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.init _)
wenzelm@53274
   412
wenzelm@62973
   413
      val content = JEdit_Sessions.session_content(false)
wenzelm@56801
   414
      val resources =
wenzelm@56801
   415
        new JEdit_Resources(content.loaded_theories, content.known_theories, content.syntax)
wenzelm@49524
   416
wenzelm@62051
   417
      PIDE.session.stop()
wenzelm@56208
   418
      PIDE.session = new Session(resources) {
wenzelm@50207
   419
        override def output_delay = PIDE.options.seconds("editor_output_delay")
wenzelm@57867
   420
        override def prune_delay = PIDE.options.seconds("editor_prune_delay")
wenzelm@57974
   421
        override def syslog_limit = PIDE.options.int("editor_syslog_limit")
wenzelm@50205
   422
        override def reparse_limit = PIDE.options.int("editor_reparse_limit")
wenzelm@49288
   423
      }
wenzelm@48870
   424
wenzelm@56715
   425
      PIDE.session.phase_changed += session_phase
wenzelm@50205
   426
      PIDE.startup_failure = None
wenzelm@49099
   427
    }
wenzelm@49099
   428
    catch {
wenzelm@49099
   429
      case exn: Throwable =>
wenzelm@50205
   430
        PIDE.startup_failure = Some(exn)
wenzelm@50205
   431
        PIDE.startup_notified = false
wenzelm@62228
   432
        Log.log(Log.ERROR, this, exn)
wenzelm@49099
   433
    }
wenzelm@34318
   434
  }
wenzelm@34618
   435
wenzelm@39628
   436
  override def stop()
wenzelm@34618
   437
  {
wenzelm@53274
   438
    JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.exit _)
wenzelm@53274
   439
wenzelm@53337
   440
    if (PIDE.startup_failure.isEmpty) {
wenzelm@50205
   441
      PIDE.options.value.save_prefs()
wenzelm@53337
   442
      PIDE.completion_history.value.save()
wenzelm@53337
   443
    }
wenzelm@49245
   444
wenzelm@56715
   445
    PIDE.session.phase_changed -= session_phase
wenzelm@50344
   446
    PIDE.exit_models(JEdit_Lib.jedit_buffers().toList)
wenzelm@50205
   447
    PIDE.session.stop()
wenzelm@34318
   448
  }
wenzelm@34318
   449
}