src/Pure/System/session.scala
author wenzelm
Thu, 12 Aug 2010 13:49:08 +0200
changeset 38360 53224a4d2f0e
parent 38359 96b22dfeb56a
child 38363 af7f41a8a0a8
permissions -rw-r--r--
specific Session.Commands_Changed;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36676
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     1
/*  Title:      Pure/System/session.scala
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     2
    Author:     Makarius
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
     3
    Options:    :folding=explicit:collapseFolds=1:
36676
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     4
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     5
Isabelle session, potentially with running prover.
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     6
*/
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
     7
34871
e596a0b71f3c incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents: 34859
diff changeset
     8
package isabelle
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
     9
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    10
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
    11
import scala.actors.TIMEOUT
38226
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
    12
import scala.actors.Actor
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    13
import scala.actors.Actor._
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    14
34815
6bae73cd8e33 unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents: 34813
diff changeset
    15
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    16
object Session
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    17
{
34813
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    18
  /* events */
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    19
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    20
  case object Global_Settings
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    21
  case object Perspective
38360
53224a4d2f0e specific Session.Commands_Changed;
wenzelm
parents: 38359
diff changeset
    22
  case class Commands_Changed(set: Set[Command])
53224a4d2f0e specific Session.Commands_Changed;
wenzelm
parents: 38359
diff changeset
    23
34813
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    24
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    25
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    26
  /* managed entities */
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    27
38355
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    28
  type Entity_ID = Long
34813
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    29
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    30
  trait Entity
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    31
  {
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    32
    val id: Entity_ID
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
    33
    def consume(message: XML.Tree, forward: Command => Unit): Unit
34813
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    34
  }
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    35
}
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    36
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    37
34851
304a86164dd2 provide global "Isabelle" within interpreter loop -- using import instead of val avoids pontential conflicts with later import isabelle.jedit._;
wenzelm
parents: 34848
diff changeset
    38
