src/Tools/jEdit/src/rendering.scala
author wenzelm
Sat Mar 01 16:34:30 2014 +0100 (2014-03-01 ago)
changeset 55823 0331b6d2ab0c
parent 55820 61869776ce1f
child 55824 22bc50a19afa
permissions -rw-r--r--
font size change with delay, to avoid GUI lagging behind user input;
wenzelm@50202
     1
/*  Title:      Tools/jEdit/src/rendering.scala
wenzelm@39178
     2
    Author:     Makarius
wenzelm@39178
     3
wenzelm@50199
     4
Isabelle-specific implementation of quasi-abstract rendering and
wenzelm@50199
     5
markup interpretation.
wenzelm@39178
     6
*/
wenzelm@39178
     7
wenzelm@39178
     8
package isabelle.jedit
wenzelm@39178
     9
wenzelm@39178
    10
wenzelm@39178
    11
import isabelle._
wenzelm@39178
    12
wenzelm@39178
    13
import java.awt.Color
wenzelm@46227
    14
import javax.swing.Icon
wenzelm@39178
    15
wenzelm@43414
    16
import org.gjt.sp.jedit.syntax.{Token => JEditToken}
wenzelm@53272
    17
import org.gjt.sp.jedit.{jEdit, View}
wenzelm@39178
    18
wenzelm@45460
    19
import scala.collection.immutable.SortedMap
wenzelm@45460
    20
wenzelm@39178
    21
wenzelm@50199
    22
