author | wenzelm |
Mon, 17 Apr 2017 12:11:02 +0200 | |
changeset 65487 | 7847807b07ce |
parent 65332 | 7dbb780f24a9 |
child 65488 | 331f09d9535e |
permissions | -rw-r--r-- |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
64621
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/jedit_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 |
|
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
64621
diff
changeset
|
4 |
Isabelle/jEdit-specific implementation of quasi-abstract rendering and |
50199
6d04e2422769
quasi-abstract module Rendering, with Isabelle-specific implementation;
wenzelm
parents:
50196
diff
changeset
|
5 |
markup interpretation. |
39178
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 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
8 |
package isabelle.jedit |
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 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
11 |
import isabelle._ |
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
12 |
|
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
13 |
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
|
14 |
import javax.swing.Icon |
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} |
61175 | 17 |
import org.gjt.sp.jedit.jEdit |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
18 |
|
45460 | 19 |
import scala.collection.immutable.SortedMap |
20 |
||
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
21 |
|
64621 | 22 |
object JEdit_Rendering |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
23 |
{ |
64621 | 24 |
def apply(snapshot: Document.Snapshot, options: Options): JEdit_Rendering = |
25 |
new JEdit_Rendering(snapshot, options) |
|
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
26 |
|
49356 | 27 |
|
53230 | 28 |
/* popup window bounds */ |
29 |
||
30 |
def popup_bounds: Double = (PIDE.options.real("jedit_popup_bounds") max 0.2) min 0.8 |
|
31 |
||
32 |
||
55501 | 33 |
/* Isabelle/Isar token markup */ |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
34 |
|
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
35 |
private val command_style: Map[String, Byte] = |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
36 |
{ |
43414 | 37 |
import JEditToken._ |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
38 |
Map[String, Byte]( |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
39 |
Keyword.THY_END -> KEYWORD2, |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
40 |
Keyword.PRF_ASM -> KEYWORD3, |
59125 | 41 |
Keyword.PRF_ASM_GOAL -> KEYWORD3 |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
42 |
).withDefaultValue(KEYWORD1) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
43 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
44 |
|
43414 | 45 |
private val token_style: Map[Token.Kind.Value, Byte] = |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
46 |
{ |
43414 | 47 |
import JEditToken._ |
48 |
Map[Token.Kind.Value, Byte]( |
|
49 |
Token.Kind.KEYWORD -> KEYWORD2, |
|
50 |
Token.Kind.IDENT -> NULL, |
|
51 |
Token.Kind.LONG_IDENT -> NULL, |
|
52 |
Token.Kind.SYM_IDENT -> NULL, |
|
53 |
Token.Kind.VAR -> NULL, |
|
54 |
Token.Kind.TYPE_IDENT -> NULL, |
|
55 |
Token.Kind.TYPE_VAR -> NULL, |
|
56 |
Token.Kind.NAT -> NULL, |
|
57 |
Token.Kind.FLOAT -> NULL, |
|
59081 | 58 |
Token.Kind.SPACE -> NULL, |
43431 | 59 |
Token.Kind.STRING -> LITERAL1, |
60 |
Token.Kind.ALT_STRING -> LITERAL2, |
|
43414 | 61 |
Token.Kind.VERBATIM -> COMMENT3, |
55033 | 62 |
Token.Kind.CARTOUCHE -> COMMENT4, |
43414 | 63 |
Token.Kind.COMMENT -> COMMENT1, |
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48751
diff
changeset
|
64 |
Token.Kind.ERROR -> INVALID |
39179
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
65 |
).withDefaultValue(NULL) |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
66 |
} |
591bbab9ef59
moved token markup tables to isabelle_markup.scala;
wenzelm
parents:
39178
diff
changeset
|
67 |
|
43414 | 68 |
def token_markup(syntax: Outer_Syntax, token: Token): Byte = |
63441 | 69 |
if (token.is_command) command_style(syntax.keywords.kinds.getOrElse(token.content, "")) |
61579 | 70 |
else if (token.is_keyword && token.source == Symbol.comment_decoded) JEditToken.NULL |
55505 | 71 |
else if (token.is_delimiter) JEditToken.OPERATOR |
43414 | 72 |
else token_style(token.kind) |
55500 | 73 |
|
55501 | 74 |
|
75 |
/* Isabelle/ML token markup */ |
|
76 |
||
55500 | 77 |
private val ml_token_style: Map[ML_Lex.Kind.Value, Byte] = |
78 |
{ |
|
79 |
import JEditToken._ |
|
80 |
Map[ML_Lex.Kind.Value, Byte]( |
|
55505 | 81 |
ML_Lex.Kind.KEYWORD -> NULL, |
55500 | 82 |
ML_Lex.Kind.IDENT -> NULL, |
83 |
ML_Lex.Kind.LONG_IDENT -> NULL, |
|
84 |
ML_Lex.Kind.TYPE_VAR -> NULL, |
|
55503 | 85 |
ML_Lex.Kind.WORD -> DIGIT, |
86 |
ML_Lex.Kind.INT -> DIGIT, |
|
87 |
ML_Lex.Kind.REAL -> DIGIT, |
|
55500 | 88 |
ML_Lex.Kind.CHAR -> LITERAL2, |
89 |
ML_Lex.Kind.STRING -> LITERAL1, |
|
90 |
ML_Lex.Kind.SPACE -> NULL, |
|
91 |
ML_Lex.Kind.COMMENT -> COMMENT1, |
|
55512 | 92 |
ML_Lex.Kind.ANTIQ -> NULL, |
93 |
ML_Lex.Kind.ANTIQ_START -> LITERAL4, |
|
94 |
ML_Lex.Kind.ANTIQ_STOP -> LITERAL4, |
|
95 |
ML_Lex.Kind.ANTIQ_OTHER -> NULL, |
|
55514
8ef781e282d9
more uniform rendering of text that is formally interpreted: avoid clash with inner markup;
wenzelm
parents:
55512
diff
changeset
|
96 |
ML_Lex.Kind.ANTIQ_STRING -> NULL, |
8ef781e282d9
more uniform rendering of text that is formally interpreted: avoid clash with inner markup;
wenzelm
parents:
55512
diff
changeset
|
97 |
ML_Lex.Kind.ANTIQ_ALT_STRING -> NULL, |
8ef781e282d9
more uniform rendering of text that is formally interpreted: avoid clash with inner markup;
wenzelm
parents:
55512
diff
changeset
|
98 |
ML_Lex.Kind.ANTIQ_CARTOUCHE -> NULL, |
55500 | 99 |
ML_Lex.Kind.ERROR -> INVALID |
100 |
).withDefaultValue(NULL) |
|
101 |
} |
|
102 |
||
103 |
def ml_token_markup(token: ML_Lex.Token): Byte = |
|
55501 | 104 |
if (!token.is_keyword) ml_token_style(token.kind) |
55505 | 105 |
else if (token.is_delimiter) JEditToken.OPERATOR |
106 |
else if (ML_Lex.keywords2(token.source)) JEditToken.KEYWORD2 |
|
107 |
else if (ML_Lex.keywords3(token.source)) JEditToken.KEYWORD3 |
|
55501 | 108 |
else JEditToken.KEYWORD1 |
55647 | 109 |
|
110 |
||
111 |
/* markup elements */ |
|
112 |
||
63474
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
113 |
private val indentation_elements = |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
114 |
Markup.Elements(Markup.Command_Indent.name) |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
115 |
|
56173 | 116 |
private val language_context_elements = |
59081 | 117 |
Markup.Elements(Markup.STRING, Markup.ALT_STRING, Markup.VERBATIM, |
55647 | 118 |
Markup.CARTOUCHE, Markup.COMMENT, Markup.LANGUAGE, |
61598 | 119 |
Markup.ML_STRING, Markup.ML_COMMENT) |
55647 | 120 |
|
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56743
diff
changeset
|
121 |
private val language_elements = Markup.Elements(Markup.LANGUAGE) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56743
diff
changeset
|
122 |
|
58592 | 123 |
private val citation_elements = Markup.Elements(Markup.CITATION) |
124 |
||
60878
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
125 |
private val breakpoint_elements = Markup.Elements(Markup.ML_BREAKPOINT) |
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
126 |
|
55647 | 127 |
private val highlight_elements = |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
58464
diff
changeset
|
128 |
Markup.Elements(Markup.EXPRESSION, Markup.CITATION, Markup.LANGUAGE, Markup.ML_TYPING, |
61718
309c20b21451
clarified rendering of Markup.DOC: like Markup.PATH / Markup.URL;
wenzelm
parents:
61660
diff
changeset
|
129 |
Markup.TOKEN_RANGE, Markup.ENTITY, Markup.PATH, Markup.DOC, Markup.URL, Markup.SORTING, |
63347 | 130 |
Markup.TYPING, Markup.CLASS_PARAMETER, Markup.FREE, Markup.SKOLEM, Markup.BOUND, |
61450 | 131 |
Markup.VAR, Markup.TFREE, Markup.TVAR, Markup.ML_BREAKPOINT, |
132 |
Markup.MARKDOWN_PARAGRAPH, Markup.Markdown_List.name) |
|
55647 | 133 |
|
134 |
private val hyperlink_elements = |
|
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61603
diff
changeset
|
135 |
Markup.Elements(Markup.ENTITY, Markup.PATH, Markup.DOC, Markup.POSITION, |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61603
diff
changeset
|
136 |
Markup.CITATION, Markup.URL) |
55647 | 137 |
|
138 |
private val gutter_elements = |
|
59203
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
139 |
Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR) |
55647 | 140 |
|
141 |
private val squiggly_elements = |
|
59203
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
142 |
Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR) |
55647 | 143 |
|
144 |
private val line_background_elements = |
|
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59129
diff
changeset
|
145 |
Markup.Elements(Markup.WRITELN_MESSAGE, Markup.STATE_MESSAGE, Markup.INFORMATION_MESSAGE, |
59203
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
146 |
Markup.TRACING_MESSAGE, Markup.WARNING_MESSAGE, Markup.LEGACY_MESSAGE, |
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
147 |
Markup.ERROR_MESSAGE) |
55647 | 148 |
|
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55790
diff
changeset
|
149 |
private val separator_elements = |
56743 | 150 |
Markup.Elements(Markup.SEPARATOR) |
55647 | 151 |
|
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55790
diff
changeset
|
152 |
private val bullet_elements = |
60913 | 153 |
Markup.Elements(Markup.BULLET, Markup.ML_BREAKPOINT) |
55647 | 154 |
|
155 |
private val fold_depth_elements = |
|
56743 | 156 |
Markup.Elements(Markup.TEXT_FOLD, Markup.GOAL, Markup.SUBGOAL) |
39178
83e9f3ccea9f
concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff
changeset
|
157 |
} |
49356 | 158 |
|
159 |
||
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
64621
diff
changeset
|
160 |
class JEdit_Rendering(snapshot: Document.Snapshot, options: Options) |
65213
51c0f094dc02
proper local debugger state, depending on session;
wenzelm
parents:
65190
diff
changeset
|
161 |
extends Rendering(snapshot, options, PIDE.session) |
49356 | 162 |
{ |
163 |
/* colors */ |
|
164 |
||
65144 | 165 |
def color(s: String): Color = |
65145 | 166 |
if (s == "main_color") main_color |
65144 | 167 |
else Color_Value(options.string(s)) |
168 |
||
169 |
def color(c: Rendering.Color.Value): Color = _rendering_colors(c) |
|
49356 | 170 |
|
65101 | 171 |
lazy val _rendering_colors: Map[Rendering.Color.Value, Color] = |
65102 | 172 |
Rendering.Color.values.iterator.map(c => c -> color(c.toString + "_color")).toMap |
65101 | 173 |
|
65145 | 174 |
val main_color = jEdit.getColorProperty("view.fgColor") |
175 |
||
65102 | 176 |
val outdated_color = color("outdated_color") |
177 |
val unprocessed_color = color("unprocessed_color") |
|
178 |
val running_color = color("running_color") |
|
179 |
val bullet_color = color("bullet_color") |
|
180 |
val tooltip_color = color("tooltip_color") |
|
181 |
val warning_color = color("warning_color") |
|
182 |
val error_color = color("error_color") |
|
183 |
val spell_checker_color = color("spell_checker_color") |
|
184 |
val entity_ref_color = color("entity_ref_color") |
|
185 |
val breakpoint_disabled_color = color("breakpoint_disabled_color") |
|
186 |
val breakpoint_enabled_color = color("breakpoint_enabled_color") |
|
187 |
val caret_debugger_color = color("caret_debugger_color") |
|
188 |
val highlight_color = color("highlight_color") |
|
189 |
val hyperlink_color = color("hyperlink_color") |
|
190 |
val active_hover_color = color("active_hover_color") |
|
191 |
val caret_invisible_color = color("caret_invisible_color") |
|
192 |
val completion_color = color("completion_color") |
|
193 |
val search_color = color("search_color") |
|
49356 | 194 |
|
195 |
||
63474
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
196 |
/* indentation */ |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
197 |
|
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
198 |
def indentation(range: Text.Range): Int = |
64621 | 199 |
snapshot.select(range, JEdit_Rendering.indentation_elements, _ => |
63474
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
200 |
{ |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
201 |
case Text.Info(_, XML.Elem(Markup.Command_Indent(i), _)) => Some(i) |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
202 |
case _ => None |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
203 |
}).headOption.map(_.info).getOrElse(0) |
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
204 |
|
f66e3c3b0fb1
semantic indentation for unstructured proof scripts;
wenzelm
parents:
63441
diff
changeset
|
205 |
|
55674 | 206 |
/* completion */ |
207 |
||
56173 | 208 |
def language_context(range: Text.Range): Option[Completion.Language_Context] = |
64621 | 209 |
snapshot.select(range, JEdit_Rendering.language_context_elements, _ => |
55690
d73949233c2e
clarified stretch_point_range wrt. UTF-16 surrogates;
wenzelm
parents:
55689
diff
changeset
|
210 |
{ |
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
55825
diff
changeset
|
211 |
case Text.Info(_, XML.Elem(Markup.Language(language, symbols, antiquotes, delimited), _)) => |
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
55825
diff
changeset
|
212 |
if (delimited) Some(Completion.Language_Context(language, symbols, antiquotes)) |
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
55825
diff
changeset
|
213 |
else None |
55690
d73949233c2e
clarified stretch_point_range wrt. UTF-16 surrogates;
wenzelm
parents:
55689
diff
changeset
|
214 |
case Text.Info(_, elem) |
61598 | 215 |
if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT => |
55749 | 216 |
Some(Completion.Language_Context.ML_inner) |
55690
d73949233c2e
clarified stretch_point_range wrt. UTF-16 surrogates;
wenzelm
parents:
55689
diff
changeset
|
217 |
case Text.Info(_, _) => |
55749 | 218 |
Some(Completion.Language_Context.inner) |
55690
d73949233c2e
clarified stretch_point_range wrt. UTF-16 surrogates;
wenzelm
parents:
55689
diff
changeset
|
219 |
}).headOption.map(_.info) |
55615
bf4bbe72f740
completion of keywords and symbols based on language context;
wenzelm
parents:
55550
diff
changeset
|
220 |
|
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56743
diff
changeset
|
221 |
def language_path(range: Text.Range): Option[Text.Range] = |
64621 | 222 |
snapshot.select(range, JEdit_Rendering.language_elements, _ => |
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56743
diff
changeset
|
223 |
{ |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56743
diff
changeset
|
224 |
case Text.Info(info_range, XML.Elem(Markup.Language(Markup.Language.PATH, _, _, _), _)) => |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56743
diff
changeset
|
225 |
Some(snapshot.convert(info_range)) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56743
diff
changeset
|
226 |
case _ => None |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56743
diff
changeset
|
227 |
}).headOption.map(_.info) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56743
diff
changeset
|
228 |
|
58592 | 229 |
def citation(range: Text.Range): Option[Text.Info[String]] = |
64621 | 230 |
snapshot.select(range, JEdit_Rendering.citation_elements, _ => |
58592 | 231 |
{ |
232 |
case Text.Info(info_range, XML.Elem(Markup.Citation(name), _)) => |
|
233 |
Some(Text.Info(snapshot.convert(info_range), name)) |
|
234 |
case _ => None |
|
235 |
}).headOption.map(_.info) |
|
236 |
||
55615
bf4bbe72f740
completion of keywords and symbols based on language context;
wenzelm
parents:
55550
diff
changeset
|
237 |
|
60878
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
238 |
/* breakpoints */ |
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
239 |
|
60880
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
240 |
def breakpoint(range: Text.Range): Option[(Command, Long)] = |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
241 |
if (snapshot.is_outdated) None |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
242 |
else |
64621 | 243 |
snapshot.select(range, JEdit_Rendering.breakpoint_elements, command_states => |
60880
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
244 |
{ |
60882 | 245 |
case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) => |
60880
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
246 |
command_states match { |
60882 | 247 |
case st :: _ => Some((st.command, breakpoint)) |
60880
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
248 |
case _ => None |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
249 |
} |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
250 |
case _ => None |
fa958e24ff24
set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents:
60878
diff
changeset
|
251 |
}).headOption.map(_.info) |
60878
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
252 |
|
1f0d2bbcf38b
added action to toggle breakpoints (on editor side);
wenzelm
parents:
60876
diff
changeset
|
253 |
|
55626 | 254 |
/* command status overview */ |
49356 | 255 |
|
256 |
def overview_color(range: Text.Range): Option[Color] = |
|
257 |
{ |
|
258 |
if (snapshot.is_outdated) None |
|
259 |
else { |
|
260 |
val results = |
|
56395
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
261 |
snapshot.cumulate[List[Markup]](range, Nil, Protocol.liberal_status_elements, _ => |
49356 | 262 |
{ |
56395
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
263 |
case (status, Text.Info(_, elem)) => Some(elem.markup :: status) |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55649
diff
changeset
|
264 |
}, status = true) |
49356 | 265 |
if (results.isEmpty) None |
266 |
else { |
|
56395
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
267 |
val status = Protocol.Status.make(results.iterator.flatMap(_.info)) |
49356 | 268 |
|
50895 | 269 |
if (status.is_running) Some(running_color) |
56980
9c5220e05e04
proper priority for error over warning, which got mixed up in 0546e036d1c0 and 4df2727a0b5f;
wenzelm
parents:
56883
diff
changeset
|
270 |
else if (status.is_failed) Some(error_color) |
56395
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
271 |
else if (status.is_warned) Some(warning_color) |
49356 | 272 |
else if (status.is_unprocessed) Some(unprocessed_color) |
273 |
else None |
|
274 |
} |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
||
62986 | 279 |
/* caret focus */ |
280 |
||
62991 | 281 |
def entity_ref(range: Text.Range, focus: Set[Long]): List[Text.Info[Color]] = |
64767 | 282 |
snapshot.select(range, Rendering.caret_focus_elements, _ => |
62988 | 283 |
{ |
62991 | 284 |
case Text.Info(_, XML.Elem(Markup(Markup.ENTITY, Markup.Entity.Ref(i)), _)) if focus(i) => |
285 |
Some(entity_ref_color) |
|
62988 | 286 |
case _ => None |
287 |
}) |
|
288 |
||
62986 | 289 |
|
55626 | 290 |
/* highlighted area */ |
49356 | 291 |
|
49358 | 292 |
def highlight(range: Text.Range): Option[Text.Info[Color]] = |
64621 | 293 |
snapshot.select(range, JEdit_Rendering.highlight_elements, _ => |
55620 | 294 |
{ |
295 |
case info => Some(Text.Info(snapshot.convert(info.range), highlight_color)) |
|
55689 | 296 |
}).headOption.map(_.info) |
49356 | 297 |
|
298 |
||
55626 | 299 |
/* hyperlinks */ |
300 |
||
65246 | 301 |
def hyperlink(range: Text.Range): Option[Text.Info[JEdit_Editor.Hyperlink]] = |
49356 | 302 |
{ |
65246 | 303 |
snapshot.cumulate[Vector[Text.Info[JEdit_Editor.Hyperlink]]]( |
64621 | 304 |
range, Vector.empty, JEdit_Rendering.hyperlink_elements, _ => |
49356 | 305 |
{ |
56458
a8d960baa5c2
simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents:
56395
diff
changeset
|
306 |
case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _))) => |
65487 | 307 |
val file = perhaps_append_file(snapshot.node_name.master_dir, name) |
65246 | 308 |
val link = JEdit_Editor.hyperlink_file(true, file) |
55622
ce575c2212fc
clarified markup cumulation order (see also 25306d92f4ad and 0009a6ebc83b), e.g. relevant for completion_context;
wenzelm
parents:
55620
diff
changeset
|
309 |
Some(links :+ Text.Info(snapshot.convert(info_range), link)) |
49356 | 310 |
|
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61603
diff
changeset
|
311 |
case (links, Text.Info(info_range, XML.Elem(Markup.Doc(name), _))) => |
65246 | 312 |
JEdit_Editor.hyperlink_doc(name).map(link => |
61660
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61603
diff
changeset
|
313 |
(links :+ Text.Info(snapshot.convert(info_range), link))) |
78b371644654
added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents:
61603
diff
changeset
|
314 |
|
54702
3daeba5130f0
added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents:
54515
diff
changeset
|
315 |
case (links, Text.Info(info_range, XML.Elem(Markup.Url(name), _))) => |
65246 | 316 |
val link = JEdit_Editor.hyperlink_url(name) |
55622
ce575c2212fc
clarified markup cumulation order (see also 25306d92f4ad and 0009a6ebc83b), e.g. relevant for completion_context;
wenzelm
parents:
55620
diff
changeset
|
317 |
Some(links :+ Text.Info(snapshot.convert(info_range), link)) |
54702
3daeba5130f0
added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents:
54515
diff
changeset
|
318 |
|
64660 | 319 |
case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _))) => |
65246 | 320 |
val opt_link = JEdit_Editor.hyperlink_def_position(true, snapshot, props) |
60215 | 321 |
opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link)) |
49356 | 322 |
|
55545 | 323 |
case (links, Text.Info(info_range, XML.Elem(Markup(Markup.POSITION, props), _))) => |
65246 | 324 |
val opt_link = JEdit_Editor.hyperlink_position(true, snapshot, props) |
60215 | 325 |
opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link)) |
52889
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52873
diff
changeset
|
326 |
|
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
58464
diff
changeset
|
327 |
case (links, Text.Info(info_range, XML.Elem(Markup.Citation(name), _))) => |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
58464
diff
changeset
|
328 |
val opt_link = |
64829
07f209e957bc
refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents:
64767
diff
changeset
|
329 |
Document_Model.bibtex_entries_iterator.collectFirst( |
64831 | 330 |
{ case Text.Info(entry_range, (entry, model)) if entry == name => |
65246 | 331 |
JEdit_Editor.hyperlink_model(true, model, entry_range.start) }) |
60215 | 332 |
opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link)) |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
58464
diff
changeset
|
333 |
|
52889
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52873
diff
changeset
|
334 |
case _ => None |
55622
ce575c2212fc
clarified markup cumulation order (see also 25306d92f4ad and 0009a6ebc83b), e.g. relevant for completion_context;
wenzelm
parents:
55620
diff
changeset
|
335 |
}) match { case Text.Info(_, _ :+ info) :: _ => Some(info) case _ => None } |
49356 | 336 |
} |
337 |
||
338 |
||
55626 | 339 |
/* active elements */ |
340 |
||
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50215
diff
changeset
|
341 |
def active(range: Text.Range): Option[Text.Info[XML.Elem]] = |
65101 | 342 |
snapshot.select(range, Rendering.active_elements, command_states => |
55620 | 343 |
{ |
344 |
case Text.Info(info_range, elem) => |
|
55623 | 345 |
if (elem.name == Markup.DIALOG) { |
346 |
elem match { |
|
347 |
case Protocol.Dialog(_, serial, _) |
|
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56352
diff
changeset
|
348 |
if !command_states.exists(st => st.results.defined(serial)) => |
55623 | 349 |
Some(Text.Info(snapshot.convert(info_range), elem)) |
350 |
case _ => None |
|
351 |
} |
|
352 |
} |
|
353 |
else Some(Text.Info(snapshot.convert(info_range), elem)) |
|
55689 | 354 |
}).headOption.map(_.info) |
49492 | 355 |
|
55626 | 356 |
|
357 |
/* tooltips */ |
|
358 |
||
55647 | 359 |
def tooltip_margin: Int = options.int("jedit_tooltip_margin") |
64622
529bbb8977c7
more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents:
64621
diff
changeset
|
360 |
def timing_threshold: Double = options.real("jedit_timing_threshold") |
50554
0493efcc97e9
more general handling of graphics configurations, to increase chance of proper positioning of tooltips in multi-screen environment;
wenzelm
parents:
50547
diff
changeset
|
361 |
|
64748 | 362 |
def tooltip(range: Text.Range): Option[Text.Info[XML.Body]] = |
65132 | 363 |
tooltips(Rendering.tooltip_elements, range).map(info => info.map(Pretty.fbreaks(_))) |
65129
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65128
diff
changeset
|
364 |
|
06a7c2d316cf
more general tooltips, with uniform info range handling;
wenzelm
parents:
65128
diff
changeset
|
365 |
def tooltip_message(range: Text.Range): Option[Text.Info[XML.Body]] = |
65132 | 366 |
tooltips(Rendering.tooltip_message_elements, range).map(info => info.map(Pretty.fbreaks(_))) |
64748 | 367 |
|
52873 | 368 |
lazy val tooltip_close_icon = JEdit_Lib.load_icon(options.string("tooltip_close_icon")) |
369 |
lazy val tooltip_detach_icon = JEdit_Lib.load_icon(options.string("tooltip_detach_icon")) |
|
52472
3a43a8b1ecb0
load icons via options -- prefer IntelliJ IDEA for now;
wenzelm
parents:
52471
diff
changeset
|
370 |
|
3a43a8b1ecb0
load icons via options -- prefer IntelliJ IDEA for now;
wenzelm
parents:
52471
diff
changeset
|
371 |
|
56495 | 372 |
/* gutter */ |
373 |
||
374 |
private def gutter_message_pri(msg: XML.Tree): Int = |
|
64676 | 375 |
if (Protocol.is_error(msg)) Rendering.error_pri |
376 |
else if (Protocol.is_legacy(msg)) Rendering.legacy_pri |
|
377 |
else if (Protocol.is_warning(msg)) Rendering.warning_pri |
|
378 |
else if (Protocol.is_information(msg)) Rendering.information_pri |
|
56495 | 379 |
else 0 |
55626 | 380 |
|
59129
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
59125
diff
changeset
|
381 |
private lazy val gutter_message_content = Map( |
64676 | 382 |
Rendering.information_pri -> |
65127 | 383 |
(JEdit_Lib.load_icon(options.string("gutter_information_icon")), |
384 |
color(Rendering.Color.information_message)), |
|
64676 | 385 |
Rendering.warning_pri -> |
65127 | 386 |
(JEdit_Lib.load_icon(options.string("gutter_warning_icon")), |
387 |
color(Rendering.Color.warning_message)), |
|
64676 | 388 |
Rendering.legacy_pri -> |
65127 | 389 |
(JEdit_Lib.load_icon(options.string("gutter_legacy_icon")), |
390 |
color(Rendering.Color.legacy_message)), |
|
64676 | 391 |
Rendering.error_pri -> |
65127 | 392 |
(JEdit_Lib.load_icon(options.string("gutter_error_icon")), |
393 |
color(Rendering.Color.error_message))) |
|
49356 | 394 |
|
59129
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
59125
diff
changeset
|
395 |
def gutter_content(range: Text.Range): Option[(Icon, Color)] = |
49356 | 396 |
{ |
56495 | 397 |
val pris = |
64621 | 398 |
snapshot.cumulate[Int](range, 0, JEdit_Rendering.gutter_elements, _ => |
49356 | 399 |
{ |
56495 | 400 |
case (pri, Text.Info(_, msg @ XML.Elem(Markup(_, Markup.Serial(serial)), _))) => |
401 |
Some(pri max gutter_message_pri(msg)) |
|
52889
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52873
diff
changeset
|
402 |
case _ => None |
56495 | 403 |
}).map(_.info) |
404 |
||
59129
6959ceb53ac8
more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents:
59125
diff
changeset
|
405 |
gutter_message_content.get((0 /: pris)(_ max _)) |
49356 | 406 |
} |
407 |
||
408 |
||
65128 | 409 |
/* message output */ |
55626 | 410 |
|
65121 | 411 |
def squiggly_underline(range: Text.Range): List[Text.Info[Rendering.Color.Value]] = |
412 |
message_underline_color(JEdit_Rendering.squiggly_elements, range) |
|
49356 | 413 |
|
65124 | 414 |
def line_background(range: Text.Range): Option[(Rendering.Color.Value, Boolean)] = |
49473 | 415 |
{ |
49474 | 416 |
val results = |
64621 | 417 |
snapshot.cumulate[Int](range, 0, JEdit_Rendering.line_background_elements, _ => |
49473 | 418 |
{ |
64676 | 419 |
case (pri, Text.Info(_, elem)) => Some(pri max Rendering.message_pri(elem.name)) |
49474 | 420 |
}) |
421 |
val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 } |
|
422 |
||
65124 | 423 |
Rendering.message_background_color.get(pri).map(message_color => |
61719
318f324d41f5
less intrusive rendering, notably for State dockable;
wenzelm
parents:
61718
diff
changeset
|
424 |
{ |
318f324d41f5
less intrusive rendering, notably for State dockable;
wenzelm
parents:
61718
diff
changeset
|
425 |
val is_separator = |
64621 | 426 |
snapshot.cumulate[Boolean](range, false, JEdit_Rendering.separator_elements, _ => |
61719
318f324d41f5
less intrusive rendering, notably for State dockable;
wenzelm
parents:
61718
diff
changeset
|
427 |
{ |
318f324d41f5
less intrusive rendering, notably for State dockable;
wenzelm
parents:
61718
diff
changeset
|
428 |
case _ => Some(true) |
318f324d41f5
less intrusive rendering, notably for State dockable;
wenzelm
parents:
61718
diff
changeset
|
429 |
}).exists(_.info) |
318f324d41f5
less intrusive rendering, notably for State dockable;
wenzelm
parents:
61718
diff
changeset
|
430 |
(message_color, is_separator) |
318f324d41f5
less intrusive rendering, notably for State dockable;
wenzelm
parents:
61718
diff
changeset
|
431 |
}) |
49473 | 432 |
} |
49356 | 433 |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50499
diff
changeset
|
434 |
|
55626 | 435 |
/* text color */ |
436 |
||
65144 | 437 |
def text_color(range: Text.Range, current_color: Color): List[Text.Info[Color]] = |
49356 | 438 |
{ |
65258 | 439 |
if (current_color == Syntax_Style.hidden_color) List(Text.Info(range, current_color)) |
50196
94886ebf090f
retain hidden_color (i.e. transparent white) instead of replacing it by semantic text color, to make control symbols more hidden and avoid "dirty" lines with some fonts;
wenzelm
parents:
50164
diff
changeset
|
440 |
else |
65144 | 441 |
snapshot.cumulate(range, current_color, Rendering.text_color_elements, _ => |
50196
94886ebf090f
retain hidden_color (i.e. transparent white) instead of replacing it by semantic text color, to make control symbols more hidden and avoid "dirty" lines with some fonts;
wenzelm
parents:
50164
diff
changeset
|
442 |
{ |
65144 | 443 |
case (_, Text.Info(_, elem)) => Rendering.text_color.get(elem.name).map(color(_)) |
50196
94886ebf090f
retain hidden_color (i.e. transparent white) instead of replacing it by semantic text color, to make control symbols more hidden and avoid "dirty" lines with some fonts;
wenzelm
parents:
50164
diff
changeset
|
444 |
}) |
49356 | 445 |
} |
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
446 |
|
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
447 |
|
55626 | 448 |
/* virtual bullets */ |
449 |
||
450 |
def bullet(range: Text.Range): List[Text.Info[Color]] = |
|
64621 | 451 |
snapshot.select(range, JEdit_Rendering.bullet_elements, _ => |
60913 | 452 |
{ |
453 |
case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) => |
|
65247 | 454 |
PIDE.session.debugger.active_breakpoint_state(breakpoint).map(b => |
60913 | 455 |
if (b) breakpoint_enabled_color else breakpoint_disabled_color) |
456 |
case _ => Some(bullet_color) |
|
457 |
}) |
|
55626 | 458 |
|
459 |
||
460 |
/* text folds */ |
|
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
461 |
|
52900
d29bf6db8a2d
more elementary list structures for markup tree traversal;
wenzelm
parents:
52890
diff
changeset
|
462 |
def fold_depth(range: Text.Range): List[Text.Info[Int]] = |
64621 | 463 |
snapshot.cumulate[Int](range, 0, JEdit_Rendering.fold_depth_elements, _ => |
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
464 |
{ |
55620 | 465 |
case (depth, _) => Some(depth + 1) |
50542
58bd88159f8f
fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents:
50507
diff
changeset
|
466 |
}) |
49356 | 467 |
} |