class Session(system: Isabelle_System)
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    39
{
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    40
  /* real time parameters */  // FIXME properties or settings (!?)
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    41
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    42
  // user input (e.g. text edits, cursor movement)
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    43
  val input_delay = 300
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    44
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    45
  // prover output (markup, common messages)
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    46
  val output_delay = 100
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    47
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    48
  // GUI layout updates
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    49
  val update_delay = 500
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    50
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    51
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    52
  /* pervasive event buses */
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    53
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    54
  val global_settings = new Event_Bus[Session.Global_Settings.type]
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    55
  val raw_results = new Event_Bus[Isabelle_Process.Result]
37065
2a73253b5898 separate event bus and dockable for raw output (stdout);
wenzelm
parents: 37063
diff changeset
    56
  val raw_output = new Event_Bus[Isabelle_Process.Result]
38360
53224a4d2f0e specific Session.Commands_Changed;
wenzelm
parents: 38359
diff changeset
    57
  val commands_changed = new Event_Bus[Session.Commands_Changed]
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    58
  val perspective = new Event_Bus[Session.Perspective.type]
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    59
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    60
34778
8eccd35e975e removed unused Session.prover_logic;
wenzelm
parents: 34777
diff changeset
    61
  /* unique ids */
8eccd35e975e removed unused Session.prover_logic;
wenzelm
parents: 34777
diff changeset
    62
38355
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    63
  private var id_count: Long = 0
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    64
  def create_id(): Session.Entity_ID = synchronized {
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    65
    require(id_count > java.lang.Long.MIN_VALUE)
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    66
    id_count -= 1
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    67
    id_count
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    68
  }
34778
8eccd35e975e removed unused Session.prover_logic;
wenzelm
parents: 34777
diff changeset
    69
8eccd35e975e removed unused Session.prover_logic;
wenzelm
parents: 34777
diff changeset
    70
34826
6b38fc0b3406 eliminated redundant session documents database;
wenzelm
parents: 34825
diff changeset
    71
6b38fc0b3406 eliminated redundant session documents database;
wenzelm
parents: 34825
diff changeset
    72
  /** main actor **/
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    73
34851
304a86164dd2 provide global "Isabelle" within interpreter loop -- using import instead of val avoids pontential conflicts with later import isabelle.jedit._;
wenzelm
parents: 34848
diff changeset
    74
  @volatile private var syntax = new Outer_Syntax(system.symbols)
34819
86cb7f8e5a0d tuned signature;
wenzelm
parents: 34818
diff changeset
    75
  def current_syntax: Outer_Syntax = syntax
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    76
34816
d33312514220 maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents: 34815
diff changeset
    77
  @volatile private var entities = Map[Session.Entity_ID, Session.Entity]()
d33312514220 maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents: 34815
diff changeset
    78
  def lookup_entity(id: Session.Entity_ID): Option[Session.Entity] = entities.get(id)
34835
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
    79
  def lookup_command(id: Session.Entity_ID): Option[Command] =
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
    80
    lookup_entity(id) match {
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
    81
      case Some(cmd: Command) => Some(cmd)
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
    82
      case _ => None
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
    83
    }
34816
d33312514220 maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents: 34815
diff changeset
    84
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
    85
  private case class Started(timeout: Int, args: List[String])
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    86
  private case object Stop
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    87
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
    88
  private lazy val session_actor = actor {
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    89
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    90
    var prover: Isabelle_Process with Isar_Document = null
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    91
34816
d33312514220 maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents: 34815
diff changeset
    92
    def register(entity: Session.Entity) { entities += (entity.id -> entity) }
d33312514220 maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents: 34815
diff changeset
    93
38150
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
    94
    var documents = Map[Document.Version_ID, Document]()
34835
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
    95
    def register_document(doc: Document) { documents += (doc.id -> doc) }
38150
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
    96
    register_document(Document.init)
34835
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
    97
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    98
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    99
    /* document changes */
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   100
38227
6bbb42843b6e concentrate structural document notions in document.scala;
wenzelm
parents: 38226
diff changeset
   101
    def handle_change(change: Document.Change)
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   102
    //{{{
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   103
    {
34824
ac35eee85f5c renamed current_document to recent_document (might be a bit older than current_change);
wenzelm
parents: 34823
diff changeset
   104
      require(change.parent.isDefined)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   105
38150
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   106
      val (node_edits, doc) = change.result.join
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   107
      val id_edits =
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   108
        node_edits map {
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   109
          case (name, None) => (name, None)
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   110
          case (name, Some(cmd_edits)) =>
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   111
            val chs =
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   112
              cmd_edits map {
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   113
                case (c1, c2) =>
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   114
                  val id1 = c1.map(_.id)
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   115
                  val id2 =
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   116
                    c2 match {
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   117
                      case None => None
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   118
                      case Some(command) =>
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   119
                        if (!lookup_command(command.id).isDefined) {
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   120
                          register(command)
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   121
                          prover.define_command(command.id, system.symbols.encode(command.source))
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   122
                        }
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   123
                        Some(command.id)
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   124
                    }
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   125
                  (id1, id2)
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   126
              }
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   127
            (name -> Some(chs))
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   128
        }
34835
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
   129
      register_document(doc)
38150
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   130
      prover.edit_document(change.parent.get.id, doc.id, id_edits)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   131
    }
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   132
    //}}}
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   133
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   134
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   135
    /* prover results */
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   136
34836
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   137
    def bad_result(result: Isabelle_Process.Result)
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   138
    {
37041
dae419819a80 bad_result: report fully explicit message;
wenzelm
parents: 36947
diff changeset
   139
      System.err.println("Ignoring prover result: " + result.message.toString)
34836
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   140
    }
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   141
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   142
    def handle_result(result: Isabelle_Process.Result)
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   143
    //{{{
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   144
    {
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   145
      raw_results.event(result)
34799
0330a4284a9b just one variable for outer syntax keywords and completion;
wenzelm
parents: 34795
diff changeset
   146
38230
ed147003de4b simplified type XML.Tree: embed Markup directly, avoid slightly odd triple;
wenzelm
parents: 38227
diff changeset
   147
      val target_id: Option[Session.Entity_ID] = Position.get_id(result.properties)
34813
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
   148
      val target: Option[Session.Entity] =
34835
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
   149
        target_id match {
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   150
          case None => None
34835
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
   151
          case Some(id) => lookup_entity(id)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   152
        }
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   153
      if (target.isDefined) target.get.consume(result.message, indicate_command_change)
37689
628eabe2213a simplified Isabelle_Process.Result: use markup directly;
wenzelm
parents: 37132
diff changeset
   154
      else if (result.is_status) {
34818
7df68a8f0e3e register Proof_Document instances as session entities -- handle Markup.EDIT messages locally;
wenzelm
parents: 34817
diff changeset
   155
        // global status message
34836
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   156
        result.body match {
34835
67733fd0e3fa back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents: 34833
diff changeset
   157
35013
f3d491658893 fixed spelling;
wenzelm
parents: 34871
diff changeset
   158
          // document state assignment
36682
3f989067f87d extractors for document updates;
wenzelm
parents: 36676
diff changeset
   159
          case List(Isar_Document.Assign(edits)) if target_id.isDefined =>
34836
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   160
            documents.get(target_id.get) match {
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   161
              case Some(doc) =>
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   162
                val states =
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   163
                  for {
36682
3f989067f87d extractors for document updates;
wenzelm
parents: 36676
diff changeset
   164
                    Isar_Document.Edit(cmd_id, state_id) <- edits
34836
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   165
                    cmd <- lookup_command(cmd_id)
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   166
                  } yield {
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   167
                    val st = cmd.assign_state(state_id)
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   168
                    register(st)
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   169
                    (cmd, st)
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   170
                  }
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   171
                doc.assign_states(states)
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   172
              case None => bad_result(result)
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   173
            }
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   174
36682
3f989067f87d extractors for document updates;
wenzelm
parents: 36676
diff changeset
   175
          // keyword declarations
36947
285b39022372 renamed Outer_Keyword to Keyword (in Scala);
wenzelm
parents: 36782
diff changeset
   176
          case List(Keyword.Command_Decl(name, kind)) => syntax += (name, kind)
285b39022372 renamed Outer_Keyword to Keyword (in Scala);
wenzelm
parents: 36782
diff changeset
   177
          case List(Keyword.Keyword_Decl(name)) => syntax += name
34836
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   178
34839
3457436a1110 more precise notion of bad messages;
wenzelm
parents: 34837
diff changeset
   179
          case _ => if (!result.is_ready) bad_result(result)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   180
        }
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   181
      }
37689
628eabe2213a simplified Isabelle_Process.Result: use markup directly;
wenzelm
parents: 37132
diff changeset
   182
      else if (result.kind == Markup.EXIT)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   183
        prover = null
37065
2a73253b5898 separate event bus and dockable for raw output (stdout);
wenzelm
parents: 37063
diff changeset
   184
      else if (result.is_raw)
2a73253b5898 separate event bus and dockable for raw output (stdout);
wenzelm
parents: 37063
diff changeset
   185
        raw_output.event(result)
37063
492bc98a8809 ignore system messages;
wenzelm
parents: 37041
diff changeset
   186
      else if (!result.is_system)   // FIXME syslog (!?)
34837
aa73039d5d14 result.is_ready is not bad;
wenzelm
parents: 34836
diff changeset
   187
        bad_result(result)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   188
    }
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   189
    //}}}
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   190
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   191
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   192
    /* prover startup */
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   193
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   194
    def startup_error(): String =
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   195
    {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   196
      val buf = new StringBuilder
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   197
      while (
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   198
        receiveWithin(0) {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   199
          case result: Isabelle_Process.Result =>
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   200
            if (result.is_raw) {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   201
              for (text <- XML.content(result.message))
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   202
                buf.append(text)
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   203
            }
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   204
            true
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   205
          case TIMEOUT => false
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   206
        }) {}
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   207
      buf.toString
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   208
    }
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   209
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   210
    def prover_startup(timeout: Int): Option[String] =
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   211
    {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   212
      receiveWithin(timeout) {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   213
        case result: Isabelle_Process.Result
37689
628eabe2213a simplified Isabelle_Process.Result: use markup directly;
wenzelm
parents: 37132
diff changeset
   214
          if result.kind == Markup.INIT =>
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   215
          while (receive {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   216
            case result: Isabelle_Process.Result =>
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   217
              handle_result(result); !result.is_ready
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   218
            }) {}
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   219
          None
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   220
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   221
        case result: Isabelle_Process.Result
37689
628eabe2213a simplified Isabelle_Process.Result: use markup directly;
wenzelm
parents: 37132
diff changeset
   222
          if result.kind == Markup.EXIT =>
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   223
          Some(startup_error())
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   224
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   225
        case TIMEOUT =>  // FIXME clarify
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   226
          prover.kill; Some(startup_error())
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   227
      }
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   228
    }
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   229
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   230
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   231
    /* main loop */
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   232
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   233
    val xml_cache = new XML.Cache(131071)
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   234
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   235
    loop {
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   236
      react {
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   237
        case Started(timeout, args) =>
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   238
          if (prover == null) {
34851
304a86164dd2 provide global "Isabelle" within interpreter loop -- using import instead of val avoids pontential conflicts with later import isabelle.jedit._;
wenzelm
parents: 34848
diff changeset
   239
            prover = new Isabelle_Process(system, self, args:_*) with Isar_Document
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   240
            val origin = sender
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   241
            val opt_err = prover_startup(timeout)
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   242
            if (opt_err.isDefined) prover = null
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   243
            origin ! opt_err
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   244
          }
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   245
          else reply(None)
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   246
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   247
        case Stop =>  // FIXME clarify; synchronous
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   248
          if (prover != null) {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   249
            prover.kill
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   250
            prover = null
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   251
          }
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   252
38227
6bbb42843b6e concentrate structural document notions in document.scala;
wenzelm
parents: 38226
diff changeset
   253
        case change: Document.Change if prover != null =>
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   254
          handle_change(change)
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   255
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   256
        case result: Isabelle_Process.Result =>
34795
c97335b7e8c3 cache results;
wenzelm
parents: 34792
diff changeset
   257
          handle_result(result.cache(xml_cache))
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   258
36782
0499d05663dd ignore spurious TIMEOUT messages, maybe caused by change of actor semantics in scala-2.8;
wenzelm
parents: 36682
diff changeset
   259
        case TIMEOUT =>  // FIXME clarify!
0499d05663dd ignore spurious TIMEOUT messages, maybe caused by change of actor semantics in scala-2.8;
wenzelm
parents: 36682
diff changeset
   260
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   261
        case bad if prover != null =>
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   262
          System.err.println("session_actor: ignoring bad message " + bad)
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   263
      }
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   264
    }
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   265
  }
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   266
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   267
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   268
38226
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   269
  /** buffered command changes (delay_first discipline) **/
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   270
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   271
  private lazy val command_change_buffer = actor
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   272
  //{{{
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   273
  {
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   274
    import scala.compat.Platform.currentTime
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   275
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   276
    var changed: Set[Command] = Set()
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   277
    var flush_time: Option[Long] = None
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   278
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   279
    def flush_timeout: Long =
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   280
      flush_time match {
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   281
        case None => 5000L
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   282
        case Some(time) => (time - currentTime) max 0
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   283
      }
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   284
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   285
    def flush()
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   286
    {
38360
53224a4d2f0e specific Session.Commands_Changed;
wenzelm
parents: 38359
diff changeset
   287
      if (!changed.isEmpty) commands_changed.event(Session.Commands_Changed(changed))
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   288
      changed = Set()
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   289
      flush_time = None
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   290
    }
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   291
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   292
    def invoke()
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   293
    {
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   294
      val now = currentTime
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   295
      flush_time match {
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
   296
        case None => flush_time = Some(now + output_delay)
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   297
        case Some(time) => if (now >= time) flush()
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   298
      }
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   299
    }
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   300
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   301
    loop {
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   302
      reactWithin(flush_timeout) {
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   303
        case command: Command => changed += command; invoke()
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   304
        case TIMEOUT => flush()
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   305
        case bad => System.err.println("command_change_buffer: ignoring bad message " + bad)
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   306
      }
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   307
    }
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   308
  }
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   309
  //}}}
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   310
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   311
  def indicate_command_change(command: Command)
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   312
  {
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   313
    command_change_buffer ! command
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   314
  }
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   315
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   316
38226
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   317
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   318
  /** editor history **/
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   319
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   320
  private case class Edit_Document(edits: List[Document.Node_Text_Edit])
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   321
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   322
  private val editor_history = new Actor
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   323
  {
38227
6bbb42843b6e concentrate structural document notions in document.scala;
wenzelm
parents: 38226
diff changeset
   324
    @volatile private var history = Document.Change.init
6bbb42843b6e concentrate structural document notions in document.scala;
wenzelm
parents: 38226
diff changeset
   325
    def current_change(): Document.Change = history
38226
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   326
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   327
    def act
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   328
    {
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   329
      loop {
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   330
        react {
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   331
          case Edit_Document(edits) =>
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   332
            val old_change = history
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   333
            val new_id = create_id()
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   334
            val result: isabelle.Future[(List[Document.Edit[Command]], Document)] =
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   335
              isabelle.Future.fork {
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   336
                val old_doc = old_change.join_document
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   337
                old_doc.await_assignment
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   338
                Document.text_edits(Session.this, old_doc, new_id, edits)
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   339
              }
38227
6bbb42843b6e concentrate structural document notions in document.scala;
wenzelm
parents: 38226
diff changeset
   340
            val new_change = new Document.Change(new_id, Some(old_change), edits, result)
38226
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   341
            history = new_change
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   342
            new_change.result.map(_ => session_actor ! new_change)
38260
d4a1c7a19be3 edit_document: synchronous reply to ensure consistent state wrt. calling (AWT) thread;
wenzelm
parents: 38230
diff changeset
   343
            reply(())
38226
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   344
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   345
          case bad => System.err.println("editor_model: ignoring bad message " + bad)
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   346
        }
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   347
      }
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   348
    }
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   349
  }
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   350
  editor_history.start
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   351
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   352
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   353
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   354
  /** main methods **/
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   355
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   356
  def started(timeout: Int, args: List[String]): Option[String] =
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   357
    (session_actor !? Started(timeout, args)).asInstanceOf[Option[String]]
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   358
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   359
  def stop() { session_actor ! Stop }
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   360
38359
96b22dfeb56a consider snapshot as service of Session, not Document.Change;
wenzelm
parents: 38355
diff changeset
   361
  def snapshot(name: String, pending_edits: List[Text_Edit]): Document.Snapshot =
96b22dfeb56a consider snapshot as service of Session, not Document.Change;
wenzelm
parents: 38355
diff changeset
   362
    editor_history.current_change().snapshot(name, pending_edits)
38260
d4a1c7a19be3 edit_document: synchronous reply to ensure consistent state wrt. calling (AWT) thread;
wenzelm
parents: 38230
diff changeset
   363
d4a1c7a19be3 edit_document: synchronous reply to ensure consistent state wrt. calling (AWT) thread;
wenzelm
parents: 38230
diff changeset
   364
  def edit_document(edits: List[Document.Node_Text_Edit]) { editor_history !? Edit_Document(edits) }
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   365
}