object Rendering
wenzelm@39178
    23
{
wenzelm@50199
    24
  def apply(snapshot: Document.Snapshot, options: Options): Rendering =
wenzelm@50199
    25
    new Rendering(snapshot, options)
wenzelm@39178
    26
wenzelm@49356
    27
wenzelm@49406
    28
  /* message priorities */
wenzelm@43388
    29
wenzelm@46227
    30
  private val writeln_pri = 1
wenzelm@52644
    31
  private val information_pri = 2
wenzelm@52644
    32
  private val tracing_pri = 3
wenzelm@52644
    33
  private val warning_pri = 4
wenzelm@52644
    34
  private val legacy_pri = 5
wenzelm@52644
    35
  private val error_pri = 6
wenzelm@49474
    36
wenzelm@49474
    37
  private val message_pri = Map(
wenzelm@50201
    38
    Markup.WRITELN -> writeln_pri, Markup.WRITELN_MESSAGE -> writeln_pri,
wenzelm@50201
    39
    Markup.TRACING -> tracing_pri, Markup.TRACING_MESSAGE -> tracing_pri,
wenzelm@50201
    40
    Markup.WARNING -> warning_pri, Markup.WARNING_MESSAGE -> warning_pri,
wenzelm@50201
    41
    Markup.ERROR -> error_pri, Markup.ERROR_MESSAGE -> error_pri)
wenzelm@39178
    42
wenzelm@49406
    43
wenzelm@50206
    44
  /* jEdit font */
wenzelm@50206
    45
wenzelm@50206
    46
  def font_family(): String = jEdit.getProperty("view.font")
wenzelm@50206
    47
wenzelm@53272
    48
  private def view_font_size(): Int = jEdit.getIntegerProperty("view.fontsize", 16)
wenzelm@53272
    49
  private val font_size0 = 5
wenzelm@53272
    50
  private val font_size1 = 250
wenzelm@53272
    51
wenzelm@50206
    52
  def font_size(scale: String): Float =
wenzelm@53272
    53
    (view_font_size() * PIDE.options.real(scale)).toFloat max font_size0 min font_size1
wenzelm@53272
    54
wenzelm@53272
    55
  def font_size_change(view: View, change: Int => Int)
wenzelm@53272
    56
  {
wenzelm@55823
    57
    val size0 = view_font_size()
wenzelm@55823
    58
    val size = change(size0) max font_size0 min font_size1
wenzelm@55823
    59
    if (size != size0) {
wenzelm@55823
    60
      jEdit.setIntegerProperty("view.fontsize", size)
wenzelm@55823
    61
      jEdit.propertiesChanged()
wenzelm@55823
    62
      jEdit.saveSettings()
wenzelm@55823
    63
      view.getStatus.setMessageAndClear("Text font size: " + size)
wenzelm@55823
    64
    }
wenzelm@53272
    65
  }
wenzelm@50206
    66
wenzelm@50206
    67
wenzelm@53230
    68
  /* popup window bounds */
wenzelm@53230
    69
wenzelm@53230
    70
  def popup_bounds: Double = (PIDE.options.real("jedit_popup_bounds") max 0.2) min 0.8
wenzelm@53230
    71
wenzelm@53230
    72
wenzelm@55501
    73
  /* Isabelle/Isar token markup */
wenzelm@39179
    74
wenzelm@39179
    75
  private val command_style: Map[String, Byte] =
wenzelm@39179
    76
  {
wenzelm@43414
    77
    import JEditToken._
wenzelm@39179
    78
    Map[String, Byte](
wenzelm@39179
    79
      Keyword.THY_END -> KEYWORD2,
wenzelm@39179
    80
      Keyword.THY_SCRIPT -> LABEL,
wenzelm@53571
    81
      Keyword.QED_SCRIPT -> DIGIT,
wenzelm@50643
    82
      Keyword.PRF_SCRIPT -> DIGIT,
wenzelm@39179
    83
      Keyword.PRF_ASM -> KEYWORD3,
wenzelm@53371
    84
      Keyword.PRF_ASM_GOAL -> KEYWORD3,
wenzelm@53371
    85
      Keyword.PRF_ASM_GOAL_SCRIPT -> DIGIT
wenzelm@39179
    86
    ).withDefaultValue(KEYWORD1)
wenzelm@39179
    87
  }
wenzelm@39179
    88
wenzelm@43414
    89
  private val token_style: Map[Token.Kind.Value, Byte] =
wenzelm@39179
    90
  {
wenzelm@43414
    91
    import JEditToken._
wenzelm@43414
    92
    Map[Token.Kind.Value, Byte](
wenzelm@43414
    93
      Token.Kind.KEYWORD -> KEYWORD2,
wenzelm@43414
    94
      Token.Kind.IDENT -> NULL,
wenzelm@43414
    95
      Token.Kind.LONG_IDENT -> NULL,
wenzelm@43414
    96
      Token.Kind.SYM_IDENT -> NULL,
wenzelm@43414
    97
      Token.Kind.VAR -> NULL,
wenzelm@43414
    98
      Token.Kind.TYPE_IDENT -> NULL,
wenzelm@43414
    99
      Token.Kind.TYPE_VAR -> NULL,
wenzelm@43414
   100
      Token.Kind.NAT -> NULL,
wenzelm@43414
   101
      Token.Kind.FLOAT -> NULL,
wenzelm@43431
   102
      Token.Kind.STRING -> LITERAL1,
wenzelm@43431
   103
      Token.Kind.ALT_STRING -> LITERAL2,
wenzelm@43414
   104
      Token.Kind.VERBATIM -> COMMENT3,
wenzelm@55033
   105
      Token.Kind.CARTOUCHE -> COMMENT4,
wenzelm@43414
   106
      Token.Kind.SPACE -> NULL,
wenzelm@43414
   107
      Token.Kind.COMMENT -> COMMENT1,
wenzelm@48754
   108
      Token.Kind.ERROR -> INVALID
wenzelm@39179
   109
    ).withDefaultValue(NULL)
wenzelm@39179
   110
  }
wenzelm@39179
   111
wenzelm@43414
   112
  def token_markup(syntax: Outer_Syntax, token: Token): Byte =
wenzelm@43430
   113
    if (token.is_command) command_style(syntax.keyword_kind(token.content).getOrElse(""))
wenzelm@55505
   114
    else if (token.is_delimiter) JEditToken.OPERATOR
wenzelm@43414
   115
    else token_style(token.kind)
wenzelm@55500
   116
wenzelm@55501
   117
wenzelm@55501
   118
  /* Isabelle/ML token markup */
wenzelm@55501
   119
wenzelm@55500
   120
  private val ml_token_style: Map[ML_Lex.Kind.Value, Byte] =
wenzelm@55500
   121
  {
wenzelm@55500
   122
    import JEditToken._
wenzelm@55500
   123
    Map[ML_Lex.Kind.Value, Byte](
wenzelm@55505
   124
      ML_Lex.Kind.KEYWORD -> NULL,
wenzelm@55500
   125
      ML_Lex.Kind.IDENT -> NULL,
wenzelm@55500
   126
      ML_Lex.Kind.LONG_IDENT -> NULL,
wenzelm@55500
   127
      ML_Lex.Kind.TYPE_VAR -> NULL,
wenzelm@55503
   128
      ML_Lex.Kind.WORD -> DIGIT,
wenzelm@55503
   129
      ML_Lex.Kind.INT -> DIGIT,
wenzelm@55503
   130
      ML_Lex.Kind.REAL -> DIGIT,
wenzelm@55500
   131
      ML_Lex.Kind.CHAR -> LITERAL2,
wenzelm@55500
   132
      ML_Lex.Kind.STRING -> LITERAL1,
wenzelm@55500
   133
      ML_Lex.Kind.SPACE -> NULL,
wenzelm@55500
   134
      ML_Lex.Kind.COMMENT -> COMMENT1,
wenzelm@55512
   135
      ML_Lex.Kind.ANTIQ -> NULL,
wenzelm@55512
   136
      ML_Lex.Kind.ANTIQ_START -> LITERAL4,
wenzelm@55512
   137
      ML_Lex.Kind.ANTIQ_STOP -> LITERAL4,
wenzelm@55512
   138
      ML_Lex.Kind.ANTIQ_OTHER -> NULL,
wenzelm@55514
   139
      ML_Lex.Kind.ANTIQ_STRING -> NULL,
wenzelm@55514
   140
      ML_Lex.Kind.ANTIQ_ALT_STRING -> NULL,
wenzelm@55514
   141
      ML_Lex.Kind.ANTIQ_CARTOUCHE -> NULL,
wenzelm@55500
   142
      ML_Lex.Kind.ERROR -> INVALID
wenzelm@55500
   143
    ).withDefaultValue(NULL)
wenzelm@55500
   144
  }
wenzelm@55500
   145
wenzelm@55500
   146
  def ml_token_markup(token: ML_Lex.Token): Byte =
wenzelm@55501
   147
    if (!token.is_keyword) ml_token_style(token.kind)
wenzelm@55505
   148
    else if (token.is_delimiter) JEditToken.OPERATOR
wenzelm@55505
   149
    else if (ML_Lex.keywords2(token.source)) JEditToken.KEYWORD2
wenzelm@55505
   150
    else if (ML_Lex.keywords3(token.source)) JEditToken.KEYWORD3
wenzelm@55501
   151
    else JEditToken.KEYWORD1
wenzelm@55647
   152
wenzelm@55647
   153
wenzelm@55647
   154
  /* markup elements */
wenzelm@55647
   155
wenzelm@55820
   156
  private val completion_names_elements =
wenzelm@55820
   157
    Document.Elements(Markup.COMPLETION)
wenzelm@55674
   158
wenzelm@55749
   159
  private val language_context_elements =
wenzelm@55820
   160
    Document.Elements(Markup.STRING, Markup.ALTSTRING, Markup.VERBATIM,
wenzelm@55647
   161
      Markup.CARTOUCHE, Markup.COMMENT, Markup.LANGUAGE,
wenzelm@55647
   162
      Markup.ML_STRING, Markup.ML_COMMENT)
wenzelm@55647
   163
wenzelm@55647
   164
  private val highlight_elements =
wenzelm@55820
   165
    Document.Elements(Markup.LANGUAGE, Markup.ML_TYPING, Markup.TOKEN_RANGE,
wenzelm@55647
   166
      Markup.ENTITY, Markup.PATH, Markup.URL, Markup.SORTING,
wenzelm@55647
   167
      Markup.TYPING, Markup.FREE, Markup.SKOLEM, Markup.BOUND,
wenzelm@55647
   168
      Markup.VAR, Markup.TFREE, Markup.TVAR)
wenzelm@55647
   169
wenzelm@55647
   170
  private val hyperlink_elements =
wenzelm@55820
   171
    Document.Elements(Markup.ENTITY, Markup.PATH, Markup.POSITION, Markup.URL)
wenzelm@55647
   172
wenzelm@55647
   173
  private val active_elements =
wenzelm@55820
   174
    Document.Elements(Markup.DIALOG, Markup.BROWSER, Markup.GRAPHVIEW,
wenzelm@55647
   175
      Markup.SENDBACK, Markup.SIMP_TRACE)
wenzelm@55647
   176
wenzelm@55647
   177
  private val tooltip_message_elements =
wenzelm@55820
   178
    Document.Elements(Markup.WRITELN, Markup.WARNING, Markup.ERROR, Markup.BAD)
wenzelm@55647
   179
wenzelm@55647
   180
  private val tooltip_descriptions =
wenzelm@55647
   181
    Map(
wenzelm@55647
   182
      Markup.TOKEN_RANGE -> "inner syntax token",
wenzelm@55647
   183
      Markup.FREE -> "free variable",
wenzelm@55647
   184
      Markup.SKOLEM -> "skolem variable",
wenzelm@55647
   185
      Markup.BOUND -> "bound variable",
wenzelm@55647
   186
      Markup.VAR -> "schematic variable",
wenzelm@55647
   187
      Markup.TFREE -> "free type variable",
wenzelm@55647
   188
      Markup.TVAR -> "schematic type variable")
wenzelm@55647
   189
wenzelm@55647
   190
  private val tooltip_elements =
wenzelm@55820
   191
    Document.Elements(Markup.LANGUAGE, Markup.TIMING, Markup.ENTITY, Markup.SORTING,
wenzelm@55647
   192
      Markup.TYPING, Markup.ML_TYPING, Markup.PATH, Markup.URL) ++
wenzelm@55820
   193
    Document.Elements(tooltip_descriptions.keySet)
wenzelm@55647
   194
wenzelm@55647
   195
  private val gutter_elements =
wenzelm@55820
   196
    Document.Elements(Markup.WRITELN, Markup.WARNING, Markup.ERROR)
wenzelm@55647
   197
wenzelm@55647
   198
  private val squiggly_elements =
wenzelm@55820
   199
    Document.Elements(Markup.WRITELN, Markup.WARNING, Markup.ERROR)
wenzelm@55647
   200
wenzelm@55647
   201
  private val line_background_elements =
wenzelm@55820
   202
    Document.Elements(Markup.WRITELN_MESSAGE, Markup.TRACING_MESSAGE,
wenzelm@55647
   203
      Markup.WARNING_MESSAGE, Markup.ERROR_MESSAGE,
wenzelm@55647
   204
      Markup.INFORMATION)
wenzelm@55647
   205
wenzelm@55820
   206
  private val separator_elements =
wenzelm@55820
   207
    Document.Elements(Markup.SEPARATOR)
wenzelm@55647
   208
wenzelm@55790
   209
  private val background_elements =
wenzelm@55647
   210
    Protocol.command_status_elements + Markup.WRITELN_MESSAGE +
wenzelm@55647
   211
      Markup.TRACING_MESSAGE + Markup.WARNING_MESSAGE +
wenzelm@55647
   212
      Markup.ERROR_MESSAGE + Markup.BAD + Markup.INTENSIFY ++
wenzelm@55647
   213
      active_elements
wenzelm@55647
   214
wenzelm@55647
   215
  private val foreground_elements =
wenzelm@55820
   216
    Document.Elements(Markup.STRING, Markup.ALTSTRING, Markup.VERBATIM,
wenzelm@55647
   217
      Markup.CARTOUCHE, Markup.ANTIQUOTED)
wenzelm@55647
   218
wenzelm@55820
   219
  private val bullet_elements =
wenzelm@55820
   220
    Document.Elements(Markup.BULLET)
wenzelm@55647
   221
wenzelm@55647
   222
  private val fold_depth_elements =
wenzelm@55820
   223
    Document.Elements(Markup.TEXT_FOLD, Markup.GOAL, Markup.SUBGOAL)
wenzelm@39178
   224
}
wenzelm@49356
   225
