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