author | wenzelm |
Fri, 21 Sep 2012 11:42:14 +0200 | |
changeset 49476 | 8ae5804c4ba8 |
parent 49474 | e7ff10e1a155 |
child 49492 | 2e3e7ea5ce8e |
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} |
49406 | 17 |
import org.gjt.sp.jedit.GUIUtilities |
18 |
import org.gjt.sp.util.Log |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
19 |
|
45460 | 20 |
import scala.collection.immutable.SortedMap |
21 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
22 |
|
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
|
23 |
object Isabelle_Rendering |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
24 |
{ |
49356 | 25 |
def apply(snapshot: Document.Snapshot, options: Options): Isabelle_Rendering = |
26 |
new Isabelle_Rendering(snapshot, options) |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
27 |
|
49356 | 28 |
|
49406 | 29 |
/* message priorities */ |
43388 | 30 |
|
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
|
31 |
private val writeln_pri = 1 |
49474 | 32 |
private val tracing_pri = 2 |
33 |
private val warning_pri = 3 |
|
34 |
private val legacy_pri = 4 |
|
35 |
private val error_pri = 5 |
|
36 |
||
37 |
private val message_pri = Map( |
|
38 |
Isabelle_Markup.WRITELN -> writeln_pri, Isabelle_Markup.WRITELN_MESSAGE -> writeln_pri, |
|
39 |
Isabelle_Markup.TRACING -> tracing_pri, Isabelle_Markup.TRACING_MESSAGE -> tracing_pri, |
|
40 |
Isabelle_Markup.WARNING -> warning_pri, Isabelle_Markup.WARNING_MESSAGE -> warning_pri, |
|
41 |
Isabelle_Markup.ERROR -> error_pri, Isabelle_Markup.ERROR_MESSAGE -> error_pri) |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
42 |
|
49406 | 43 |
|
44 |
/* icons */ |
|
45 |
||
46 |
private def load_icon(name: String): Icon = |
|
47 |
{ |
|
48 |
val icon = GUIUtilities.loadIcon(name) |
|
49 |
if (icon.getIconWidth < 0 || icon.getIconHeight < 0) |
|
50 |
Log.log(Log.ERROR, icon, "Bad icon: " + name) |
|
51 |
icon |
|
52 |
} |
|
53 |
||
46234 | 54 |
private val gutter_icons = Map( |
49406 | 55 |
warning_pri -> load_icon("16x16/status/dialog-information.png"), |
56 |
legacy_pri -> load_icon("16x16/status/dialog-warning.png"), |
|
57 |
error_pri -> load_icon("16x16/status/dialog-error.png")) |
|
46234 | 58 |
|
59 |
||
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
60 |
/* token markup -- text styles */ |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
61 |
|
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
62 |
private val command_style: Map[String, Byte] = |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
63 |
{ |
43414 | 64 |
import JEditToken._ |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
65 |
Map[String, Byte]( |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
66 |
Keyword.THY_END -> KEYWORD2, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
67 |
Keyword.THY_SCRIPT -> LABEL, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
68 |
Keyword.PRF_SCRIPT -> LABEL, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
69 |
Keyword.PRF_ASM -> KEYWORD3, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
70 |
Keyword.PRF_ASM_GOAL -> KEYWORD3 |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
71 |
).withDefaultValue(KEYWORD1) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
72 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
73 |
|
43414 | 74 |
private val token_style: Map[Token.Kind.Value, Byte] = |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
75 |
{ |
43414 | 76 |
import JEditToken._ |
77 |
Map[Token.Kind.Value, Byte]( |
|
78 |
Token.Kind.KEYWORD -> KEYWORD2, |
|
79 |
Token.Kind.IDENT -> NULL, |
|
80 |
Token.Kind.LONG_IDENT -> NULL, |
|
81 |
Token.Kind.SYM_IDENT -> NULL, |
|
82 |
Token.Kind.VAR -> NULL, |
|
83 |
Token.Kind.TYPE_IDENT -> NULL, |
|
84 |
Token.Kind.TYPE_VAR -> NULL, |
|
85 |
Token.Kind.NAT -> NULL, |
|
86 |
Token.Kind.FLOAT -> NULL, |
|
43431 | 87 |
Token.Kind.STRING -> LITERAL1, |
88 |
Token.Kind.ALT_STRING -> LITERAL2, |
|
43414 | 89 |
Token.Kind.VERBATIM -> COMMENT3, |
90 |
Token.Kind.SPACE -> NULL, |
|
91 |
Token.Kind.COMMENT -> COMMENT1, |
|
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48751
diff
changeset
|
92 |
Token.Kind.ERROR -> INVALID |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
93 |
).withDefaultValue(NULL) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
94 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
95 |
|
43414 | 96 |
def token_markup(syntax: Outer_Syntax, token: Token): Byte = |
43430
1ed88ddf1268
more uniform treatment of "keyword" vs. "operator";
wenzelm
parents:
43418
diff
changeset
|
97 |
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
|
98 |
else if (token.is_operator) JEditToken.OPERATOR |
43414 | 99 |
else token_style(token.kind) |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
100 |
} |
49356 | 101 |
|
102 |
||
103 |
class Isabelle_Rendering private(val snapshot: Document.Snapshot, val options: Options) |
|
104 |
{ |
|
105 |
/* colors */ |
|
106 |
||
107 |
def color_value(s: String): Color = Color_Value(options.string(s)) |
|
108 |
||
109 |
val outdated_color = color_value("outdated_color") |
|
110 |
val unprocessed_color = color_value("unprocessed_color") |
|
111 |
val unprocessed1_color = color_value("unprocessed1_color") |
|
112 |
val running_color = color_value("running_color") |
|
113 |
val running1_color = color_value("running1_color") |
|
114 |
val light_color = color_value("light_color") |
|
115 |
val writeln_color = color_value("writeln_color") |
|
116 |
val warning_color = color_value("warning_color") |
|
117 |
val error_color = color_value("error_color") |
|
118 |
val error1_color = color_value("error1_color") |
|
49418 | 119 |
val writeln_message_color = color_value("writeln_message_color") |
120 |
val tracing_message_color = color_value("tracing_message_color") |
|
121 |
val warning_message_color = color_value("warning_message_color") |
|
122 |
val error_message_color = color_value("error_message_color") |
|
49356 | 123 |
val bad_color = color_value("bad_color") |
49358 | 124 |
val intensify_color = color_value("intensify_color") |
49356 | 125 |
val quoted_color = color_value("quoted_color") |
49358 | 126 |
val highlight_color = color_value("highlight_color") |
49356 | 127 |
val hyperlink_color = color_value("hyperlink_color") |
128 |
val keyword1_color = color_value("keyword1_color") |
|
129 |
val keyword2_color = color_value("keyword2_color") |
|
130 |
||
131 |
val tfree_color = color_value("tfree_color") |
|
132 |
val tvar_color = color_value("tvar_color") |
|
133 |
val free_color = color_value("free_color") |
|
134 |
val skolem_color = color_value("skolem_color") |
|
135 |
val bound_color = color_value("bound_color") |
|
136 |
val var_color = color_value("var_color") |
|
137 |
val inner_numeral_color = color_value("inner_numeral_color") |
|
138 |
val inner_quoted_color = color_value("inner_quoted_color") |
|
139 |
val inner_comment_color = color_value("inner_comment_color") |
|
140 |
val antiquotation_color = color_value("antiquotation_color") |
|
141 |
val dynamic_color = color_value("dynamic_color") |
|
142 |
||
143 |
||
144 |
/* command overview */ |
|
145 |
||
146 |
def overview_color(range: Text.Range): Option[Color] = |
|
147 |
{ |
|
148 |
if (snapshot.is_outdated) None |
|
149 |
else { |
|
150 |
val results = |
|
151 |
snapshot.cumulate_markup[(Protocol.Status, Int)]( |
|
152 |
range, (Protocol.Status.init, 0), |
|
153 |
Some(Protocol.command_status_markup + Isabelle_Markup.WARNING + Isabelle_Markup.ERROR), |
|
154 |
{ |
|
155 |
case ((status, pri), Text.Info(_, XML.Elem(markup, _))) => |
|
49474 | 156 |
if (markup.name == Isabelle_Markup.WARNING || markup.name == Isabelle_Markup.ERROR) |
157 |
(status, pri max Isabelle_Rendering.message_pri(markup.name)) |
|
49356 | 158 |
else (Protocol.command_status(status, markup), pri) |
159 |
}) |
|
160 |
if (results.isEmpty) None |
|
161 |
else { |
|
162 |
val (status, pri) = |
|
163 |
((Protocol.Status.init, 0) /: results) { |
|
164 |
case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) } |
|
165 |
||
166 |
if (pri == Isabelle_Rendering.warning_pri) Some(warning_color) |
|
167 |
else if (pri == Isabelle_Rendering.error_pri) Some(error_color) |
|
168 |
else if (status.is_unprocessed) Some(unprocessed_color) |
|
169 |
else if (status.is_running) Some(running_color) |
|
170 |
else if (status.is_failed) Some(error_color) |
|
171 |
else None |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
||
176 |
||
177 |
/* markup selectors */ |
|
178 |
||
49358 | 179 |
private val highlight_include = |
49356 | 180 |
Set(Isabelle_Markup.SORT, Isabelle_Markup.TYP, Isabelle_Markup.TERM, Isabelle_Markup.PROP, |
181 |
Isabelle_Markup.ML_TYPING, Isabelle_Markup.TOKEN_RANGE, Isabelle_Markup.ENTITY, |
|
182 |
Isabelle_Markup.PATH, Isabelle_Markup.TYPING, Isabelle_Markup.FREE, Isabelle_Markup.SKOLEM, |
|
183 |
Isabelle_Markup.BOUND, Isabelle_Markup.VAR, Isabelle_Markup.TFREE, Isabelle_Markup.TVAR, |
|
184 |
Isabelle_Markup.ML_SOURCE, Isabelle_Markup.DOCUMENT_SOURCE) |
|
185 |
||
49358 | 186 |
def highlight(range: Text.Range): Option[Text.Info[Color]] = |
49356 | 187 |
{ |
49358 | 188 |
snapshot.select_markup(range, Some(highlight_include), |
49356 | 189 |
{ |
49358 | 190 |
case Text.Info(info_range, XML.Elem(Markup(name, _), _)) if highlight_include(name) => |
191 |
Text.Info(snapshot.convert(info_range), highlight_color) |
|
49356 | 192 |
}) match { case Text.Info(_, info) #:: _ => Some(info) case _ => None } |
193 |
} |
|
194 |
||
195 |
||
196 |
private val hyperlink_include = Set(Isabelle_Markup.ENTITY, Isabelle_Markup.PATH) |
|
197 |
||
198 |
def hyperlink(range: Text.Range): Option[Text.Info[Hyperlink]] = |
|
199 |
{ |
|
200 |
snapshot.cumulate_markup[List[Text.Info[Hyperlink]]](range, Nil, Some(hyperlink_include), |
|
201 |
{ |
|
202 |
case (links, Text.Info(info_range, XML.Elem(Isabelle_Markup.Path(name), _))) |
|
203 |
if Path.is_ok(name) => |
|
204 |
val jedit_file = Isabelle.thy_load.append(snapshot.node_name.dir, Path.explode(name)) |
|
205 |
Text.Info(snapshot.convert(info_range), Hyperlink(jedit_file, 0, 0)) :: links |
|
206 |
||
207 |
case (links, Text.Info(info_range, XML.Elem(Markup(Isabelle_Markup.ENTITY, props), _))) |
|
208 |
if (props.find( |
|
209 |
{ case (Markup.KIND, Isabelle_Markup.ML_OPEN) => true |
|
210 |
case (Markup.KIND, Isabelle_Markup.ML_STRUCT) => true |
|
211 |
case _ => false }).isEmpty) => |
|
212 |
||
213 |
props match { |
|
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49418
diff
changeset
|
214 |
case Position.Def_Line_File(line, name) if Path.is_ok(name) => |
49356 | 215 |
Isabelle_System.source_file(Path.explode(name)) match { |
216 |
case Some(path) => |
|
217 |
val jedit_file = Isabelle_System.platform_path(path) |
|
218 |
Text.Info(snapshot.convert(info_range), Hyperlink(jedit_file, line, 0)) :: links |
|
219 |
case None => links |
|
220 |
} |
|
221 |
||
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
49418
diff
changeset
|
222 |
case Position.Def_Id_Offset(id, offset) => |
49356 | 223 |
snapshot.state.find_command(snapshot.version, id) match { |
224 |
case Some((node, command)) => |
|
225 |
val sources = |
|
226 |
node.commands.iterator.takeWhile(_ != command).map(_.source) ++ |
|
227 |
Iterator.single(command.source(Text.Range(0, command.decode(offset)))) |
|
228 |
val (line, column) = ((1, 1) /: sources)(Symbol.advance_line_column) |
|
229 |
Text.Info(snapshot.convert(info_range), |
|
230 |
Hyperlink(command.node_name.node, line, column)) :: links |
|
231 |
case None => links |
|
232 |
} |
|
233 |
||
234 |
case _ => links |
|
235 |
} |
|
236 |
}) match { case Text.Info(_, info :: _) #:: _ => Some(info) case _ => None } |
|
237 |
} |
|
238 |
||
239 |
||
240 |
private def tooltip_text(msg: XML.Tree): String = |
|
241 |
Pretty.string_of(List(msg), margin = options.int("jedit_tooltip_margin")) |
|
242 |
||
243 |
def tooltip_message(range: Text.Range): Option[String] = |
|
244 |
{ |
|
245 |
val msgs = |
|
246 |
snapshot.cumulate_markup[SortedMap[Long, String]](range, SortedMap.empty, |
|
247 |
Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR, |
|
248 |
Isabelle_Markup.BAD)), |
|
249 |
{ |
|
250 |
case (msgs, Text.Info(_, msg @ |
|
251 |
XML.Elem(Markup(markup, Isabelle_Markup.Serial(serial)), _))) |
|
252 |
if markup == Isabelle_Markup.WRITELN || |
|
253 |
markup == Isabelle_Markup.WARNING || |
|
254 |
markup == Isabelle_Markup.ERROR => |
|
255 |
msgs + (serial -> tooltip_text(msg)) |
|
256 |
case (msgs, Text.Info(_, msg @ XML.Elem(Markup(Isabelle_Markup.BAD, _), body))) |
|
257 |
if !body.isEmpty => msgs + (Document.new_id() -> tooltip_text(msg)) |
|
258 |
}).toList.flatMap(_.info) |
|
259 |
if (msgs.isEmpty) None else Some(cat_lines(msgs.iterator.map(_._2))) |
|
260 |
} |
|
261 |
||
262 |
||
263 |
private val tooltips: Map[String, String] = |
|
264 |
Map( |
|
265 |
Isabelle_Markup.SORT -> "sort", |
|
266 |
Isabelle_Markup.TYP -> "type", |
|
267 |
Isabelle_Markup.TERM -> "term", |
|
268 |
Isabelle_Markup.PROP -> "proposition", |
|
269 |
Isabelle_Markup.TOKEN_RANGE -> "inner syntax token", |
|
270 |
Isabelle_Markup.FREE -> "free variable", |
|
271 |
Isabelle_Markup.SKOLEM -> "skolem variable", |
|
272 |
Isabelle_Markup.BOUND -> "bound variable", |
|
273 |
Isabelle_Markup.VAR -> "schematic variable", |
|
274 |
Isabelle_Markup.TFREE -> "free type variable", |
|
275 |
Isabelle_Markup.TVAR -> "schematic type variable", |
|
276 |
Isabelle_Markup.ML_SOURCE -> "ML source", |
|
277 |
Isabelle_Markup.DOCUMENT_SOURCE -> "document source") |
|
278 |
||
279 |
private val tooltip_elements = |
|
280 |
Set(Isabelle_Markup.ENTITY, Isabelle_Markup.TYPING, Isabelle_Markup.ML_TYPING, |
|
281 |
Isabelle_Markup.PATH) ++ tooltips.keys |
|
282 |
||
283 |
private def string_of_typing(kind: String, body: XML.Body): String = |
|
284 |
Pretty.string_of(List(Pretty.block(XML.Text(kind) :: Pretty.Break(1) :: body)), |
|
285 |
margin = options.int("jedit_tooltip_margin")) |
|
286 |
||
287 |
def tooltip(range: Text.Range): Option[String] = |
|
288 |
{ |
|
289 |
def add(prev: Text.Info[List[(Boolean, String)]], r: Text.Range, p: (Boolean, String)) = |
|
290 |
if (prev.range == r) Text.Info(r, p :: prev.info) else Text.Info(r, List(p)) |
|
291 |
||
292 |
val tips = |
|
293 |
snapshot.cumulate_markup[Text.Info[(List[(Boolean, String)])]]( |
|
294 |
range, Text.Info(range, Nil), Some(tooltip_elements), |
|
295 |
{ |
|
296 |
case (prev, Text.Info(r, XML.Elem(Isabelle_Markup.Entity(kind, name), _))) => |
|
297 |
val kind1 = space_explode('_', kind).mkString(" ") |
|
298 |
add(prev, r, (true, kind1 + " " + quote(name))) |
|
299 |
case (prev, Text.Info(r, XML.Elem(Isabelle_Markup.Path(name), _))) |
|
300 |
if Path.is_ok(name) => |
|
301 |
val jedit_file = Isabelle.thy_load.append(snapshot.node_name.dir, Path.explode(name)) |
|
302 |
add(prev, r, (true, "file " + quote(jedit_file))) |
|
303 |
case (prev, Text.Info(r, XML.Elem(Markup(Isabelle_Markup.TYPING, _), body))) => |
|
304 |
add(prev, r, (true, string_of_typing("::", body))) |
|
305 |
case (prev, Text.Info(r, XML.Elem(Markup(Isabelle_Markup.ML_TYPING, _), body))) => |
|
306 |
add(prev, r, (false, string_of_typing("ML:", body))) |
|
307 |
case (prev, Text.Info(r, XML.Elem(Markup(name, _), _))) |
|
308 |
if tooltips.isDefinedAt(name) => add(prev, r, (true, tooltips(name))) |
|
309 |
}).toList.flatMap(_.info.info) |
|
310 |
||
311 |
val all_tips = |
|
312 |
(tips.filter(_._1) ++ tips.filter(!_._1).lastOption.toList).map(_._2) |
|
313 |
if (all_tips.isEmpty) None else Some(cat_lines(all_tips)) |
|
314 |
} |
|
315 |
||
316 |
||
317 |
def gutter_message(range: Text.Range): Option[Icon] = |
|
318 |
{ |
|
319 |
val results = |
|
320 |
snapshot.cumulate_markup[Int](range, 0, |
|
321 |
Some(Set(Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)), |
|
322 |
{ |
|
323 |
case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.WARNING, _), body))) => |
|
324 |
body match { |
|
325 |
case List(XML.Elem(Markup(Isabelle_Markup.LEGACY, _), _)) => |
|
326 |
pri max Isabelle_Rendering.legacy_pri |
|
327 |
case _ => pri max Isabelle_Rendering.warning_pri |
|
328 |
} |
|
329 |
case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ERROR, _), _))) => |
|
330 |
pri max Isabelle_Rendering.error_pri |
|
331 |
}) |
|
332 |
val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 } |
|
333 |
Isabelle_Rendering.gutter_icons.get(pri) |
|
334 |
} |
|
335 |
||
336 |
||
337 |
private val squiggly_colors = Map( |
|
338 |
Isabelle_Rendering.writeln_pri -> writeln_color, |
|
339 |
Isabelle_Rendering.warning_pri -> warning_color, |
|
340 |
Isabelle_Rendering.error_pri -> error_color) |
|
341 |
||
342 |
def squiggly_underline(range: Text.Range): Stream[Text.Info[Color]] = |
|
343 |
{ |
|
344 |
val results = |
|
345 |
snapshot.cumulate_markup[Int](range, 0, |
|
346 |
Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)), |
|
347 |
{ |
|
49474 | 348 |
case (pri, Text.Info(_, XML.Elem(Markup(name, _), _))) |
349 |
if name == Isabelle_Markup.WRITELN || |
|
350 |
name == Isabelle_Markup.WARNING || |
|
351 |
name == Isabelle_Markup.ERROR => pri max Isabelle_Rendering.message_pri(name) |
|
49356 | 352 |
}) |
353 |
for { |
|
354 |
Text.Info(r, pri) <- results |
|
355 |
color <- squiggly_colors.get(pri) |
|
356 |
} yield Text.Info(r, color) |
|
357 |
} |
|
358 |
||
49474 | 359 |
|
360 |
private val message_colors = Map( |
|
361 |
Isabelle_Rendering.writeln_pri -> writeln_message_color, |
|
362 |
Isabelle_Rendering.tracing_pri -> tracing_message_color, |
|
363 |
Isabelle_Rendering.warning_pri -> warning_message_color, |
|
364 |
Isabelle_Rendering.error_pri -> error_message_color) |
|
365 |
||
49473 | 366 |
def line_background(range: Text.Range): Option[(Color, Boolean)] = |
367 |
{ |
|
368 |
val messages = |
|
49474 | 369 |
Set(Isabelle_Markup.WRITELN_MESSAGE, Isabelle_Markup.TRACING_MESSAGE, |
370 |
Isabelle_Markup.WARNING_MESSAGE, Isabelle_Markup.ERROR_MESSAGE) |
|
371 |
val results = |
|
372 |
snapshot.cumulate_markup[Int](range, 0, Some(messages), |
|
49473 | 373 |
{ |
49474 | 374 |
case (pri, Text.Info(_, XML.Elem(Markup(name, _), _))) |
375 |
if name == Isabelle_Markup.WRITELN_MESSAGE || |
|
376 |
name == Isabelle_Markup.TRACING_MESSAGE || |
|
377 |
name == Isabelle_Markup.WARNING_MESSAGE || |
|
378 |
name == Isabelle_Markup.ERROR_MESSAGE => pri max Isabelle_Rendering.message_pri(name) |
|
379 |
}) |
|
380 |
val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 } |
|
381 |
||
382 |
val is_separator = pri > 0 && |
|
383 |
snapshot.cumulate_markup[Boolean](range, false, Some(Set(Isabelle_Markup.SEPARATOR)), |
|
49473 | 384 |
{ |
385 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.SEPARATOR, _), _))) => true |
|
386 |
}).exists(_.info) |
|
387 |
||
49474 | 388 |
message_colors.get(pri).map((_, is_separator)) |
49473 | 389 |
} |
49356 | 390 |
|
391 |
def background1(range: Text.Range): Stream[Text.Info[Color]] = |
|
392 |
{ |
|
393 |
if (snapshot.is_outdated) Stream(Text.Info(range, outdated_color)) |
|
394 |
else |
|
395 |
for { |
|
396 |
Text.Info(r, result) <- |
|
397 |
snapshot.cumulate_markup[(Option[Protocol.Status], Option[Color])]( |
|
398 |
range, (Some(Protocol.Status.init), None), |
|
49418 | 399 |
Some(Protocol.command_status_markup + Isabelle_Markup.WRITELN_MESSAGE + |
400 |
Isabelle_Markup.TRACING_MESSAGE + Isabelle_Markup.WARNING_MESSAGE + |
|
401 |
Isabelle_Markup.ERROR_MESSAGE + Isabelle_Markup.BAD + Isabelle_Markup.INTENSIFY), |
|
49356 | 402 |
{ |
403 |
case (((Some(status), color), Text.Info(_, XML.Elem(markup, _)))) |
|
404 |
if (Protocol.command_status_markup(markup.name)) => |
|
405 |
(Some(Protocol.command_status(status, markup)), color) |
|
406 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.BAD, _), _))) => |
|
407 |
(None, Some(bad_color)) |
|
49358 | 408 |
case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.INTENSIFY, _), _))) => |
409 |
(None, Some(intensify_color)) |
|
49356 | 410 |
}) |
411 |
color <- |
|
412 |
(result match { |
|
413 |
case (Some(status), opt_color) => |
|
414 |
if (status.is_unprocessed) Some(unprocessed1_color) |
|
415 |
else if (status.is_running) Some(running1_color) |
|
416 |
else opt_color |
|
417 |
case (_, opt_color) => opt_color |
|
418 |
}) |
|
419 |
} yield Text.Info(r, color) |
|
420 |
} |
|
421 |
||
422 |
||
423 |
def background2(range: Text.Range): Stream[Text.Info[Color]] = |
|
424 |
snapshot.select_markup(range, |
|
425 |
Some(Set(Isabelle_Markup.TOKEN_RANGE)), |
|
426 |
{ |
|
427 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.TOKEN_RANGE, _), _)) => light_color |
|
428 |
}) |
|
429 |
||
430 |
||
431 |
def foreground(range: Text.Range): Stream[Text.Info[Color]] = |
|
432 |
snapshot.select_markup(range, |
|
433 |
Some(Set(Isabelle_Markup.STRING, Isabelle_Markup.ALTSTRING, Isabelle_Markup.VERBATIM)), |
|
434 |
{ |
|
435 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.STRING, _), _)) => quoted_color |
|
436 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ALTSTRING, _), _)) => quoted_color |
|
437 |
case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.VERBATIM, _), _)) => quoted_color |
|
438 |
}) |
|
439 |
||
440 |
||
441 |
private val text_colors: Map[String, Color] = Map( |
|
442 |
Isabelle_Markup.STRING -> Color.BLACK, |
|
443 |
Isabelle_Markup.ALTSTRING -> Color.BLACK, |
|
444 |
Isabelle_Markup.VERBATIM -> Color.BLACK, |
|
445 |
Isabelle_Markup.LITERAL -> keyword1_color, |
|
446 |
Isabelle_Markup.DELIMITER -> Color.BLACK, |
|
447 |
Isabelle_Markup.TFREE -> tfree_color, |
|
448 |
Isabelle_Markup.TVAR -> tvar_color, |
|
449 |
Isabelle_Markup.FREE -> free_color, |
|
450 |
Isabelle_Markup.SKOLEM -> skolem_color, |
|
451 |
Isabelle_Markup.BOUND -> bound_color, |
|
452 |
Isabelle_Markup.VAR -> var_color, |
|
453 |
Isabelle_Markup.INNER_STRING -> inner_quoted_color, |
|
454 |
Isabelle_Markup.INNER_COMMENT -> inner_comment_color, |
|
455 |
Isabelle_Markup.DYNAMIC_FACT -> dynamic_color, |
|
456 |
Isabelle_Markup.ML_KEYWORD -> keyword1_color, |
|
457 |
Isabelle_Markup.ML_DELIMITER -> Color.BLACK, |
|
458 |
Isabelle_Markup.ML_NUMERAL -> inner_numeral_color, |
|
459 |
Isabelle_Markup.ML_CHAR -> inner_quoted_color, |
|
460 |
Isabelle_Markup.ML_STRING -> inner_quoted_color, |
|
461 |
Isabelle_Markup.ML_COMMENT -> inner_comment_color, |
|
462 |
Isabelle_Markup.ANTIQ -> antiquotation_color) |
|
463 |
||
464 |
private val text_color_elements = Set.empty[String] ++ text_colors.keys |
|
465 |
||
466 |
def text_color(range: Text.Range, color: Color) |
|
467 |
: Stream[Text.Info[Color]] = |
|
468 |
{ |
|
469 |
snapshot.cumulate_markup(range, color, Some(text_color_elements), |
|
470 |
{ |
|
471 |
case (_, Text.Info(_, XML.Elem(Markup(m, _), _))) |
|
472 |
if text_colors.isDefinedAt(m) => text_colors(m) |
|
473 |
}) |
|
474 |
} |
|
475 |
} |