wenzelm@49356
   226
wenzelm@50199
   227
class Rendering private(val snapshot: Document.Snapshot, val options: Options)
wenzelm@49356
   228
{
wenzelm@55710
   229
  override def toString: String = "Rendering(" + snapshot.toString + ")"
wenzelm@55710
   230
wenzelm@55710
   231
wenzelm@49356
   232
  /* colors */
wenzelm@49356
   233
wenzelm@49356
   234
  def color_value(s: String): Color = Color_Value(options.string(s))
wenzelm@49356
   235
wenzelm@49356
   236
  val outdated_color = color_value("outdated_color")
wenzelm@49356
   237
  val unprocessed_color = color_value("unprocessed_color")
wenzelm@49356
   238
  val unprocessed1_color = color_value("unprocessed1_color")
wenzelm@49356
   239
  val running_color = color_value("running_color")
wenzelm@49356
   240
  val running1_color = color_value("running1_color")
wenzelm@51574
   241
  val bullet_color = color_value("bullet_color")
wenzelm@49706
   242
  val tooltip_color = color_value("tooltip_color")
wenzelm@49356
   243
  val writeln_color = color_value("writeln_color")
wenzelm@52650
   244
  val information_color = color_value("information_color")
wenzelm@49356
   245
  val warning_color = color_value("warning_color")
wenzelm@49356
   246
  val error_color = color_value("error_color")
wenzelm@49356
   247
  val error1_color = color_value("error1_color")
wenzelm@49418
   248
  val writeln_message_color = color_value("writeln_message_color")
wenzelm@52650
   249
  val information_message_color = color_value("information_message_color")
wenzelm@49418
   250
  val tracing_message_color = color_value("tracing_message_color")
wenzelm@49418
   251
  val warning_message_color = color_value("warning_message_color")
wenzelm@49418
   252
  val error_message_color = color_value("error_message_color")
wenzelm@49356
   253
  val bad_color = color_value("bad_color")
wenzelm@49358
   254
  val intensify_color = color_value("intensify_color")
wenzelm@49356
   255
  val quoted_color = color_value("quoted_color")
wenzelm@52101
   256
  val antiquoted_color = color_value("antiquoted_color")
wenzelm@55526
   257
  val antiquote_color = color_value("antiquote_color")
wenzelm@49358
   258
  val highlight_color = color_value("highlight_color")
wenzelm@49356
   259
  val hyperlink_color = color_value("hyperlink_color")
wenzelm@50450
   260
  val active_color = color_value("active_color")
wenzelm@50450
   261
  val active_hover_color = color_value("active_hover_color")
wenzelm@50498
   262
  val active_result_color = color_value("active_result_color")
wenzelm@49356
   263
  val keyword1_color = color_value("keyword1_color")
wenzelm@49356
   264
  val keyword2_color = color_value("keyword2_color")
wenzelm@55505
   265
  val keyword3_color = color_value("keyword3_color")
wenzelm@55713
   266
  val caret_invisible_color = color_value("caret_invisible_color")
wenzelm@55747
   267
  val completion_color = color_value("completion_color")
wenzelm@49356
   268
wenzelm@49356
   269
  val tfree_color = color_value("tfree_color")
wenzelm@49356
   270
  val tvar_color = color_value("tvar_color")
wenzelm@49356
   271
  val free_color = color_value("free_color")
wenzelm@49356
   272
  val skolem_color = color_value("skolem_color")
wenzelm@49356
   273
  val bound_color = color_value("bound_color")
wenzelm@49356
   274
  val var_color = color_value("var_color")
wenzelm@49356
   275
  val inner_numeral_color = color_value("inner_numeral_color")
wenzelm@49356
   276
  val inner_quoted_color = color_value("inner_quoted_color")
wenzelm@55033
   277
  val inner_cartouche_color = color_value("inner_cartouche_color")
wenzelm@49356
   278
  val inner_comment_color = color_value("inner_comment_color")
wenzelm@49356
   279
  val dynamic_color = color_value("dynamic_color")
wenzelm@49356
   280
wenzelm@49356
   281
wenzelm@55674
   282
  /* completion */
wenzelm@55674
   283
wenzelm@55690
   284
  def completion_names(range: Text.Range): Option[Completion.Names] =
wenzelm@55690
   285
    if (snapshot.is_outdated) None
wenzelm@55690
   286
    else {
wenzelm@55690
   287
      snapshot.select(range, Rendering.completion_names_elements, _ =>
wenzelm@55688
   288
        {
wenzelm@55688
   289
          case Completion.Names.Info(names) => Some(names)
wenzelm@55688
   290
          case _ => None
wenzelm@55688
   291
        }).headOption.map(_.info)
wenzelm@55674
   292
    }
wenzelm@55615
   293
wenzelm@55749
   294
  def language_context(range: Text.Range): Option[Completion.Language_Context] =
wenzelm@55749
   295
    snapshot.select(range, Rendering.language_context_elements, _ =>
wenzelm@55690
   296
      {
wenzelm@55746
   297
        case Text.Info(_, XML.Elem(Markup.Language(language, symbols, antiquotes), _)) =>
wenzelm@55749
   298
          Some(Completion.Language_Context(language, symbols, antiquotes))
wenzelm@55690
   299
        case Text.Info(_, elem)
wenzelm@55690
   300
        if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT =>
wenzelm@55749
   301
          Some(Completion.Language_Context.ML_inner)
wenzelm@55690
   302
        case Text.Info(_, _) =>
wenzelm@55749
   303
          Some(Completion.Language_Context.inner)
wenzelm@55690
   304
      }).headOption.map(_.info)
wenzelm@55615
   305
wenzelm@55615
   306
wenzelm@55626
   307
  /* command status overview */
wenzelm@49356
   308
wenzelm@55647
   309
  def overview_limit: Int = options.int("jedit_text_overview_limit")
wenzelm@49969
   310
wenzelm@49356
   311
  def overview_color(range: Text.Range): Option[Color] =
wenzelm@49356
   312
  {
wenzelm@49356
   313
    if (snapshot.is_outdated) None
wenzelm@49356
   314
    else {
wenzelm@49356
   315
      val results =
wenzelm@55651
   316
        snapshot.cumulate[(Protocol.Status, Int)](
wenzelm@55646
   317
          range, (Protocol.Status.init, 0), Protocol.status_elements, _ =>
wenzelm@49356
   318
          {
wenzelm@52890
   319
            case ((status, pri), Text.Info(_, elem)) =>
wenzelm@55646
   320
              if (Protocol.command_status_elements(elem.name))
wenzelm@55623
   321
                Some((Protocol.command_status(status, elem.markup), pri))
wenzelm@55623
   322
              else
wenzelm@52890
   323
                Some((status, pri max Rendering.message_pri(elem.name)))
wenzelm@55651
   324
          }, status = true)
wenzelm@49356
   325
      if (results.isEmpty) None
wenzelm@49356
   326
      else {
wenzelm@49356
   327
        val (status, pri) =
wenzelm@49356
   328
          ((Protocol.Status.init, 0) /: results) {
wenzelm@49356
   329
            case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) }
wenzelm@49356
   330
wenzelm@50895
   331
        if (status.is_running) Some(running_color)
wenzelm@50895
   332
        else if (pri == Rendering.warning_pri) Some(warning_color)
wenzelm@50199
   333
        else if (pri == Rendering.error_pri) Some(error_color)
wenzelm@49356
   334
        else if (status.is_unprocessed) Some(unprocessed_color)
wenzelm@49356
   335
        else if (status.is_failed) Some(error_color)
wenzelm@49356
   336
        else None
wenzelm@49356
   337
      }
wenzelm@49356
   338
    }
wenzelm@49356
   339
  }
