| author | wenzelm | 
| Sat, 05 Dec 2020 12:43:21 +0100 | |
| changeset 72817 | 1c378ab75d48 | 
| parent 72816 | ea4f86914cb2 | 
| child 72818 | 55792cb3892f | 
| 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: 
37849 
diff
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: 
38417 
diff
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: 
34868 
diff
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: 
37849 
diff
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: 
52976 
diff
changeset
 | 
18  | 
/* overlays -- print functions with arguments */  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
19  | 
|
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
20  | 
object Overlays  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
21  | 
  {
 | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
22  | 
val empty = new Overlays(Map.empty)  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
23  | 
}  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
24  | 
|
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
25  | 
final class Overlays private(rep: Map[Node.Name, Node.Overlays])  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
26  | 
  {
 | 
| 64799 | 27  | 
def apply(name: Node.Name): Node.Overlays =  | 
| 
52977
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
28  | 
rep.getOrElse(name, Node.Overlays.empty)  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
29  | 
|
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
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: 
52976 
diff
changeset
 | 
31  | 
    {
 | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
32  | 
val node_overlays = f(apply(name))  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
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: 
52976 
diff
changeset
 | 
34  | 
}  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
35  | 
|
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
36  | 
def insert(command: Command, fn: String, args: List[String]): Overlays =  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
37  | 
update(command.node_name, _.insert(command, fn, args))  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
38  | 
|
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
39  | 
def remove(command: Command, fn: String, args: List[String]): Overlays =  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
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: 
52976 
diff
changeset
 | 
43  | 
}  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
44  | 
|
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
45  | 
|
| 55783 | 46  | 
/* document blobs: auxiliary files */  | 
47  | 
||
| 
67265
 
f32287c95432
store full blob source for the sake of markup_to_XML;
 
wenzelm 
parents: 
67264 
diff
changeset
 | 
