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