wenzelm@49356
   340
wenzelm@49356
   341
wenzelm@55626
   342
  /* highlighted area */
wenzelm@49356
   343
wenzelm@49358
   344
  def highlight(range: Text.Range): Option[Text.Info[Color]] =
wenzelm@55651
   345
    snapshot.select(range, Rendering.highlight_elements, _ =>
wenzelm@55620
   346
      {
wenzelm@55620
   347
        case info => Some(Text.Info(snapshot.convert(info.range), highlight_color))
wenzelm@55689
   348
      }).headOption.map(_.info)
wenzelm@49356
   349
wenzelm@49356
   350
wenzelm@55626
   351
  /* hyperlinks */
wenzelm@55626
   352
wenzelm@55547
   353
  private def hyperlink_file(line: Int, name: String): Option[PIDE.editor.Hyperlink] =
wenzelm@55547
   354
    if (Path.is_ok(name))
wenzelm@55547
   355
      Isabelle_System.source_file(Path.explode(name)).map(path =>
wenzelm@55547
   356
        PIDE.editor.hyperlink_file(Isabelle_System.platform_path(path), line))
wenzelm@55547
   357
    else None
wenzelm@55547
   358
wenzelm@55547
   359
  private def hyperlink_command(id: Document_ID.Generic, offset: Text.Offset)
wenzelm@55547
   360
      : Option[PIDE.editor.Hyperlink] =
wenzelm@55547
   361
    snapshot.state.find_command(snapshot.version, id) match {
wenzelm@55547
   362
      case Some((node, command)) =>
wenzelm@55547
   363
        PIDE.editor.hyperlink_command(snapshot, command, offset)
wenzelm@55547
   364
      case None => None
wenzelm@55547
   365
    }
wenzelm@49356
   366
wenzelm@52980
   367
  def hyperlink(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] =
wenzelm@49356
   368
  {
wenzelm@55651
   369
    snapshot.cumulate[Vector[Text.Info[PIDE.editor.Hyperlink]]](
wenzelm@55647
   370
      range, Vector.empty, Rendering.hyperlink_elements, _ =>
wenzelm@49356
   371
        {
wenzelm@50201
   372
          case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _)))