48  | 
sealed case class Blob(bytes: Bytes, source: String, 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: 
56314 
diff
changeset
 | 
49  | 
  {
 | 
| 
 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 
wenzelm 
parents: 
56314 
diff
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: 
56314 
diff
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  | 
  {
 | 
| 56336 | 61  | 
def get(name: Node.Name): Option[Blob] = blobs.get(name)  | 
| 55783 | 62  | 
|
63  | 
def changed(name: Node.Name): Boolean =  | 
|
64  | 
      get(name) match {
 | 
|
65  | 
case Some(blob) => blob.changed  | 
|
66  | 
case None => false  | 
|
67  | 
}  | 
|
68  | 
||
| 55800 | 69  | 
    override def toString: String = blobs.mkString("Blobs(", ",", ")")
 | 
| 55783 | 70  | 
}  | 
71  | 
||
72  | 
||
73  | 
/* document nodes: theories and auxiliary files */  | 
|
| 38424 | 74  | 
|
| 44615 | 75  | 
type Edit[A, B] = (Node.Name, Node.Edit[A, B])  | 
| 44384 | 76  | 
type Edit_Text = Edit[Text.Edit, Text.Perspective]  | 
| 52849 | 77  | 
type Edit_Command = Edit[Command.Edit, Command.Perspective]  | 
| 38151 | 78  | 
|
79  | 
object Node  | 
|
80  | 
  {
 | 
|
| 52887 | 81  | 
/* header and name */  | 
82  | 
||
| 
48707
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
83  | 
sealed case class Header(  | 
| 
70638
 
f164cec7ac22
clarified signature: prefer operations without position;
 
wenzelm 
parents: 
70636 
diff
changeset
 | 
84  | 
imports_pos: List[(Name, Position.T)] = Nil,  | 
| 63020 | 85  | 
keywords: Thy_Header.Keywords = Nil,  | 
| 63579 | 86  | 
abbrevs: Thy_Header.Abbrevs = Nil,  | 
| 63020 | 87  | 
errors: List[String] = Nil)  | 
| 
48707
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
88  | 
    {
 | 
| 72669 | 89  | 
def imports_offset: Map[Int, Name] =  | 
90  | 
        (for { (name, Position.Offset(i)) <- imports_pos } yield i -> name).toMap
 | 
|
91  | 
||
| 
70638
 
f164cec7ac22
clarified signature: prefer operations without position;
 
wenzelm 
parents: 
70636 
diff
changeset
 | 
92  | 
def imports: List[Name] = imports_pos.map(_._1)  | 
| 
 
f164cec7ac22
clarified signature: prefer operations without position;
 
wenzelm 
parents: 
70636 
diff
changeset
 | 
93  | 
|
| 66773 | 94  | 
def append_errors(msgs: List[String]): Header =  | 
95  | 
copy(errors = errors ::: msgs)  | 
|
| 
54549
 
2a3053472ec3
actually expose errors of cumulative theory dependencies;
 
wenzelm 
parents: 
54530 
diff
changeset
 | 
96  | 
|
| 
 
2a3053472ec3
actually expose errors of cumulative theory dependencies;
 
wenzelm 
parents: 
54530 
diff
changeset
 | 
97  | 
def cat_errors(msg2: String): Header =  | 
| 62492 | 98  | 
copy(errors = errors.map(msg1 => Exn.cat_message(msg1, msg2)))  | 
| 
48707
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
99  | 
}  | 
| 
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
100  | 
|
| 71601 | 101  | 
val no_header: Header = Header()  | 
| 63020 | 102  | 
def bad_header(msg: String): Header = Header(errors = List(msg))  | 
| 46737 | 103  | 
|
| 
44957
 
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
 
wenzelm 
parents: 
44676 
diff
changeset
 | 
104  | 
object Name  | 
| 
 
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
 
wenzelm 
parents: 
44676 
diff
changeset
 | 
105  | 
    {
 | 
| 71601 | 106  | 
      val empty: Name = Name("")
 | 
| 46723 | 107  | 
|
108  | 
object Ordering extends scala.math.Ordering[Name]  | 
|
109  | 
      {
 | 
|
110  | 
def compare(name1: Name, name2: Name): Int = name1.node compare name2.node  | 
|
111  | 
}  | 
|
| 70636 | 112  | 
|
| 
70674
 
29bb1ebb188f
clarified signature: proper Document.Node.Ordering conforming to equality (e.g. required in situations where theory names are ambiguous due to overlapping session directories);
 
wenzelm 
parents: 
70650 
diff
changeset
 | 
113  | 
type Graph[A] = isabelle.Graph[Node.Name, A]  | 
| 
 
29bb1ebb188f
clarified signature: proper Document.Node.Ordering conforming to equality (e.g. required in situations where theory names are ambiguous due to overlapping session directories);
 
wenzelm 
parents: 
70650 
diff
changeset
 | 
114  | 
|
| 70692 | 115  | 
def make_graph[A](entries: List[((Name, A), List[Name])]): Graph[A] =  | 
116  | 
Graph.make(entries, symmetric = true)(Ordering)  | 
|
| 
44957
 
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
 
wenzelm 
parents: 
44676 
diff
changeset
 | 
117  | 
}  | 
| 52887 | 118  | 
|
| 54515 | 119  | 
sealed case class Name(node: String, master_dir: String = "", theory: String = "")  | 
| 44615 | 120  | 
    {
 | 
121  | 
override def hashCode: Int = node.hashCode  | 
|
122  | 
override def equals(that: Any): Boolean =  | 
|
123  | 
        that match {
 | 
|
124  | 
case other: Name => node == other.node  | 
|
125  | 
case _ => false  | 
|
126  | 
}  | 
|
| 
54509
 
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
 
wenzelm 
parents: 
54462 
diff
changeset
 | 
127  | 
|
| 66849 | 128  | 
def path: Path = Path.explode(File.standard_path(node))  | 
| 70676 | 129  | 
def master_dir_path: Path = Path.explode(File.standard_path(master_dir))  | 
| 66716 | 130  | 
|
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
131  | 
def expand: Name =  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
132  | 
Name(path.expand.implode, master_dir_path.expand.implode, theory)  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
133  | 
def symbolic: Name =  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
134  | 
Name(path.implode_symbolic, master_dir_path.implode_symbolic, theory)  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
135  | 
|
| 59319 | 136  | 
def is_theory: Boolean = theory.nonEmpty  | 
| 65409 | 137  | 
|
| 65439 | 138  | 
def theory_base_name: String = Long_Name.base_name(theory)  | 
139  | 
||
| 54510 | 140  | 
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: 
56746 
diff
changeset
 | 
141  | 
|
| 
 
8dd9df88f647
some support for session-qualified theories: allow to refer to resources via qualified name instead of odd file-system path;
 
wenzelm 
parents: 
56746 
diff
changeset
 | 
142  | 
def map(f: String => String): Name = copy(f(node), f(master_dir), theory)  | 
| 66195 | 143  | 
def map_theory(f: String => String): Name = copy(node, master_dir, f(theory))  | 
| 67943 | 144  | 
|
145  | 
def json: JSON.Object.T =  | 
|
146  | 
        JSON.Object("node_name" -> node, "theory_name" -> theory)
 | 
|
| 44615 | 147  | 
}  | 
148  | 
||
| 66714 | 149  | 
sealed case class Entry(name: Node.Name, header: Node.Header)  | 
150  | 
    {
 | 
|
| 
68306
 
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
 
wenzelm 
parents: 
68300 
diff
changeset
 | 
151  | 
def map(f: String => String): Entry = copy(name = name.map(f))  | 
| 
 
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
 
wenzelm 
parents: 
68300 
diff
changeset
 | 
152  | 
|
| 66714 | 153  | 
override def toString: String = name.toString  | 
154  | 
}  | 
|
155  | 
||
| 52887 | 156  | 
|
| 
52977
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
157  | 
/* node overlays */  | 
| 52887 | 158  | 
|
159  | 
object Overlays  | 
|
160  | 
    {
 | 
|
| 52976 | 161  | 
val empty = new Overlays(Multi_Map.empty)  | 
| 52887 | 162  | 
}  | 
163  | 
||
| 
52977
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
164  | 
final class Overlays private(rep: Multi_Map[Command, (String, List[String])])  | 
| 52887 | 165  | 
    {
 | 
166  | 
def commands: Set[Command] = rep.keySet  | 
|
167  | 
def is_empty: Boolean = rep.isEmpty  | 
|
| 
52977
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
168  | 
def dest: List[(Command, (String, List[String]))] = rep.iterator.toList  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
169  | 
def insert(cmd: Command, fn: String, args: List[String]): Overlays =  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
170  | 
new Overlays(rep.insert(cmd, (fn, args)))  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
171  | 
def remove(cmd: Command, fn: String, args: List[String]): Overlays =  | 
| 
 
15254e32d299
central management of Document.Overlays, independent of Document_Model;
 
wenzelm 
parents: 
52976 
diff
changeset
 | 
172  | 
new Overlays(rep.remove(cmd, (fn, args)))  | 
| 55800 | 173  | 
|
174  | 
      override def toString: String = rep.mkString("Node.Overlays(", ",", ")")
 | 
|
| 52887 | 175  | 
}  | 
176  | 
||
177  | 
||
178  | 
/* edits */  | 
|
179  | 
||
| 44384 | 180  | 
sealed abstract class Edit[A, B]  | 
| 44156 | 181  | 
    {
 | 
| 44383 | 182  | 
def foreach(f: A => Unit)  | 
183  | 
      {
 | 
|
| 44156 | 184  | 
        this match {
 | 
| 44383 | 185  | 
case Edits(es) => es.foreach(f)  | 
186  | 
case _ =>  | 
|
| 44156 | 187  | 
}  | 
| 44383 | 188  | 
}  | 
| 57621 | 189  | 
|
190  | 
def is_void: Boolean =  | 
|
191  | 
        this match {
 | 
|
192  | 
case Edits(Nil) => true  | 
|
193  | 
case _ => false  | 
|
194  | 
}  | 
|
| 44156 | 195  | 
}  | 
| 
56335
 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 
wenzelm 
parents: 
56314 
diff
changeset
 | 
196  | 
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: 
54549 
diff
changeset
 | 
197  | 
|
| 44384 | 198  | 
case class Edits[A, B](edits: List[A]) extends Edit[A, B]  | 
| 
48707
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
199  | 
case class Deps[A, B](header: Header) extends Edit[A, B]  | 
| 52849 | 200  | 
case class Perspective[A, B](required: Boolean, visible: B, overlays: Overlays) extends Edit[A, B]  | 
| 57610 | 201  | 
|
202  | 
||
203  | 
/* perspective */  | 
|
204  | 
||
| 
52808
 
143f225e50f5
allow explicit indication of required node: full eval, no prints;
 
wenzelm 
parents: 
52568 
diff
changeset
 | 
205  | 
type Perspective_Text = Perspective[Text.Edit, Text.Perspective]  | 
| 52849 | 206  | 
type Perspective_Command = Perspective[Command.Edit, Command.Perspective]  | 
| 44156 | 207  | 
|
| 
57615
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
208  | 
val no_perspective_text: Perspective_Text =  | 
| 57610 | 209  | 
Perspective(false, Text.Perspective.empty, Overlays.empty)  | 
210  | 
||
| 
57615
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
211  | 
val no_perspective_command: Perspective_Command =  | 
| 57614 | 212  | 
Perspective(false, Command.Perspective.empty, Overlays.empty)  | 
213  | 
||
| 64867 | 214  | 
def is_no_perspective_text(perspective: Perspective_Text): Boolean =  | 
215  | 
!perspective.required &&  | 
|
216  | 
perspective.visible.is_empty &&  | 
|
217  | 
perspective.overlays.is_empty  | 
|
218  | 
||
| 
57615
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
219  | 
def is_no_perspective_command(perspective: Perspective_Command): Boolean =  | 
| 
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
220  | 
!perspective.required &&  | 
| 
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
221  | 
perspective.visible.is_empty &&  | 
| 
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
222  | 
perspective.overlays.is_empty  | 
| 
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
223  | 
|
| 52887 | 224  | 
|
225  | 
/* commands */  | 
|
226  | 
||
| 
52901
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
227  | 
object Commands  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
228  | 
    {
 | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
229  | 
def apply(commands: Linear_Set[Command]): Commands = new Commands(commands)  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
230  | 
val empty: Commands = apply(Linear_Set.empty)  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
231  | 
|
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
232  | 
def starts(commands: Iterator[Command], offset: Text.Offset = 0)  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
233  | 
: Iterator[(Command, Text.Offset)] =  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
234  | 
      {
 | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
235  | 
var i = offset  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
236  | 
        for (command <- commands) yield {
 | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
237  | 
val start = i  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
238  | 
i += command.length  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
239  | 
(command, start)  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
240  | 
}  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
241  | 
}  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
242  | 
|
| 67895 | 243  | 
def starts_pos(commands: Iterator[Command], pos: Token.Pos = Token.Pos.start)  | 
244  | 
: Iterator[(Command, Token.Pos)] =  | 
|
245  | 
      {
 | 
|
246  | 
var p = pos  | 
|
247  | 
        for (command <- commands) yield {
 | 
|
248  | 
val start = p  | 
|
249  | 
p = (p /: command.span.content)(_.advance(_))  | 
|
250  | 
(command, start)  | 
|
251  | 
}  | 
|
252  | 
}  | 
|
253  | 
||
| 
56398
 
15d0821c8667
afford larger full_index, to save a few milliseconds during rendering (notably text_overview);
 
wenzelm 
parents: 
56394 
diff
changeset
 | 
254  | 
private val block_size = 256  | 
| 
52901
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
255  | 
}  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
256  | 
|
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
257  | 
final class Commands private(val commands: Linear_Set[Command])  | 
| 
38227
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
258  | 
    {
 | 
| 56314 | 259  | 
lazy val load_commands: List[Command] =  | 
| 59319 | 260  | 
commands.iterator.filter(cmd => cmd.blobs.nonEmpty).toList  | 
| 54462 | 261  | 
|
| 
52901
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
262  | 
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: 
52900 
diff
changeset
 | 
263  | 
      {
 | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
264  | 
val blocks = new mutable.ListBuffer[(Command, Text.Offset)]  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
265  | 
var next_block = 0  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
266  | 
var last_stop = 0  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
267  | 
        for ((command, start) <- Commands.starts(commands.iterator)) {
 | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
268  | 
last_stop = start + command.length  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
269  | 
          while (last_stop + 1 > next_block) {
 | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
270  | 
blocks += (command -> start)  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
271  | 
next_block += Commands.block_size  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
272  | 
}  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
273  | 
}  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
274  | 
(blocks.toArray, Text.Range(0, last_stop))  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
275  | 
}  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
276  | 
|
| 66043 | 277  | 
private def full_range: Text.Range = full_index._2  | 
| 
52901
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
278  | 
|
| 
56373
 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 
wenzelm 
parents: 
56372 
diff
changeset
 | 
279  | 
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: 
52900 
diff
changeset
 | 
280  | 
      {
 | 
| 59319 | 281  | 
        if (commands.nonEmpty && full_range.contains(i)) {
 | 
| 
52901
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
282  | 
val (cmd0, start0) = full_index._1(i / Commands.block_size)  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
283  | 
          Node.Commands.starts(commands.iterator(cmd0), start0) dropWhile {
 | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
284  | 
case (cmd, start) => start + cmd.length <= i }  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
285  | 
}  | 
| 
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
286  | 
else Iterator.empty  | 
| 
38227
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
287  | 
}  | 
| 
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
288  | 
}  | 
| 57614 | 289  | 
|
290  | 
val empty: Node = new Node()  | 
|
| 38151 | 291  | 
}  | 
292  | 
||
| 46712 | 293  | 
final class Node private(  | 
| 
56335
 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 
wenzelm 
parents: 
56314 
diff
changeset
 | 
294  | 
val get_blob: Option[Document.Blob] = None,  | 
| 
57615
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
295  | 
val header: Node.Header = Node.no_header,  | 
| 
63584
 
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
 
wenzelm 
parents: 
63579 
diff
changeset
 | 
296  | 
val syntax: Option[Outer_Syntax] = None,  | 
| 
59372
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
297  | 
val text_perspective: Text.Perspective = Text.Perspective.empty,  | 
| 
57615
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
298  | 
val perspective: Node.Perspective_Command = Node.no_perspective_command,  | 
| 
52901
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
299  | 
_commands: Node.Commands = Node.Commands.empty)  | 
| 38151 | 300  | 
  {
 | 
| 
57615
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
301  | 
def is_empty: Boolean =  | 
| 
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
302  | 
get_blob.isEmpty &&  | 
| 
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
303  | 
header == Node.no_header &&  | 
| 
59372
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
304  | 
text_perspective.is_empty &&  | 
| 
57615
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
305  | 
Node.is_no_perspective_command(perspective) &&  | 
| 
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
306  | 
commands.isEmpty  | 
| 
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
307  | 
|
| 
59702
 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 
wenzelm 
parents: 
59695 
diff
changeset
 | 
308  | 
def has_header: Boolean = header != Node.no_header  | 
| 
 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 
wenzelm 
parents: 
59695 
diff
changeset
 | 
309  | 
|
| 69556 | 310  | 
override def toString: String =  | 
311  | 
if (is_empty) "empty"  | 
|
312  | 
else if (get_blob.isDefined) "blob"  | 
|
313  | 
else "node"  | 
|
314  | 
||
| 
57615
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
315  | 
def commands: Linear_Set[Command] = _commands.commands  | 
| 
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
316  | 
def load_commands: List[Command] = _commands.load_commands  | 
| 64799 | 317  | 
def load_commands_changed(doc_blobs: Blobs): Boolean =  | 
318  | 
load_commands.exists(_.blobs_changed(doc_blobs))  | 
|
| 
57615
 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 
wenzelm 
parents: 
57614 
diff
changeset
 | 
319  | 
|
| 64799 | 320  | 
def init_blob(blob: Blob): Node = new Node(get_blob = Some(blob.unchanged))  | 
| 
55435
 
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
 
wenzelm 
parents: 
55434 
diff
changeset
 | 
321  | 
|
| 
48707
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
322  | 
def update_header(new_header: Node.Header): Node =  | 
| 
59372
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
323  | 
new Node(get_blob, new_header, syntax, text_perspective, perspective, _commands)  | 
| 
59077
 
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
 
wenzelm 
parents: 
57976 
diff
changeset
 | 
324  | 
|
| 
63584
 
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
 
wenzelm 
parents: 
63579 
diff
changeset
 | 
325  | 
def update_syntax(new_syntax: Option[Outer_Syntax]): Node =  | 
| 
59372
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
326  | 
new Node(get_blob, header, new_syntax, text_perspective, perspective, _commands)  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
327  | 
|
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
328  | 
def update_perspective(  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
329  | 
new_text_perspective: Text.Perspective,  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
330  | 
new_perspective: Node.Perspective_Command): Node =  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
331  | 
new Node(get_blob, header, syntax, new_text_perspective, new_perspective, _commands)  | 
| 46680 | 332  | 
|
| 
59372
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
333  | 
def edit_perspective: Node.Edit[Text.Edit, Text.Perspective] =  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
334  | 
Node.Perspective(perspective.required, text_perspective, perspective.overlays)  | 
| 46680 | 335  | 
|
| 
59372
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
336  | 
def same_perspective(  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
337  | 
other_text_perspective: Text.Perspective,  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
338  | 
other_perspective: Node.Perspective_Command): Boolean =  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
339  | 
text_perspective == other_text_perspective &&  | 
| 52849 | 340  | 
perspective.required == other_perspective.required &&  | 
341  | 
perspective.visible.same(other_perspective.visible) &&  | 
|
342  | 
perspective.overlays == other_perspective.overlays  | 
|
| 
52808
 
143f225e50f5
allow explicit indication of required node: full eval, no prints;
 
wenzelm 
parents: 
52568 
diff
changeset
 | 
343  | 
|
| 
52901
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
344  | 
def update_commands(new_commands: Linear_Set[Command]): Node =  | 
| 
52918
 
038458a4d11b
proper low-level comparison -- heed warning by Scala compiler;
 
wenzelm 
parents: 
52901 
diff
changeset
 | 
345  | 
if (new_commands eq _commands.commands) this  | 
| 
59372
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
346  | 
else  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
347  | 
new Node(get_blob, header, syntax, text_perspective, perspective,  | 
| 
 
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
 
wenzelm 
parents: 
59319 
diff
changeset
 | 
348  | 
Node.Commands(new_commands))  | 
| 38151 | 349  | 
|
| 
56373
 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 
wenzelm 
parents: 
56372 
diff
changeset
 | 
350  | 
def command_iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] =  | 
| 
 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 
wenzelm 
parents: 
56372 
diff
changeset
 | 
351  | 
_commands.iterator(i)  | 
| 38151 | 352  | 
|
| 
56373
 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 
wenzelm 
parents: 
56372 
diff
changeset
 | 
353  | 
def command_iterator(range: Text.Range): Iterator[(Command, Text.Offset)] =  | 
| 
 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 
wenzelm 
parents: 
56372 
diff
changeset
 | 
354  | 
      command_iterator(range.start) takeWhile { case (_, start) => start < range.stop }
 | 
| 38151 | 355  | 
|
| 
38879
 
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
 
wenzelm 
parents: 
38872 
diff
changeset
 | 
356  | 
def command_start(cmd: Command): Option[Text.Offset] =  | 
| 
52901
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52900 
diff
changeset
 | 
357  | 
Node.Commands.starts(commands.iterator).find(_._1 == cmd).map(_._2)  | 
| 67247 | 358  | 
|
| 67251 | 359  | 
def source: String =  | 
| 67247 | 360  | 
      get_blob match {
 | 
| 
67265
 
f32287c95432
store full blob source for the sake of markup_to_XML;
 
wenzelm 
parents: 
67264 
diff
changeset
 | 
361  | 
case Some(blob) => blob.source  | 
| 67247 | 362  | 
        case None => command_iterator(0).map({ case (cmd, _) => cmd.source }).mkString
 | 
363  | 
}  | 
|
| 38151 | 364  | 
}  | 
365  | 
||
366  | 
||
| 46723 | 367  | 
/* development graph */  | 
368  | 
||
369  | 
object Nodes  | 
|
370  | 
  {
 | 
|
371  | 
val empty: Nodes = new Nodes(Graph.empty(Node.Name.Ordering))  | 
|
372  | 
}  | 
|
373  | 
||
374  | 
final class Nodes private(graph: Graph[Node.Name, Node])  | 
|
375  | 
  {
 | 
|
376  | 
def apply(name: Node.Name): Node =  | 
|
377  | 
graph.default_node(name, Node.empty).get_node(name)  | 
|
378  | 
||
| 
68299
 
0b5a23477911
clarified signature -- avoid confusion with Resources.is_hidden;
 
wenzelm 
parents: 
68114 
diff
changeset
 | 
379  | 
def is_suppressed(name: Node.Name): Boolean =  | 
| 57619 | 380  | 
    {
 | 
381  | 
val graph1 = graph.default_node(name, Node.empty)  | 
|
382  | 
graph1.is_maximal(name) && graph1.get_node(name).is_empty  | 
|
383  | 
}  | 
|
| 57617 | 384  | 
|
| 
68300
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
385  | 
def purge_suppressed: Option[Nodes] =  | 
| 71601 | 386  | 
      graph.keys_iterator.filter(is_suppressed).toList match {
 | 
| 67112 | 387  | 
case Nil => None  | 
388  | 
case del => Some(new Nodes((graph /: del)(_.del_node(_))))  | 
|
389  | 
}  | 
|
| 
67110
 
3156faac30a7
purge hidden nodes more thoroughly: is_hidden may become true only later;
 
wenzelm 
parents: 
67014 
diff
changeset
 | 
390  | 
|
| 46723 | 391  | 
def + (entry: (Node.Name, Node)): Nodes =  | 
392  | 
    {
 | 
|
393  | 
val (name, node) = entry  | 
|
| 
70638
 
f164cec7ac22
clarified signature: prefer operations without position;
 
wenzelm 
parents: 
70636 
diff
changeset
 | 
394  | 
val imports = node.header.imports  | 
| 46723 | 395  | 
val graph1 =  | 
| 
46739
 
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
 
wenzelm 
parents: 
46737 
diff
changeset
 | 
396  | 
(graph.default_node(name, Node.empty) /: imports)((g, p) => g.default_node(p, Node.empty))  | 
| 46723 | 397  | 
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: 
46737 
diff
changeset
 | 
398  | 
val graph3 = (graph2 /: imports)((g, dep) => g.add_edge(dep, name))  | 
| 
67110
 
3156faac30a7
purge hidden nodes more thoroughly: is_hidden may become true only later;
 
wenzelm 
parents: 
67014 
diff
changeset
 | 
399  | 
new Nodes(graph3.map_node(name, _ => node))  | 
| 46723 | 400  | 
}  | 
401  | 
||
| 68321 | 402  | 
def domain: Set[Node.Name] = graph.domain  | 
403  | 
||
| 
56372
 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 
wenzelm 
parents: 
56354 
diff
changeset
 | 
404  | 
def iterator: Iterator[(Node.Name, Node)] =  | 
| 
 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 
wenzelm 
parents: 
56354 
diff
changeset
 | 
405  | 
      graph.iterator.map({ case (name, (node, _)) => (name, node) })
 | 
| 46723 | 406  | 
|
| 
70539
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
407  | 
def theory_name(theory: String): Option[Node.Name] =  | 
| 
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
408  | 
graph.keys_iterator.find(name => name.theory == theory)  | 
| 
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70284 
diff
changeset
 | 
409  | 
|
| 64799 | 410  | 
def commands_loading(file_name: Node.Name): List[Command] =  | 
| 54528 | 411  | 
      (for {
 | 
| 
56372
 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 
wenzelm 
parents: 
56354 
diff
changeset
 | 
412  | 
(_, node) <- iterator  | 
| 56314 | 413  | 
cmd <- node.load_commands.iterator  | 
| 
54530
 
2c1440f70028
ranges of thy_load commands count as visible within perspective;
 
wenzelm 
parents: 
54528 
diff
changeset
 | 
414  | 
name <- cmd.blobs_names.iterator  | 
| 54528 | 415  | 
if name == file_name  | 
416  | 
} yield cmd).toList  | 
|
417  | 
||
| 
46942
 
f5c2d66faa04
basic support for outer syntax keywords in theory header;
 
wenzelm 
parents: 
46941 
diff
changeset
 | 
418  | 
def descendants(names: List[Node.Name]): List[Node.Name] = graph.all_succs(names)  | 
| 
72065
 
11dc8929832d
clarified order --- proper sorting of requirements;
 
wenzelm 
parents: 
71601 
diff
changeset
 | 
419  | 
def requirements(names: List[Node.Name]): List[Node.Name] = graph.all_preds_rev(names)  | 
| 46723 | 420  | 
def topological_order: List[Node.Name] = graph.topological_order  | 
| 56337 | 421  | 
|
422  | 
    override def toString: String = topological_order.mkString("Nodes(", ",", ")")
 | 
|
| 46723 | 423  | 
}  | 
424  | 
||
425  | 
||
| 38424 | 426  | 
|
427  | 
/** versioning **/  | 
|
428  | 
||
429  | 
/* particular document versions */  | 
|
| 34485 | 430  | 
|
| 38417 | 431  | 
object Version  | 
432  | 
  {
 | 
|
| 46681 | 433  | 
val init: Version = new Version()  | 
| 
59077
 
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
 
wenzelm 
parents: 
57976 
diff
changeset
 | 
434  | 
def make(nodes: Nodes): Version = new Version(Document_ID.make(), nodes)  | 
| 67112 | 435  | 
|
| 
68066
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
436  | 
def purge_future(versions: Map[Document_ID.Version, Version], future: Future[Version])  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
437  | 
: Future[Version] =  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
438  | 
    {
 | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
439  | 
      if (future.is_finished) {
 | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
440  | 
val version = future.join  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
441  | 
        versions.get(version.id) match {
 | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
442  | 
case Some(version1) if !(version eq version1) => Future.value(version1)  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
443  | 
case _ => future  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
444  | 
}  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
445  | 
}  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
446  | 
else future  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
447  | 
}  | 
| 
68300
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
448  | 
|
| 
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
449  | 
def purge_suppressed(  | 
| 
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
450  | 
versions: Map[Document_ID.Version, Version]): Map[Document_ID.Version, Version] =  | 
| 
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
451  | 
    {
 | 
| 
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
452  | 
(versions /:  | 
| 
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
453  | 
(for ((id, v) <- versions.iterator; v1 <- v.purge_suppressed) yield (id, v1)))(_ + _)  | 
| 
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
454  | 
}  | 
| 38417 | 455  | 
}  | 
456  | 
||
| 46712 | 457  | 
final class Version private(  | 
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
458  | 
val id: Document_ID.Version = Document_ID.none,  | 
| 46723 | 459  | 
val nodes: Nodes = Nodes.empty)  | 
| 46941 | 460  | 
  {
 | 
| 55777 | 461  | 
    override def toString: String = "Version(" + id + ")"
 | 
| 
67110
 
3156faac30a7
purge hidden nodes more thoroughly: is_hidden may become true only later;
 
wenzelm 
parents: 
67014 
diff
changeset
 | 
462  | 
|
| 
68299
 
0b5a23477911
clarified signature -- avoid confusion with Resources.is_hidden;
 
wenzelm 
parents: 
68114 
diff
changeset
 | 
463  | 
def purge_suppressed: Option[Version] =  | 
| 
68300
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
464  | 
nodes.purge_suppressed.map(new Version(id, _))  | 
| 46941 | 465  | 
}  | 
| 34660 | 466  | 
|
| 34859 | 467  | 
|
| 38424 | 468  | 
/* changes of plain text, eventually resulting in document edits */  | 
| 
38227
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
469  | 
|
| 
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
470  | 
object Change  | 
| 
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
471  | 
  {
 | 
| 46678 | 472  | 
val init: Change = new Change()  | 
473  | 
||
474  | 
def make(previous: Future[Version], edits: List[Edit_Text], version: Future[Version]): Change =  | 
|
| 
57620
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
475  | 
new Change(Some(previous), edits.reverse, version)  | 
| 
38227
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
476  | 
}  | 
| 
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
477  | 
|
| 46712 | 478  | 
final class Change private(  | 
| 46677 | 479  | 
val previous: Option[Future[Version]] = Some(Future.value(Version.init)),  | 
| 
57620
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
480  | 
val rev_edits: List[Edit_Text] = Nil,  | 
| 46677 | 481  | 
val version: Future[Version] = Future.value(Version.init))  | 
| 
38227
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
482  | 
  {
 | 
| 44672 | 483  | 
def is_finished: Boolean =  | 
484  | 
      (previous match { case None => true case Some(future) => future.is_finished }) &&
 | 
|
485  | 
version.is_finished  | 
|
486  | 
||
| 46678 | 487  | 
def truncate: Change = new Change(None, Nil, version)  | 
| 
68066
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
488  | 
|
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
489  | 
def purge(versions: Map[Document_ID.Version, Version]): Option[Change] =  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
490  | 
    {
 | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
491  | 
val previous1 = previous.map(Version.purge_future(versions, _))  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
492  | 
val version1 = Version.purge_future(versions, version)  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
493  | 
if ((previous eq previous1) && (version eq version1)) None  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
494  | 
else Some(new Change(previous1, rev_edits, version1))  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
495  | 
}  | 
| 
38227
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
496  | 
}  | 
| 
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
497  | 
|
| 
 
6bbb42843b6e
concentrate structural document notions in document.scala;
 
wenzelm 
parents: 
38220 
diff
changeset
 | 
498  | 
|
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
499  | 
/* history navigation */  | 
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
500  | 
|
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
501  | 
object History  | 
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
502  | 
  {
 | 
| 46679 | 503  | 
val init: History = new History()  | 
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
504  | 
}  | 
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
505  | 
|
| 46712 | 506  | 
final class History private(  | 
| 46679 | 507  | 
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: 
38569 
diff
changeset
 | 
508  | 
  {
 | 
| 67114 | 509  | 
    override def toString: String = "History(" + undo_list.length + ")"
 | 
510  | 
||
| 46679 | 511  | 
def tip: Change = undo_list.head  | 
512  | 
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: 
38569 
diff
changeset
 | 
513  | 
|
| 46679 | 514  | 
def prune(check: Change => Boolean, retain: Int): Option[(List[Change], History)] =  | 
515  | 
    {
 | 
|
516  | 
val n = undo_list.iterator.zipWithIndex.find(p => check(p._1)).get._2 + 1  | 
|
517  | 
val (retained, dropped) = undo_list.splitAt(n max retain)  | 
|
518  | 
||
519  | 
      retained.splitAt(retained.length - 1) match {
 | 
|
520  | 
case (prefix, List(last)) => Some(dropped, new History(prefix ::: List(last.truncate)))  | 
|
521  | 
case _ => None  | 
|
522  | 
}  | 
|
523  | 
}  | 
|
| 
68066
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
524  | 
|
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
525  | 
def purge(versions: Map[Document_ID.Version, Version]): History =  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
526  | 
    {
 | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
527  | 
val undo_list1 = undo_list.map(_.purge(versions))  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
528  | 
if (undo_list1.forall(_.isEmpty)) this  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
529  | 
else new History(for ((a, b) <- undo_list1 zip undo_list) yield a.getOrElse(b))  | 
| 
 
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
 
wenzelm 
parents: 
67943 
diff
changeset
 | 
530  | 
}  | 
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
531  | 
}  | 
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
532  | 
|
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
533  | 
|
| 
55820
 
61869776ce1f
tuned signature -- more explicit Document.Elements;
 
wenzelm 
parents: 
55801 
diff
changeset
 | 
534  | 
/* snapshot */  | 
| 38424 | 535  | 
|
| 52972 | 536  | 
object Snapshot  | 
537  | 
  {
 | 
|
| 71601 | 538  | 
val init: Snapshot = State.init.snapshot()  | 
| 52972 | 539  | 
}  | 
540  | 
||
| 38424 | 541  | 
abstract class Snapshot  | 
542  | 
  {
 | 
|
| 64798 | 543  | 
def state: State  | 
544  | 
def version: Version  | 
|
545  | 
def is_outdated: Boolean  | 
|
| 
55649
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
546  | 
|
| 38427 | 547  | 
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: 
52887 
diff
changeset
 | 
548  | 
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: 
38976 
diff
changeset
 | 
549  | 
def convert(range: Text.Range): Text.Range  | 
| 
 
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
 
wenzelm 
parents: 
38976 
diff
changeset
 | 
550  | 
def revert(range: Text.Range): Text.Range  | 
| 52972 | 551  | 
|
| 64798 | 552  | 
def node_name: Node.Name  | 
553  | 
def node: Node  | 
|
| 69556 | 554  | 
def nodes: List[(Node.Name, Node)]  | 
| 66040 | 555  | 
|
| 64799 | 556  | 
def commands_loading: List[Command]  | 
557  | 
def commands_loading_ranges(pred: Node.Name => Boolean): List[Text.Range]  | 
|
| 
65199
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
558  | 
def current_command(other_node_name: Node.Name, offset: Text.Offset): Option[Command]  | 
| 
55649
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
559  | 
|
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
560  | 
def get_snippet_command: Option[Command]  | 
| 
72817
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
561  | 
|
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
562  | 
def node_files: List[Node.Name] =  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
563  | 
      get_snippet_command match {
 | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
564  | 
case None => List(node_name)  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
565  | 
case Some(command) => node_name :: command.blobs_names  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
566  | 
}  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
567  | 
|
| 72718 | 568  | 
def command_snippet(command: Command): Snapshot =  | 
569  | 
    {
 | 
|
570  | 
val node_name = command.node_name  | 
|
571  | 
||
572  | 
val nodes0 = version.nodes  | 
|
573  | 
val nodes1 = nodes0 + (node_name -> nodes0(node_name).update_commands(Linear_Set(command)))  | 
|
574  | 
val version1 = Document.Version.make(nodes1)  | 
|
575  | 
||
576  | 
val edits: List[Edit_Text] =  | 
|
577  | 
List(node_name -> Node.Edits(List(Text.Edit.insert(0, command.source))))  | 
|
578  | 
||
579  | 
val state0 = state.define_command(command)  | 
|
580  | 
val state1 =  | 
|
581  | 
state0.continue_history(Future.value(version), edits, Future.value(version1))  | 
|
582  | 
.define_version(version1, state0.the_assignment(version))  | 
|
583  | 
.assign(version1.id, Nil, List(command.id -> List(Document_ID.make())))._2  | 
|
584  | 
||
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
585  | 
state1.snapshot(name = node_name, snippet_command = Some(command))  | 
| 72718 | 586  | 
}  | 
587  | 
||
| 72723 | 588  | 
def xml_markup(  | 
589  | 
range: Text.Range = Text.Range.full,  | 
|
590  | 
elements: Markup.Elements = Markup.Elements.full): XML.Body  | 
|
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
591  | 
|
| 
72817
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
592  | 
def xml_markup_blobs(elements: Markup.Elements = Markup.Elements.full): List[XML.Body] =  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
593  | 
    {
 | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
594  | 
      get_snippet_command match {
 | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
595  | 
case None => Nil  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
596  | 
case Some(command) =>  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
597  | 
for (Exn.Res(blob) <- command.blobs)  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
598  | 
          yield {
 | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
599  | 
val text = blob.read_file  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
600  | 
val markup = command.init_markups(Command.Markup_Index.blob(blob))  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
601  | 
markup.to_XML(Text.Range(0, text.length), text, elements)  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
602  | 
}  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
603  | 
}  | 
| 
 
1c378ab75d48
clarified signature, notably access to blob files;
 
wenzelm 
parents: 
72816 
diff
changeset
 | 
604  | 
}  | 
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
605  | 
|
| 68365 | 606  | 
def messages: List[(XML.Tree, Position.T)]  | 
607  | 
def exports: List[Export.Entry]  | 
|
| 68417 | 608  | 
def exports_map: Map[String, Export.Entry]  | 
| 66040 | 609  | 
|
| 64665 | 610  | 
def find_command(id: Document_ID.Generic): Option[(Node, Command)]  | 
611  | 
def find_command_position(id: Document_ID.Generic, offset: Symbol.Offset)  | 
|
612  | 
: Option[Line.Node_Position]  | 
|
613  | 
||
| 
55651
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
614  | 
def cumulate[A](  | 
| 
55649
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
615  | 
range: Text.Range,  | 
| 
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
616  | 
info: A,  | 
| 56743 | 617  | 
elements: Markup.Elements,  | 
| 
56354
 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 
wenzelm 
parents: 
56337 
diff
changeset
 | 
618  | 
result: List[Command.State] => (A, Text.Markup) => Option[A],  | 
| 
55651
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
619  | 
status: Boolean = false): List[Text.Info[A]]  | 
| 
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
620  | 
|
| 
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
621  | 
def select[A](  | 
| 
55649
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
622  | 
range: Text.Range,  | 
| 56743 | 623  | 
elements: Markup.Elements,  | 
| 
56354
 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 
wenzelm 
parents: 
56337 
diff
changeset
 | 
624  | 
result: List[Command.State] => Text.Markup => Option[A],  | 
| 
55651
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
625  | 
status: Boolean = false): List[Text.Info[A]]  | 
| 65332 | 626  | 
|
627  | 
def command_results(range: Text.Range): Command.Results  | 
|
628  | 
def command_results(command: Command): Command.Results  | 
|
| 68836 | 629  | 
|
630  | 
def command_id_map: Map[Document_ID.Generic, Command]  | 
|
| 38424 | 631  | 
}  | 
632  | 
||
| 
55820
 
61869776ce1f
tuned signature -- more explicit Document.Elements;
 
wenzelm 
parents: 
55801 
diff
changeset
 | 
633  | 
|
| 64814 | 634  | 
/* model */  | 
635  | 
||
| 65221 | 636  | 
trait Session  | 
637  | 
  {
 | 
|
638  | 
def resources: Resources  | 
|
639  | 
}  | 
|
640  | 
||
| 64814 | 641  | 
trait Model  | 
642  | 
  {
 | 
|
643  | 
def session: Session  | 
|
| 
64827
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
644  | 
def is_stable: Boolean  | 
| 
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
645  | 
def snapshot(): Snapshot  | 
| 64814 | 646  | 
|
| 65356 | 647  | 
def node_name: Node.Name  | 
| 64814 | 648  | 
def is_theory: Boolean = node_name.is_theory  | 
649  | 
override def toString: String = node_name.toString  | 
|
650  | 
||
| 67014 | 651  | 
def get_text(range: Text.Range): Option[String]  | 
| 66114 | 652  | 
|
| 64815 | 653  | 
def node_required: Boolean  | 
| 65356 | 654  | 
def get_blob: Option[Blob]  | 
| 66150 | 655  | 
def bibtex_entries: List[Text.Info[String]]  | 
| 64815 | 656  | 
|
| 
64827
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
657  | 
def node_edits(  | 
| 64867 | 658  | 
node_header: Node.Header,  | 
659  | 
text_edits: List[Text.Edit],  | 
|
660  | 
perspective: Node.Perspective_Text): List[Edit_Text] =  | 
|
| 
64827
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
661  | 
    {
 | 
| 
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
662  | 
val edits: List[Node.Edit[Text.Edit, Text.Perspective]] =  | 
| 
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
663  | 
        get_blob match {
 | 
| 
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
664  | 
case None =>  | 
| 
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
665  | 
List(  | 
| 65356 | 666  | 
Node.Deps(  | 
| 66773 | 667  | 
                if (session.resources.session_base.loaded_theory(node_name)) {
 | 
668  | 
node_header.append_errors(  | 
|
669  | 
                    List("Cannot update finished theory " + quote(node_name.theory)))
 | 
|
670  | 
}  | 
|
| 
64827
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
671  | 
else node_header),  | 
| 65356 | 672  | 
Node.Edits(text_edits), perspective)  | 
673  | 
case Some(blob) => List(Node.Blob(blob), Node.Edits(text_edits))  | 
|
| 
64827
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
674  | 
}  | 
| 
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
675  | 
edits.flatMap(edit => if (edit.is_void) None else Some(node_name -> edit))  | 
| 
 
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
 
wenzelm 
parents: 
64819 
diff
changeset
 | 
676  | 
}  | 
| 64814 | 677  | 
}  | 
678  | 
||
679  | 
||
| 
55820
 
61869776ce1f
tuned signature -- more explicit Document.Elements;
 
wenzelm 
parents: 
55801 
diff
changeset
 | 
680  | 
/** global state -- document structure, execution process, editing history **/  | 
| 
 
61869776ce1f
tuned signature -- more explicit Document.Elements;
 
wenzelm 
parents: 
55801 
diff
changeset
 | 
681  | 
|
| 52563 | 682  | 
type Assign_Update =  | 
683  | 
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: 
44475 
diff
changeset
 | 
684  | 
|
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
685  | 
object State  | 
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
686  | 
  {
 | 
| 38373 | 687  | 
class Fail(state: State) extends Exception  | 
688  | 
||
| 
44479
 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 
wenzelm 
parents: 
44477 
diff
changeset
 | 
689  | 
object Assignment  | 
| 
 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 
wenzelm 
parents: 
44477 
diff
changeset
 | 
690  | 
    {
 | 
| 46683 | 691  | 
val init: Assignment = new Assignment()  | 
| 
44479
 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 
wenzelm 
parents: 
44477 
diff
changeset
 | 
692  | 
}  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
693  | 
|
| 46712 | 694  | 
final class Assignment private(  | 
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
695  | 
val command_execs: Map[Document_ID.Command, List[Document_ID.Exec]] = Map.empty,  | 
| 46677 | 696  | 
val is_finished: Boolean = false)  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
697  | 
    {
 | 
| 67114 | 698  | 
      override def toString: String = "Assignment(" + command_execs.size + "," + is_finished + ")"
 | 
699  | 
||
| 44477 | 700  | 
      def check_finished: Assignment = { require(is_finished); this }
 | 
| 
47388
 
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
 
wenzelm 
parents: 
46997 
diff
changeset
 | 
701  | 
def unfinished: Assignment = new Assignment(command_execs, false)  | 
| 
44479
 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 
wenzelm 
parents: 
44477 
diff
changeset
 | 
702  | 
|
| 52563 | 703  | 
def assign(update: Assign_Update): Assignment =  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
704  | 
      {
 | 
| 
38976
 
a4a465dc89d9
Document.State.Assignment: eliminated promise in favour of plain values -- signalling is done via event bus in Session;
 
wenzelm 
parents: 
38885 
diff
changeset
 | 
705  | 
require(!is_finished)  | 
| 
44479
 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 
wenzelm 
parents: 
44477 
diff
changeset
 | 
706  | 
val command_execs1 =  | 
| 52563 | 707  | 
          (command_execs /: update) {
 | 
708  | 
case (res, (command_id, exec_ids)) =>  | 
|
709  | 
if (exec_ids.isEmpty) res - command_id  | 
|
710  | 
else res + (command_id -> exec_ids)  | 
|
| 
44479
 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 
wenzelm 
parents: 
44477 
diff
changeset
 | 
711  | 
}  | 
| 
47388
 
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
 
wenzelm 
parents: 
46997 
diff
changeset
 | 
712  | 
new Assignment(command_execs1, true)  | 
| 
38150
 
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
 
wenzelm 
parents: 
37849 
diff
changeset
 | 
713  | 
}  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
714  | 
}  | 
| 46682 | 715  | 
|
716  | 
val init: State =  | 
|
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69633 
diff
changeset
 | 
717  | 
State().define_version(Version.init, Assignment.init).assign(Version.init.id, Nil, Nil)._2  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
718  | 
}  | 
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
719  | 
|
| 46712 | 720  | 
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: 
56468 
diff
changeset
 | 
721  | 
/*reachable versions*/  | 
| 60215 | 722  | 
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: 
56468 
diff
changeset
 | 
723  | 
/*inlined auxiliary files*/  | 
| 60215 | 724  | 
blobs: Set[SHA1.Digest] = Set.empty,  | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
725  | 
/*loaded theories in batch builds*/  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
726  | 
theories: Map[Document_ID.Exec, Command.State] = Map.empty,  | 
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
727  | 
/*static markup from define_command*/  | 
| 60215 | 728  | 
commands: Map[Document_ID.Command, Command.State] = Map.empty,  | 
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
729  | 
/*dynamic markup from execution*/  | 
| 60215 | 730  | 
execs: Map[Document_ID.Exec, Command.State] = Map.empty,  | 
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
731  | 
/*command-exec assignment for each version*/  | 
| 60215 | 732  | 
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: 
56468 
diff
changeset
 | 
733  | 
/*commands with markup produced by other commands (imm_succs)*/  | 
| 60215 | 734  | 
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: 
56468 
diff
changeset
 | 
735  | 
/*explicit (linear) history*/  | 
| 60215 | 736  | 
history: History = History.init,  | 
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57842 
diff
changeset
 | 
737  | 
/*intermediate state between remove_versions/removed_versions*/  | 
| 60215 | 738  | 
removing_versions: Boolean = false)  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
739  | 
  {
 | 
| 68496 | 740  | 
override def toString: String =  | 
741  | 
"State(versions = " + versions.size +  | 
|
742  | 
", blobs = " + blobs.size +  | 
|
743  | 
", commands = " + commands.size +  | 
|
744  | 
", execs = " + execs.size +  | 
|
745  | 
", assignments = " + assignments.size +  | 
|
746  | 
", commands_redirection = " + commands_redirection.size +  | 
|
747  | 
", history = " + history.undo_list.size +  | 
|
748  | 
", removing_versions = " + removing_versions + ")"  | 
|
749  | 
||
| 38373 | 750  | 
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: 
38367 
diff
changeset
 | 
751  | 
|
| 
44479
 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 
wenzelm 
parents: 
44477 
diff
changeset
 | 
752  | 
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: 
38367 
diff
changeset
 | 
753  | 
    {
 | 
| 38417 | 754  | 
val id = version.id  | 
755  | 
copy(versions = versions + (id -> version),  | 
|
| 
44479
 
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
 
wenzelm 
parents: 
44477 
diff
changeset
 | 
756  | 
assignments = assignments + (id -> assignment.unfinished))  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
757  | 
}  | 
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
758  | 
|
| 
54519
 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 
wenzelm 
parents: 
54515 
diff
changeset
 | 
759  | 
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: 
54515 
diff
changeset
 | 
760  | 
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: 
54515 
diff
changeset
 | 
761  | 
|
| 38373 | 762  | 
def define_command(command: Command): State =  | 
763  | 
    {
 | 
|
764  | 
val id = command.id  | 
|
| 72719 | 765  | 
if (commands.isDefinedAt(id)) fail  | 
766  | 
else copy(commands = commands + (id -> command.init_state))  | 
|
| 38373 | 767  | 
}  | 
768  | 
||
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
769  | 
def defined_command(id: Document_ID.Command): Boolean = commands.isDefinedAt(id)  | 
| 44582 | 770  | 
|
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
771  | 
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: 
52563 
diff
changeset
 | 
772  | 
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: 
52563 
diff
changeset
 | 
773  | 
def the_dynamic_state(id: Document_ID.Exec): Command.State = execs.getOrElse(id, fail)  | 
| 52563 | 774  | 
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: 
38367 
diff
changeset
 | 
775  | 
|
| 68857 | 776  | 
def lookup_id(id: Document_ID.Generic): Option[Command.State] =  | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
777  | 
theories.get(id) orElse commands.get(id) orElse execs.get(id)  | 
| 68857 | 778  | 
|
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
779  | 
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: 
56176 
diff
changeset
 | 
780  | 
id == st.command.id ||  | 
| 
 
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
 
wenzelm 
parents: 
56176 
diff
changeset
 | 
781  | 
      (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: 
56176 
diff
changeset
 | 
782  | 
|
| 72780 | 783  | 
private def other_id(node_name: Node.Name, id: Document_ID.Generic)  | 
| 
63032
 
e0fa59bbc956
reactivated other_id reports (see also db929027e701, 8eda56033203);
 
wenzelm 
parents: 
63020 
diff
changeset
 | 
784  | 
: Option[(Symbol.Text_Chunk.Id, Symbol.Text_Chunk)] =  | 
| 72780 | 785  | 
    {
 | 
786  | 
      for {
 | 
|
787  | 
st <- lookup_id(id)  | 
|
788  | 
if st.command.node_name == node_name  | 
|
789  | 
} yield (Symbol.Text_Chunk.Id(st.command.id), st.command.chunk)  | 
|
790  | 
}  | 
|
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
791  | 
|
| 56475 | 792  | 
private def redirection(st: Command.State): Graph[Document_ID.Command, Unit] =  | 
793  | 
      (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: 
56468 
diff
changeset
 | 
794  | 
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: 
56468 
diff
changeset
 | 
795  | 
|
| 67825 | 796  | 
def accumulate(id: Document_ID.Generic, message: XML.Elem, xml_cache: XML.Cache)  | 
797  | 
: (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: 
56468 
diff
changeset
 | 
798  | 
    {
 | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
799  | 
def update(st: Command.State): (Command.State, State) =  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
800  | 
      {
 | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
801  | 
val st1 = st.accumulate(self_id(st), other_id, message, xml_cache)  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
802  | 
(st1, copy(commands_redirection = redirection(st1)))  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
803  | 
}  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
804  | 
      execs.get(id).map(update) match {
 | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
805  | 
case Some((st1, state1)) => (st1, state1.copy(execs = execs + (id -> st1)))  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
806  | 
case None =>  | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
807  | 
          commands.get(id).map(update) match {
 | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
808  | 
case Some((st1, state1)) => (st1, state1.copy(commands = commands + (id -> st1)))  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
809  | 
case None =>  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
810  | 
              theories.get(id).map(update) match {
 | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
811  | 
case Some((st1, state1)) => (st1, state1.copy(theories = theories + (id -> st1)))  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
812  | 
case None => fail  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
813  | 
}  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
814  | 
}  | 
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
815  | 
}  | 
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
816  | 
}  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
817  | 
|
| 68101 | 818  | 
def add_export(id: Document_ID.Generic, entry: Command.Exports.Entry): (Command.State, State) =  | 
819  | 
    {
 | 
|
820  | 
      execs.get(id) match {
 | 
|
821  | 
case Some(st) =>  | 
|
| 68114 | 822  | 
          st.add_export(entry) match {
 | 
823  | 
case Some(new_st) => (new_st, copy(execs = execs + (id -> new_st)))  | 
|
824  | 
case None => fail  | 
|
825  | 
}  | 
|
| 68101 | 826  | 
case None =>  | 
827  | 
          commands.get(id) match {
 | 
|
828  | 
case Some(st) =>  | 
|
| 68114 | 829  | 
              st.add_export(entry) match {
 | 
830  | 
case Some(new_st) => (new_st, copy(commands = commands + (id -> new_st)))  | 
|
831  | 
case None => fail  | 
|
832  | 
}  | 
|
| 68101 | 833  | 
case None => fail  | 
834  | 
}  | 
|
835  | 
}  | 
|
836  | 
}  | 
|
837  | 
||
| 69633 | 838  | 
def node_exports(version: Version, node_name: Node.Name): Command.Exports =  | 
839  | 
Command.Exports.merge(  | 
|
840  | 
        for {
 | 
|
841  | 
command <- version.nodes(node_name).commands.iterator  | 
|
842  | 
st <- command_states(version, command).iterator  | 
|
843  | 
} yield st.exports)  | 
|
844  | 
||
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
845  | 
def begin_theory(  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
846  | 
node_name: Node.Name,  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
847  | 
id: Document_ID.Exec,  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
848  | 
source: String,  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
849  | 
blobs_info: Command.Blobs_Info): State =  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
850  | 
    {
 | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
851  | 
if (theories.isDefinedAt(id)) fail  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
852  | 
      else {
 | 
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
853  | 
val command =  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
854  | 
Command.unparsed(source, theory = true, id = id, node_name = node_name,  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
855  | 
blobs_info = blobs_info)  | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
856  | 
copy(theories = theories + (id -> command.empty_state))  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
857  | 
}  | 
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
858  | 
}  | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
859  | 
|
| 
72721
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
860  | 
def end_theory(theory: String): (Snapshot, State) =  | 
| 
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
861  | 
      theories.collectFirst({ case (_, st) if st.command.node_name.theory == theory => st }) match {
 | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
862  | 
case None => fail  | 
| 
72721
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
863  | 
case Some(st) =>  | 
| 
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
864  | 
val command = st.command  | 
| 
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
865  | 
val node_name = command.node_name  | 
| 
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
866  | 
val command1 =  | 
| 
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
867  | 
Command.unparsed(command.source, theory = true, id = command.id, node_name = node_name,  | 
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
868  | 
blobs_info = command.blobs_info, results = st.results, markups = st.markups)  | 
| 
72721
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
869  | 
val state1 = copy(theories = theories - command1.id)  | 
| 
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
870  | 
val snapshot = state1.snapshot(name = node_name).command_snippet(command1)  | 
| 
 
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
 
wenzelm 
parents: 
72719 
diff
changeset
 | 
871  | 
(snapshot, state1)  | 
| 
72692
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
872  | 
}  | 
| 
 
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
 
wenzelm 
parents: 
72669 
diff
changeset
 | 
873  | 
|
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69633 
diff
changeset
 | 
874  | 
def assign(id: Document_ID.Version, edited: List[String], update: Assign_Update)  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69633 
diff
changeset
 | 
875  | 
: ((List[Node.Name], List[Command]), State) =  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
876  | 
    {
 | 
| 38417 | 877  | 
val version = the_version(id)  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
878  | 
|
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69633 
diff
changeset
 | 
879  | 
val edited_set = edited.toSet  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69633 
diff
changeset
 | 
880  | 
val edited_nodes =  | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69633 
diff
changeset
 | 
881  | 
        (for { (name, _) <- version.nodes.iterator if edited_set(name.node) } yield name).toList
 | 
| 
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69633 
diff
changeset
 | 
882  | 
|
| 
52566
 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 
wenzelm 
parents: 
52564 
diff
changeset
 | 
883  | 
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: 
52564 
diff
changeset
 | 
884  | 
: Option[(Document_ID.Exec, Command.State)] =  | 
| 
 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 
wenzelm 
parents: 
52564 
diff
changeset
 | 
885  | 
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: 
52564 
diff
changeset
 | 
886  | 
|
| 44543 | 887  | 
val (changed_commands, new_execs) =  | 
| 52563 | 888  | 
        ((Nil: List[Command], execs) /: update) {
 | 
| 
52566
 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 
wenzelm 
parents: 
52564 
diff
changeset
 | 
889  | 
case ((commands1, execs1), (command_id, exec)) =>  | 
| 
 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 
wenzelm 
parents: 
52564 
diff
changeset
 | 
890  | 
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: 
52564 
diff
changeset
 | 
891  | 
val command = st.command  | 
| 
52527
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52508 
diff
changeset
 | 
892  | 
val commands2 = command :: commands1  | 
| 44543 | 893  | 
val execs2 =  | 
894  | 
              exec match {
 | 
|
| 
52527
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52508 
diff
changeset
 | 
895  | 
case Nil => execs1  | 
| 
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52508 
diff
changeset
 | 
896  | 
case eval_id :: print_ids =>  | 
| 
52566
 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 
wenzelm 
parents: 
52564 
diff
changeset
 | 
897  | 
execs1 ++ upd(eval_id, st) ++  | 
| 
 
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
 
wenzelm 
parents: 
52564 
diff
changeset
 | 
898  | 
(for (id <- print_ids; up <- upd(id, command.empty_state)) yield up)  | 
| 44543 | 899  | 
}  | 
900  | 
(commands2, execs2)  | 
|
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
901  | 
}  | 
| 52563 | 902  | 
val new_assignment = the_assignment(version).assign(update)  | 
| 43722 | 903  | 
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: 
44475 
diff
changeset
 | 
904  | 
|
| 
70284
 
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
 
wenzelm 
parents: 
69633 
diff
changeset
 | 
905  | 
((edited_nodes, changed_commands), new_state)  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
906  | 
}  | 
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
907  | 
|
| 38417 | 908  | 
def is_assigned(version: Version): Boolean =  | 
| 43722 | 909  | 
      assignments.get(version.id) match {
 | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
910  | 
case Some(assgn) => assgn.is_finished  | 
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
911  | 
case None => false  | 
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
912  | 
}  | 
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
913  | 
|
| 
44436
 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 
wenzelm 
parents: 
44385 
diff
changeset
 | 
914  | 
def is_stable(change: Change): Boolean =  | 
| 
 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 
wenzelm 
parents: 
44385 
diff
changeset
 | 
915  | 
change.is_finished && is_assigned(change.version.get_finished)  | 
| 
 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 
wenzelm 
parents: 
44385 
diff
changeset
 | 
916  | 
|
| 
46944
 
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
917  | 
def recent_finished: Change = history.undo_list.find(_.is_finished) getOrElse fail  | 
| 44672 | 918  | 
def recent_stable: Change = history.undo_list.find(is_stable) getOrElse fail  | 
| 
60933
 
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
 
wenzelm 
parents: 
60916 
diff
changeset
 | 
919  | 
def stable_tip_version: Option[Version] =  | 
| 
 
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
 
wenzelm 
parents: 
60916 
diff
changeset
 | 
920  | 
if (is_stable(history.tip)) Some(history.tip.version.get_finished) else None  | 
| 
44436
 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 
wenzelm 
parents: 
44385 
diff
changeset
 | 
921  | 
|
| 44446 | 922  | 
def continue_history(  | 
| 56711 | 923  | 
previous: Future[Version],  | 
924  | 
edits: List[Edit_Text],  | 
|
925  | 
version: Future[Version]): State =  | 
|
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
926  | 
    {
 | 
| 46678 | 927  | 
val change = Change.make(previous, edits, version)  | 
| 56711 | 928  | 
copy(history = history + change)  | 
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
929  | 
}  | 
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
930  | 
|
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57842 
diff
changeset
 | 
931  | 
def remove_versions(retain: Int = 0): (List[Version], State) =  | 
| 44672 | 932  | 
    {
 | 
| 46679 | 933  | 
      history.prune(is_stable, retain) match {
 | 
934  | 
case Some((dropped, history1)) =>  | 
|
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57842 
diff
changeset
 | 
935  | 
val old_versions = dropped.map(change => change.version.get_finished)  | 
| 59319 | 936  | 
val removing = old_versions.nonEmpty  | 
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57842 
diff
changeset
 | 
937  | 
val state1 = copy(history = history1, removing_versions = removing)  | 
| 
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57842 
diff
changeset
 | 
938  | 
(old_versions, state1)  | 
| 46679 | 939  | 
case None => fail  | 
| 44672 | 940  | 
}  | 
941  | 
}  | 
|
942  | 
||
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
943  | 
def removed_versions(removed: List[Document_ID.Version]): State =  | 
| 44676 | 944  | 
    {
 | 
| 
68300
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
945  | 
val versions1 = Version.purge_suppressed(versions -- removed)  | 
| 
67110
 
3156faac30a7
purge hidden nodes more thoroughly: is_hidden may become true only later;
 
wenzelm 
parents: 
67014 
diff
changeset
 | 
946  | 
|
| 44676 | 947  | 
val assignments1 = assignments -- removed  | 
| 67112 | 948  | 
var blobs1_names = Set.empty[Node.Name]  | 
| 
54519
 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 
wenzelm 
parents: 
54515 
diff
changeset
 | 
949  | 
var blobs1 = Set.empty[SHA1.Digest]  | 
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
950  | 
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: 
52527 
diff
changeset
 | 
951  | 
var execs1 = Map.empty[Document_ID.Exec, Command.State]  | 
| 44676 | 952  | 
      for {
 | 
| 67112 | 953  | 
(version_id, version) <- versions1.iterator  | 
| 46997 | 954  | 
command_execs = assignments1(version_id).command_execs  | 
| 
56372
 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 
wenzelm 
parents: 
56354 
diff
changeset
 | 
955  | 
(_, node) <- version.nodes.iterator  | 
| 44676 | 956  | 
command <- node.commands.iterator  | 
957  | 
      } {
 | 
|
| 67112 | 958  | 
        for ((name, digest) <- command.blobs_defined) {
 | 
959  | 
blobs1_names += name  | 
|
| 
54519
 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 
wenzelm 
parents: 
54515 
diff
changeset
 | 
960  | 
blobs1 += digest  | 
| 67112 | 961  | 
}  | 
| 
54519
 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 
wenzelm 
parents: 
54515 
diff
changeset
 | 
962  | 
|
| 52568 | 963  | 
if (!commands1.isDefinedAt(command.id))  | 
964  | 
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: 
54515 
diff
changeset
 | 
965  | 
|
| 52568 | 966  | 
        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: 
52508 
diff
changeset
 | 
967  | 
if (!execs1.isDefinedAt(exec_id))  | 
| 
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52508 
diff
changeset
 | 
968  | 
execs.get(exec_id).foreach(st => execs1 += (exec_id -> st))  | 
| 44676 | 969  | 
}  | 
970  | 
}  | 
|
| 67112 | 971  | 
|
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
972  | 
copy(  | 
| 
68300
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
973  | 
versions = versions1,  | 
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
974  | 
blobs = blobs1,  | 
| 
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
975  | 
commands = commands1,  | 
| 
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
976  | 
execs = execs1,  | 
| 70699 | 977  | 
commands_redirection = commands_redirection.restrict(commands1.keySet),  | 
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57842 
diff
changeset
 | 
978  | 
assignments = assignments1,  | 
| 
68300
 
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
 
wenzelm 
parents: 
68299 
diff
changeset
 | 
979  | 
history = history.purge(versions1),  | 
| 
57976
 
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
 
wenzelm 
parents: 
57842 
diff
changeset
 | 
980  | 
removing_versions = false)  | 
| 44676 | 981  | 
}  | 
982  | 
||
| 68836 | 983  | 
def command_id_map(version: Version, commands: Iterable[Command])  | 
984  | 
: Map[Document_ID.Generic, Command] =  | 
|
985  | 
    {
 | 
|
986  | 
require(is_assigned(version))  | 
|
987  | 
val assignment = the_assignment(version).check_finished  | 
|
988  | 
      (for {
 | 
|
989  | 
command <- commands.iterator  | 
|
990  | 
id <- (command.id :: assignment.command_execs.getOrElse(command.id, Nil)).iterator  | 
|
991  | 
} yield (id -> command)).toMap  | 
|
992  | 
}  | 
|
993  | 
||
| 
70780
 
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
 
wenzelm 
parents: 
70716 
diff
changeset
 | 
994  | 
def command_maybe_consolidated(version: Version, command: Command): Boolean =  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
995  | 
    {
 | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
996  | 
require(is_assigned(version))  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
997  | 
      try {
 | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
998  | 
        the_assignment(version).check_finished.command_execs.getOrElse(command.id, Nil) match {
 | 
| 
70780
 
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
 
wenzelm 
parents: 
70716 
diff
changeset
 | 
999  | 
case eval_id :: print_ids =>  | 
| 
 
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
 
wenzelm 
parents: 
70716 
diff
changeset
 | 
1000  | 
the_dynamic_state(eval_id).maybe_consolidated &&  | 
| 
 
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
 
wenzelm 
parents: 
70716 
diff
changeset
 | 
1001  | 
!print_ids.exists(print_id => the_dynamic_state(print_id).consolidating)  | 
| 
 
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
 
wenzelm 
parents: 
70716 
diff
changeset
 | 
1002  | 
case Nil => false  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
1003  | 
}  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
1004  | 
}  | 
| 
70780
 
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
 
wenzelm 
parents: 
70716 
diff
changeset
 | 
1005  | 
      catch { case _: State.Fail => false }
 | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
1006  | 
}  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
1007  | 
|
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
1008  | 
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: 
56468 
diff
changeset
 | 
1009  | 
: List[(Document_ID.Generic, Command.State)] =  | 
| 44613 | 1010  | 
    {
 | 
1011  | 
require(is_assigned(version))  | 
|
1012  | 
      try {
 | 
|
| 
52527
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52508 
diff
changeset
 | 
1013  | 
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: 
56468 
diff
changeset
 | 
1014  | 
          .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: 
52508 
diff
changeset
 | 
1015  | 
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: 
56468 
diff
changeset
 | 
1016  | 
case res => res  | 
| 
52527
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52508 
diff
changeset
 | 
1017  | 
}  | 
| 44613 | 1018  | 
}  | 
| 
47395
 
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
 
wenzelm 
parents: 
47388 
diff
changeset
 | 
1019  | 
      catch {
 | 
| 
 
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
 
wenzelm 
parents: 
47388 
diff
changeset
 | 
1020  | 
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: 
56468 
diff
changeset
 | 
1021  | 
          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: 
56468 
diff
changeset
 | 
1022  | 
          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: 
47388 
diff
changeset
 | 
1023  | 
}  | 
| 44613 | 1024  | 
}  | 
1025  | 
||
| 
56470
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
1026  | 
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: 
56468 
diff
changeset
 | 
1027  | 
    {
 | 
| 
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
1028  | 
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: 
56468 
diff
changeset
 | 
1029  | 
val others =  | 
| 56475 | 1030  | 
        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: 
56468 
diff
changeset
 | 
1031  | 
          (for {
 | 
| 56475 | 1032  | 
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: 
56468 
diff
changeset
 | 
1033  | 
(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: 
56468 
diff
changeset
 | 
1034  | 
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: 
56468 
diff
changeset
 | 
1035  | 
} 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: 
56468 
diff
changeset
 | 
1036  | 
}  | 
| 
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
1037  | 
else Nil  | 
| 56489 | 1038  | 
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: 
56468 
diff
changeset
 | 
1039  | 
}  | 
| 
 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 
wenzelm 
parents: 
56468 
diff
changeset
 | 
1040  | 
|
| 
56299
 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 
wenzelm 
parents: 
56298 
diff
changeset
 | 
1041  | 
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: 
56298 
diff
changeset
 | 
1042  | 
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: 
56298 
diff
changeset
 | 
1043  | 
|
| 
56301
 
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
 
wenzelm 
parents: 
56300 
diff
changeset
 | 
1044  | 
def command_markup(version: Version, command: Command, index: Command.Markup_Index,  | 
| 56743 | 1045  | 
range: Text.Range, elements: Markup.Elements): Markup_Tree =  | 
| 
56301
 
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
 
wenzelm 
parents: 
56300 
diff
changeset
 | 
1046  | 
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: 
56298 
diff
changeset
 | 
1047  | 
|
| 72723 | 1048  | 
def xml_markup(  | 
| 66041 | 1049  | 
version: Version,  | 
| 67264 | 1050  | 
node_name: Node.Name,  | 
| 72723 | 1051  | 
range: Text.Range = Text.Range.full,  | 
1052  | 
elements: Markup.Elements = Markup.Elements.full): XML.Body =  | 
|
| 66041 | 1053  | 
    {
 | 
| 67264 | 1054  | 
val node = version.nodes(node_name)  | 
1055  | 
      if (node_name.is_theory) {
 | 
|
1056  | 
val markup_index = Command.Markup_Index.markup  | 
|
1057  | 
        (for {
 | 
|
1058  | 
command <- node.commands.iterator  | 
|
1059  | 
command_range <- command.range.try_restrict(range).iterator  | 
|
1060  | 
markup = command_markup(version, command, markup_index, command_range, elements)  | 
|
1061  | 
tree <- markup.to_XML(command_range, command.source, elements).iterator  | 
|
1062  | 
} yield tree).toList  | 
|
1063  | 
}  | 
|
1064  | 
      else {
 | 
|
| 
67265
 
f32287c95432
store full blob source for the sake of markup_to_XML;
 
wenzelm 
parents: 
67264 
diff
changeset
 | 
1065  | 
val node_source = node.source  | 
| 67264 | 1066  | 
        Text.Range(0, node_source.length).try_restrict(range) match {
 | 
1067  | 
case None => Nil  | 
|
1068  | 
case Some(node_range) =>  | 
|
1069  | 
val markup =  | 
|
1070  | 
              version.nodes.commands_loading(node_name).headOption match {
 | 
|
1071  | 
case None => Markup_Tree.empty  | 
|
1072  | 
case Some(command) =>  | 
|
1073  | 
val chunk_name = Symbol.Text_Chunk.File(node_name.node)  | 
|
1074  | 
val markup_index = Command.Markup_Index(false, chunk_name)  | 
|
1075  | 
command_markup(version, command, markup_index, node_range, elements)  | 
|
1076  | 
}  | 
|
1077  | 
markup.to_XML(node_range, node_source, elements)  | 
|
1078  | 
}  | 
|
1079  | 
}  | 
|
| 66041 | 1080  | 
}  | 
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1081  | 
|
| 68323 | 1082  | 
def node_initialized(version: Version, name: Node.Name): Boolean =  | 
1083  | 
name.is_theory &&  | 
|
1084  | 
      (version.nodes(name).commands.iterator.find(_.potentially_initialized) match {
 | 
|
1085  | 
case None => false  | 
|
1086  | 
case Some(command) => command_states(version, command).headOption.exists(_.initialized)  | 
|
1087  | 
})  | 
|
1088  | 
||
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
1089  | 
def node_maybe_consolidated(version: Version, name: Node.Name): Boolean =  | 
| 
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
1090  | 
name.is_theory &&  | 
| 
70780
 
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
 
wenzelm 
parents: 
70716 
diff
changeset
 | 
1091  | 
version.nodes(name).commands.reverse.iterator.forall(command_maybe_consolidated(version, _))  | 
| 
68381
 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 
wenzelm 
parents: 
68365 
diff
changeset
 | 
1092  | 
|
| 
66379
 
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
 
wenzelm 
parents: 
66195 
diff
changeset
 | 
1093  | 
def node_consolidated(version: Version, name: Node.Name): Boolean =  | 
| 
 
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
 
wenzelm 
parents: 
66195 
diff
changeset
 | 
1094  | 
!name.is_theory ||  | 
| 68335 | 1095  | 
      {
 | 
1096  | 
val it = version.nodes(name).commands.reverse.iterator  | 
|
1097  | 
it.hasNext && command_states(version, it.next).exists(_.consolidated)  | 
|
1098  | 
}  | 
|
| 
66379
 
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
 
wenzelm 
parents: 
66195 
diff
changeset
 | 
1099  | 
|
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1100  | 
// persistent user-view  | 
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
1101  | 
def snapshot(  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
1102  | 
name: Node.Name = Node.Name.empty,  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
1103  | 
pending_edits: List[Text.Edit] = Nil,  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
1104  | 
snippet_command: Option[Command] = None): Snapshot =  | 
| 
38370
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
1105  | 
    {
 | 
| 44672 | 1106  | 
val stable = recent_stable  | 
| 
44436
 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 
wenzelm 
parents: 
44385 
diff
changeset
 | 
1107  | 
val latest = history.tip  | 
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1108  | 
|
| 
57620
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1109  | 
|
| 
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1110  | 
/* pending edits and unstable changes */  | 
| 
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1111  | 
|
| 
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1112  | 
val rev_pending_changes =  | 
| 
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1113  | 
        for {
 | 
| 
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1114  | 
change <- history.undo_list.takeWhile(_ != stable)  | 
| 
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1115  | 
(a, edits) <- change.rev_edits  | 
| 
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1116  | 
if a == name  | 
| 
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1117  | 
} yield edits  | 
| 
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1118  | 
|
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1119  | 
val edits =  | 
| 64819 | 1120  | 
        (pending_edits /: rev_pending_changes)({
 | 
1121  | 
case (edits, Node.Edits(es)) => es ::: edits  | 
|
1122  | 
case (edits, _) => edits  | 
|
1123  | 
})  | 
|
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1124  | 
lazy val reverse_edits = edits.reverse  | 
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1125  | 
|
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1126  | 
new Snapshot  | 
| 
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1127  | 
      {
 | 
| 52972 | 1128  | 
/* global information */  | 
1129  | 
||
| 64798 | 1130  | 
val state: State = State.this  | 
1131  | 
val version: Version = stable.version.get_finished  | 
|
1132  | 
val is_outdated: Boolean = pending_edits.nonEmpty || latest != stable  | 
|
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1133  | 
|
| 
55649
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
1134  | 
|
| 
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
1135  | 
/* local node content */  | 
| 
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
1136  | 
|
| 71601 | 1137  | 
def convert(offset: Text.Offset): Text.Offset = (offset /: edits)((i, edit) => edit.convert(i))  | 
1138  | 
def revert(offset: Text.Offset): Text.Offset = (offset /: reverse_edits)((i, edit) => edit.revert(i))  | 
|
| 
57620
 
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
 
wenzelm 
parents: 
57619 
diff
changeset
 | 
1139  | 
|
| 71601 | 1140  | 
def convert(range: Text.Range): Text.Range = range.map(convert)  | 
1141  | 
def revert(range: Text.Range): Text.Range = range.map(revert)  | 
|
| 
39177
 
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
 
wenzelm 
parents: 
38976 
diff
changeset
 | 
1142  | 
|
| 64798 | 1143  | 
val node_name: Node.Name = name  | 
| 64799 | 1144  | 
val node: Node = version.nodes(name)  | 
| 52972 | 1145  | 
|
| 69556 | 1146  | 
def nodes: List[(Node.Name, Node)] =  | 
1147  | 
(node_name :: node.load_commands.flatMap(_.blobs_names)).  | 
|
1148  | 
map(name => (name, version.nodes(name)))  | 
|
1149  | 
||
| 64799 | 1150  | 
val commands_loading: List[Command] =  | 
| 
55432
 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 
wenzelm 
parents: 
55431 
diff
changeset
 | 
1151  | 
if (node_name.is_theory) Nil  | 
| 64799 | 1152  | 
else version.nodes.commands_loading(node_name)  | 
| 
55432
 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 
wenzelm 
parents: 
55431 
diff
changeset
 | 
1153  | 
|
| 64799 | 1154  | 
def commands_loading_ranges(pred: Node.Name => Boolean): List[Text.Range] =  | 
1155  | 
          (for {
 | 
|
1156  | 
cmd <- node.load_commands.iterator  | 
|
1157  | 
blob_name <- cmd.blobs_names.iterator  | 
|
1158  | 
if pred(blob_name)  | 
|
1159  | 
start <- node.command_start(cmd)  | 
|
| 68728 | 1160  | 
} yield convert(cmd.core_range + start)).toList  | 
| 
56176
 
0bc9b0ad6287
tuned rendering -- avoid flashing background of aux. files that are disconnected from the document model;
 
wenzelm 
parents: 
55820 
diff
changeset
 | 
1161  | 
|
| 
65199
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1162  | 
def current_command(other_node_name: Node.Name, offset: Text.Offset): Option[Command] =  | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1163  | 
          if (other_node_name.is_theory) {
 | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1164  | 
val other_node = version.nodes(other_node_name)  | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1165  | 
val iterator = other_node.command_iterator(revert(offset) max 0)  | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1166  | 
            if (iterator.hasNext) {
 | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1167  | 
val (command0, _) = iterator.next  | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1168  | 
other_node.commands.reverse.iterator(command0).find(command => !command.is_ignored)  | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1169  | 
}  | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1170  | 
else other_node.commands.reverse.iterator.find(command => !command.is_ignored)  | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1171  | 
}  | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1172  | 
else version.nodes.commands_loading(other_node_name).headOption  | 
| 
 
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
 
wenzelm 
parents: 
65196 
diff
changeset
 | 
1173  | 
|
| 
72816
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
1174  | 
def get_snippet_command: Option[Command] = snippet_command  | 
| 
 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 
wenzelm 
parents: 
72780 
diff
changeset
 | 
1175  | 
|
| 72723 | 1176  | 
def xml_markup(  | 
1177  | 
range: Text.Range = Text.Range.full,  | 
|
1178  | 
elements: Markup.Elements = Markup.Elements.full): XML.Body =  | 
|
1179  | 
state.xml_markup(version, node_name, range = range, elements = elements)  | 
|
| 66040 | 1180  | 
|
| 68417 | 1181  | 
lazy val messages: List[(XML.Tree, Position.T)] =  | 
| 68365 | 1182  | 
          (for {
 | 
1183  | 
(command, start) <-  | 
|
1184  | 
Document.Node.Commands.starts_pos(  | 
|
1185  | 
node.commands.iterator, Token.Pos.file(node_name.node))  | 
|
1186  | 
pos = command.span.keyword_pos(start).position(command.span.name)  | 
|
1187  | 
(_, tree) <- state.command_results(version, command).iterator  | 
|
1188  | 
} yield (tree, pos)).toList  | 
|
1189  | 
||
| 68417 | 1190  | 
lazy val exports: List[Export.Entry] =  | 
| 69633 | 1191  | 
state.node_exports(version, node_name).iterator.map(_._2).toList  | 
| 68365 | 1192  | 
|
| 68417 | 1193  | 
lazy val exports_map: Map[String, Export.Entry] =  | 
1194  | 
(for (entry <- exports.iterator) yield (entry.name, entry)).toMap  | 
|
1195  | 
||
| 
55649
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
1196  | 
|
| 64665 | 1197  | 
/* find command */  | 
1198  | 
||
1199  | 
def find_command(id: Document_ID.Generic): Option[(Node, Command)] =  | 
|
| 68857 | 1200  | 
          state.lookup_id(id) match {
 | 
| 64665 | 1201  | 
case None => None  | 
1202  | 
case Some(st) =>  | 
|
1203  | 
val command = st.command  | 
|
1204  | 
val node = version.nodes(command.node_name)  | 
|
1205  | 
if (node.commands.contains(command)) Some((node, command)) else None  | 
|
1206  | 
}  | 
|
1207  | 
||
1208  | 
def find_command_position(id: Document_ID.Generic, offset: Symbol.Offset)  | 
|
1209  | 
: Option[Line.Node_Position] =  | 
|
1210  | 
for ((node, command) <- find_command(id))  | 
|
1211  | 
          yield {
 | 
|
1212  | 
val name = command.node_name.node  | 
|
1213  | 
val sources_iterator =  | 
|
1214  | 
node.commands.iterator.takeWhile(_ != command).map(_.source) ++  | 
|
1215  | 
(if (offset == 0) Iterator.empty  | 
|
1216  | 
else Iterator.single(command.source(Text.Range(0, command.chunk.decode(offset)))))  | 
|
| 
65196
 
e8760a98db78
discontinued pointless Text.Length: Javascript and Java agree in old-fashioned UTF-16;
 
wenzelm 
parents: 
65195 
diff
changeset
 | 
1217  | 
val pos = (Line.Position.zero /: sources_iterator)(_.advance(_))  | 
| 64665 | 1218  | 
Line.Node_Position(name, pos)  | 
1219  | 
}  | 
|
1220  | 
||
1221  | 
||
| 
55649
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
1222  | 
/* cumulate markup */  | 
| 
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
1223  | 
|
| 
55651
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
1224  | 
def cumulate[A](  | 
| 
55649
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
1225  | 
range: Text.Range,  | 
| 
 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 
wenzelm 
parents: 
55620 
diff
changeset
 | 
1226  | 
info: A,  | 
| 56743 | 1227  | 
elements: Markup.Elements,  | 
| 
56354
 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 
wenzelm 
parents: 
56337 
diff
changeset
 | 
1228  | 
result: List[Command.State] => (A, Text.Markup) => Option[A],  | 
| 
55651
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
1229  | 
status: Boolean = false): List[Text.Info[A]] =  | 
| 45459 | 1230  | 
        {
 | 
| 
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: 
56514 
diff
changeset
 | 
1231  | 
val former_range = revert(range).inflate_singularity  | 
| 
56462
 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 
wenzelm 
parents: 
56398 
diff
changeset
 | 
1232  | 
val (chunk_name, command_iterator) =  | 
| 65187 | 1233  | 
            commands_loading.headOption match {
 | 
1234  | 
case None => (Symbol.Text_Chunk.Default, node.command_iterator(former_range))  | 
|
1235  | 
case Some(command) => (Symbol.Text_Chunk.File(node_name.node), Iterator((command, 0)))  | 
|
| 56309 | 1236  | 
}  | 
| 
56462
 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 
wenzelm 
parents: 
56398 
diff
changeset
 | 
1237  | 
val markup_index = Command.Markup_Index(status, chunk_name)  | 
| 56309 | 1238  | 
          (for {
 | 
| 
56373
 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 
wenzelm 
parents: 
56372 
diff
changeset
 | 
1239  | 
(command, command_start) <- command_iterator  | 
| 
56462
 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 
wenzelm 
parents: 
56398 
diff
changeset
 | 
1240  | 
chunk <- command.chunks.get(chunk_name).iterator  | 
| 56309 | 1241  | 
states = state.command_states(version, command)  | 
| 
56354
 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 
wenzelm 
parents: 
56337 
diff
changeset
 | 
1242  | 
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: 
56514 
diff
changeset
 | 
1243  | 
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: 
56514 
diff
changeset
 | 
1244  | 
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: 
56514 
diff
changeset
 | 
1245  | 
Text.Info(r0, a) <- markup.cumulate[A](markup_range, info, elements,  | 
| 56309 | 1246  | 
              {
 | 
1247  | 
case (a, Text.Info(r0, b)) => res(a, Text.Info(convert(r0 + command_start), b))  | 
|
1248  | 
}).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: 
56514 
diff
changeset
 | 
1249  | 
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: 
56514 
diff
changeset
 | 
1250  | 
} yield Text.Info(r1, a)).toList  | 
| 45459 | 1251  | 
}  | 
1252  | 
||
| 
55651
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
1253  | 
def select[A](  | 
| 
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
1254  | 
range: Text.Range,  | 
| 56743 | 1255  | 
elements: Markup.Elements,  | 
| 
56354
 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 
wenzelm 
parents: 
56337 
diff
changeset
 | 
1256  | 
result: List[Command.State] => Text.Markup => Option[A],  | 
| 
55651
 
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
 
wenzelm 
parents: 
55650 
diff
changeset
 | 
1257  | 
status: Boolean = false): List[Text.Info[A]] =  | 
| 
38845
 
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
 
wenzelm 
parents: 
38841 
diff
changeset
 | 
1258  | 
        {
 | 
| 
56354
 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 
wenzelm 
parents: 
56337 
diff
changeset
 | 
1259  | 
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: 
50204 
diff
changeset
 | 
1260  | 
          {
 | 
| 
56354
 
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
 
wenzelm 
parents: 
56337 
diff
changeset
 | 
1261  | 
val res = result(states)  | 
| 
52889
 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 
wenzelm 
parents: 
52887 
diff
changeset
 | 
1262  | 
(_: Option[A], x: Text.Markup) =>  | 
| 
 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 
wenzelm 
parents: 
52887 
diff
changeset
 | 
1263  | 
              res(x) match {
 | 
| 
 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 
wenzelm 
parents: 
52887 
diff
changeset
 | 
1264  | 
case None => None  | 
| 
 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 
wenzelm 
parents: 
52887 
diff
changeset
 | 
1265  | 
case some => Some(some)  | 
| 
 
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
 
wenzelm 
parents: 
52887 
diff
changeset
 | 
1266  | 
}  | 
| 
50500
 
c94bba7906d2
identify dialogs via official serial and maintain as result message;
 
wenzelm 
parents: 
50204 
diff
changeset
 | 
1267  | 
}  | 
| 71601 | 1268  | 
for (Text.Info(r, Some(x)) <- cumulate(range, None, elements, result1, status))  | 
| 
46198
 
cd040c5772de
improved select_markup: include filtering of defined results;
 
wenzelm 
parents: 
46178 
diff
changeset
 | 
1269  | 
yield Text.Info(r, x)  | 
| 
38845
 
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
 
wenzelm 
parents: 
38841 
diff
changeset
 | 
1270  | 
}  | 
| 55800 | 1271  | 
|
1272  | 
||
| 65332 | 1273  | 
/* command results */  | 
1274  | 
||
1275  | 
def command_results(range: Text.Range): Command.Results =  | 
|
1276  | 
Command.State.merge_results(  | 
|
1277  | 
select[List[Command.State]](range, Markup.Elements.full, command_states =>  | 
|
1278  | 
              { case _ => Some(command_states) }).flatMap(_.info))
 | 
|
1279  | 
||
1280  | 
def command_results(command: Command): Command.Results =  | 
|
1281  | 
state.command_results(version, command)  | 
|
1282  | 
||
1283  | 
||
| 68836 | 1284  | 
/* command ids: static and dynamic */  | 
1285  | 
||
1286  | 
def command_id_map: Map[Document_ID.Generic, Command] =  | 
|
1287  | 
state.command_id_map(version, version.nodes(node_name).commands)  | 
|
1288  | 
||
1289  | 
||
| 55800 | 1290  | 
/* output */  | 
1291  | 
||
1292  | 
override def toString: String =  | 
|
1293  | 
"Snapshot(node = " + node_name.node + ", version = " + version.id +  | 
|
1294  | 
(if (is_outdated) ", outdated" else "") + ")"  | 
|
| 
38841
 
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
 
wenzelm 
parents: 
38569 
diff
changeset
 | 
1295  | 
}  | 
| 
38150
 
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
 
wenzelm 
parents: 
37849 
diff
changeset
 | 
1296  | 
}  | 
| 34485 | 1297  | 
}  | 
| 
34840
 
6c5560d48561
more precise treatment of document/state assigment;
 
wenzelm 
parents: 
34838 
diff
changeset
 | 
1298  | 
}  |