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