wenzelm@49356
   373
          if Path.is_ok(name) =>
wenzelm@54515
   374
            val jedit_file = PIDE.thy_load.append(snapshot.node_name.master_dir, Path.explode(name))
wenzelm@52980
   375
            val link = PIDE.editor.hyperlink_file(jedit_file)
wenzelm@55622
   376
            Some(links :+ Text.Info(snapshot.convert(info_range), link))
wenzelm@49356
   377
wenzelm@54702
   378
          case (links, Text.Info(info_range, XML.Elem(Markup.Url(name), _))) =>
wenzelm@54702
   379
            val link = PIDE.editor.hyperlink_url(name)
wenzelm@55622
   380
            Some(links :+ Text.Info(snapshot.convert(info_range), link))
wenzelm@54702
   381
wenzelm@50201
   382
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _)))
wenzelm@49815
   383
          if !props.exists(
wenzelm@50201
   384
            { case (Markup.KIND, Markup.ML_OPEN) => true
wenzelm@50201
   385
              case (Markup.KIND, Markup.ML_STRUCT) => true
wenzelm@49815
   386
              case _ => false }) =>
wenzelm@49356
   387
wenzelm@55547
   388
            val opt_link =
wenzelm@55547
   389
              props match {
wenzelm@55547
   390
                case Position.Def_Line_File(line, name) => hyperlink_file(line, name)
wenzelm@55547
   391
                case Position.Def_Id_Offset(id, offset) => hyperlink_command(id, offset)
wenzelm@55547
   392
                case _ => None
wenzelm@55547
   393
              }
wenzelm@55622
   394
            opt_link.map(link => (links :+ Text.Info(snapshot.convert(info_range), link)))
wenzelm@49356
   395
wenzelm@55547
   396
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.POSITION, props), _))) =>
wenzelm@55547
   397
            val opt_link =
wenzelm@55547
   398
              props match {
wenzelm@55547
   399
                case Position.Line_File(line, name) => hyperlink_file(line, name)
wenzelm@55547
   400
                case Position.Id_Offset(id, offset) => hyperlink_command(id, offset)
wenzelm@55547
   401
                case _ => None
wenzelm@55547
   402
              }
wenzelm@55622
   403
            opt_link.map(link => links :+ (Text.Info(snapshot.convert(info_range), link)))
wenzelm@52889
   404
wenzelm@52889
   405
          case _ => None
wenzelm@55622
   406
        }) match { case Text.Info(_, _ :+ info) :: _ => Some(info) case _ => None }
wenzelm@49356
   407
  }
wenzelm@49356
   408
wenzelm@49356
   409
wenzelm@55626
   410
  /* active elements */
wenzelm@55626
   411
wenzelm@50450
   412
  def active(range: Text.Range): Option[Text.Info[XML.Elem]] =
wenzelm@55651
   413
    snapshot.select(range, Rendering.active_elements, command_state =>
wenzelm@55620
   414
      {
wenzelm@55620
   415
        case Text.Info(info_range, elem) =>
wenzelm@55623
   416
          if (elem.name == Markup.DIALOG) {
wenzelm@55623
   417
            elem match {
wenzelm@55623
   418
              case Protocol.Dialog(_, serial, _)
wenzelm@55623
   419
              if !command_state.results.defined(serial) =>
wenzelm@55623
   420
                Some(Text.Info(snapshot.convert(info_range), elem))
wenzelm@55623
   421
              case _ => None
wenzelm@55623
   422
            }
wenzelm@55623
   423
          }
wenzelm@55623
   424
          else Some(Text.Info(snapshot.convert(info_range), elem))
wenzelm@55689
   425
      }).headOption.map(_.info)
wenzelm@49492
   426
wenzelm@50502
   427
  def command_results(range: Text.Range): Command.Results =
wenzelm@50502
   428
  {
wenzelm@50502
   429
    val results =
wenzelm@55820
   430
      snapshot.select[Command.Results](range, Document.Elements.full, command_state =>
wenzelm@52889
   431
        { case _ => Some(command_state.results) }).map(_.info)
wenzelm@50507
   432
    (Command.Results.empty /: results)(_ ++ _)
wenzelm@50502
   433
  }
wenzelm@50502
   434
wenzelm@55626
   435
wenzelm@55626
   436
  /* tooltip messages */
wenzelm@55626
   437
wenzelm@51496
   438
  def tooltip_message(range: Text.Range): Option[Text.Info[XML.Body]] =
wenzelm@49356
   439
  {
wenzelm@51496
   440
    val results =
wenzelm@55651
   441
      snapshot.cumulate[List[Text.Info[Command.Results.Entry]]](
wenzelm@55647
   442
        range, Nil, Rendering.tooltip_message_elements, _ =>
wenzelm@51496
   443
        {
wenzelm@51496
   444
          case (msgs, Text.Info(info_range,
wenzelm@51496
   445
            XML.Elem(Markup(name, props @ Markup.Serial(serial)), body)))
wenzelm@51496
   446
          if name == Markup.WRITELN || name == Markup.WARNING || name == Markup.ERROR =>
wenzelm@51496
   447
            val entry: Command.Results.Entry =
wenzelm@51496
   448
              (serial -> XML.Elem(Markup(Markup.message(name), props), body))
wenzelm@52889
   449
            Some(Text.Info(snapshot.convert(info_range), entry) :: msgs)
wenzelm@51496
   450
wenzelm@51496
   451
          case (msgs, Text.Info(info_range, msg @ XML.Elem(Markup(Markup.BAD, _), body)))
wenzelm@51496
   452
          if !body.isEmpty =>
wenzelm@52530
   453
            val entry: Command.Results.Entry = (Document_ID.make(), msg)
wenzelm@52889
   454
            Some(Text.Info(snapshot.convert(info_range), entry) :: msgs)
wenzelm@52889
   455
wenzelm@52889
   456
          case _ => None
wenzelm@52900
   457
        }).flatMap(_.info)
wenzelm@51496
   458
    if (results.isEmpty) None
wenzelm@51496
   459
    else {
wenzelm@51496
   460
      val r = Text.Range(results.head.range.start, results.last.range.stop)
wenzelm@51496
   461
      val msgs = Command.Results.make(results.map(_.info))
wenzelm@51496
   462
      Some(Text.Info(r, Pretty.separate(msgs.entries.map(_._2).toList)))
wenzelm@51496
   463
    }
wenzelm@49356
   464
  }
wenzelm@49356
   465
wenzelm@49356
   466
wenzelm@55626
   467
  /* tooltips */
