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