| author | wenzelm | 
| Tue, 20 May 2014 14:25:28 +0200 | |
| changeset 57021 | 6a8fd2ac6756 | 
| parent 56801 | 8dd9df88f647 | 
| child 57610 | 518e28a7c74b | 
| permissions | -rw-r--r-- | 
| 36676 | 1 | /* Title: Pure/PIDE/document.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 38150 
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
 wenzelm parents: 
37849diff
changeset | 4 | Document as collection of named nodes, each consisting of an editable | 
| 38418 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 5 | list of commands, associated with asynchronous execution process. | 
| 36676 | 6 | */ | 
| 34407 | 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: 
34868diff
changeset | 8 | package isabelle | 
| 34318 
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
 wenzelm parents: diff
changeset | 9 | |
| 34760 | 10 | |
| 38150 
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
 wenzelm parents: 
37849diff
changeset | 11 | import scala.collection.mutable | 
| 37073 | 12 | |
| 13 | ||
| 34823 | 14 | object Document | 
| 34483 | 15 | {
 | 
| 38424 | 16 | /** document structure **/ | 
| 17 | ||
| 52977 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 18 | /* overlays -- print functions with arguments */ | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 19 | |
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 20 | object Overlays | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 21 |   {
 | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 22 | val empty = new Overlays(Map.empty) | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 23 | } | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 24 | |
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 25 | final class Overlays private(rep: Map[Node.Name, Node.Overlays]) | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 26 |   {
 | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 27 | def apply(name: Document.Node.Name): Node.Overlays = | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 28 | rep.getOrElse(name, Node.Overlays.empty) | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 29 | |
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 30 | private def update(name: Node.Name, f: Node.Overlays => Node.Overlays): Overlays = | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 31 |     {
 | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 32 | val node_overlays = f(apply(name)) | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 33 | new Overlays(if (node_overlays.is_empty) rep - name else rep + (name -> node_overlays)) | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 34 | } | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 35 | |
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 36 | def insert(command: Command, fn: String, args: List[String]): Overlays = | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 37 | update(command.node_name, _.insert(command, fn, args)) | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 38 | |
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 39 | def remove(command: Command, fn: String, args: List[String]): Overlays = | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 40 | update(command.node_name, _.remove(command, fn, args)) | 
| 55800 | 41 | |
| 42 |     override def toString: String = rep.mkString("Overlays(", ",", ")")
 | |
| 52977 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 43 | } | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 44 | |
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 45 | |
| 55783 | 46 | /* document blobs: auxiliary files */ | 
| 47 | ||
| 56746 | 48 | sealed case class Blob(bytes: Bytes, chunk: Symbol.Text_Chunk, changed: Boolean) | 
| 56335 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 wenzelm parents: 
56314diff
changeset | 49 |   {
 | 
| 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 wenzelm parents: 
56314diff
changeset | 50 | def unchanged: Blob = copy(changed = false) | 
| 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 wenzelm parents: 
56314diff
changeset | 51 | } | 
| 55783 | 52 | |
| 53 | object Blobs | |
| 54 |   {
 | |
| 56336 | 55 | def apply(blobs: Map[Node.Name, Blob]): Blobs = new Blobs(blobs) | 
| 55783 | 56 | val empty: Blobs = apply(Map.empty) | 
| 57 | } | |
| 58 | ||
| 56336 | 59 | final class Blobs private(blobs: Map[Node.Name, Blob]) | 
| 55783 | 60 |   {
 | 
| 55801 | 61 | private lazy val digests: Map[SHA1.Digest, Blob] = | 
| 62 | for ((_, blob) <- blobs) yield (blob.bytes.sha1_digest, blob) | |
| 63 | ||
| 64 | def get(digest: SHA1.Digest): Option[Blob] = digests.get(digest) | |
| 56336 | 65 | def get(name: Node.Name): Option[Blob] = blobs.get(name) | 
| 55783 | 66 | |
| 67 | def changed(name: Node.Name): Boolean = | |
| 68 |       get(name) match {
 | |
| 69 | case Some(blob) => blob.changed | |
| 70 | case None => false | |
| 71 | } | |
| 72 | ||
| 55800 | 73 |     override def toString: String = blobs.mkString("Blobs(", ",", ")")
 | 
| 55783 | 74 | } | 
| 75 | ||
| 76 | ||
| 77 | /* document nodes: theories and auxiliary files */ | |
| 38424 | 78 | |
| 44615 | 79 | type Edit[A, B] = (Node.Name, Node.Edit[A, B]) | 
| 44384 | 80 | type Edit_Text = Edit[Text.Edit, Text.Perspective] | 
| 52849 | 81 | type Edit_Command = Edit[Command.Edit, Command.Perspective] | 
| 38151 | 82 | |
| 83 | object Node | |
| 84 |   {
 | |
| 52887 | 85 | val empty: Node = new Node() | 
| 86 | ||
| 87 | ||
| 88 | /* header and name */ | |
| 89 | ||
| 48707 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 90 | sealed case class Header( | 
| 46938 
cda018294515
some support for outer syntax keyword declarations within theory header;
 wenzelm parents: 
46814diff
changeset | 91 | imports: List[Name], | 
| 48706 | 92 | keywords: Thy_Header.Keywords, | 
| 48707 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 93 | errors: List[String] = Nil) | 
| 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 94 |     {
 | 
| 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 95 | def error(msg: String): Header = copy(errors = errors ::: List(msg)) | 
| 54549 
2a3053472ec3
actually expose errors of cumulative theory dependencies;
 wenzelm parents: 
54530diff
changeset | 96 | |
| 
2a3053472ec3
actually expose errors of cumulative theory dependencies;
 wenzelm parents: 
54530diff
changeset | 97 | def cat_errors(msg2: String): Header = | 
| 
2a3053472ec3
actually expose errors of cumulative theory dependencies;
 wenzelm parents: 
54530diff
changeset | 98 | copy(errors = errors.map(msg1 => Library.cat_message(msg1, msg2))) | 
| 48707 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 99 | } | 
| 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 100 | |
| 51294 
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
 wenzelm parents: 
51293diff
changeset | 101 | def bad_header(msg: String): Header = Header(Nil, Nil, List(msg)) | 
| 46737 | 102 | |
| 54509 
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
 wenzelm parents: 
54462diff
changeset | 103 |     val no_header = bad_header("No theory header")
 | 
| 
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
 wenzelm parents: 
54462diff
changeset | 104 | |
| 44957 
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
 wenzelm parents: 
44676diff
changeset | 105 | object Name | 
| 
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
 wenzelm parents: 
44676diff
changeset | 106 |     {
 | 
| 54515 | 107 |       val empty = Name("")
 | 
| 46723 | 108 | |
| 109 | object Ordering extends scala.math.Ordering[Name] | |
| 110 |       {
 | |
| 111 | def compare(name1: Name, name2: Name): Int = name1.node compare name2.node | |
| 112 | } | |
| 44957 
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
 wenzelm parents: 
44676diff
changeset | 113 | } | 
| 52887 | 114 | |
| 54515 | 115 | sealed case class Name(node: String, master_dir: String = "", theory: String = "") | 
| 44615 | 116 |     {
 | 
| 117 | override def hashCode: Int = node.hashCode | |
| 118 | override def equals(that: Any): Boolean = | |
| 119 |         that match {
 | |
| 120 | case other: Name => node == other.node | |
| 121 | case _ => false | |
| 122 | } | |
| 54509 
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
 wenzelm parents: 
54462diff
changeset | 123 | |
| 
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
 wenzelm parents: 
54462diff
changeset | 124 | def is_theory: Boolean = !theory.isEmpty | 
| 54510 | 125 | override def toString: String = if (is_theory) theory else node | 
| 56801 
8dd9df88f647
some support for session-qualified theories: allow to refer to resources via qualified name instead of odd file-system path;
 wenzelm parents: 
56746diff
changeset | 126 | |
| 
8dd9df88f647
some support for session-qualified theories: allow to refer to resources via qualified name instead of odd file-system path;
 wenzelm parents: 
56746diff
changeset | 127 | def map(f: String => String): Name = copy(f(node), f(master_dir), theory) | 
| 44615 | 128 | } | 
| 129 | ||
| 52887 | 130 | |
| 52977 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 131 | /* node overlays */ | 
| 52887 | 132 | |
| 133 | object Overlays | |
| 134 |     {
 | |
| 52976 | 135 | val empty = new Overlays(Multi_Map.empty) | 
| 52887 | 136 | } | 
| 137 | ||
| 52977 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 138 | final class Overlays private(rep: Multi_Map[Command, (String, List[String])]) | 
| 52887 | 139 |     {
 | 
| 140 | def commands: Set[Command] = rep.keySet | |
| 141 | def is_empty: Boolean = rep.isEmpty | |
| 52977 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 142 | def dest: List[(Command, (String, List[String]))] = rep.iterator.toList | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 143 | def insert(cmd: Command, fn: String, args: List[String]): Overlays = | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 144 | new Overlays(rep.insert(cmd, (fn, args))) | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 145 | def remove(cmd: Command, fn: String, args: List[String]): Overlays = | 
| 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 wenzelm parents: 
52976diff
changeset | 146 | new Overlays(rep.remove(cmd, (fn, args))) | 
| 55800 | 147 | |
| 148 |       override def toString: String = rep.mkString("Node.Overlays(", ",", ")")
 | |
| 52887 | 149 | } | 
| 150 | ||
| 151 | ||
| 152 | /* edits */ | |
| 153 | ||
| 44384 | 154 | sealed abstract class Edit[A, B] | 
| 44156 | 155 |     {
 | 
| 44383 | 156 | def foreach(f: A => Unit) | 
| 157 |       {
 | |
| 44156 | 158 |         this match {
 | 
| 44383 | 159 | case Edits(es) => es.foreach(f) | 
| 160 | case _ => | |
| 44156 | 161 | } | 
| 44383 | 162 | } | 
| 44156 | 163 | } | 
| 44384 | 164 | case class Clear[A, B]() extends Edit[A, B] | 
| 56335 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 wenzelm parents: 
56314diff
changeset | 165 | case class Blob[A, B](blob: Document.Blob) extends Edit[A, B] | 
| 54562 
301a721af68b
clarified node edits sent to prover -- Clear/Blob only required for text edits within editor;
 wenzelm parents: 
54549diff
changeset | 166 | |
| 44384 | 167 | case class Edits[A, B](edits: List[A]) extends Edit[A, B] | 
| 48707 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 168 | case class Deps[A, B](header: Header) extends Edit[A, B] | 
| 52849 | 169 | case class Perspective[A, B](required: Boolean, visible: B, overlays: Overlays) extends Edit[A, B] | 
| 52808 
143f225e50f5
allow explicit indication of required node: full eval, no prints;
 wenzelm parents: 
52568diff
changeset | 170 | type Perspective_Text = Perspective[Text.Edit, Text.Perspective] | 
| 52849 | 171 | type Perspective_Command = Perspective[Command.Edit, Command.Perspective] | 
| 44156 | 172 | |
| 52887 | 173 | |
| 174 | /* commands */ | |
| 175 | ||
| 52901 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 176 | object Commands | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 177 |     {
 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 178 | def apply(commands: Linear_Set[Command]): Commands = new Commands(commands) | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 179 | val empty: Commands = apply(Linear_Set.empty) | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 180 | |
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 181 | def starts(commands: Iterator[Command], offset: Text.Offset = 0) | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 182 | : Iterator[(Command, Text.Offset)] = | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 183 |       {
 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 184 | var i = offset | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 185 |         for (command <- commands) yield {
 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 186 | val start = i | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 187 | i += command.length | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 188 | (command, start) | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 189 | } | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 190 | } | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 191 | |
| 56398 
15d0821c8667
afford larger full_index, to save a few milliseconds during rendering (notably text_overview);
 wenzelm parents: 
56394diff
changeset | 192 | private val block_size = 256 | 
| 52901 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 193 | } | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 194 | |
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 195 | final class Commands private(val commands: Linear_Set[Command]) | 
| 38227 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 196 |     {
 | 
| 56314 | 197 | lazy val load_commands: List[Command] = | 
| 54513 | 198 | commands.iterator.filter(cmd => !cmd.blobs.isEmpty).toList | 
| 54462 | 199 | |
| 52901 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 200 | private lazy val full_index: (Array[(Command, Text.Offset)], Text.Range) = | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 201 |       {
 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 202 | val blocks = new mutable.ListBuffer[(Command, Text.Offset)] | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 203 | var next_block = 0 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 204 | var last_stop = 0 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 205 |         for ((command, start) <- Commands.starts(commands.iterator)) {
 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 206 | last_stop = start + command.length | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 207 |           while (last_stop + 1 > next_block) {
 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 208 | blocks += (command -> start) | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 209 | next_block += Commands.block_size | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 210 | } | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 211 | } | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 212 | (blocks.toArray, Text.Range(0, last_stop)) | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 213 | } | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 214 | |
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 215 | private def full_range: Text.Range = full_index._2 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 216 | |
| 56373 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 wenzelm parents: 
56372diff
changeset | 217 | def iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = | 
| 52901 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 218 |       {
 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 219 |         if (!commands.isEmpty && full_range.contains(i)) {
 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 220 | val (cmd0, start0) = full_index._1(i / Commands.block_size) | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 221 |           Node.Commands.starts(commands.iterator(cmd0), start0) dropWhile {
 | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 222 | case (cmd, start) => start + cmd.length <= i } | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 223 | } | 
| 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 224 | else Iterator.empty | 
| 38227 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 225 | } | 
| 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 226 | } | 
| 38151 | 227 | } | 
| 228 | ||
| 46712 | 229 | final class Node private( | 
| 56335 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 wenzelm parents: 
56314diff
changeset | 230 | val get_blob: Option[Document.Blob] = None, | 
| 48707 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 231 |     val header: Node.Header = Node.bad_header("Bad theory header"),
 | 
| 52849 | 232 | val perspective: Node.Perspective_Command = | 
| 52887 | 233 | Node.Perspective(false, Command.Perspective.empty, Node.Overlays.empty), | 
| 52901 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 234 | _commands: Node.Commands = Node.Commands.empty) | 
| 38151 | 235 |   {
 | 
| 46680 | 236 | def clear: Node = new Node(header = header) | 
| 237 | ||
| 56335 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 wenzelm parents: 
56314diff
changeset | 238 | def init_blob(blob: Document.Blob): Node = new Node(Some(blob.unchanged)) | 
| 55435 
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
 wenzelm parents: 
55434diff
changeset | 239 | |
| 48707 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 240 | def update_header(new_header: Node.Header): Node = | 
| 56335 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 wenzelm parents: 
56314diff
changeset | 241 | new Node(get_blob, new_header, perspective, _commands) | 
| 46680 | 242 | |
| 52849 | 243 | def update_perspective(new_perspective: Node.Perspective_Command): Node = | 
| 56335 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 wenzelm parents: 
56314diff
changeset | 244 | new Node(get_blob, header, new_perspective, _commands) | 
| 46680 | 245 | |
| 52849 | 246 | def same_perspective(other_perspective: Node.Perspective_Command): Boolean = | 
| 247 | perspective.required == other_perspective.required && | |
| 248 | perspective.visible.same(other_perspective.visible) && | |
| 249 | perspective.overlays == other_perspective.overlays | |
| 52808 
143f225e50f5
allow explicit indication of required node: full eval, no prints;
 wenzelm parents: 
52568diff
changeset | 250 | |
| 52901 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 251 | def commands: Linear_Set[Command] = _commands.commands | 
| 56314 | 252 | def load_commands: List[Command] = _commands.load_commands | 
| 43697 
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
 wenzelm parents: 
43662diff
changeset | 253 | |
| 52901 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 254 | def update_commands(new_commands: Linear_Set[Command]): Node = | 
| 52918 
038458a4d11b
proper low-level comparison -- heed warning by Scala compiler;
 wenzelm parents: 
52901diff
changeset | 255 | if (new_commands eq _commands.commands) this | 
| 56335 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 wenzelm parents: 
56314diff
changeset | 256 | else new Node(get_blob, header, perspective, Node.Commands(new_commands)) | 
| 38151 | 257 | |
| 56373 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 wenzelm parents: 
56372diff
changeset | 258 | def command_iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = | 
| 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 wenzelm parents: 
56372diff
changeset | 259 | _commands.iterator(i) | 
| 38151 | 260 | |
| 56373 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 wenzelm parents: 
56372diff
changeset | 261 | def command_iterator(range: Text.Range): Iterator[(Command, Text.Offset)] = | 
| 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 wenzelm parents: 
56372diff
changeset | 262 |       command_iterator(range.start) takeWhile { case (_, start) => start < range.stop }
 | 
| 38151 | 263 | |
| 38879 
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
 wenzelm parents: 
38872diff
changeset | 264 | def command_start(cmd: Command): Option[Text.Offset] = | 
| 52901 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 wenzelm parents: 
52900diff
changeset | 265 | Node.Commands.starts(commands.iterator).find(_._1 == cmd).map(_._2) | 
| 38151 | 266 | } | 
| 267 | ||
| 268 | ||
| 46723 | 269 | /* development graph */ | 
| 270 | ||
| 271 | object Nodes | |
| 272 |   {
 | |
| 273 | val empty: Nodes = new Nodes(Graph.empty(Node.Name.Ordering)) | |
| 274 | } | |
| 275 | ||
| 276 | final class Nodes private(graph: Graph[Node.Name, Node]) | |
| 277 |   {
 | |
| 278 | def get_name(s: String): Option[Node.Name] = | |
| 56372 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 wenzelm parents: 
56354diff
changeset | 279 | graph.keys_iterator.find(name => name.node == s) | 
| 46723 | 280 | |
| 281 | def apply(name: Node.Name): Node = | |
| 282 | graph.default_node(name, Node.empty).get_node(name) | |
| 283 | ||
| 284 | def + (entry: (Node.Name, Node)): Nodes = | |
| 285 |     {
 | |
| 286 | val (name, node) = entry | |
| 48707 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 wenzelm parents: 
48706diff
changeset | 287 | val imports = node.header.imports | 
| 46723 | 288 | val graph1 = | 
| 46739 
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
 wenzelm parents: 
46737diff
changeset | 289 | (graph.default_node(name, Node.empty) /: imports)((g, p) => g.default_node(p, Node.empty)) | 
| 46723 | 290 | val graph2 = (graph1 /: graph1.imm_preds(name))((g, dep) => g.del_edge(dep, name)) | 
| 46739 
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
 wenzelm parents: 
46737diff
changeset | 291 | val graph3 = (graph2 /: imports)((g, dep) => g.add_edge(dep, name)) | 
| 46723 | 292 | new Nodes(graph3.map_node(name, _ => node)) | 
| 293 | } | |
| 294 | ||
| 56372 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 wenzelm parents: 
56354diff
changeset | 295 | def iterator: Iterator[(Node.Name, Node)] = | 
| 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 wenzelm parents: 
56354diff
changeset | 296 |       graph.iterator.map({ case (name, (node, _)) => (name, node) })
 | 
| 46723 | 297 | |
| 56314 | 298 | def load_commands(file_name: Node.Name): List[Command] = | 
| 54528 | 299 |       (for {
 | 
| 56372 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 wenzelm parents: 
56354diff
changeset | 300 | (_, node) <- iterator | 
| 56314 | 301 | cmd <- node.load_commands.iterator | 
| 54530 
2c1440f70028
ranges of thy_load commands count as visible within perspective;
 wenzelm parents: 
54528diff
changeset | 302 | name <- cmd.blobs_names.iterator | 
| 54528 | 303 | if name == file_name | 
| 304 | } yield cmd).toList | |
| 305 | ||
| 46942 
f5c2d66faa04
basic support for outer syntax keywords in theory header;
 wenzelm parents: 
46941diff
changeset | 306 | def descendants(names: List[Node.Name]): List[Node.Name] = graph.all_succs(names) | 
| 46723 | 307 | def topological_order: List[Node.Name] = graph.topological_order | 
| 56337 | 308 | |
| 309 |     override def toString: String = topological_order.mkString("Nodes(", ",", ")")
 | |
| 46723 | 310 | } | 
| 311 | ||
| 312 | ||
| 38424 | 313 | |
| 314 | /** versioning **/ | |
| 315 | ||
| 316 | /* particular document versions */ | |
| 34485 | 317 | |
| 38417 | 318 | object Version | 
| 319 |   {
 | |
| 46681 | 320 | val init: Version = new Version() | 
| 321 | ||
| 56394 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 wenzelm parents: 
56393diff
changeset | 322 | def make(syntax: Option[Prover.Syntax], nodes: Nodes): Version = | 
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 323 | new Version(Document_ID.make(), syntax, nodes) | 
| 38417 | 324 | } | 
| 325 | ||
| 46712 | 326 | final class Version private( | 
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 327 | val id: Document_ID.Version = Document_ID.none, | 
| 56394 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 wenzelm parents: 
56393diff
changeset | 328 | val syntax: Option[Prover.Syntax] = None, | 
| 46723 | 329 | val nodes: Nodes = Nodes.empty) | 
| 46941 | 330 |   {
 | 
| 55777 | 331 |     override def toString: String = "Version(" + id + ")"
 | 
| 46941 | 332 | } | 
| 34660 | 333 | |
| 34859 | 334 | |
| 38424 | 335 | /* changes of plain text, eventually resulting in document edits */ | 
| 38227 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 336 | |
| 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 337 | object Change | 
| 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 338 |   {
 | 
| 46678 | 339 | val init: Change = new Change() | 
| 340 | ||
| 341 | def make(previous: Future[Version], edits: List[Edit_Text], version: Future[Version]): Change = | |
| 342 | new Change(Some(previous), edits, version) | |
| 38227 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 343 | } | 
| 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 344 | |
| 46712 | 345 | final class Change private( | 
| 46677 | 346 | val previous: Option[Future[Version]] = Some(Future.value(Version.init)), | 
| 347 | val edits: List[Edit_Text] = Nil, | |
| 348 | val version: Future[Version] = Future.value(Version.init)) | |
| 38227 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 349 |   {
 | 
| 44672 | 350 | def is_finished: Boolean = | 
| 351 |       (previous match { case None => true case Some(future) => future.is_finished }) &&
 | |
| 352 | version.is_finished | |
| 353 | ||
| 46678 | 354 | def truncate: Change = new Change(None, Nil, version) | 
| 38227 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 355 | } | 
| 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 356 | |
| 
6bbb42843b6e
concentrate structural document notions in document.scala;
 wenzelm parents: 
38220diff
changeset | 357 | |
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 358 | /* history navigation */ | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 359 | |
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 360 | object History | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 361 |   {
 | 
| 46679 | 362 | val init: History = new History() | 
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 363 | } | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 364 | |
| 46712 | 365 | final class History private( | 
| 46679 | 366 | val undo_list: List[Change] = List(Change.init)) // non-empty list | 
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 367 |   {
 | 
| 46679 | 368 | def tip: Change = undo_list.head | 
| 369 | def + (change: Change): History = new History(change :: undo_list) | |
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 370 | |
| 46679 | 371 | def prune(check: Change => Boolean, retain: Int): Option[(List[Change], History)] = | 
| 372 |     {
 | |
| 373 | val n = undo_list.iterator.zipWithIndex.find(p => check(p._1)).get._2 + 1 | |
| 374 | val (retained, dropped) = undo_list.splitAt(n max retain) | |
| 375 | ||
| 376 |       retained.splitAt(retained.length - 1) match {
 | |
| 377 | case (prefix, List(last)) => Some(dropped, new History(prefix ::: List(last.truncate))) | |
| 378 | case _ => None | |
| 379 | } | |
| 380 | } | |
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 381 | } | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 382 | |
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 383 | |
| 55820 
61869776ce1f
tuned signature -- more explicit Document.Elements;
 wenzelm parents: 
55801diff
changeset | 384 | /* snapshot */ | 
| 38424 | 385 | |
| 52972 | 386 | object Snapshot | 
| 387 |   {
 | |
| 388 | val init = State.init.snapshot() | |
| 389 | } | |
| 390 | ||
| 38424 | 391 | abstract class Snapshot | 
| 392 |   {
 | |
| 44582 | 393 | val state: State | 
| 38424 | 394 | val version: Version | 
| 395 | val is_outdated: Boolean | |
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 396 | |
| 38427 | 397 | def convert(i: Text.Offset): Text.Offset | 
| 52889 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 wenzelm parents: 
52887diff
changeset | 398 | def revert(i: Text.Offset): Text.Offset | 
| 39177 
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
 wenzelm parents: 
38976diff
changeset | 399 | def convert(range: Text.Range): Text.Range | 
| 
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
 wenzelm parents: 
38976diff
changeset | 400 | def revert(range: Text.Range): Text.Range | 
| 52972 | 401 | |
| 402 | val node_name: Node.Name | |
| 403 | val node: Node | |
| 56314 | 404 | val load_commands: List[Command] | 
| 56176 
0bc9b0ad6287
tuned rendering -- avoid flashing background of aux. files that are disconnected from the document model;
 wenzelm parents: 
55820diff
changeset | 405 | def is_loaded: Boolean | 
| 51494 | 406 | def eq_content(other: Snapshot): Boolean | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 407 | |
| 55651 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 408 | def cumulate[A]( | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 409 | range: Text.Range, | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 410 | info: A, | 
| 56743 | 411 | elements: Markup.Elements, | 
| 56354 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 wenzelm parents: 
56337diff
changeset | 412 | result: List[Command.State] => (A, Text.Markup) => Option[A], | 
| 55651 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 413 | status: Boolean = false): List[Text.Info[A]] | 
| 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 414 | |
| 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 415 | def select[A]( | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 416 | range: Text.Range, | 
| 56743 | 417 | elements: Markup.Elements, | 
| 56354 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 wenzelm parents: 
56337diff
changeset | 418 | result: List[Command.State] => Text.Markup => Option[A], | 
| 55651 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 419 | status: Boolean = false): List[Text.Info[A]] | 
| 38424 | 420 | } | 
| 421 | ||
| 55820 
61869776ce1f
tuned signature -- more explicit Document.Elements;
 wenzelm parents: 
55801diff
changeset | 422 | |
| 
61869776ce1f
tuned signature -- more explicit Document.Elements;
 wenzelm parents: 
55801diff
changeset | 423 | |
| 
61869776ce1f
tuned signature -- more explicit Document.Elements;
 wenzelm parents: 
55801diff
changeset | 424 | /** global state -- document structure, execution process, editing history **/ | 
| 
61869776ce1f
tuned signature -- more explicit Document.Elements;
 wenzelm parents: 
55801diff
changeset | 425 | |
| 52563 | 426 | type Assign_Update = | 
| 427 | List[(Document_ID.Command, List[Document_ID.Exec])] // update of exec state assignment | |
| 44476 
e8a87398f35d
propagate information about last command with exec state assignment through document model;
 wenzelm parents: 
44475diff
changeset | 428 | |
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 429 | object State | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 430 |   {
 | 
| 38373 | 431 | class Fail(state: State) extends Exception | 
| 432 | ||
| 44479 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 wenzelm parents: 
44477diff
changeset | 433 | object Assignment | 
| 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 wenzelm parents: 
44477diff
changeset | 434 |     {
 | 
| 46683 | 435 | val init: Assignment = new Assignment() | 
| 44479 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 wenzelm parents: 
44477diff
changeset | 436 | } | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 437 | |
| 46712 | 438 | final class Assignment private( | 
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 439 | val command_execs: Map[Document_ID.Command, List[Document_ID.Exec]] = Map.empty, | 
| 46677 | 440 | val is_finished: Boolean = false) | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 441 |     {
 | 
| 44477 | 442 |       def check_finished: Assignment = { require(is_finished); this }
 | 
| 47388 
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
 wenzelm parents: 
46997diff
changeset | 443 | def unfinished: Assignment = new Assignment(command_execs, false) | 
| 44479 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 wenzelm parents: 
44477diff
changeset | 444 | |
| 52563 | 445 | def assign(update: Assign_Update): Assignment = | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 446 |       {
 | 
| 38976 
a4a465dc89d9
Document.State.Assignment: eliminated promise in favour of plain values -- signalling is done via event bus in Session;
 wenzelm parents: 
38885diff
changeset | 447 | require(!is_finished) | 
| 44479 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 wenzelm parents: 
44477diff
changeset | 448 | val command_execs1 = | 
| 52563 | 449 |           (command_execs /: update) {
 | 
| 450 | case (res, (command_id, exec_ids)) => | |
| 451 | if (exec_ids.isEmpty) res - command_id | |
| 452 | else res + (command_id -> exec_ids) | |
| 44479 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 wenzelm parents: 
44477diff
changeset | 453 | } | 
| 47388 
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
 wenzelm parents: 
46997diff
changeset | 454 | new Assignment(command_execs1, true) | 
| 38150 
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
 wenzelm parents: 
37849diff
changeset | 455 | } | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 456 | } | 
| 46682 | 457 | |
| 458 | val init: State = | |
| 52563 | 459 | State().define_version(Version.init, Assignment.init).assign(Version.init.id, Nil)._2 | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 460 | } | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 461 | |
| 46712 | 462 | final case class State private( | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 463 | /*reachable versions*/ | 
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 464 | val versions: Map[Document_ID.Version, Version] = Map.empty, | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 465 | /*inlined auxiliary files*/ | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 466 | val blobs: Set[SHA1.Digest] = Set.empty, | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 467 | /*static markup from define_command*/ | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 468 | val commands: Map[Document_ID.Command, Command.State] = Map.empty, | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 469 | /*dynamic markup from execution*/ | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 470 | val execs: Map[Document_ID.Exec, Command.State] = Map.empty, | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 471 | /*command-exec assignment for each version*/ | 
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 472 | val assignments: Map[Document_ID.Version, State.Assignment] = Map.empty, | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 473 | /*commands with markup produced by other commands (imm_succs)*/ | 
| 56475 | 474 | val commands_redirection: Graph[Document_ID.Command, Unit] = Graph.long, | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 475 | /*explicit (linear) history*/ | 
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 476 | val history: History = History.init) | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 477 |   {
 | 
| 38373 | 478 | private def fail[A]: A = throw new State.Fail(this) | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 479 | |
| 44479 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 wenzelm parents: 
44477diff
changeset | 480 | def define_version(version: Version, assignment: State.Assignment): State = | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 481 |     {
 | 
| 38417 | 482 | val id = version.id | 
| 483 | copy(versions = versions + (id -> version), | |
| 44479 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 wenzelm parents: 
44477diff
changeset | 484 | assignments = assignments + (id -> assignment.unfinished)) | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 485 | } | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 486 | |
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54515diff
changeset | 487 | def define_blob(digest: SHA1.Digest): State = copy(blobs = blobs + digest) | 
| 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54515diff
changeset | 488 | def defined_blob(digest: SHA1.Digest): Boolean = blobs.contains(digest) | 
| 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54515diff
changeset | 489 | |
| 38373 | 490 | def define_command(command: Command): State = | 
| 491 |     {
 | |
| 492 | val id = command.id | |
| 49414 | 493 | copy(commands = commands + (id -> command.init_state)) | 
| 38373 | 494 | } | 
| 495 | ||
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 496 | def defined_command(id: Document_ID.Command): Boolean = commands.isDefinedAt(id) | 
| 44582 | 497 | |
| 52531 | 498 | def find_command(version: Version, id: Document_ID.Generic): Option[(Node, Command)] = | 
| 44582 | 499 |       commands.get(id) orElse execs.get(id) match {
 | 
| 500 | case None => None | |
| 501 | case Some(st) => | |
| 502 | val command = st.command | |
| 46681 | 503 | val node = version.nodes(command.node_name) | 
| 54328 
ffa4e0b1701e
more strict find_command -- avoid invalid hyperlink_command;
 wenzelm parents: 
52978diff
changeset | 504 | if (node.commands.contains(command)) Some((node, command)) else None | 
| 44582 | 505 | } | 
| 38373 | 506 | |
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 507 | def the_version(id: Document_ID.Version): Version = versions.getOrElse(id, fail) | 
| 52564 
4e855c120f6a
tuned signature -- NB: Command.read is actually part of Command.eval;
 wenzelm parents: 
52563diff
changeset | 508 | def the_static_state(id: Document_ID.Command): Command.State = commands.getOrElse(id, fail) | 
| 
4e855c120f6a
tuned signature -- NB: Command.read is actually part of Command.eval;
 wenzelm parents: 
52563diff
changeset | 509 | def the_dynamic_state(id: Document_ID.Exec): Command.State = execs.getOrElse(id, fail) | 
| 52563 | 510 | def the_assignment(version: Version): State.Assignment = assignments.getOrElse(version.id, fail) | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 511 | |
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 512 | private def self_id(st: Command.State)(id: Document_ID.Generic): Boolean = | 
| 56295 
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
 wenzelm parents: 
56176diff
changeset | 513 | id == st.command.id || | 
| 
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
 wenzelm parents: 
56176diff
changeset | 514 |       (execs.get(id) match { case Some(st1) => st1.command.id == st.command.id case None => false })
 | 
| 
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
 wenzelm parents: 
56176diff
changeset | 515 | |
| 56746 | 516 | private def other_id(id: Document_ID.Generic) | 
| 517 | : Option[(Symbol.Text_Chunk.Id, Symbol.Text_Chunk)] = None | |
| 56514 
db929027e701
ignore other_id reports for now (see 8eda56033203): massive amounts of redirections to 'class' etc. makes it difficult to edit main HOL;
 wenzelm parents: 
56489diff
changeset | 518 | /* FIXME | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 519 | (execs.get(id) orElse commands.get(id)).map(st => | 
| 56746 | 520 | ((Symbol.Text_Chunk.Id(st.command.id), st.command.chunk))) | 
| 56514 
db929027e701
ignore other_id reports for now (see 8eda56033203): massive amounts of redirections to 'class' etc. makes it difficult to edit main HOL;
 wenzelm parents: 
56489diff
changeset | 521 | */ | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 522 | |
| 56475 | 523 | private def redirection(st: Command.State): Graph[Document_ID.Command, Unit] = | 
| 524 |       (commands_redirection /: st.markups.redirection_iterator)({ case (graph, id) =>
 | |
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 525 | graph.default_node(id, ()).default_node(st.command.id, ()).add_edge(id, st.command.id) }) | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 526 | |
| 52531 | 527 | def accumulate(id: Document_ID.Generic, message: XML.Elem): (Command.State, State) = | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 528 |     {
 | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 529 |       execs.get(id) match {
 | 
| 44446 | 530 | case Some(st) => | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 531 | val new_st = st.accumulate(self_id(st), other_id _, message) | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 532 | val execs1 = execs + (id -> new_st) | 
| 56475 | 533 | (new_st, copy(execs = execs1, commands_redirection = redirection(new_st))) | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 534 | case None => | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 535 |           commands.get(id) match {
 | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 536 | case Some(st) => | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 537 | val new_st = st.accumulate(self_id(st), other_id _, message) | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 538 | val commands1 = commands + (id -> new_st) | 
| 56475 | 539 | (new_st, copy(commands = commands1, commands_redirection = redirection(new_st))) | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 540 | case None => fail | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 541 | } | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 542 | } | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 543 | } | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 544 | |
| 52563 | 545 | def assign(id: Document_ID.Version, update: Assign_Update): (List[Command], State) = | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 546 |     {
 | 
| 38417 | 547 | val version = the_version(id) | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 548 | |
| 52566 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 wenzelm parents: 
52564diff
changeset | 549 | def upd(exec_id: Document_ID.Exec, st: Command.State) | 
| 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 wenzelm parents: 
52564diff
changeset | 550 | : Option[(Document_ID.Exec, Command.State)] = | 
| 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 wenzelm parents: 
52564diff
changeset | 551 | if (execs.isDefinedAt(exec_id)) None else Some(exec_id -> st) | 
| 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 wenzelm parents: 
52564diff
changeset | 552 | |
| 44543 | 553 | val (changed_commands, new_execs) = | 
| 52563 | 554 |         ((Nil: List[Command], execs) /: update) {
 | 
| 52566 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 wenzelm parents: 
52564diff
changeset | 555 | case ((commands1, execs1), (command_id, exec)) => | 
| 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 wenzelm parents: 
52564diff
changeset | 556 | val st = the_static_state(command_id) | 
| 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 wenzelm parents: 
52564diff
changeset | 557 | val command = st.command | 
| 52527 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52508diff
changeset | 558 | val commands2 = command :: commands1 | 
| 44543 | 559 | val execs2 = | 
| 560 |               exec match {
 | |
| 52527 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52508diff
changeset | 561 | case Nil => execs1 | 
| 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52508diff
changeset | 562 | case eval_id :: print_ids => | 
| 52566 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 wenzelm parents: 
52564diff
changeset | 563 | execs1 ++ upd(eval_id, st) ++ | 
| 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 wenzelm parents: 
52564diff
changeset | 564 | (for (id <- print_ids; up <- upd(id, command.empty_state)) yield up) | 
| 44543 | 565 | } | 
| 566 | (commands2, execs2) | |
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 567 | } | 
| 52563 | 568 | val new_assignment = the_assignment(version).assign(update) | 
| 43722 | 569 | val new_state = copy(assignments = assignments + (id -> new_assignment), execs = new_execs) | 
| 44476 
e8a87398f35d
propagate information about last command with exec state assignment through document model;
 wenzelm parents: 
44475diff
changeset | 570 | |
| 44543 | 571 | (changed_commands, new_state) | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 572 | } | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 573 | |
| 38417 | 574 | def is_assigned(version: Version): Boolean = | 
| 43722 | 575 |       assignments.get(version.id) match {
 | 
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 576 | case Some(assgn) => assgn.is_finished | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 577 | case None => false | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 578 | } | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 579 | |
| 44436 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 wenzelm parents: 
44385diff
changeset | 580 | def is_stable(change: Change): Boolean = | 
| 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 wenzelm parents: 
44385diff
changeset | 581 | change.is_finished && is_assigned(change.version.get_finished) | 
| 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 wenzelm parents: 
44385diff
changeset | 582 | |
| 46944 
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
 wenzelm parents: 
46942diff
changeset | 583 | def recent_finished: Change = history.undo_list.find(_.is_finished) getOrElse fail | 
| 44672 | 584 | def recent_stable: Change = history.undo_list.find(is_stable) getOrElse fail | 
| 44436 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 wenzelm parents: 
44385diff
changeset | 585 | def tip_stable: Boolean = is_stable(history.tip) | 
| 44475 | 586 | def tip_version: Version = history.tip.version.get_finished | 
| 44436 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 wenzelm parents: 
44385diff
changeset | 587 | |
| 44446 | 588 | def continue_history( | 
| 56711 | 589 | previous: Future[Version], | 
| 590 | edits: List[Edit_Text], | |
| 591 | version: Future[Version]): State = | |
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 592 |     {
 | 
| 46678 | 593 | val change = Change.make(previous, edits, version) | 
| 56711 | 594 | copy(history = history + change) | 
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 595 | } | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 596 | |
| 44672 | 597 | def prune_history(retain: Int = 0): (List[Version], State) = | 
| 598 |     {
 | |
| 46679 | 599 |       history.prune(is_stable, retain) match {
 | 
| 600 | case Some((dropped, history1)) => | |
| 44672 | 601 | val dropped_versions = dropped.map(change => change.version.get_finished) | 
| 46679 | 602 | val state1 = copy(history = history1) | 
| 44672 | 603 | (dropped_versions, state1) | 
| 46679 | 604 | case None => fail | 
| 44672 | 605 | } | 
| 606 | } | |
| 607 | ||
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 608 | def removed_versions(removed: List[Document_ID.Version]): State = | 
| 44676 | 609 |     {
 | 
| 610 | val versions1 = versions -- removed | |
| 611 | val assignments1 = assignments -- removed | |
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54515diff
changeset | 612 | var blobs1 = Set.empty[SHA1.Digest] | 
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 613 | var commands1 = Map.empty[Document_ID.Command, Command.State] | 
| 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 614 | var execs1 = Map.empty[Document_ID.Exec, Command.State] | 
| 44676 | 615 |       for {
 | 
| 616 | (version_id, version) <- versions1.iterator | |
| 46997 | 617 | command_execs = assignments1(version_id).command_execs | 
| 56372 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 wenzelm parents: 
56354diff
changeset | 618 | (_, node) <- version.nodes.iterator | 
| 44676 | 619 | command <- node.commands.iterator | 
| 620 |       } {
 | |
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54515diff
changeset | 621 | for (digest <- command.blobs_digests; if !blobs1.contains(digest)) | 
| 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54515diff
changeset | 622 | blobs1 += digest | 
| 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54515diff
changeset | 623 | |
| 52568 | 624 | if (!commands1.isDefinedAt(command.id)) | 
| 625 | commands.get(command.id).foreach(st => commands1 += (command.id -> st)) | |
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54515diff
changeset | 626 | |
| 52568 | 627 |         for (exec_id <- command_execs.getOrElse(command.id, Nil)) {
 | 
| 52527 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52508diff
changeset | 628 | if (!execs1.isDefinedAt(exec_id)) | 
| 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52508diff
changeset | 629 | execs.get(exec_id).foreach(st => execs1 += (exec_id -> st)) | 
| 44676 | 630 | } | 
| 631 | } | |
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 632 | copy( | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 633 | versions = versions1, | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 634 | blobs = blobs1, | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 635 | commands = commands1, | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 636 | execs = execs1, | 
| 56475 | 637 | commands_redirection = commands_redirection.restrict(commands1.isDefinedAt(_)), | 
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54515diff
changeset | 638 | assignments = assignments1) | 
| 44676 | 639 | } | 
| 640 | ||
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 641 | private def command_states_self(version: Version, command: Command) | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 642 | : List[(Document_ID.Generic, Command.State)] = | 
| 44613 | 643 |     {
 | 
| 644 | require(is_assigned(version)) | |
| 645 |       try {
 | |
| 52527 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52508diff
changeset | 646 | the_assignment(version).check_finished.command_execs.getOrElse(command.id, Nil) | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 647 |           .map(id => id -> the_dynamic_state(id)) match {
 | 
| 52527 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52508diff
changeset | 648 | case Nil => fail | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 649 | case res => res | 
| 52527 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52508diff
changeset | 650 | } | 
| 44613 | 651 | } | 
| 47395 
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
 wenzelm parents: 
47388diff
changeset | 652 |       catch {
 | 
| 
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
 wenzelm parents: 
47388diff
changeset | 653 | case _: State.Fail => | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 654 |           try { List(command.id -> the_static_state(command.id)) }
 | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 655 |           catch { case _: State.Fail => List(command.id -> command.init_state) }
 | 
| 47395 
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
 wenzelm parents: 
47388diff
changeset | 656 | } | 
| 44613 | 657 | } | 
| 658 | ||
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 659 | def command_states(version: Version, command: Command): List[Command.State] = | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 660 |     {
 | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 661 | val self = command_states_self(version, command) | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 662 | val others = | 
| 56475 | 663 |         if (commands_redirection.defined(command.id)) {
 | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 664 |           (for {
 | 
| 56475 | 665 | command_id <- commands_redirection.imm_succs(command.id).iterator | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 666 | (id, st) <- command_states_self(version, the_static_state(command_id).command) | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 667 | if !self.exists(_._1 == id) | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 668 | } yield (id, st)).toMap.valuesIterator.toList | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 669 | } | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 670 | else Nil | 
| 56489 | 671 | self.map(_._2) ::: others.flatMap(_.redirect(command)) | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 672 | } | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56468diff
changeset | 673 | |
| 56299 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 674 | def command_results(version: Version, command: Command): Command.Results = | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 675 | Command.State.merge_results(command_states(version, command)) | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 676 | |
| 56301 
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
 wenzelm parents: 
56300diff
changeset | 677 | def command_markup(version: Version, command: Command, index: Command.Markup_Index, | 
| 56743 | 678 | range: Text.Range, elements: Markup.Elements): Markup_Tree = | 
| 56301 
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
 wenzelm parents: 
56300diff
changeset | 679 | Command.State.merge_markup(command_states(version, command), index, range, elements) | 
| 56299 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 680 | |
| 56743 | 681 | def markup_to_XML(version: Version, node: Node, elements: Markup.Elements): XML.Body = | 
| 56299 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 682 |       (for {
 | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 683 | command <- node.commands.iterator | 
| 56301 
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
 wenzelm parents: 
56300diff
changeset | 684 | markup = | 
| 
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
 wenzelm parents: 
56300diff
changeset | 685 | command_markup(version, command, Command.Markup_Index.markup, command.range, elements) | 
| 56300 | 686 | tree <- markup.to_XML(command.range, command.source, elements) | 
| 56299 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 687 | } yield tree).toList | 
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 688 | |
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 689 | // persistent user-view | 
| 49346 | 690 | def snapshot(name: Node.Name = Node.Name.empty, pending_edits: List[Text.Edit] = Nil) | 
| 691 | : Snapshot = | |
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 692 |     {
 | 
| 44672 | 693 | val stable = recent_stable | 
| 44436 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 wenzelm parents: 
44385diff
changeset | 694 | val latest = history.tip | 
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 695 | |
| 44156 | 696 | // FIXME proper treatment of removed nodes | 
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 697 | val edits = | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 698 | (pending_edits /: history.undo_list.takeWhile(_ != stable))((edits, change) => | 
| 44156 | 699 | (for ((a, Node.Edits(es)) <- change.edits if a == name) yield es).flatten ::: edits) | 
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 700 | lazy val reverse_edits = edits.reverse | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 701 | |
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 702 | new Snapshot | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 703 |       {
 | 
| 52972 | 704 | /* global information */ | 
| 705 | ||
| 44582 | 706 | val state = State.this | 
| 39698 | 707 | val version = stable.version.get_finished | 
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 708 | val is_outdated = !(pending_edits.isEmpty && latest == stable) | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 709 | |
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 710 | |
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 711 | /* local node content */ | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 712 | |
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 713 | def convert(offset: Text.Offset) = (offset /: edits)((i, edit) => edit.convert(i)) | 
| 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 714 | def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i)) | 
| 43425 | 715 | def convert(range: Text.Range) = (range /: edits)((r, edit) => edit.convert(r)) | 
| 716 | def revert(range: Text.Range) = (range /: reverse_edits)((r, edit) => edit.revert(r)) | |
| 39177 
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
 wenzelm parents: 
38976diff
changeset | 717 | |
| 52972 | 718 | val node_name = name | 
| 719 | val node = version.nodes(name) | |
| 720 | ||
| 56314 | 721 | val load_commands: List[Command] = | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 722 | if (node_name.is_theory) Nil | 
| 56314 | 723 | else version.nodes.load_commands(node_name) | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 724 | |
| 56314 | 725 | val is_loaded: Boolean = node_name.is_theory || !load_commands.isEmpty | 
| 56176 
0bc9b0ad6287
tuned rendering -- avoid flashing background of aux. files that are disconnected from the document model;
 wenzelm parents: 
55820diff
changeset | 726 | |
| 51494 | 727 | def eq_content(other: Snapshot): Boolean = | 
| 55434 | 728 |         {
 | 
| 729 | def eq_commands(commands: (Command, Command)): Boolean = | |
| 56299 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 730 |           {
 | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 731 | val states1 = state.command_states(version, commands._1) | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 732 | val states2 = other.state.command_states(other.version, commands._2) | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 733 | states1.length == states2.length && | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 734 |             (states1 zip states2).forall({ case (st1, st2) => st1 eq_content st2 })
 | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56298diff
changeset | 735 | } | 
| 55434 | 736 | |
| 49346 | 737 | !is_outdated && !other.is_outdated && | 
| 55434 | 738 | node.commands.size == other.node.commands.size && | 
| 739 | (node.commands.iterator zip other.node.commands.iterator).forall(eq_commands) && | |
| 56314 | 740 | load_commands.length == other.load_commands.length && | 
| 741 | (load_commands zip other.load_commands).forall(eq_commands) | |
| 55434 | 742 | } | 
| 49346 | 743 | |
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 744 | |
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 745 | /* cumulate markup */ | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 746 | |
| 55651 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 747 | def cumulate[A]( | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 748 | range: Text.Range, | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55620diff
changeset | 749 | info: A, | 
| 56743 | 750 | elements: Markup.Elements, | 
| 56354 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 wenzelm parents: 
56337diff
changeset | 751 | result: List[Command.State] => (A, Text.Markup) => Option[A], | 
| 55651 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 752 | status: Boolean = false): List[Text.Info[A]] = | 
| 45459 | 753 |         {
 | 
| 56590 
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
 wenzelm parents: 
56514diff
changeset | 754 | val former_range = revert(range).inflate_singularity | 
| 56462 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 wenzelm parents: 
56398diff
changeset | 755 | val (chunk_name, command_iterator) = | 
| 56314 | 756 |             load_commands match {
 | 
| 56746 | 757 | case command :: _ => (Symbol.Text_Chunk.File(node_name.node), Iterator((command, 0))) | 
| 758 | case _ => (Symbol.Text_Chunk.Default, node.command_iterator(former_range)) | |
| 56309 | 759 | } | 
| 56462 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 wenzelm parents: 
56398diff
changeset | 760 | val markup_index = Command.Markup_Index(status, chunk_name) | 
| 56309 | 761 |           (for {
 | 
| 56373 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 wenzelm parents: 
56372diff
changeset | 762 | (command, command_start) <- command_iterator | 
| 56462 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 wenzelm parents: 
56398diff
changeset | 763 | chunk <- command.chunks.get(chunk_name).iterator | 
| 56309 | 764 | states = state.command_states(version, command) | 
| 56354 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 wenzelm parents: 
56337diff
changeset | 765 | res = result(states) | 
| 56590 
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
 wenzelm parents: 
56514diff
changeset | 766 | markup_range <- (former_range - command_start).try_restrict(chunk.range).iterator | 
| 
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
 wenzelm parents: 
56514diff
changeset | 767 | markup = Command.State.merge_markup(states, markup_index, markup_range, elements) | 
| 
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
 wenzelm parents: 
56514diff
changeset | 768 | Text.Info(r0, a) <- markup.cumulate[A](markup_range, info, elements, | 
| 56309 | 769 |               {
 | 
| 770 | case (a, Text.Info(r0, b)) => res(a, Text.Info(convert(r0 + command_start), b)) | |
| 771 | }).iterator | |
| 56590 
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
 wenzelm parents: 
56514diff
changeset | 772 | r1 <- convert(r0 + command_start).try_restrict(range).iterator | 
| 
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
 wenzelm parents: 
56514diff
changeset | 773 | } yield Text.Info(r1, a)).toList | 
| 45459 | 774 | } | 
| 775 | ||
| 55651 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 776 | def select[A]( | 
| 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 777 | range: Text.Range, | 
| 56743 | 778 | elements: Markup.Elements, | 
| 56354 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 wenzelm parents: 
56337diff
changeset | 779 | result: List[Command.State] => Text.Markup => Option[A], | 
| 55651 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 780 | status: Boolean = false): List[Text.Info[A]] = | 
| 38845 
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
 wenzelm parents: 
38841diff
changeset | 781 |         {
 | 
| 56354 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 wenzelm parents: 
56337diff
changeset | 782 | def result1(states: List[Command.State]): (Option[A], Text.Markup) => Option[Option[A]] = | 
| 50500 
c94bba7906d2
identify dialogs via official serial and maintain as result message;
 wenzelm parents: 
50204diff
changeset | 783 |           {
 | 
| 56354 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 wenzelm parents: 
56337diff
changeset | 784 | val res = result(states) | 
| 52889 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 wenzelm parents: 
52887diff
changeset | 785 | (_: Option[A], x: Text.Markup) => | 
| 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 wenzelm parents: 
52887diff
changeset | 786 |               res(x) match {
 | 
| 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 wenzelm parents: 
52887diff
changeset | 787 | case None => None | 
| 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 wenzelm parents: 
52887diff
changeset | 788 | case some => Some(some) | 
| 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 wenzelm parents: 
52887diff
changeset | 789 | } | 
| 50500 
c94bba7906d2
identify dialogs via official serial and maintain as result message;
 wenzelm parents: 
50204diff
changeset | 790 | } | 
| 55651 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 wenzelm parents: 
55650diff
changeset | 791 | for (Text.Info(r, Some(x)) <- cumulate(range, None, elements, result1 _, status)) | 
| 46198 
cd040c5772de
improved select_markup: include filtering of defined results;
 wenzelm parents: 
46178diff
changeset | 792 | yield Text.Info(r, x) | 
| 38845 
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
 wenzelm parents: 
38841diff
changeset | 793 | } | 
| 55800 | 794 | |
| 795 | ||
| 796 | /* output */ | |
| 797 | ||
| 798 | override def toString: String = | |
| 799 | "Snapshot(node = " + node_name.node + ", version = " + version.id + | |
| 800 | (if (is_outdated) ", outdated" else "") + ")" | |
| 38841 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 wenzelm parents: 
38569diff
changeset | 801 | } | 
| 38150 
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
 wenzelm parents: 
37849diff
changeset | 802 | } | 
| 34485 | 803 | } | 
| 34840 
6c5560d48561
more precise treatment of document/state assigment;
 wenzelm parents: 
34838diff
changeset | 804 | } | 
| 
6c5560d48561
more precise treatment of document/state assigment;
 wenzelm parents: 
34838diff
changeset | 805 |