wenzelm@55626
   468
wenzelm@49700
   469
  private def pretty_typing(kind: String, body: XML.Body): XML.Tree =
wenzelm@49700
   470
    Pretty.block(XML.Text(kind) :: Pretty.Break(1) :: body)
wenzelm@49356
   471
wenzelm@55647
   472
  private def timing_threshold: Double = options.real("jedit_timing_threshold")
wenzelm@51588
   473
wenzelm@51496
   474
  def tooltip(range: Text.Range): Option[Text.Info[XML.Body]] =
wenzelm@49356
   475
  {
wenzelm@55622
   476
    def add(prev: Text.Info[(Timing, Vector[(Boolean, XML.Tree)])],
wenzelm@55622
   477
      r0: Text.Range, p: (Boolean, XML.Tree)): Text.Info[(Timing, Vector[(Boolean, XML.Tree)])] =
wenzelm@51496
   478
    {
wenzelm@51496
   479
      val r = snapshot.convert(r0)
wenzelm@51588
   480
      val (t, info) = prev.info
wenzelm@55622
   481
      if (prev.range == r)
wenzelm@55622
   482
        Text.Info(r, (t, info :+ p))
wenzelm@55622
   483
      else Text.Info(r, (t, Vector(p)))
wenzelm@51496
   484
    }
wenzelm@49356
   485
wenzelm@51496
   486
    val results =
wenzelm@55651
   487
      snapshot.cumulate[Text.Info[(Timing, Vector[(Boolean, XML.Tree)])]](
wenzelm@55647
   488
        range, Text.Info(range, (Timing.zero, Vector.empty)), Rendering.tooltip_elements, _ =>
wenzelm@49356
   489
        {
wenzelm@51588
   490
          case (Text.Info(r, (t1, info)), Text.Info(_, XML.Elem(Markup.Timing(t2), _))) =>
wenzelm@52889
   491
            Some(Text.Info(r, (t1 + t2, info)))
wenzelm@50201
   492
          case (prev, Text.Info(r, XML.Elem(Markup.Entity(kind, name), _))) =>
wenzelm@49356
   493
            val kind1 = space_explode('_', kind).mkString(" ")
wenzelm@51588
   494
            val txt1 = kind1 + " " + quote(name)
wenzelm@51588
   495
            val t = prev.info._1
wenzelm@51588
   496
            val txt2 =
wenzelm@51588
   497
              if (kind == Markup.COMMAND && t.elapsed.seconds >= timing_threshold)
wenzelm@51588
   498
                "\n" + t.message
wenzelm@51588
   499
              else ""
wenzelm@52889
   500
            Some(add(prev, r, (true, XML.Text(txt1 + txt2))))
wenzelm@50201
   501
          case (prev, Text.Info(r, XML.Elem(Markup.Path(name), _)))
wenzelm@49356
   502
          if Path.is_ok(name) =>
wenzelm@54515
   503
            val jedit_file = PIDE.thy_load.append(snapshot.node_name.master_dir, Path.explode(name))
wenzelm@52889
   504
            Some(add(prev, r, (true, XML.Text("file " + quote(jedit_file)))))
wenzelm@54702
   505
          case (prev, Text.Info(r, XML.Elem(Markup.Url(name), _))) =>
wenzelm@54702
   506
            Some(add(prev, r, (true, XML.Text("URL " + quote(name)))))
wenzelm@49674
   507
          case (prev, Text.Info(r, XML.Elem(Markup(name, _), body)))
wenzelm@50201
   508
          if name == Markup.SORTING || name == Markup.TYPING =>
wenzelm@52889
   509
            Some(add(prev, r, (true, pretty_typing("::", body))))
wenzelm@50201
   510
          case (prev, Text.Info(r, XML.Elem(Markup(Markup.ML_TYPING, _), body))) =>
wenzelm@52889
   511
            Some(add(prev, r, (false, pretty_typing("ML:", body))))
wenzelm@55666
   512
          case (prev, Text.Info(r, XML.Elem(Markup.Language(language, _, _), _))) =>
wenzelm@55615
   513
            Some(add(prev, r, (true, XML.Text("language: " + language))))
wenzelm@52889
   514
          case (prev, Text.Info(r, XML.Elem(Markup(name, _), _))) =>
wenzelm@55647
   515
            Rendering.tooltip_descriptions.get(name).
wenzelm@55647
   516
              map(descr => add(prev, r, (true, XML.Text(descr))))
wenzelm@52900
   517
        }).map(_.info)
wenzelm@49356
   518
wenzelm@55622
   519
    results.map(_.info).flatMap(res => res._2.toList) match {
wenzelm@51496
   520
      case Nil => None
wenzelm@51496
   521
      case tips =>
wenzelm@51496
   522
        val r = Text.Range(results.head.range.start, results.last.range.stop)
wenzelm@51496
   523
        val all_tips = (tips.filter(_._1) ++ tips.filter(!_._1).lastOption.toList).map(_._2)
wenzelm@51496
   524
        Some(Text.Info(r, Library.separate(Pretty.FBreak, all_tips)))
wenzelm@51496
   525
    }
wenzelm@49356
   526
  }
wenzelm@49356
   527
wenzelm@55647
   528
  def tooltip_margin: Int = options.int("jedit_tooltip_margin")
wenzelm@50554
   529
wenzelm@52873
   530
  lazy val tooltip_close_icon = JEdit_Lib.load_icon(options.string("tooltip_close_icon"))
wenzelm@52873
   531
  lazy val tooltip_detach_icon = JEdit_Lib.load_icon(options.string("tooltip_detach_icon"))
wenzelm@52472
   532
wenzelm@52472
   533
wenzelm@55626
   534
  /* gutter icons */
wenzelm@55626
   535
wenzelm@52472
   536
  private lazy val gutter_icons = Map(
wenzelm@52873
   537
    Rendering.information_pri -> JEdit_Lib.load_icon(options.string("gutter_information_icon")),
wenzelm@52873
   538
    Rendering.warning_pri -> JEdit_Lib.load_icon(options.string("gutter_warning_icon")),
wenzelm@52873
   539
    Rendering.legacy_pri -> JEdit_Lib.load_icon(options.string("gutter_legacy_icon")),
wenzelm@52873
   540
    Rendering.error_pri -> JEdit_Lib.load_icon(options.string("gutter_error_icon")))
wenzelm@49356
   541
wenzelm@49356
   542
  def gutter_message(range: Text.Range): Option[Icon] =
