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