author | wenzelm |
Tue, 11 Sep 2012 22:54:12 +0200 | |
changeset 49294 | a600c017f814 |
parent 49245 | cb70157293c0 |
child 49321 | a48f9bbbe720 |
permissions | -rw-r--r-- |
45665
129db1416717
renamed Isabelle_Markup to Isabelle_Rendering to emphasize its meaning and make room for Pure Isabelle_Markup module;
wenzelm
parents:
45489
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/isabelle_rendering.scala |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
3 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
4 |
Isabelle specific physical rendering and markup selection. |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
6 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.jedit |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
8 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
9 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
10 |
import isabelle._ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
11 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
12 |
import java.awt.Color |
46227
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
13 |
import javax.swing.Icon |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
14 |
import java.io.{File => JFile} |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
15 |
|
43414 | 16 |
import org.gjt.sp.jedit.syntax.{Token => JEditToken} |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
17 |
|
45460 | 18 |
import scala.collection.immutable.SortedMap |
19 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
20 |
|
45665
129db1416717
renamed Isabelle_Markup to Isabelle_Rendering to emphasize its meaning and make room for Pure Isabelle_Markup module;
wenzelm
parents:
45489
diff
changeset
|
21 |
object Isabelle_Rendering |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
22 |
{ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
23 |
/* physical rendering */ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
24 |
|
49294 | 25 |
def color_value(s: String): Color = Color_Value(Isabelle.options.value.string(s)) |
43388 | 26 |
|
46227
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
27 |
private val writeln_pri = 1 |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
28 |
private val warning_pri = 2 |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
29 |
private val legacy_pri = 3 |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
30 |
private val error_pri = 4 |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
31 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
32 |
|
46166 | 33 |
/* command overview */ |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
34 |
|
46227
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
35 |
def overview_color(snapshot: Document.Snapshot, range: Text.Range): Option[Color] = |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
36 |
{ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
37 |
if (snapshot.is_outdated) None |
46166 | 38 |
else { |
46227
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
39 |
val results = |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
40 |
snapshot.cumulate_markup[(Protocol.Status, Int)]( |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
41 |
range, (Protocol.Status.init, 0), |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
42 |
Some(Protocol.command_status_markup + Isabelle_Markup.WARNING + Isabelle_Markup.ERROR), |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
43 |
{ |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
44 |
case ((status, pri), Text.Info(_, XML.Elem(markup, _))) => |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
45 |
if (markup.name == Isabelle_Markup.WARNING) (status, pri max warning_pri) |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
46 |
else if (markup.name == Isabelle_Markup.ERROR) (status, pri max error_pri) |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
47 |
else (Protocol.command_status(status, markup), pri) |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
48 |
}) |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
49 |
if (results.isEmpty) None |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
50 |
else { |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
51 |
val (status, pri) = |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
52 |
((Protocol.Status.init, 0) /: results) { |
4aa84f84d5e8
more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents:
46224
diff
changeset
|
53 |
case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) } |
46166 | 54 |
|
49294 | 55 |
if (pri == warning_pri) Some(color_value("color_warning")) |
56 |
else if (pri == error_pri) Some(color_value("color_error")) |
|
57 |
else if (status.is_unprocessed) Some(color_value("color_unprocessed")) |
|
58 |
else if (status.is_running) Some(color_value("color_running")) |
|
59 |
else if (status.is_failed) Some(color_value("color_error")) |
|
46166 | 60 |
else None |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
61 |
} |
46166 | 62 |
} |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
63 |
} |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
64 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
65 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
66 |
/* markup selectors */ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
67 |
|
46234 | 68 |
private val subexp_include = |
69 |
Set(Isabelle_Markup.SORT, Isabelle_Markup.TYP, Isabelle_Markup.TERM, Isabelle_Markup.PROP, |
|
70 |
Isabelle_Markup.ML_TYPING, Isabelle_Markup.TOKEN_RANGE, Isabelle_Markup.ENTITY, |
|
49164
bde6d900b42a
proper subsexp projection of Isabelle_Markup.Path, in correspondence to 5d0cd770828e;
wenzelm
parents:
49163
diff
changeset
|
71 |
Isabelle_Markup.PATH, Isabelle_Markup.TYPING, Isabelle_Markup.FREE, Isabelle_Markup.SKOLEM, |
bde6d900b42a
proper subsexp projection of Isabelle_Markup.Path, in correspondence to 5d0cd770828e;
wenzelm
parents:
49163
diff
changeset
|
72 |
Isabelle_Markup.BOUND, Isabelle_Markup.VAR, Isabelle_Markup.TFREE, Isabelle_Markup.TVAR, |
bde6d900b42a
proper subsexp projection of Isabelle_Markup.Path, in correspondence to 5d0cd770828e;
wenzelm
parents:
49163
diff
changeset
|
73 |
Isabelle_Markup.ML_SOURCE, Isabelle_Markup.DOC_SOURCE) |
46234 | 74 |
|
75 |
def subexp(snapshot: Document.Snapshot, range: Text.Range): Option[Text.Info[Color]] = |
|
76 |
{ |
|
77 |
snapshot.select_markup(range, Some(subexp_include), |
|
78 |
{ |
|
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
79 |
case Text.Info(info_range, XML.Elem(Markup(name, _), _)) if subexp_include(name) => |
49294 | 80 |
Text.Info(snapshot.convert(info_range), color_value("color_subexp")) |
46234 | 81 |
}) match { case Text.Info(_, info) #:: _ => Some(info) case _ => None } |
82 |
} |
|
83 |
||
84 |
||
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
85 |
private val hyperlink_include = Set(Isabelle_Markup.ENTITY, Isabelle_Markup.PATH) |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
86 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
87 |
def hyperlink(snapshot: Document.Snapshot, range: Text.Range): Option[Text.Info[Hyperlink]] = |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
88 |
{ |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
89 |
snapshot.cumulate_markup[List[Text.Info[Hyperlink]]](range, Nil, Some(hyperlink_include), |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
90 |
{ |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
91 |
case (links, Text.Info(info_range, XML.Elem(Isabelle_Markup.Path(name), _))) |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
92 |
if Path.is_ok(name) => |
48923
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48922
diff
changeset
|
93 |
val jedit_file = Isabelle.thy_load.append(snapshot.node_name.dir, Path.explode(name)) |
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48922
diff
changeset
|
94 |
Text.Info(snapshot.convert(info_range), Hyperlink(jedit_file, 0, 0)) :: links |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
95 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
96 |
case (links, Text.Info(info_range, XML.Elem(Markup(Isabelle_Markup.ENTITY, props), _))) |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
97 |
if (props.find( |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
98 |
{ case (Markup.KIND, Isabelle_Markup.ML_OPEN) => true |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
99 |
case (Markup.KIND, Isabelle_Markup.ML_STRUCT) => true |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
100 |
case _ => false }).isEmpty) => |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
101 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
102 |
props match { |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
103 |
case Position.Line_File(line, name) if Path.is_ok(name) => |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
104 |
Isabelle_System.source_file(Path.explode(name)) match { |
48923
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48922
diff
changeset
|
105 |
case Some(path) => |
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48922
diff
changeset
|
106 |
val jedit_file = Isabelle_System.platform_path(path) |
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48922
diff
changeset
|
107 |
Text.Info(snapshot.convert(info_range), Hyperlink(jedit_file, line, 0)) :: links |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
108 |
case None => links |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
109 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
110 |
|
48922 | 111 |
case Position.Id_Offset(id, offset) if !snapshot.is_outdated => |
112 |
snapshot.state.find_command(snapshot.version, id) match { |
|
113 |
case Some((node, command)) => |
|
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
114 |
val sources = |
48922 | 115 |
node.commands.iterator.takeWhile(_ != command).map(_.source) ++ |
116 |
Iterator.single(command.source(Text.Range(0, command.decode(offset)))) |
|
117 |
val (line, column) = ((1, 1) /: sources)(Symbol.advance_line_column) |
|
48923
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48922
diff
changeset
|
118 |
Text.Info(snapshot.convert(info_range), |
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48922
diff
changeset
|
119 |
Hyperlink(command.node_name.node, line, column)) :: links |
48921
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
120 |
case None => links |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
121 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
122 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
123 |
case _ => links |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
124 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
125 |
}) match { case Text.Info(_, info :: _) #:: _ => Some(info) case _ => None } |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
126 |
} |
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
127 |
|
5d8d409b897e
support for direct hyperlinks, without the Hyperlinks plugin;
wenzelm
parents:
48768
diff
changeset
|
128 |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
129 |
private def tooltip_text(msg: XML.Tree): String = |
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
49164
diff
changeset
|
130 |
Pretty.string_of(List(msg), margin = Isabelle.options.int("jedit_tooltip_margin")) |
48756
1c843142758e
sneak message into "bad" markup as property -- to be displayed after YXML parsing;
wenzelm
parents:
48754
diff
changeset
|
131 |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
132 |
def tooltip_message(snapshot: Document.Snapshot, range: Text.Range): Option[String] = |
46199 | 133 |
{ |
134 |
val msgs = |
|
135 |
snapshot.cumulate_markup[SortedMap[Long, String]](range, SortedMap.empty, |
|
48756
1c843142758e
sneak message into "bad" markup as property -- to be displayed after YXML parsing;
wenzelm
parents:
48754
diff
changeset
|
136 |
Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR, |
1c843142758e
sneak message into "bad" markup as property -- to be displayed after YXML parsing;
wenzelm
parents:
48754
diff
changeset
|
137 |
Isabelle_Markup.BAD)), |
46199 | 138 |
{ |
48756
1c843142758e
sneak message into "bad" markup as property -- to be displayed after YXML parsing;
wenzelm
parents:
48754
diff
changeset
|
139 |
case (msgs, Text.Info(_, msg @ |
1c843142758e
sneak message into "bad" markup as property -- to be displayed after YXML parsing;
wenzelm
parents:
48754
diff
changeset
|
140 |
XML.Elem(Markup(markup, Isabelle_Markup.Serial(serial)), _))) |
46199 | 141 |
if markup == Isabelle_Markup.WRITELN || |
142 |
markup == Isabelle_Markup.WARNING || |
|
143 |
markup == Isabelle_Markup.ERROR => |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
144 |
msgs + (serial -> tooltip_text(msg)) |
49040 | 145 |
case (msgs, Text.Info(_, msg @ XML.Elem(Markup(Isabelle_Markup.BAD, _), body))) |
146 |
if !body.isEmpty => msgs + (Document.new_id() -> tooltip_text(msg)) |
|
46199 | 147 |
}).toList.flatMap(_.info) |
148 |
if (msgs.isEmpty) None else Some(cat_lines(msgs.iterator.map(_._2))) |
|
149 |
} |
|
39740 | 150 |
|
43376
0f6880c1c759
some direct text foreground painting, instead of token marking;
wenzelm
parents:
43282
diff
changeset
|
151 |
|
43431 | 152 |
private val tooltips: Map[String, String] = |
153 |
Map( |
|
45666 | 154 |
Isabelle_Markup.SORT -> "sort", |
155 |
Isabelle_Markup.TYP -> "type", |
|
156 |
Isabelle_Markup.TERM -> "term", |
|
157 |
Isabelle_Markup.PROP -> "proposition", |
|
158 |
Isabelle_Markup.TOKEN_RANGE -> "inner syntax token", |
|
159 |
Isabelle_Markup.FREE -> "free variable", |
|
160 |
Isabelle_Markup.SKOLEM -> "skolem variable", |
|
161 |
Isabelle_Markup.BOUND -> "bound variable", |
|
162 |
Isabelle_Markup.VAR -> "schematic variable", |
|
163 |
Isabelle_Markup.TFREE -> "free type variable", |
|
164 |
Isabelle_Markup.TVAR -> "schematic type variable", |
|
165 |
Isabelle_Markup.ML_SOURCE -> "ML source", |
|
166 |
Isabelle_Markup.DOC_SOURCE -> "document source") |
|
43431 | 167 |
|
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
168 |
private val tooltip_elements = |
49163
5d0cd770828e
added tooltip to reveal jEdit platform file name;
wenzelm
parents:
49040
diff
changeset
|
169 |
Set(Isabelle_Markup.ENTITY, Isabelle_Markup.TYPING, Isabelle_Markup.ML_TYPING, |
5d0cd770828e
added tooltip to reveal jEdit platform file name;
wenzelm
parents:
49040
diff
changeset
|
170 |
Isabelle_Markup.PATH) ++ tooltips.keys |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
171 |
|
45445
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
wenzelm
parents:
44866
diff
changeset
|
172 |
private def string_of_typing(kind: String, body: XML.Body): String = |
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
wenzelm
parents:
44866
diff
changeset
|
173 |
Pretty.string_of(List(Pretty.block(XML.Text(kind) :: Pretty.Break(1) :: body)), |
49245
cb70157293c0
manage Isabelle/jEdit options as Isabelle/Scala options (with persistent preferences);
wenzelm
parents:
49164
diff
changeset
|
174 |
margin = Isabelle.options.int("jedit_tooltip_margin")) |
45445
41e641a870de
pass term positions into check phase, where resulting types are reported accordingly, and eventually shown as tooltips;
wenzelm
parents:
44866
diff
changeset
|
175 |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
176 |
def tooltip(snapshot: Document.Snapshot, range: Text.Range): Option[String] = |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
177 |
{ |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
178 |
def add(prev: Text.Info[List[(Boolean, String)]], r: Text.Range, p: (Boolean, String)) = |
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
179 |
if (prev.range == r) Text.Info(r, p :: prev.info) else Text.Info(r, List(p)) |
42302 | 180 |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
181 |
val tips = |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
182 |
snapshot.cumulate_markup[Text.Info[(List[(Boolean, String)])]]( |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
183 |
range, Text.Info(range, Nil), Some(tooltip_elements), |
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
184 |
{ |
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
185 |
case (prev, Text.Info(r, XML.Elem(Isabelle_Markup.Entity(kind, name), _))) => |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
186 |
add(prev, r, (true, kind + " " + quote(name))) |
49163
5d0cd770828e
added tooltip to reveal jEdit platform file name;
wenzelm
parents:
49040
diff
changeset
|
187 |
case (prev, Text.Info(r, XML.Elem(Isabelle_Markup.Path(name), _))) |
5d0cd770828e
added tooltip to reveal jEdit platform file name;
wenzelm
parents:
49040
diff
changeset
|
188 |
if Path.is_ok(name) => |
5d0cd770828e
added tooltip to reveal jEdit platform file name;
wenzelm
parents:
49040
diff
changeset
|
189 |
val jedit_file = Isabelle.thy_load.append(snapshot.node_name.dir, Path.explode(name)) |
5d0cd770828e
added tooltip to reveal jEdit platform file name;
wenzelm
parents:
49040
diff
changeset
|
190 |
add(prev, r, (true, "file " + quote(jedit_file))) |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
191 |
case (prev, Text.Info(r, XML.Elem(Markup(Isabelle_Markup.TYPING, _), body))) => |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
192 |
add(prev, r, (true, string_of_typing("::", body))) |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
193 |
case (prev, Text.Info(r, XML.Elem(Markup(Isabelle_Markup.ML_TYPING, _), body))) => |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
194 |
add(prev, r, (false, string_of_typing("ML:", body))) |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
195 |
case (prev, Text.Info(r, XML.Elem(Markup(name, _), _))) |
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
196 |
if tooltips.isDefinedAt(name) => add(prev, r, (true, tooltips(name))) |
46235
e4e0b5190f3d
more careful cumulation of tooltips -- ensure uniform range;
wenzelm
parents:
46234
diff
changeset
|
197 |
}).toList.flatMap(_.info.info) |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
198 |
|
47540
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
199 |
val all_tips = |
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
200 |
(tips.filter(_._1) ++ tips.filter(!_._1).lastOption.toList).map(_._2) |
1de8a8b1ae79
render last ML_TYPING only -- relevant for inline antiquotations like @{term};
wenzelm
parents:
46235
diff
changeset
|
201 |
if (all_tips.isEmpty) None else Some(cat_lines(all_tips)) |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
202 |
} |
45460 | 203 |
|
46234 | 204 |
|
205 |
private val gutter_icons = Map( |
|
206 |
warning_pri -> Isabelle.load_icon("16x16/status/dialog-information.png"), |
|
207 |
legacy_pri -> Isabelle.load_icon("16x16/status/dialog-warning.png"), |
|
208 |
error_pri -> Isabelle.load_icon("16x16/status/dialog-error.png")) |
|
209 |
||
210 |
def gutter_message(snapshot: Document.Snapshot, range: Text.Range): Option[Icon] = |
|
211 |
{ |
|
212 |
val results = |
|
213 |
snapshot.cumulate_markup[Int](range, 0, |
|
214 |
Some(Set(Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)), |
|
215 |
{ |
|
216 |
case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.WARNING, _), body))) => |
|
217 |
body match { |
|
218 |
case List(XML.Elem(Markup(Isabelle_Markup.LEGACY, _), _)) => pri max legacy_pri |
|
219 |
case _ => pri max warning_pri |
|
220 |
} |
|
221 |
case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ERROR, _), _))) => |
|
222 |
pri max error_pri |
|
223 |
}) |
|
224 |
val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 } |
|
225 |
gutter_icons.get(pri) |
|
226 |
} |
|
227 |
||
228 |
||
229 |
def squiggly_underline(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] = |
|
230 |
{ |
|
49294 | 231 |
val squiggly_colors = Map( |
232 |
writeln_pri -> color_value("color_writeln"), |
|
233 |
warning_pri -> color_value("color_warning"), |
|
234 |
error_pri -> color_value("color_error")) |
|
235 |
||
46234 | 236 |
val results = |
237 |
snapshot.cumulate_markup[Int](range, 0, |
|
238 |
Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)), |
|
239 |
{ |
|
240 |
case (pri, Text.Info(_, XML.Elem(Markup(name, _), _))) => |
|
241 |
name match { |
|
242 |
case Isabelle_Markup.WRITELN => pri max writeln_pri |
|
243 |
case Isabelle_Markup.WARNING => pri max warning_pri |
|
244 |
case Isabelle_Markup.ERROR => pri max error_pri |
|
245 |
case _ => pri |
|
246 |
} |
|
247 |
}) |
|
248 |
for { |
|
249 |
Text.Info(r, pri) <- results |
|
250 |
color <- squiggly_colors.get(pri) |
|
251 |
} yield Text.Info(r, color) |
|
252 |
} |
|
253 |
||
42302 | 254 |
|
46234 | 255 |
def background1(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] = |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
256 |
{ |
49294 | 257 |
if (snapshot.is_outdated) Stream(Text.Info(range, color_value("color_outdated"))) |
46234 | 258 |
else |
259 |
for { |
|
260 |
Text.Info(r, result) <- |
|
261 |
snapshot.cumulate_markup[(Option[Protocol.Status], Option[Color])]( |
|
262 |
range, (Some(Protocol.Status.init), None), |
|
263 |
Some(Protocol.command_status_markup + Isabelle_Markup.BAD + Isabelle_Markup.HILITE), |
|
264 |
{ |
|
265 |
case (((Some(status), color), Text.Info(_, XML.Elem(markup, _)))) |
|
266 |
if (Protocol.command_status_markup(markup.name)) => |
|
267 |
(Some(Protocol.command_status(status, markup)), color) |
|
268 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.BAD, _), _))) => |
|
49294 | 269 |
(None, Some(color_value("color_bad"))) |
46234 | 270 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.HILITE, _), _))) => |
49294 | 271 |
(None, Some(color_value("color_hilite"))) |
46234 | 272 |
}) |
273 |
color <- |
|
274 |
(result match { |
|
49037
d7a1973b063c
more markup for failed goal forks, reusing "bad";
wenzelm
parents:
49036
diff
changeset
|
275 |
case (Some(status), opt_color) => |
49294 | 276 |
if (status.is_unprocessed) Some(color_value("color_unprocessed1")) |
277 |
else if (status.is_running) Some(color_value("color_running1")) |
|
49037
d7a1973b063c
more markup for failed goal forks, reusing "bad";
wenzelm
parents:
49036
diff
changeset
|
278 |
else opt_color |
46234 | 279 |
case (_, opt_color) => opt_color |
280 |
}) |
|
281 |
} yield Text.Info(r, color) |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46166
diff
changeset
|
282 |
} |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
283 |
|
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
284 |
|
46234 | 285 |
def background2(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] = |
286 |
snapshot.select_markup(range, |
|
287 |
Some(Set(Isabelle_Markup.TOKEN_RANGE)), |
|
288 |
{ |
|
49294 | 289 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.TOKEN_RANGE, _), _)) => |
290 |
color_value("color_light") |
|
46234 | 291 |
}) |
292 |
||
293 |
||
294 |
def foreground(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] = |
|
295 |
snapshot.select_markup(range, |
|
296 |
Some(Set(Isabelle_Markup.STRING, Isabelle_Markup.ALTSTRING, Isabelle_Markup.VERBATIM)), |
|
297 |
{ |
|
49294 | 298 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.STRING, _), _)) => |
299 |
color_value("color_quoted") |
|
300 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ALTSTRING, _), _)) => |
|
301 |
color_value("color_quoted") |
|
302 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.VERBATIM, _), _)) => |
|
303 |
color_value("color_quoted") |
|
46234 | 304 |
}) |
305 |
||
306 |
||
307 |
def text_color(snapshot: Document.Snapshot, range: Text.Range, color: Color) |
|
308 |
: Stream[Text.Info[Color]] = |
|
49294 | 309 |
{ |
310 |
val text_colors: Map[String, Color] = Map( |
|
311 |
Isabelle_Markup.STRING -> Color.BLACK, |
|
312 |
Isabelle_Markup.ALTSTRING -> Color.BLACK, |
|
313 |
Isabelle_Markup.VERBATIM -> Color.BLACK, |
|
314 |
Isabelle_Markup.LITERAL -> color_value("color_keyword1"), |
|
315 |
Isabelle_Markup.DELIMITER -> Color.BLACK, |
|
316 |
Isabelle_Markup.TFREE -> color_value("color_variable_type"), |
|
317 |
Isabelle_Markup.TVAR -> color_value("color_variable_type"), |
|
318 |
Isabelle_Markup.FREE -> color_value("color_variable_free"), |
|
319 |
Isabelle_Markup.SKOLEM -> color_value("color_variable_skolem"), |
|
320 |
Isabelle_Markup.BOUND -> color_value("color_variable_bound"), |
|
321 |
Isabelle_Markup.VAR -> color_value("color_variable_schematic"), |
|
322 |
Isabelle_Markup.INNER_STRING -> color_value("color_inner_quoted"), |
|
323 |
Isabelle_Markup.INNER_COMMENT -> color_value("color_inner_comment"), |
|
324 |
Isabelle_Markup.DYNAMIC_FACT -> color_value("color_dynamic"), |
|
325 |
Isabelle_Markup.ML_KEYWORD -> color_value("color_keyword1"), |
|
326 |
Isabelle_Markup.ML_DELIMITER -> Color.BLACK, |
|
327 |
Isabelle_Markup.ML_NUMERAL -> color_value("color_inner_numeral"), |
|
328 |
Isabelle_Markup.ML_CHAR -> color_value("color_inner_quoted"), |
|
329 |
Isabelle_Markup.ML_STRING -> color_value("color_inner_quoted"), |
|
330 |
Isabelle_Markup.ML_COMMENT -> color_value("color_inner_comment"), |
|
331 |
Isabelle_Markup.ANTIQ -> color_value("color_antiquotation")) |
|
332 |
||
333 |
val text_color_elements = Set.empty[String] ++ text_colors.keys |
|
334 |
||
46234 | 335 |
snapshot.cumulate_markup(range, color, Some(text_color_elements), |
336 |
{ |
|
337 |
case (_, Text.Info(_, XML.Elem(Markup(m, _), _))) |
|
338 |
if text_colors.isDefinedAt(m) => text_colors(m) |
|
339 |
}) |
|
49294 | 340 |
} |
46234 | 341 |
|
342 |
||
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
343 |
/* token markup -- text styles */ |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
344 |
|
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
345 |
private val command_style: Map[String, Byte] = |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
346 |
{ |
43414 | 347 |
import JEditToken._ |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
348 |
Map[String, Byte]( |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
349 |
Keyword.THY_END -> KEYWORD2, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
350 |
Keyword.THY_SCRIPT -> LABEL, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
351 |
Keyword.PRF_SCRIPT -> LABEL, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
352 |
Keyword.PRF_ASM -> KEYWORD3, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
353 |
Keyword.PRF_ASM_GOAL -> KEYWORD3 |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
354 |
).withDefaultValue(KEYWORD1) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
355 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
356 |
|
43414 | 357 |
private val token_style: Map[Token.Kind.Value, Byte] = |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
358 |
{ |
43414 | 359 |
import JEditToken._ |
360 |
Map[Token.Kind.Value, Byte]( |
|
361 |
Token.Kind.KEYWORD -> KEYWORD2, |
|
362 |
Token.Kind.IDENT -> NULL, |
|
363 |
Token.Kind.LONG_IDENT -> NULL, |
|
364 |
Token.Kind.SYM_IDENT -> NULL, |
|
365 |
Token.Kind.VAR -> NULL, |
|
366 |
Token.Kind.TYPE_IDENT -> NULL, |
|
367 |
Token.Kind.TYPE_VAR -> NULL, |
|
368 |
Token.Kind.NAT -> NULL, |
|
369 |
Token.Kind.FLOAT -> NULL, |
|
43431 | 370 |
Token.Kind.STRING -> LITERAL1, |
371 |
Token.Kind.ALT_STRING -> LITERAL2, |
|
43414 | 372 |
Token.Kind.VERBATIM -> COMMENT3, |
373 |
Token.Kind.SPACE -> NULL, |
|
374 |
Token.Kind.COMMENT -> COMMENT1, |
|
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48751
diff
changeset
|
375 |
Token.Kind.ERROR -> INVALID |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
376 |
).withDefaultValue(NULL) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
377 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
378 |
|
43414 | 379 |
def token_markup(syntax: Outer_Syntax, token: Token): Byte = |
43430
1ed88ddf1268
more uniform treatment of "keyword" vs. "operator";
wenzelm
parents:
43418
diff
changeset
|
380 |
if (token.is_command) command_style(syntax.keyword_kind(token.content).getOrElse("")) |
1ed88ddf1268
more uniform treatment of "keyword" vs. "operator";
wenzelm
parents:
43418
diff
changeset
|
381 |
else if (token.is_operator) JEditToken.OPERATOR |
43414 | 382 |
else token_style(token.kind) |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
383 |
} |