wenzelm@49356
   543
  {
wenzelm@49356
   544
    val results =
wenzelm@55651
   545
      snapshot.cumulate[Int](range, 0, Rendering.gutter_elements, _ =>
wenzelm@49356
   546
        {
wenzelm@52644
   547
          case (pri, Text.Info(_, XML.Elem(Markup(Markup.WRITELN, _),
wenzelm@52644
   548
              List(XML.Elem(Markup(Markup.INFORMATION, _), _))))) =>
wenzelm@52889
   549
            Some(pri max Rendering.information_pri)
wenzelm@50201
   550
          case (pri, Text.Info(_, XML.Elem(Markup(Markup.WARNING, _), body))) =>
wenzelm@49356
   551
            body match {
wenzelm@50201
   552
              case List(XML.Elem(Markup(Markup.LEGACY, _), _)) =>
wenzelm@52889
   553
                Some(pri max Rendering.legacy_pri)
wenzelm@52889
   554
              case _ =>
wenzelm@52889
   555
                Some(pri max Rendering.warning_pri)
wenzelm@49356
   556
            }
wenzelm@50201
   557
          case (pri, Text.Info(_, XML.Elem(Markup(Markup.ERROR, _), _))) =>
wenzelm@52889
   558
            Some(pri max Rendering.error_pri)
wenzelm@52889
   559
          case _ => None
wenzelm@49356
   560
        })
wenzelm@49356
   561
    val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
wenzelm@52472
   562
    gutter_icons.get(pri)
wenzelm@49356
   563
  }
wenzelm@49356
   564
wenzelm@49356
   565
wenzelm@55626
   566
  /* squiggly underline */
wenzelm@55626
   567
wenzelm@55647
   568
  private lazy val squiggly_colors = Map(
wenzelm@50199
   569
    Rendering.writeln_pri -> writeln_color,
wenzelm@52650
   570
    Rendering.information_pri -> information_color,
wenzelm@50199
   571
    Rendering.warning_pri -> warning_color,
wenzelm@50199
   572
    Rendering.error_pri -> error_color)
wenzelm@49356
   573
wenzelm@52900
   574
  def squiggly_underline(range: Text.Range): List[Text.Info[Color]] =
wenzelm@49356
   575
  {
wenzelm@49356
   576
    val results =
wenzelm@55651
   577
      snapshot.cumulate[Int](range, 0, Rendering.squiggly_elements, _ =>
wenzelm@49356
   578
        {
wenzelm@52890
   579
          case (pri, Text.Info(_, elem)) =>
wenzelm@52890
   580
            if (Protocol.is_information(elem))
wenzelm@52889
   581
              Some(pri max Rendering.information_pri)
wenzelm@55620
   582
            else
wenzelm@52890
   583
              Some(pri max Rendering.message_pri(elem.name))
wenzelm@49356
   584
        })
wenzelm@49356
   585
    for {
wenzelm@49356
   586
      Text.Info(r, pri) <- results
wenzelm@49356
   587
      color <- squiggly_colors.get(pri)
wenzelm@49356
   588
    } yield Text.Info(r, color)
wenzelm@49356
   589
  }
wenzelm@49356
   590
wenzelm@49474
   591
wenzelm@55626
   592
  /* message output */
wenzelm@55626
   593
wenzelm@55647
   594
  private lazy val message_colors = Map(
wenzelm@50199
   595
    Rendering.writeln_pri -> writeln_message_color,
wenzelm@52650
   596
    Rendering.information_pri -> information_message_color,
wenzelm@50199
   597
    Rendering.tracing_pri -> tracing_message_color,
wenzelm@50199
   598
    Rendering.warning_pri -> warning_message_color,
wenzelm@50199
   599
    Rendering.error_pri -> error_message_color)
wenzelm@49474
   600
wenzelm@49473
   601
  def line_background(range: Text.Range): Option[(Color, Boolean)] =
wenzelm@49473
   602
  {
wenzelm@49474
   603
    val results =
wenzelm@55651
   604
      snapshot.cumulate[Int](range, 0, Rendering.line_background_elements, _ =>
wenzelm@49473
   605
        {
wenzelm@52890
   606
          case (pri, Text.Info(_, elem)) =>
wenzelm@55623
   607
            if (elem.name == Markup.INFORMATION)
wenzelm@52890
   608
              Some(pri max Rendering.information_pri)
wenzelm@55623
   609
            else
wenzelm@55623
   610
              Some(pri max Rendering.message_pri(elem.name))
wenzelm@49474
   611
        })
wenzelm@49474
   612
    val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
wenzelm@49474
   613
wenzelm@55623
   614
    val is_separator =
wenzelm@55623
   615
      pri > 0 &&
wenzelm@55651
   616
      snapshot.cumulate[Boolean](range, false, Rendering.separator_elements, _ =>
wenzelm@49473
   617
        {
wenzelm@55623
   618
          case _ => Some(true)
wenzelm@49473
   619
        }).exists(_.info)
wenzelm@49473
   620
wenzelm@49474
   621
    message_colors.get(pri).map((_, is_separator))
wenzelm@49473
   622
  }
wenzelm@49356
   623
wenzelm@50500
   624
  def output_messages(st: Command.State): List[XML.Tree] =
wenzelm@50507
   625
    st.results.entries.map(_._2).filterNot(Protocol.is_result(_)).toList
wenzelm@50500
   626
wenzelm@50500
   627
wenzelm@55626
   628
  /* text background */
wenzelm@55626
   629
wenzelm@55790
   630
  def background(range: Text.Range): List[Text.Info[Color]] =
