| author | wenzelm |
| Sat, 02 Apr 2016 14:17:03 +0200 | |
| changeset 62812 | ce22e5c3d4ce |
| parent 62104 | fb73c0d7bb37 |
| child 63421 | 3bf02e7fa8a3 |
| permissions | -rw-r--r-- |
| 43414 | 1 |
/* Title: Tools/jEdit/src/token_markup.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Outer syntax token markup. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
12 |
import java.awt.{Font, Color}
|
| 53785 | 13 |
import java.awt.font.TextAttribute |
|
43491
7b7baa283434
hidden font: full height makes cursor more visible;
wenzelm
parents:
43489
diff
changeset
|
14 |
import java.awt.geom.AffineTransform |
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
15 |
|
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
16 |
import org.gjt.sp.util.SyntaxUtilities |
|
59076
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
17 |
import org.gjt.sp.jedit.{jEdit, Mode, Buffer}
|
|
58701
cc83453fac15
make double-sure that line context is present, e.g. relevant for last line after visible text;
wenzelm
parents:
58699
diff
changeset
|
18 |
import org.gjt.sp.jedit.syntax.{Token => JEditToken, TokenMarker, TokenHandler, DummyTokenHandler,
|
|
cc83453fac15
make double-sure that line context is present, e.g. relevant for last line after visible text;
wenzelm
parents:
58699
diff
changeset
|
19 |
ParserRuleSet, ModeProvider, XModeHandler, SyntaxStyle} |
| 50183 | 20 |
import org.gjt.sp.jedit.textarea.{TextArea, Selection}
|
| 61192 | 21 |
import org.gjt.sp.jedit.buffer.JEditBuffer |
|
43452
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
22 |
|
| 43414 | 23 |
import javax.swing.text.Segment |
24 |
||
25 |
||
26 |
object Token_Markup |
|
27 |
{
|
|
| 50183 | 28 |
/* editing support for control symbols */ |
29 |
||
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
30 |
def edit_control_style(text_area: TextArea, control: String) |
| 50183 | 31 |
{
|
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57126
diff
changeset
|
32 |
GUI_Thread.assert {}
|
| 50183 | 33 |
|
34 |
val buffer = text_area.getBuffer |
|
35 |
||
|
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
36 |
val control_decoded = Isabelle_Encoding.maybe_decode(buffer, control) |
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
37 |
|
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
38 |
def update_style(text: String): String = |
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
39 |
{
|
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
40 |
val result = new StringBuilder |
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
41 |
for (sym <- Symbol.iterator(text) if !HTML.control.isDefinedAt(sym)) {
|
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
42 |
if (Symbol.is_controllable(sym)) result ++= control_decoded |
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
43 |
result ++= sym |
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
44 |
} |
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
45 |
result.toString |
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
46 |
} |
|
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
47 |
|
|
50663
f8d7d332fec0
more liberal edit_control_style: include preceeding control symbol to reduce potential for user surprise;
wenzelm
parents:
50210
diff
changeset
|
48 |
text_area.getSelection.foreach(sel => {
|
|
f8d7d332fec0
more liberal edit_control_style: include preceeding control symbol to reduce potential for user surprise;
wenzelm
parents:
50210
diff
changeset
|
49 |
val before = JEdit_Lib.point_range(buffer, sel.getStart - 1) |
|
f8d7d332fec0
more liberal edit_control_style: include preceeding control symbol to reduce potential for user surprise;
wenzelm
parents:
50210
diff
changeset
|
50 |
JEdit_Lib.try_get_text(buffer, before) match {
|
|
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
51 |
case Some(s) if HTML.control.isDefinedAt(s) => |
|
50663
f8d7d332fec0
more liberal edit_control_style: include preceeding control symbol to reduce potential for user surprise;
wenzelm
parents:
50210
diff
changeset
|
52 |
text_area.extendSelection(before.start, before.stop) |
|
f8d7d332fec0
more liberal edit_control_style: include preceeding control symbol to reduce potential for user surprise;
wenzelm
parents:
50210
diff
changeset
|
53 |
case _ => |
|
f8d7d332fec0
more liberal edit_control_style: include preceeding control symbol to reduce potential for user surprise;
wenzelm
parents:
50210
diff
changeset
|
54 |
} |
|
f8d7d332fec0
more liberal edit_control_style: include preceeding control symbol to reduce potential for user surprise;
wenzelm
parents:
50210
diff
changeset
|
55 |
}) |
|
f8d7d332fec0
more liberal edit_control_style: include preceeding control symbol to reduce potential for user surprise;
wenzelm
parents:
50210
diff
changeset
|
56 |
|
| 50183 | 57 |
text_area.getSelection.toList match {
|
|
50210
747db833fbf7
no special treatment of control_reset, in accordance to other control styles;
wenzelm
parents:
50205
diff
changeset
|
58 |
case Nil => |
|
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
59 |
text_area.setSelectedText(control_decoded) |
| 50183 | 60 |
case sels => |
|
50195
863b1dfc396c
prefer buffer_edit combinator over Java-style boilerplate;
wenzelm
parents:
50187
diff
changeset
|
61 |
JEdit_Lib.buffer_edit(buffer) {
|
| 50183 | 62 |
sels.foreach(sel => |
|
62104
fb73c0d7bb37
clarified symbol insertion, depending on buffer encoding;
wenzelm
parents:
61192
diff
changeset
|
63 |
text_area.setSelectedText(sel, update_style(text_area.getSelectedText(sel)))) |
| 50183 | 64 |
} |
65 |
} |
|
66 |
} |
|
67 |
||
68 |
||
|
43443
5d9693c2337e
basic support for extended syntax styles: sub/superscript;
wenzelm
parents:
43440
diff
changeset
|
69 |
/* extended syntax styles */ |
| 43414 | 70 |
|
| 43440 | 71 |
private val plain_range: Int = JEditToken.ID_COUNT |
| 43488 | 72 |
private val full_range = 6 * plain_range + 1 |
| 43414 | 73 |
private def check_range(i: Int) { require(0 <= i && i < plain_range) }
|
74 |
||
75 |
def subscript(i: Byte): Byte = { check_range(i); (i + plain_range).toByte }
|
|
76 |
def superscript(i: Byte): Byte = { check_range(i); (i + 2 * plain_range).toByte }
|
|
| 43460 | 77 |
def bold(i: Byte): Byte = { check_range(i); (i + 3 * plain_range).toByte }
|
| 43487 | 78 |
def user_font(idx: Int, i: Byte): Byte = { check_range(i); (i + (4 + idx) * plain_range).toByte }
|
79 |
val hidden: Byte = (6 * plain_range).toByte |
|
80 |
||
81 |
private def font_style(style: SyntaxStyle, f: Font => Font): SyntaxStyle = |
|
82 |
new SyntaxStyle(style.getForegroundColor, style.getBackgroundColor, f(style.getFont)) |
|
| 43414 | 83 |
|
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
84 |
private def script_style(style: SyntaxStyle, i: Int): SyntaxStyle = |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
85 |
{
|
|
43502
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
86 |
font_style(style, font0 => |
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
87 |
{
|
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
88 |
import scala.collection.JavaConversions._ |
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
89 |
val font1 = font0.deriveFont(Map(TextAttribute.SUPERSCRIPT -> new java.lang.Integer(i))) |
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
90 |
|
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
91 |
def shift(y: Float): Font = |
| 53785 | 92 |
GUI.transform_font(font1, AffineTransform.getTranslateInstance(0.0, y.toDouble)) |
|
43502
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
93 |
|
| 59230 | 94 |
val m0 = GUI.line_metrics(font0) |
95 |
val m1 = GUI.line_metrics(font1) |
|
|
43502
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
96 |
val a = m1.getAscent - m0.getAscent |
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
97 |
val b = (m1.getDescent + m1.getLeading) - (m0.getDescent + m0.getLeading) |
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
98 |
if (a > 0.0f) shift(a) |
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
99 |
else if (b > 0.0f) shift(- b) |
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
100 |
else font1 |
|
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
101 |
}) |
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
102 |
} |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
103 |
|
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
104 |
private def bold_style(style: SyntaxStyle): SyntaxStyle = |
|
57126
3a928dffc37f
more robust bold_style, e.g. relevant for accidental \<^bold> before keyword;
wenzelm
parents:
56662
diff
changeset
|
105 |
font_style(style, font => font.deriveFont(if (font.isBold) Font.PLAIN else Font.BOLD)) |
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
106 |
|
|
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:
50195
diff
changeset
|
107 |
val hidden_color: Color = new Color(255, 255, 255, 0) |
|
44356
f6a2e5ce2ce5
avoid actual Color.white, which would be turned into Color.black by org.gjt.sp.jedit.print.BufferPrintable;
wenzelm
parents:
44355
diff
changeset
|
108 |
|
|
43661
39fdbd814c7f
quasi-static Isabelle_System -- reduced tendency towards "functorial style";
wenzelm
parents:
43553
diff
changeset
|
109 |
class Style_Extender extends SyntaxUtilities.StyleExtender |
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
110 |
{
|
|
44355
9c38bdc6d755
default style for user fonts -- to prevent org.gjt.sp.jedit.print.BufferPrintable from choking on null;
wenzelm
parents:
44238
diff
changeset
|
111 |
val max_user_fonts = 2 |
|
9c38bdc6d755
default style for user fonts -- to prevent org.gjt.sp.jedit.print.BufferPrintable from choking on null;
wenzelm
parents:
44238
diff
changeset
|
112 |
if (Symbol.font_names.length > max_user_fonts) |
| 60238 | 113 |
error("Too many user symbol fonts (" + max_user_fonts + " permitted): " +
|
|
44355
9c38bdc6d755
default style for user fonts -- to prevent org.gjt.sp.jedit.print.BufferPrintable from choking on null;
wenzelm
parents:
44238
diff
changeset
|
114 |
Symbol.font_names.mkString(", "))
|
| 43487 | 115 |
|
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
116 |
override def extendStyles(styles: Array[SyntaxStyle]): Array[SyntaxStyle] = |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
117 |
{
|
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
118 |
val new_styles = new Array[SyntaxStyle](full_range) |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
119 |
for (i <- 0 until plain_range) {
|
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
120 |
val style = styles(i) |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
121 |
new_styles(i) = style |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
122 |
new_styles(subscript(i.toByte)) = script_style(style, -1) |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
123 |
new_styles(superscript(i.toByte)) = script_style(style, 1) |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
124 |
new_styles(bold(i.toByte)) = bold_style(style) |
|
44355
9c38bdc6d755
default style for user fonts -- to prevent org.gjt.sp.jedit.print.BufferPrintable from choking on null;
wenzelm
parents:
44238
diff
changeset
|
125 |
for (idx <- 0 until max_user_fonts) |
|
9c38bdc6d755
default style for user fonts -- to prevent org.gjt.sp.jedit.print.BufferPrintable from choking on null;
wenzelm
parents:
44238
diff
changeset
|
126 |
new_styles(user_font(idx, i.toByte)) = style |
|
43695
5130dfe1b7be
simplified Symbol based on lazy Symbol.Interpretation -- reduced odd "functorial style";
wenzelm
parents:
43675
diff
changeset
|
127 |
for ((family, idx) <- Symbol.font_index) |
|
59286
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
wenzelm
parents:
59230
diff
changeset
|
128 |
new_styles(user_font(idx, i.toByte)) = font_style(style, GUI.imitate_font(_, family)) |
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
129 |
} |
|
43502
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
130 |
new_styles(hidden) = |
|
44356
f6a2e5ce2ce5
avoid actual Color.white, which would be turned into Color.black by org.gjt.sp.jedit.print.BufferPrintable;
wenzelm
parents:
44355
diff
changeset
|
131 |
new SyntaxStyle(hidden_color, null, |
|
43502
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
132 |
{ val font = styles(0).getFont
|
| 53785 | 133 |
GUI.transform_font(new Font(font.getFamily, 0, 1), |
|
43502
736183a22fa4
more precise font transformations: shift sub/superscript, adjust size for user fonts;
wenzelm
parents:
43491
diff
changeset
|
134 |
AffineTransform.getScaleInstance(1.0, font.getSize.toDouble)) }) |
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
135 |
new_styles |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
136 |
} |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
137 |
} |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
138 |
|
|
43661
39fdbd814c7f
quasi-static Isabelle_System -- reduced tendency towards "functorial style";
wenzelm
parents:
43553
diff
changeset
|
139 |
def extended_styles(text: CharSequence): Map[Text.Offset, Byte => Byte] = |
|
43443
5d9693c2337e
basic support for extended syntax styles: sub/superscript;
wenzelm
parents:
43440
diff
changeset
|
140 |
{
|
|
44238
36120feb70ed
some convenience actions/shortcuts for control symbols;
wenzelm
parents:
43695
diff
changeset
|
141 |
// FIXME Symbol.bsub_decoded etc. |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
142 |
def control_style(sym: String): Option[Byte => Byte] = |
|
53021
d0fa3f446b9d
discontinued special treatment of \<^isub> and \<^isup> in rendering or editor front-end;
wenzelm
parents:
50663
diff
changeset
|
143 |
if (sym == Symbol.sub_decoded) Some(subscript(_)) |
|
d0fa3f446b9d
discontinued special treatment of \<^isub> and \<^isup> in rendering or editor front-end;
wenzelm
parents:
50663
diff
changeset
|
144 |
else if (sym == Symbol.sup_decoded) Some(superscript(_)) |
|
44238
36120feb70ed
some convenience actions/shortcuts for control symbols;
wenzelm
parents:
43695
diff
changeset
|
145 |
else if (sym == Symbol.bold_decoded) Some(bold(_)) |
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
146 |
else None |
| 43455 | 147 |
|
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
148 |
var result = Map[Text.Offset, Byte => Byte]() |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
149 |
def mark(start: Text.Offset, stop: Text.Offset, style: Byte => Byte) |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
150 |
{
|
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
151 |
for (i <- start until stop) result += (i -> style) |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
152 |
} |
|
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
153 |
var offset = 0 |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
154 |
var control = "" |
|
43675
8252d51d70e2
simplified Symbol.iterator: produce strings, which are mostly preallocated;
wenzelm
parents:
43661
diff
changeset
|
155 |
for (sym <- Symbol.iterator(text)) {
|
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
156 |
if (control_style(sym).isDefined) control = sym |
|
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
157 |
else if (control != "") {
|
|
43695
5130dfe1b7be
simplified Symbol based on lazy Symbol.Interpretation -- reduced odd "functorial style";
wenzelm
parents:
43675
diff
changeset
|
158 |
if (Symbol.is_controllable(sym) && sym != "\"" && !Symbol.fonts.isDefinedAt(sym)) {
|
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
159 |
mark(offset - control.length, offset, _ => hidden) |
|
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
160 |
mark(offset, offset + sym.length, control_style(control).get) |
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
161 |
} |
|
50187
b5a09812abc4
special handling of control symbols in Symbols dockable;
wenzelm
parents:
50183
diff
changeset
|
162 |
control = "" |
|
43443
5d9693c2337e
basic support for extended syntax styles: sub/superscript;
wenzelm
parents:
43440
diff
changeset
|
163 |
} |
|
43695
5130dfe1b7be
simplified Symbol based on lazy Symbol.Interpretation -- reduced odd "functorial style";
wenzelm
parents:
43675
diff
changeset
|
164 |
Symbol.lookup_font(sym) match {
|
| 43488 | 165 |
case Some(idx) => mark(offset, offset + sym.length, user_font(idx, _)) |
| 43487 | 166 |
case _ => |
167 |
} |
|
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
168 |
offset += sym.length |
|
43443
5d9693c2337e
basic support for extended syntax styles: sub/superscript;
wenzelm
parents:
43440
diff
changeset
|
169 |
} |
|
43482
ebb90ff55b79
added SyntaxUtilities.StyleExtender hook, with actual functionality in Isabelle/Scala;
wenzelm
parents:
43464
diff
changeset
|
170 |
result |
|
43443
5d9693c2337e
basic support for extended syntax styles: sub/superscript;
wenzelm
parents:
43440
diff
changeset
|
171 |
} |
|
5d9693c2337e
basic support for extended syntax styles: sub/superscript;
wenzelm
parents:
43440
diff
changeset
|
172 |
|
| 43414 | 173 |
|
| 58529 | 174 |
/* line context */ |
| 43414 | 175 |
|
| 58699 | 176 |
private val context_rules = new ParserRuleSet("isabelle", "MAIN")
|
177 |
||
| 58748 | 178 |
object Line_Context |
179 |
{
|
|
180 |
val init = new Line_Context(Some(Scan.Finished), Outer_Syntax.Line_Structure.init) |
|
181 |
} |
|
182 |
||
| 58699 | 183 |
class Line_Context( |
184 |
val context: Option[Scan.Line_Context], |
|
185 |
val structure: Outer_Syntax.Line_Structure) |
|
186 |
extends TokenMarker.LineContext(context_rules, null) |
|
| 43414 | 187 |
{
|
| 58699 | 188 |
override def hashCode: Int = (context, structure).hashCode |
| 43414 | 189 |
override def equals(that: Any): Boolean = |
190 |
that match {
|
|
| 58699 | 191 |
case other: Line_Context => context == other.context && structure == other.structure |
| 43414 | 192 |
case _ => false |
193 |
} |
|
194 |
} |
|
195 |
||
| 58748 | 196 |
def buffer_line_context(buffer: JEditBuffer, line: Int): Line_Context = |
| 59079 | 197 |
{
|
| 61192 | 198 |
val line_mgr = JEdit_Lib.buffer_line_manager(buffer) |
| 59079 | 199 |
def context = |
200 |
line_mgr.getLineContext(line) match {
|
|
201 |
case c: Line_Context => Some(c) |
|
202 |
case _ => None |
|
203 |
} |
|
204 |
context getOrElse {
|
|
205 |
buffer.markTokens(line, DummyTokenHandler.INSTANCE) |
|
206 |
context getOrElse Line_Context.init |
|
| 58683 | 207 |
} |
| 59079 | 208 |
} |
| 58683 | 209 |
|
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
210 |
|
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
211 |
/* tokens from line (inclusive) */ |
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
212 |
|
| 58802 | 213 |
private def try_line_tokens(syntax: Outer_Syntax, buffer: JEditBuffer, line: Int) |
214 |
: Option[List[Token]] = |
|
| 58748 | 215 |
{
|
216 |
val line_context = |
|
217 |
if (line == 0) Line_Context.init |
|
218 |
else buffer_line_context(buffer, line - 1) |
|
219 |
for {
|
|
220 |
ctxt <- line_context.context |
|
221 |
text <- JEdit_Lib.try_get_text(buffer, JEdit_Lib.line_range(buffer, line)) |
|
| 59083 | 222 |
} yield Token.explode_line(syntax.keywords, text, ctxt)._1 |
| 58748 | 223 |
} |
| 58699 | 224 |
|
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
225 |
def line_token_iterator( |
| 58750 | 226 |
syntax: Outer_Syntax, |
227 |
buffer: JEditBuffer, |
|
228 |
start_line: Int, |
|
229 |
end_line: Int): Iterator[Text.Info[Token]] = |
|
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
230 |
for {
|
| 58750 | 231 |
line <- Range(start_line max 0, end_line min buffer.getLineCount).iterator |
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
232 |
tokens <- try_line_tokens(syntax, buffer, line).iterator |
|
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
233 |
starts = |
|
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
234 |
tokens.iterator.scanLeft(buffer.getLineStartOffset(line))( |
|
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
235 |
(i, tok) => i + tok.source.length) |
| 58750 | 236 |
(i, tok) <- starts zip tokens.iterator |
237 |
} yield Text.Info(Text.Range(i, i + tok.source.length), tok) |
|
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
238 |
|
|
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
239 |
def line_token_reverse_iterator( |
| 58750 | 240 |
syntax: Outer_Syntax, |
241 |
buffer: JEditBuffer, |
|
242 |
start_line: Int, |
|
243 |
end_line: Int): Iterator[Text.Info[Token]] = |
|
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
244 |
for {
|
| 58750 | 245 |
line <- Range(start_line min (buffer.getLineCount - 1), end_line max -1, -1).iterator |
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
246 |
tokens <- try_line_tokens(syntax, buffer, line).iterator |
|
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
247 |
stops = |
|
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
248 |
tokens.reverseIterator.scanLeft(buffer.getLineEndOffset(line) min buffer.getLength)( |
|
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
249 |
(i, tok) => i - tok.source.length) |
| 58750 | 250 |
(i, tok) <- stops zip tokens.reverseIterator |
251 |
} yield Text.Info(Text.Range(i - tok.source.length, i), tok) |
|
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
252 |
|
| 58694 | 253 |
|
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
254 |
/* tokens from offset (inclusive) */ |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
255 |
|
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
256 |
def token_iterator(syntax: Outer_Syntax, buffer: JEditBuffer, offset: Text.Offset): |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
257 |
Iterator[Text.Info[Token]] = |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
258 |
if (JEdit_Lib.buffer_range(buffer).contains(offset)) |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
259 |
line_token_iterator(syntax, buffer, buffer.getLineOfOffset(offset), buffer.getLineCount). |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
260 |
dropWhile(info => !info.range.contains(offset)) |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
261 |
else Iterator.empty |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
262 |
|
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
263 |
def token_reverse_iterator(syntax: Outer_Syntax, buffer: JEditBuffer, offset: Text.Offset): |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
264 |
Iterator[Text.Info[Token]] = |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
265 |
if (JEdit_Lib.buffer_range(buffer).contains(offset)) |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
266 |
line_token_reverse_iterator(syntax, buffer, buffer.getLineOfOffset(offset), -1). |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
267 |
dropWhile(info => !info.range.contains(offset)) |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
268 |
else Iterator.empty |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
269 |
|
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
270 |
|
| 58809 | 271 |
/* command spans */ |
| 58802 | 272 |
|
273 |
def command_span(syntax: Outer_Syntax, buffer: JEditBuffer, offset: Text.Offset) |
|
274 |
: Option[Text.Info[Command_Span.Span]] = |
|
275 |
{
|
|
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
276 |
def maybe_command_start(i: Text.Offset): Option[Text.Info[Token]] = |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
277 |
token_reverse_iterator(syntax, buffer, i). |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59924
diff
changeset
|
278 |
find(info => info.info.is_command_modifier || info.info.is_command) |
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
279 |
|
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
280 |
def maybe_command_stop(i: Text.Offset): Option[Text.Info[Token]] = |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
281 |
token_iterator(syntax, buffer, i). |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59924
diff
changeset
|
282 |
find(info => info.info.is_command_modifier || info.info.is_command) |
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
283 |
|
| 58802 | 284 |
if (JEdit_Lib.buffer_range(buffer).contains(offset)) {
|
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
285 |
val start_info = |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
286 |
{
|
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
287 |
val info1 = maybe_command_start(offset) |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
288 |
info1 match {
|
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
289 |
case Some(Text.Info(range1, tok1)) if tok1.is_command => |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
290 |
val info2 = maybe_command_start(range1.start - 1) |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
291 |
info2 match {
|
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59924
diff
changeset
|
292 |
case Some(Text.Info(_, tok2)) if tok2.is_command_modifier => info2 |
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
293 |
case _ => info1 |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
294 |
} |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
295 |
case _ => info1 |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
296 |
} |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
297 |
} |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59924
diff
changeset
|
298 |
val (start_is_command_modifier, start, start_next) = |
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
299 |
start_info match {
|
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59924
diff
changeset
|
300 |
case Some(Text.Info(range, tok)) => (tok.is_command_modifier, range.start, range.stop) |
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
301 |
case None => (false, 0, 0) |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
302 |
} |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
303 |
|
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
304 |
val stop_info = |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
305 |
{
|
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
306 |
val info1 = maybe_command_stop(start_next) |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
307 |
info1 match {
|
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59924
diff
changeset
|
308 |
case Some(Text.Info(range1, tok1)) if tok1.is_command && start_is_command_modifier => |
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
309 |
maybe_command_stop(range1.stop) |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
310 |
case _ => info1 |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
311 |
} |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
312 |
} |
| 58802 | 313 |
val stop = |
|
59924
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
314 |
stop_info match {
|
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
315 |
case Some(Text.Info(range, _)) => range.start |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
316 |
case None => buffer.getLength |
|
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
wenzelm
parents:
59286
diff
changeset
|
317 |
} |
| 58802 | 318 |
|
319 |
val text = JEdit_Lib.try_get_text(buffer, Text.Range(start, stop)).getOrElse("")
|
|
320 |
val spans = syntax.parse_spans(text) |
|
321 |
||
322 |
(spans.iterator.scanLeft(start)(_ + _.length) zip spans.iterator). |
|
323 |
map({ case (i, span) => Text.Info(Text.Range(i, i + span.length), span) }).
|
|
324 |
find(_.range.contains(offset)) |
|
325 |
} |
|
326 |
else None |
|
327 |
} |
|
328 |
||
| 58809 | 329 |
private def _command_span_iterator( |
330 |
syntax: Outer_Syntax, |
|
331 |
buffer: JEditBuffer, |
|
332 |
offset: Text.Offset, |
|
333 |
next_offset: Text.Range => Text.Offset): Iterator[Text.Info[Command_Span.Span]] = |
|
334 |
new Iterator[Text.Info[Command_Span.Span]] |
|
335 |
{
|
|
336 |
private var next_span = command_span(syntax, buffer, offset) |
|
337 |
def hasNext: Boolean = next_span.isDefined |
|
338 |
def next: Text.Info[Command_Span.Span] = |
|
339 |
{
|
|
340 |
val span = next_span.getOrElse(Iterator.empty.next) |
|
341 |
next_span = command_span(syntax, buffer, next_offset(span.range)) |
|
342 |
span |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
def command_span_iterator(syntax: Outer_Syntax, buffer: JEditBuffer, offset: Text.Offset) |
|
347 |
: Iterator[Text.Info[Command_Span.Span]] = |
|
348 |
_command_span_iterator(syntax, buffer, offset max 0, range => range.stop) |
|
349 |
||
350 |
def command_span_reverse_iterator(syntax: Outer_Syntax, buffer: JEditBuffer, offset: Text.Offset) |
|
351 |
: Iterator[Text.Info[Command_Span.Span]] = |
|
352 |
_command_span_iterator(syntax, buffer, |
|
353 |
(offset min buffer.getLength) - 1, range => range.start - 1) |
|
354 |
||
| 58802 | 355 |
|
| 58694 | 356 |
/* token marker */ |
| 58683 | 357 |
|
|
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
358 |
class Marker( |
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
359 |
protected val mode: String, |
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
360 |
protected val opt_buffer: Option[Buffer]) extends TokenMarker |
|
43452
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
361 |
{
|
|
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
362 |
override def hashCode: Int = (mode, opt_buffer).hashCode |
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
363 |
override def equals(that: Any): Boolean = |
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
364 |
that match {
|
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
365 |
case other: Marker => mode == other.mode && opt_buffer == other.opt_buffer |
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
366 |
case _ => false |
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
367 |
} |
|
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59076
diff
changeset
|
368 |
|
|
59076
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
369 |
override def toString: String = |
|
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
370 |
opt_buffer match {
|
|
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
371 |
case None => "Marker(" + mode + ")"
|
|
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
372 |
case Some(buffer) => "Marker(" + mode + "," + JEdit_Lib.buffer_name(buffer) + ")"
|
|
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
373 |
} |
|
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
374 |
|
|
43452
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
375 |
override def markTokens(context: TokenMarker.LineContext, |
|
46210
553ec602d337
paranoia null check -- prevent spurious crash of jedit token markup;
wenzelm
parents:
46178
diff
changeset
|
376 |
handler: TokenHandler, raw_line: Segment): TokenMarker.LineContext = |
|
43452
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
377 |
{
|
|
46210
553ec602d337
paranoia null check -- prevent spurious crash of jedit token markup;
wenzelm
parents:
46178
diff
changeset
|
378 |
val line = if (raw_line == null) new Segment else raw_line |
| 58748 | 379 |
val line_context = context match { case c: Line_Context => c case _ => Line_Context.init }
|
380 |
val structure = line_context.structure |
|
|
46210
553ec602d337
paranoia null check -- prevent spurious crash of jedit token markup;
wenzelm
parents:
46178
diff
changeset
|
381 |
|
| 43553 | 382 |
val context1 = |
|
44702
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
383 |
{
|
|
59076
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
384 |
val opt_syntax = |
|
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
385 |
opt_buffer match {
|
|
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
386 |
case Some(buffer) => Isabelle.buffer_syntax(buffer) |
|
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
387 |
case None => Isabelle.mode_syntax(mode) |
|
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
388 |
} |
|
44702
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
389 |
val (styled_tokens, context1) = |
|
59076
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
390 |
(line_context.context, opt_syntax) match {
|
| 58694 | 391 |
case (Some(ctxt), _) if mode == "isabelle-ml" || mode == "sml" => |
392 |
val (tokens, ctxt1) = ML_Lex.tokenize_line(mode == "sml", line, ctxt) |
|
| 58529 | 393 |
val styled_tokens = tokens.map(tok => (Rendering.ml_token_markup(tok), tok.source)) |
| 58697 | 394 |
(styled_tokens, new Line_Context(Some(ctxt1), structure)) |
| 58694 | 395 |
|
396 |
case (Some(ctxt), Some(syntax)) if syntax.has_tokens => |
|
| 59083 | 397 |
val (tokens, ctxt1) = Token.explode_line(syntax.keywords, line, ctxt) |
| 58748 | 398 |
val structure1 = syntax.line_structure(tokens, structure) |
| 58694 | 399 |
val styled_tokens = |
400 |
tokens.map(tok => (Rendering.token_markup(syntax, tok), tok.source)) |
|
| 58697 | 401 |
(styled_tokens, new Line_Context(Some(ctxt1), structure1)) |
| 58694 | 402 |
|
403 |
case _ => |
|
404 |
val styled_token = (JEditToken.NULL, line.subSequence(0, line.count).toString) |
|
| 58697 | 405 |
(List(styled_token), new Line_Context(None, structure)) |
|
44702
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
406 |
} |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
407 |
|
|
53278
c31532691e55
always use extended styles (despite de26cf3191a3);
wenzelm
parents:
53277
diff
changeset
|
408 |
val extended = extended_styles(line) |
|
44702
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
409 |
|
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
410 |
var offset = 0 |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
411 |
for ((style, token) <- styled_tokens) {
|
| 55500 | 412 |
val length = token.length |
|
44702
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
413 |
val end_offset = offset + length |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
414 |
if ((offset until end_offset) exists |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
415 |
(i => extended.isDefinedAt(i) || line.charAt(i) == '\t')) {
|
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
416 |
for (i <- offset until end_offset) {
|
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
417 |
val style1 = |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
418 |
extended.get(i) match {
|
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
419 |
case None => style |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
420 |
case Some(ext) => ext(style) |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
421 |
} |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
422 |
handler.handleToken(line, style1, i, 1, context1) |
| 43553 | 423 |
} |
424 |
} |
|
|
44702
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
425 |
else handler.handleToken(line, style, offset, length, context1) |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
426 |
offset += length |
|
43452
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
427 |
} |
|
44702
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
428 |
handler.handleToken(line, JEditToken.END, line.count, 0, context1) |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
429 |
context1 |
|
eb00752507c7
improved handling of extended styles and hard tabs when prover is inactive;
wenzelm
parents:
44701
diff
changeset
|
430 |
} |
| 58694 | 431 |
|
|
43452
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
432 |
val context2 = context1.intern |
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
433 |
handler.setLineContext(context2) |
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
434 |
context2 |
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
435 |
} |
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
436 |
} |
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
437 |
|
|
43416
e730cdd97dcf
more precise imitatation of original TokenMarker: no locking, interned context etc.;
wenzelm
parents:
43414
diff
changeset
|
438 |
|
|
43452
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
439 |
/* mode provider */ |
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
440 |
|
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
441 |
class Mode_Provider(orig_provider: ModeProvider) extends ModeProvider |
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
442 |
{
|
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
443 |
for (mode <- orig_provider.getModes) addMode(mode) |
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
444 |
|
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
445 |
override def loadMode(mode: Mode, xmh: XModeHandler) |
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
446 |
{
|
|
5cf548485529
avoid setTokenMarker fluctuation on buffer reload etc. via static isabelle_token_marker, which is installed by hijacking the jEdit ModeProvider;
wenzelm
parents:
43443
diff
changeset
|
447 |
super.loadMode(mode, xmh) |
|
59076
65babcd8b0e6
clarified token marker / syntax for mode vs. buffer;
wenzelm
parents:
59063
diff
changeset
|
448 |
Isabelle.mode_token_marker(mode.getName).foreach(mode.setTokenMarker _) |
|
53277
6aa348237973
more uniform configuration of editor modes and token markers;
wenzelm
parents:
53274
diff
changeset
|
449 |
} |
|
44358
2a2df4de1bbe
more robust initialization of token marker and line context wrt. session startup;
wenzelm
parents:
44356
diff
changeset
|
450 |
} |
| 43414 | 451 |
} |