wenzelm@49356
   631
  {
wenzelm@52900
   632
    if (snapshot.is_outdated) List(Text.Info(range, outdated_color))
wenzelm@49356
   633
    else
wenzelm@49356
   634
      for {
wenzelm@49356
   635
        Text.Info(r, result) <-
wenzelm@55651
   636
          snapshot.cumulate[(Option[Protocol.Status], Option[Color])](
wenzelm@55790
   637
            range, (Some(Protocol.Status.init), None), Rendering.background_elements,
wenzelm@55647
   638
            command_state =>
wenzelm@55647
   639
              {
wenzelm@55647
   640
                case (((Some(status), color), Text.Info(_, XML.Elem(markup, _))))
wenzelm@55647
   641
                if (Protocol.command_status_elements(markup.name)) =>
wenzelm@55647
   642
                  Some((Some(Protocol.command_status(status, markup)), color))
wenzelm@55647
   643
                case (_, Text.Info(_, XML.Elem(Markup(Markup.BAD, _), _))) =>
wenzelm@55647
   644
                  Some((None, Some(bad_color)))
wenzelm@55647
   645
                case (_, Text.Info(_, XML.Elem(Markup(Markup.INTENSIFY, _), _))) =>
wenzelm@55647
   646
                  Some((None, Some(intensify_color)))
wenzelm@55647
   647
                case (acc, Text.Info(_, Protocol.Dialog(_, serial, result))) =>
wenzelm@55647
   648
                  command_state.results.get(serial) match {
wenzelm@55647
   649
                    case Some(Protocol.Dialog_Result(res)) if res == result =>
wenzelm@55647
   650
                      Some((None, Some(active_result_color)))
wenzelm@55647
   651
                    case _ =>
wenzelm@55647
   652
                      Some((None, Some(active_color)))
wenzelm@55647
   653
                  }
wenzelm@55647
   654
                case (_, Text.Info(_, elem)) =>
wenzelm@55647
   655
                  if (Rendering.active_elements(elem.name)) Some((None, Some(active_color)))
wenzelm@55647
   656
                  else None
wenzelm@55647
   657
              })
wenzelm@49356
   658
        color <-
wenzelm@49356
   659
          (result match {
wenzelm@50500
   660
            case (Some(status), opt_color) =>
wenzelm@49356
   661
              if (status.is_unprocessed) Some(unprocessed1_color)
wenzelm@49356
   662
              else if (status.is_running) Some(running1_color)
wenzelm@49356
   663
              else opt_color
wenzelm@50500
   664
            case (_, opt_color) => opt_color
wenzelm@49356
   665
          })
wenzelm@49356
   666
      } yield Text.Info(r, color)
wenzelm@49356
   667
  }
wenzelm@49356
   668
wenzelm@49356
   669
wenzelm@55626
   670
  /* text foreground */
wenzelm@51574
   671
wenzelm@52900
   672
  def foreground(range: Text.Range): List[Text.Info[Color]] =
wenzelm@55651
   673
    snapshot.select(range, Rendering.foreground_elements, _ =>
wenzelm@49356
   674
      {
wenzelm@52890
   675
        case Text.Info(_, elem) =>
wenzelm@55620
   676
          if (elem.name == Markup.ANTIQUOTED) Some(antiquoted_color) else Some(quoted_color)
wenzelm@49356
   677
      })
wenzelm@49356
   678
wenzelm@49356
   679
wenzelm@55626
   680
  /* text color */
wenzelm@55626
   681
wenzelm@55647
   682
  private lazy val text_colors: Map[String, Color] = Map(
wenzelm@50201
   683
      Markup.KEYWORD1 -> keyword1_color,
wenzelm@50201
   684
      Markup.KEYWORD2 -> keyword2_color,
wenzelm@55765
   685
      Markup.KEYWORD3 -> keyword3_color,
wenzelm@50201
   686
      Markup.STRING -> Color.BLACK,
wenzelm@50201
   687
      Markup.ALTSTRING -> Color.BLACK,
wenzelm@50201
   688
      Markup.VERBATIM -> Color.BLACK,
wenzelm@55514
   689
      Markup.CARTOUCHE -> Color.BLACK,
wenzelm@50201
   690
      Markup.LITERAL -> keyword1_color,
wenzelm@50201
   691
      Markup.DELIMITER -> Color.BLACK,
wenzelm@50201
   692
      Markup.TFREE -> tfree_color,
wenzelm@50201
   693
      Markup.TVAR -> tvar_color,
wenzelm@50201
   694
      Markup.FREE -> free_color,
wenzelm@50201
   695
      Markup.SKOLEM -> skolem_color,
wenzelm@50201
   696
      Markup.BOUND -> bound_color,
wenzelm@50201
   697
      Markup.VAR -> var_color,
wenzelm@50201
   698
      Markup.INNER_STRING -> inner_quoted_color,
wenzelm@55033
   699
      Markup.INNER_CARTOUCHE -> inner_cartouche_color,
wenzelm@50201
   700
      Markup.INNER_COMMENT -> inner_comment_color,
wenzelm@50201
   701
      Markup.DYNAMIC_FACT -> dynamic_color,
wenzelm@55526
   702
      Markup.ANTIQUOTE -> antiquote_color,
wenzelm@55505
   703
      Markup.ML_KEYWORD1 -> keyword1_color,
wenzelm@55505
   704
      Markup.ML_KEYWORD2 -> keyword2_color,
wenzelm@55505
   705
      Markup.ML_KEYWORD3 -> keyword3_color,
wenzelm@50201
   706
      Markup.ML_DELIMITER -> Color.BLACK,
wenzelm@50201
   707
      Markup.ML_NUMERAL -> inner_numeral_color,
wenzelm@50201
   708
      Markup.ML_CHAR -> inner_quoted_color,
wenzelm@50201
   709
      Markup.ML_STRING -> inner_quoted_color,
wenzelm@52101
   710
      Markup.ML_COMMENT -> inner_comment_color)
wenzelm@49356
   711
wenzelm@55820
   712
  private lazy val text_color_elements =
wenzelm@55820
   713
    Document.Elements(text_colors.keySet)
wenzelm@49356
   714
wenzelm@52900
   715
  def text_color(range: Text.Range, color: Color): List[Text.Info[Color]] =
wenzelm@49356
   716
  {
wenzelm@52900
   717
    if (color == Token_Markup.hidden_color) List(Text.Info(range, color))
wenzelm@50196
   718
    else
wenzelm@55651
   719
      snapshot.cumulate(range, color, text_color_elements, _ =>
wenzelm@50196
   720
        {
wenzelm@52890
   721
          case (_, Text.Info(_, elem)) => text_colors.get(elem.name)
wenzelm@50196
   722
        })
wenzelm@49356
   723
  }
wenzelm@50542
   724
wenzelm@50542
   725
wenzelm@55626
   726
  /* virtual bullets */
wenzelm@55626
   727
wenzelm@55626
   728
  def bullet(range: Text.Range): List[Text.Info[Color]] =
wenzelm@55651
   729
    snapshot.select(range, Rendering.bullet_elements, _ => _ => Some(bullet_color))
wenzelm@55626
   730
wenzelm@55626
   731
wenzelm@55626
   732
  /* text folds */
wenzelm@50542
   733
wenzelm@52900
   734
  def fold_depth(range: Text.Range): List[Text.Info[Int]] =
wenzelm@55651
   735
    snapshot.cumulate[Int](range, 0, Rendering.fold_depth_elements, _ =>
wenzelm@50542
   736
      {
wenzelm@55620
   737
        case (depth, _) => Some(depth + 1)
wenzelm@50542
   738
      })
wenzelm@49356
   739
}