src/Tools/jEdit/src/rendering.scala
author wenzelm
Wed Dec 10 13:45:44 2014 +0100 (2014-12-10)
changeset 59125 ee19c92ae8b4
parent 59118 fe7f91f85789
child 59129 6959ceb53ac8
permissions -rw-r--r--
more explicit markup for improper commands;
clarified CSS rendering;
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@53230
    44
  /* popup window bounds */
wenzelm@53230
    45
wenzelm@53230
    46
  def popup_bounds: Double = (PIDE.options.real("jedit_popup_bounds") max 0.2) min 0.8
wenzelm@53230
    47
wenzelm@53230
    48
wenzelm@55501
    49
  /* Isabelle/Isar token markup */
wenzelm@39179
    50
wenzelm@39179
    51
  private val command_style: Map[String, Byte] =
wenzelm@39179
    52
  {
wenzelm@43414
    53
    import JEditToken._
wenzelm@39179
    54
    Map[String, Byte](
wenzelm@39179
    55
      Keyword.THY_END -> KEYWORD2,
wenzelm@39179
    56
      Keyword.PRF_ASM -> KEYWORD3,
wenzelm@59125
    57
      Keyword.PRF_ASM_GOAL -> KEYWORD3
wenzelm@39179
    58
    ).withDefaultValue(KEYWORD1)
wenzelm@39179
    59
  }
wenzelm@39179
    60
wenzelm@43414
    61
  private val token_style: Map[Token.Kind.Value, Byte] =
wenzelm@39179
    62
  {
wenzelm@43414
    63
    import JEditToken._
wenzelm@43414
    64
    Map[Token.Kind.Value, Byte](
wenzelm@43414
    65
      Token.Kind.KEYWORD -> KEYWORD2,
wenzelm@43414
    66
      Token.Kind.IDENT -> NULL,
wenzelm@43414
    67
      Token.Kind.LONG_IDENT -> NULL,
wenzelm@43414
    68
      Token.Kind.SYM_IDENT -> NULL,
wenzelm@43414
    69
      Token.Kind.VAR -> NULL,
wenzelm@43414
    70
      Token.Kind.TYPE_IDENT -> NULL,
wenzelm@43414
    71
      Token.Kind.TYPE_VAR -> NULL,
wenzelm@43414
    72
      Token.Kind.NAT -> NULL,
wenzelm@43414
    73
      Token.Kind.FLOAT -> NULL,
wenzelm@59081
    74
      Token.Kind.SPACE -> NULL,
wenzelm@43431
    75
      Token.Kind.STRING -> LITERAL1,
wenzelm@43431
    76
      Token.Kind.ALT_STRING -> LITERAL2,
wenzelm@43414
    77
      Token.Kind.VERBATIM -> COMMENT3,
wenzelm@55033
    78
      Token.Kind.CARTOUCHE -> COMMENT4,
wenzelm@43414
    79
      Token.Kind.COMMENT -> COMMENT1,
wenzelm@48754
    80
      Token.Kind.ERROR -> INVALID
wenzelm@39179
    81
    ).withDefaultValue(NULL)
wenzelm@39179
    82
  }
wenzelm@39179
    83
wenzelm@43414
    84
  def token_markup(syntax: Outer_Syntax, token: Token): Byte =
wenzelm@58901
    85
    if (token.is_command) command_style(syntax.keywords.command_kind(token.content).getOrElse(""))
wenzelm@55505
    86
    else if (token.is_delimiter) JEditToken.OPERATOR
wenzelm@43414
    87
    else token_style(token.kind)
wenzelm@55500
    88
wenzelm@55501
    89
wenzelm@55501
    90
  /* Isabelle/ML token markup */
wenzelm@55501
    91
wenzelm@55500
    92
  private val ml_token_style: Map[ML_Lex.Kind.Value, Byte] =
wenzelm@55500
    93
  {
wenzelm@55500
    94
    import JEditToken._
wenzelm@55500
    95
    Map[ML_Lex.Kind.Value, Byte](
wenzelm@55505
    96
      ML_Lex.Kind.KEYWORD -> NULL,
wenzelm@55500
    97
      ML_Lex.Kind.IDENT -> NULL,
wenzelm@55500
    98
      ML_Lex.Kind.LONG_IDENT -> NULL,
wenzelm@55500
    99
      ML_Lex.Kind.TYPE_VAR -> NULL,
wenzelm@55503
   100
      ML_Lex.Kind.WORD -> DIGIT,
wenzelm@55503
   101
      ML_Lex.Kind.INT -> DIGIT,
wenzelm@55503
   102
      ML_Lex.Kind.REAL -> DIGIT,
wenzelm@55500
   103
      ML_Lex.Kind.CHAR -> LITERAL2,
wenzelm@55500
   104
      ML_Lex.Kind.STRING -> LITERAL1,
wenzelm@55500
   105
      ML_Lex.Kind.SPACE -> NULL,
wenzelm@59112
   106
      ML_Lex.Kind.CARTOUCHE -> COMMENT4,
wenzelm@55500
   107
      ML_Lex.Kind.COMMENT -> COMMENT1,
wenzelm@55512
   108
      ML_Lex.Kind.ANTIQ -> NULL,
wenzelm@55512
   109
      ML_Lex.Kind.ANTIQ_START -> LITERAL4,
wenzelm@55512
   110
      ML_Lex.Kind.ANTIQ_STOP -> LITERAL4,
wenzelm@55512
   111
      ML_Lex.Kind.ANTIQ_OTHER -> NULL,
wenzelm@55514
   112
      ML_Lex.Kind.ANTIQ_STRING -> NULL,
wenzelm@55514
   113
      ML_Lex.Kind.ANTIQ_ALT_STRING -> NULL,
wenzelm@55514
   114
      ML_Lex.Kind.ANTIQ_CARTOUCHE -> NULL,
wenzelm@55500
   115
      ML_Lex.Kind.ERROR -> INVALID
wenzelm@55500
   116
    ).withDefaultValue(NULL)
wenzelm@55500
   117
  }
wenzelm@55500
   118
wenzelm@55500
   119
  def ml_token_markup(token: ML_Lex.Token): Byte =
wenzelm@55501
   120
    if (!token.is_keyword) ml_token_style(token.kind)
wenzelm@55505
   121
    else if (token.is_delimiter) JEditToken.OPERATOR
wenzelm@55505
   122
    else if (ML_Lex.keywords2(token.source)) JEditToken.KEYWORD2
wenzelm@55505
   123
    else if (ML_Lex.keywords3(token.source)) JEditToken.KEYWORD3
wenzelm@55501
   124
    else JEditToken.KEYWORD1
wenzelm@55647
   125
wenzelm@55647
   126
wenzelm@55647
   127
  /* markup elements */
wenzelm@55647
   128
wenzelm@56173
   129
  private val semantic_completion_elements =
wenzelm@56743
   130
    Markup.Elements(Markup.COMPLETION, Markup.NO_COMPLETION)
wenzelm@55674
   131
wenzelm@56173
   132
  private val language_context_elements =
wenzelm@59081
   133
    Markup.Elements(Markup.STRING, Markup.ALT_STRING, Markup.VERBATIM,
wenzelm@55647
   134
      Markup.CARTOUCHE, Markup.COMMENT, Markup.LANGUAGE,
wenzelm@59118
   135
      Markup.ML_STRING, Markup.ML_CARTOUCHE, Markup.ML_COMMENT)
wenzelm@55647
   136
wenzelm@56843
   137
  private val language_elements = Markup.Elements(Markup.LANGUAGE)
wenzelm@56843
   138
wenzelm@58592
   139
  private val citation_elements = Markup.Elements(Markup.CITATION)
wenzelm@58592
   140
wenzelm@55647
   141
  private val highlight_elements =
wenzelm@58545
   142
    Markup.Elements(Markup.EXPRESSION, Markup.CITATION, Markup.LANGUAGE, Markup.ML_TYPING,
wenzelm@58464
   143
      Markup.TOKEN_RANGE, Markup.ENTITY, Markup.PATH, Markup.URL, Markup.SORTING,
wenzelm@55647
   144
      Markup.TYPING, Markup.FREE, Markup.SKOLEM, Markup.BOUND,
wenzelm@55647
   145
      Markup.VAR, Markup.TFREE, Markup.TVAR)
wenzelm@55647
   146
wenzelm@55647
   147
  private val hyperlink_elements =
wenzelm@58545
   148
    Markup.Elements(Markup.ENTITY, Markup.PATH, Markup.POSITION, Markup.CITATION, Markup.URL)
wenzelm@55647
   149
wenzelm@55647
   150
  private val active_elements =
wenzelm@56743
   151
    Markup.Elements(Markup.DIALOG, Markup.BROWSER, Markup.GRAPHVIEW,
wenzelm@57595
   152
      Markup.SENDBACK, Markup.SIMP_TRACE_PANEL)
wenzelm@55647
   153
wenzelm@55647
   154
  private val tooltip_message_elements =
wenzelm@56743
   155
    Markup.Elements(Markup.WRITELN, Markup.WARNING, Markup.ERROR, Markup.BAD)
wenzelm@55647
   156
wenzelm@55647
   157
  private val tooltip_descriptions =
wenzelm@55647
   158
    Map(
wenzelm@58464
   159
      Markup.EXPRESSION -> "expression",
wenzelm@58545
   160
      Markup.CITATION -> "citation",
wenzelm@55647
   161
      Markup.TOKEN_RANGE -> "inner syntax token",
wenzelm@55647
   162
      Markup.FREE -> "free variable",
wenzelm@55647
   163
      Markup.SKOLEM -> "skolem variable",
wenzelm@55647
   164
      Markup.BOUND -> "bound variable",
wenzelm@55647
   165
      Markup.VAR -> "schematic variable",
wenzelm@55647
   166
      Markup.TFREE -> "free type variable",
wenzelm@55647
   167
      Markup.TVAR -> "schematic type variable")
wenzelm@55647
   168
wenzelm@55647
   169
  private val tooltip_elements =
wenzelm@56743
   170
    Markup.Elements(Markup.LANGUAGE, Markup.TIMING, Markup.ENTITY, Markup.SORTING,
wenzelm@55647
   171
      Markup.TYPING, Markup.ML_TYPING, Markup.PATH, Markup.URL) ++
wenzelm@56743
   172
    Markup.Elements(tooltip_descriptions.keySet)
wenzelm@55647
   173
wenzelm@55647
   174
  private val gutter_elements =
wenzelm@56743
   175
    Markup.Elements(Markup.WRITELN, Markup.WARNING, Markup.ERROR)
wenzelm@55647
   176
wenzelm@55647
   177
  private val squiggly_elements =
wenzelm@56743
   178
    Markup.Elements(Markup.WRITELN, Markup.WARNING, Markup.ERROR)
wenzelm@55647
   179
wenzelm@55647
   180
  private val line_background_elements =
wenzelm@56743
   181
    Markup.Elements(Markup.WRITELN_MESSAGE, Markup.TRACING_MESSAGE,
wenzelm@55647
   182
      Markup.WARNING_MESSAGE, Markup.ERROR_MESSAGE,
wenzelm@55647
   183
      Markup.INFORMATION)
wenzelm@55647
   184
wenzelm@55820
   185
  private val separator_elements =
wenzelm@56743
   186
    Markup.Elements(Markup.SEPARATOR)
wenzelm@55647
   187
wenzelm@55790
   188
  private val background_elements =
wenzelm@56395
   189
    Protocol.proper_status_elements + Markup.WRITELN_MESSAGE +
wenzelm@55647
   190
      Markup.TRACING_MESSAGE + Markup.WARNING_MESSAGE +
wenzelm@55647
   191
      Markup.ERROR_MESSAGE + Markup.BAD + Markup.INTENSIFY ++
wenzelm@55647
   192
      active_elements
wenzelm@55647
   193
wenzelm@55647
   194
  private val foreground_elements =
wenzelm@59081
   195
    Markup.Elements(Markup.STRING, Markup.ALT_STRING, Markup.VERBATIM,
wenzelm@55647
   196
      Markup.CARTOUCHE, Markup.ANTIQUOTED)
wenzelm@55647
   197
wenzelm@55820
   198
  private val bullet_elements =
wenzelm@56743
   199
    Markup.Elements(Markup.BULLET)
wenzelm@55647
   200
wenzelm@55647
   201
  private val fold_depth_elements =
wenzelm@56743
   202
    Markup.Elements(Markup.TEXT_FOLD, Markup.GOAL, Markup.SUBGOAL)
wenzelm@39178
   203
}
wenzelm@49356
   204
wenzelm@49356
   205
wenzelm@50199
   206
class Rendering private(val snapshot: Document.Snapshot, val options: Options)
wenzelm@49356
   207
{
wenzelm@55710
   208
  override def toString: String = "Rendering(" + snapshot.toString + ")"
wenzelm@55710
   209
wenzelm@55710
   210
wenzelm@49356
   211
  /* colors */
wenzelm@49356
   212
wenzelm@49356
   213
  def color_value(s: String): Color = Color_Value(options.string(s))
wenzelm@49356
   214
wenzelm@49356
   215
  val outdated_color = color_value("outdated_color")
wenzelm@49356
   216
  val unprocessed_color = color_value("unprocessed_color")
wenzelm@49356
   217
  val unprocessed1_color = color_value("unprocessed1_color")
wenzelm@49356
   218
  val running_color = color_value("running_color")
wenzelm@49356
   219
  val running1_color = color_value("running1_color")
wenzelm@51574
   220
  val bullet_color = color_value("bullet_color")
wenzelm@49706
   221
  val tooltip_color = color_value("tooltip_color")
wenzelm@49356
   222
  val writeln_color = color_value("writeln_color")
wenzelm@52650
   223
  val information_color = color_value("information_color")
wenzelm@49356
   224
  val warning_color = color_value("warning_color")
wenzelm@49356
   225
  val error_color = color_value("error_color")
wenzelm@49356
   226
  val error1_color = color_value("error1_color")
wenzelm@49418
   227
  val writeln_message_color = color_value("writeln_message_color")
wenzelm@52650
   228
  val information_message_color = color_value("information_message_color")
wenzelm@49418
   229
  val tracing_message_color = color_value("tracing_message_color")
wenzelm@49418
   230
  val warning_message_color = color_value("warning_message_color")
wenzelm@49418
   231
  val error_message_color = color_value("error_message_color")
wenzelm@56550
   232
  val spell_checker_color = color_value("spell_checker_color")
wenzelm@49356
   233
  val bad_color = color_value("bad_color")
wenzelm@49358
   234
  val intensify_color = color_value("intensify_color")
wenzelm@49356
   235
  val quoted_color = color_value("quoted_color")
wenzelm@52101
   236
  val antiquoted_color = color_value("antiquoted_color")
wenzelm@55526
   237
  val antiquote_color = color_value("antiquote_color")
wenzelm@49358
   238
  val highlight_color = color_value("highlight_color")
wenzelm@49356
   239
  val hyperlink_color = color_value("hyperlink_color")
wenzelm@50450
   240
  val active_color = color_value("active_color")
wenzelm@50450
   241
  val active_hover_color = color_value("active_hover_color")
wenzelm@50498
   242
  val active_result_color = color_value("active_result_color")
wenzelm@49356
   243
  val keyword1_color = color_value("keyword1_color")
wenzelm@49356
   244
  val keyword2_color = color_value("keyword2_color")
wenzelm@55505
   245
  val keyword3_color = color_value("keyword3_color")
wenzelm@55919
   246
  val quasi_keyword_color = color_value("quasi_keyword_color")
wenzelm@56202
   247
  val improper_color = color_value("improper_color")
wenzelm@56064
   248
  val operator_color = color_value("operator_color")
wenzelm@55713
   249
  val caret_invisible_color = color_value("caret_invisible_color")
wenzelm@55747
   250
  val completion_color = color_value("completion_color")
wenzelm@56883
   251
  val search_color = color_value("search_color")
wenzelm@49356
   252
wenzelm@49356
   253
  val tfree_color = color_value("tfree_color")
wenzelm@49356
   254
  val tvar_color = color_value("tvar_color")
wenzelm@49356
   255
  val free_color = color_value("free_color")
wenzelm@49356
   256
  val skolem_color = color_value("skolem_color")
wenzelm@49356
   257
  val bound_color = color_value("bound_color")
wenzelm@49356
   258
  val var_color = color_value("var_color")
wenzelm@49356
   259
  val inner_numeral_color = color_value("inner_numeral_color")
wenzelm@49356
   260
  val inner_quoted_color = color_value("inner_quoted_color")
wenzelm@55033
   261
  val inner_cartouche_color = color_value("inner_cartouche_color")
wenzelm@49356
   262
  val inner_comment_color = color_value("inner_comment_color")
wenzelm@49356
   263
  val dynamic_color = color_value("dynamic_color")
wenzelm@49356
   264
wenzelm@49356
   265
wenzelm@55674
   266
  /* completion */
wenzelm@55674
   267
wenzelm@56173
   268
  def semantic_completion(range: Text.Range): Option[Text.Info[Completion.Semantic]] =
wenzelm@55690
   269
    if (snapshot.is_outdated) None
wenzelm@55690
   270
    else {
wenzelm@56173
   271
      snapshot.select(range, Rendering.semantic_completion_elements, _ =>
wenzelm@55688
   272
        {
wenzelm@56173
   273
          case Completion.Semantic.Info(info) => Some(info)
wenzelm@55688
   274
          case _ => None
wenzelm@55688
   275
        }).headOption.map(_.info)
wenzelm@55674
   276
    }
wenzelm@55615
   277
wenzelm@56173
   278
  def language_context(range: Text.Range): Option[Completion.Language_Context] =
wenzelm@56173
   279
    snapshot.select(range, Rendering.language_context_elements, _ =>
wenzelm@55690
   280
      {
wenzelm@55828
   281
        case Text.Info(_, XML.Elem(Markup.Language(language, symbols, antiquotes, delimited), _)) =>
wenzelm@55828
   282
          if (delimited) Some(Completion.Language_Context(language, symbols, antiquotes))
wenzelm@55828
   283
          else None
wenzelm@55690
   284
        case Text.Info(_, elem)
wenzelm@59118
   285
        if elem.name == Markup.ML_STRING ||
wenzelm@59118
   286
          elem.name == Markup.ML_CARTOUCHE ||
wenzelm@59118
   287
          elem.name == Markup.ML_COMMENT =>
wenzelm@55749
   288
          Some(Completion.Language_Context.ML_inner)
wenzelm@55690
   289
        case Text.Info(_, _) =>
wenzelm@55749
   290
          Some(Completion.Language_Context.inner)
wenzelm@55690
   291
      }).headOption.map(_.info)
wenzelm@55615
   292
wenzelm@56843
   293
  def language_path(range: Text.Range): Option[Text.Range] =
wenzelm@56843
   294
    snapshot.select(range, Rendering.language_elements, _ =>
wenzelm@56843
   295
      {
wenzelm@56843
   296
        case Text.Info(info_range, XML.Elem(Markup.Language(Markup.Language.PATH, _, _, _), _)) =>
wenzelm@56843
   297
          Some(snapshot.convert(info_range))
wenzelm@56843
   298
        case _ => None
wenzelm@56843
   299
      }).headOption.map(_.info)
wenzelm@56843
   300
wenzelm@58592
   301
  def citation(range: Text.Range): Option[Text.Info[String]] =
wenzelm@58592
   302
    snapshot.select(range, Rendering.citation_elements, _ =>
wenzelm@58592
   303
      {
wenzelm@58592
   304
        case Text.Info(info_range, XML.Elem(Markup.Citation(name), _)) =>
wenzelm@58592
   305
          Some(Text.Info(snapshot.convert(info_range), name))
wenzelm@58592
   306
        case _ => None
wenzelm@58592
   307
      }).headOption.map(_.info)
wenzelm@58592
   308
wenzelm@55615
   309
wenzelm@56551
   310
  /* spell checker */
wenzelm@56548
   311
wenzelm@56551
   312
  private lazy val spell_checker_elements =
wenzelm@56743
   313
    Markup.Elements(space_explode(',', options.string("spell_checker_elements")): _*)
wenzelm@56551
   314
wenzelm@56551
   315
  def spell_checker_ranges(range: Text.Range): List[Text.Range] =
wenzelm@56551
   316
    snapshot.select(range, spell_checker_elements, _ => _ => Some(())).map(_.range)
wenzelm@56548
   317
wenzelm@56564
   318
  def spell_checker_point(range: Text.Range): Option[Text.Range] =
wenzelm@56564
   319
    snapshot.select(range, spell_checker_elements, _ =>
wenzelm@56564
   320
      {
wenzelm@56564
   321
        case info => Some(snapshot.convert(info.range))
wenzelm@56564
   322
      }).headOption.map(_.info)
wenzelm@56564
   323
wenzelm@56548
   324
wenzelm@55626
   325
  /* command status overview */
wenzelm@49356
   326
wenzelm@55647
   327
  def overview_limit: Int = options.int("jedit_text_overview_limit")
wenzelm@49969
   328
wenzelm@49356
   329
  def overview_color(range: Text.Range): Option[Color] =
wenzelm@49356
   330
  {
wenzelm@49356
   331
    if (snapshot.is_outdated) None
wenzelm@49356
   332
    else {
wenzelm@49356
   333
      val results =
wenzelm@56395
   334
        snapshot.cumulate[List[Markup]](range, Nil, Protocol.liberal_status_elements, _ =>
wenzelm@49356
   335
          {
wenzelm@56395
   336
            case (status, Text.Info(_, elem)) => Some(elem.markup :: status)
wenzelm@55651
   337
          }, status = true)
wenzelm@49356
   338
      if (results.isEmpty) None
wenzelm@49356
   339
      else {
wenzelm@56395
   340
        val status = Protocol.Status.make(results.iterator.flatMap(_.info))
wenzelm@49356
   341
wenzelm@50895
   342
        if (status.is_running) Some(running_color)
wenzelm@56980
   343
        else if (status.is_failed) Some(error_color)
wenzelm@56395
   344
        else if (status.is_warned) Some(warning_color)
wenzelm@49356
   345
        else if (status.is_unprocessed) Some(unprocessed_color)
wenzelm@49356
   346
        else None
wenzelm@49356
   347
      }
wenzelm@49356
   348
    }
wenzelm@49356
   349
  }
wenzelm@49356
   350
wenzelm@49356
   351
wenzelm@55626
   352
  /* highlighted area */
wenzelm@49356
   353
wenzelm@49358
   354
  def highlight(range: Text.Range): Option[Text.Info[Color]] =
wenzelm@55651
   355
    snapshot.select(range, Rendering.highlight_elements, _ =>
wenzelm@55620
   356
      {
wenzelm@55620
   357
        case info => Some(Text.Info(snapshot.convert(info.range), highlight_color))
wenzelm@55689
   358
      }).headOption.map(_.info)
wenzelm@49356
   359
wenzelm@49356
   360
wenzelm@55626
   361
  /* hyperlinks */
wenzelm@55626
   362
wenzelm@56458
   363
  private def jedit_file(name: String): String =
wenzelm@56458
   364
    if (Path.is_valid(name))
wenzelm@56458
   365
      PIDE.resources.append(snapshot.node_name.master_dir, Path.explode(name))
wenzelm@56458
   366
    else name
wenzelm@56458
   367
wenzelm@52980
   368
  def hyperlink(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] =
wenzelm@49356
   369
  {
wenzelm@55651
   370
    snapshot.cumulate[Vector[Text.Info[PIDE.editor.Hyperlink]]](
wenzelm@55647
   371
      range, Vector.empty, Rendering.hyperlink_elements, _ =>
wenzelm@49356
   372
        {
wenzelm@56458
   373
          case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _))) =>
wenzelm@56458
   374
            val link = PIDE.editor.hyperlink_file(jedit_file(name))
wenzelm@55622
   375
            Some(links :+ Text.Info(snapshot.convert(info_range), link))
wenzelm@49356
   376
wenzelm@54702
   377
          case (links, Text.Info(info_range, XML.Elem(Markup.Url(name), _))) =>
wenzelm@54702
   378
            val link = PIDE.editor.hyperlink_url(name)
wenzelm@55622
   379
            Some(links :+ Text.Info(snapshot.convert(info_range), link))
wenzelm@54702
   380
wenzelm@50201
   381
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _)))
wenzelm@49815
   382
          if !props.exists(
wenzelm@50201
   383
            { case (Markup.KIND, Markup.ML_OPEN) => true
wenzelm@55837
   384
              case (Markup.KIND, Markup.ML_STRUCTURE) => true
wenzelm@49815
   385
              case _ => false }) =>
wenzelm@55883
   386
            val opt_link =
wenzelm@55883
   387
              props match {
wenzelm@55883
   388
                case Position.Def_Line_File(line, name) =>
wenzelm@55883
   389
                  val offset = Position.Def_Offset.unapply(props) getOrElse 0
wenzelm@55883
   390
                  PIDE.editor.hyperlink_source_file(name, line, offset)
wenzelm@57931
   391
                case Position.Def_Id_Offset0(id, offset) =>
wenzelm@55883
   392
                  PIDE.editor.hyperlink_command_id(snapshot, id, offset)
wenzelm@55883
   393
                case _ => None
wenzelm@55883
   394
              }
wenzelm@55883
   395
            opt_link.map(link => (links :+ Text.Info(snapshot.convert(info_range), link)))
wenzelm@49356
   396
wenzelm@55545
   397
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.POSITION, props), _))) =>
wenzelm@55883
   398
            val opt_link =
wenzelm@55883
   399
              props match {
wenzelm@55883
   400
                case Position.Line_File(line, name) =>
wenzelm@55883
   401
                  val offset = Position.Offset.unapply(props) getOrElse 0
wenzelm@55883
   402
                  PIDE.editor.hyperlink_source_file(name, line, offset)
wenzelm@57931
   403
                case Position.Id_Offset0(id, offset) =>
wenzelm@55883
   404
                  PIDE.editor.hyperlink_command_id(snapshot, id, offset)
wenzelm@55883
   405
                case _ => None
wenzelm@55883
   406
              }
wenzelm@55883
   407
            opt_link.map(link => (links :+ Text.Info(snapshot.convert(info_range), link)))
wenzelm@52889
   408
wenzelm@58545
   409
          case (links, Text.Info(info_range, XML.Elem(Markup.Citation(name), _))) =>
wenzelm@58545
   410
            val opt_link =
wenzelm@58545
   411
              Bibtex_JEdit.entries_iterator.collectFirst(
wenzelm@58545
   412
                { case (a, buffer, offset) if a == name =>
wenzelm@58545
   413
                    PIDE.editor.hyperlink_buffer(buffer, offset) })
wenzelm@58545
   414
            opt_link.map(link => (links :+ Text.Info(snapshot.convert(info_range), link)))
wenzelm@58545
   415
wenzelm@52889
   416
          case _ => None
wenzelm@55622
   417
        }) match { case Text.Info(_, _ :+ info) :: _ => Some(info) case _ => None }
wenzelm@49356
   418
  }
wenzelm@49356
   419
wenzelm@49356
   420
wenzelm@55626
   421
  /* active elements */
wenzelm@55626
   422
wenzelm@50450
   423
  def active(range: Text.Range): Option[Text.Info[XML.Elem]] =
wenzelm@56354
   424
    snapshot.select(range, Rendering.active_elements, command_states =>
wenzelm@55620
   425
      {
wenzelm@55620
   426
        case Text.Info(info_range, elem) =>
wenzelm@55623
   427
          if (elem.name == Markup.DIALOG) {
wenzelm@55623
   428
            elem match {
wenzelm@55623
   429
              case Protocol.Dialog(_, serial, _)
wenzelm@56354
   430
              if !command_states.exists(st => st.results.defined(serial)) =>
wenzelm@55623
   431
                Some(Text.Info(snapshot.convert(info_range), elem))
wenzelm@55623
   432
              case _ => None
wenzelm@55623
   433
            }
wenzelm@55623
   434
          }
wenzelm@55623
   435
          else Some(Text.Info(snapshot.convert(info_range), elem))
wenzelm@55689
   436
      }).headOption.map(_.info)
wenzelm@49492
   437
wenzelm@50502
   438
  def command_results(range: Text.Range): Command.Results =
wenzelm@56354
   439
    Command.State.merge_results(
wenzelm@56743
   440
      snapshot.select[List[Command.State]](range, Markup.Elements.full, command_states =>
wenzelm@56354
   441
        { case _ => Some(command_states) }).flatMap(_.info))
wenzelm@50502
   442
wenzelm@55626
   443
wenzelm@55626
   444
  /* tooltip messages */
wenzelm@55626
   445
wenzelm@51496
   446
  def tooltip_message(range: Text.Range): Option[Text.Info[XML.Body]] =
wenzelm@49356
   447
  {
wenzelm@51496
   448
    val results =
wenzelm@55651
   449
      snapshot.cumulate[List[Text.Info[Command.Results.Entry]]](
wenzelm@55647
   450
        range, Nil, Rendering.tooltip_message_elements, _ =>
wenzelm@51496
   451
        {
wenzelm@51496
   452
          case (msgs, Text.Info(info_range,
wenzelm@51496
   453
            XML.Elem(Markup(name, props @ Markup.Serial(serial)), body)))
wenzelm@51496
   454
          if name == Markup.WRITELN || name == Markup.WARNING || name == Markup.ERROR =>
wenzelm@51496
   455
            val entry: Command.Results.Entry =
wenzelm@51496
   456
              (serial -> XML.Elem(Markup(Markup.message(name), props), body))
wenzelm@52889
   457
            Some(Text.Info(snapshot.convert(info_range), entry) :: msgs)
wenzelm@51496
   458
wenzelm@51496
   459
          case (msgs, Text.Info(info_range, msg @ XML.Elem(Markup(Markup.BAD, _), body)))
wenzelm@51496
   460
          if !body.isEmpty =>
wenzelm@52530
   461
            val entry: Command.Results.Entry = (Document_ID.make(), msg)
wenzelm@52889
   462
            Some(Text.Info(snapshot.convert(info_range), entry) :: msgs)
wenzelm@52889
   463
wenzelm@52889
   464
          case _ => None
wenzelm@52900
   465
        }).flatMap(_.info)
wenzelm@51496
   466
    if (results.isEmpty) None
wenzelm@51496
   467
    else {
wenzelm@51496
   468
      val r = Text.Range(results.head.range.start, results.last.range.stop)
wenzelm@51496
   469
      val msgs = Command.Results.make(results.map(_.info))
wenzelm@56372
   470
      Some(Text.Info(r, Pretty.separate(msgs.iterator.map(_._2).toList)))
wenzelm@51496
   471
    }
wenzelm@49356
   472
  }
wenzelm@49356
   473
wenzelm@49356
   474
wenzelm@55626
   475
  /* tooltips */
wenzelm@55626
   476
wenzelm@49700
   477
  private def pretty_typing(kind: String, body: XML.Body): XML.Tree =
wenzelm@49700
   478
    Pretty.block(XML.Text(kind) :: Pretty.Break(1) :: body)
wenzelm@49356
   479
wenzelm@55647
   480
  private def timing_threshold: Double = options.real("jedit_timing_threshold")
wenzelm@51588
   481
wenzelm@51496
   482
  def tooltip(range: Text.Range): Option[Text.Info[XML.Body]] =
wenzelm@49356
   483
  {
wenzelm@55622
   484
    def add(prev: Text.Info[(Timing, Vector[(Boolean, XML.Tree)])],
wenzelm@55622
   485
      r0: Text.Range, p: (Boolean, XML.Tree)): Text.Info[(Timing, Vector[(Boolean, XML.Tree)])] =
wenzelm@51496
   486
    {
wenzelm@51496
   487
      val r = snapshot.convert(r0)
wenzelm@51588
   488
      val (t, info) = prev.info
wenzelm@55622
   489
      if (prev.range == r)
wenzelm@55622
   490
        Text.Info(r, (t, info :+ p))
wenzelm@55622
   491
      else Text.Info(r, (t, Vector(p)))
wenzelm@51496
   492
    }
wenzelm@49356
   493
wenzelm@51496
   494
    val results =
wenzelm@55651
   495
      snapshot.cumulate[Text.Info[(Timing, Vector[(Boolean, XML.Tree)])]](
wenzelm@55647
   496
        range, Text.Info(range, (Timing.zero, Vector.empty)), Rendering.tooltip_elements, _ =>
wenzelm@49356
   497
        {
wenzelm@51588
   498
          case (Text.Info(r, (t1, info)), Text.Info(_, XML.Elem(Markup.Timing(t2), _))) =>
wenzelm@52889
   499
            Some(Text.Info(r, (t1 + t2, info)))
wenzelm@50201
   500
          case (prev, Text.Info(r, XML.Elem(Markup.Entity(kind, name), _))) =>
wenzelm@56600
   501
            val kind1 = Word.implode(Word.explode('_', kind))
wenzelm@58048
   502
            val txt1 =
wenzelm@58048
   503
              if (name == "") kind1
wenzelm@58048
   504
              else kind1 + " " + quote(name)
wenzelm@51588
   505
            val t = prev.info._1
wenzelm@51588
   506
            val txt2 =
wenzelm@51588
   507
              if (kind == Markup.COMMAND && t.elapsed.seconds >= timing_threshold)
wenzelm@51588
   508
                "\n" + t.message
wenzelm@51588
   509
              else ""
wenzelm@52889
   510
            Some(add(prev, r, (true, XML.Text(txt1 + txt2))))
wenzelm@56458
   511
          case (prev, Text.Info(r, XML.Elem(Markup.Path(name), _))) =>
wenzelm@56458
   512
            val file = jedit_file(name)
wenzelm@56458
   513
            val text =
wenzelm@56458
   514
              if (name == file) "file " + quote(file)
wenzelm@56458
   515
              else "path " + quote(name) + "\nfile " + quote(file)
wenzelm@56134
   516
            Some(add(prev, r, (true, XML.Text(text))))
wenzelm@54702
   517
          case (prev, Text.Info(r, XML.Elem(Markup.Url(name), _))) =>
wenzelm@54702
   518
            Some(add(prev, r, (true, XML.Text("URL " + quote(name)))))
wenzelm@49674
   519
          case (prev, Text.Info(r, XML.Elem(Markup(name, _), body)))
wenzelm@50201
   520
          if name == Markup.SORTING || name == Markup.TYPING =>
wenzelm@52889
   521
            Some(add(prev, r, (true, pretty_typing("::", body))))
wenzelm@50201
   522
          case (prev, Text.Info(r, XML.Elem(Markup(Markup.ML_TYPING, _), body))) =>
wenzelm@52889
   523
            Some(add(prev, r, (false, pretty_typing("ML:", body))))
wenzelm@55828
   524
          case (prev, Text.Info(r, XML.Elem(Markup.Language(language, _, _, _), _))) =>
wenzelm@55615
   525
            Some(add(prev, r, (true, XML.Text("language: " + language))))
wenzelm@52889
   526
          case (prev, Text.Info(r, XML.Elem(Markup(name, _), _))) =>
wenzelm@55647
   527
            Rendering.tooltip_descriptions.get(name).
wenzelm@55647
   528
              map(descr => add(prev, r, (true, XML.Text(descr))))
wenzelm@52900
   529
        }).map(_.info)
wenzelm@49356
   530
wenzelm@55622
   531
    results.map(_.info).flatMap(res => res._2.toList) match {
wenzelm@51496
   532
      case Nil => None
wenzelm@51496
   533
      case tips =>
wenzelm@51496
   534
        val r = Text.Range(results.head.range.start, results.last.range.stop)
wenzelm@51496
   535
        val all_tips = (tips.filter(_._1) ++ tips.filter(!_._1).lastOption.toList).map(_._2)
wenzelm@51496
   536
        Some(Text.Info(r, Library.separate(Pretty.FBreak, all_tips)))
wenzelm@51496
   537
    }
wenzelm@49356
   538
  }
wenzelm@49356
   539
wenzelm@55647
   540
  def tooltip_margin: Int = options.int("jedit_tooltip_margin")
wenzelm@50554
   541
wenzelm@52873
   542
  lazy val tooltip_close_icon = JEdit_Lib.load_icon(options.string("tooltip_close_icon"))
wenzelm@52873
   543
  lazy val tooltip_detach_icon = JEdit_Lib.load_icon(options.string("tooltip_detach_icon"))
wenzelm@52472
   544
wenzelm@52472
   545
wenzelm@56495
   546
  /* gutter */
wenzelm@56495
   547
wenzelm@56495
   548
  private def gutter_message_pri(msg: XML.Tree): Int =
wenzelm@56495
   549
    if (Protocol.is_error(msg)) Rendering.error_pri
wenzelm@56495
   550
    else if (Protocol.is_legacy(msg)) Rendering.legacy_pri
wenzelm@56495
   551
    else if (Protocol.is_warning(msg)) Rendering.warning_pri
wenzelm@56495
   552
    else if (Protocol.is_information(msg)) Rendering.information_pri
wenzelm@56495
   553
    else 0
wenzelm@55626
   554
wenzelm@52472
   555
  private lazy val gutter_icons = Map(
wenzelm@52873
   556
    Rendering.information_pri -> JEdit_Lib.load_icon(options.string("gutter_information_icon")),
wenzelm@52873
   557
    Rendering.warning_pri -> JEdit_Lib.load_icon(options.string("gutter_warning_icon")),
wenzelm@52873
   558
    Rendering.legacy_pri -> JEdit_Lib.load_icon(options.string("gutter_legacy_icon")),
wenzelm@52873
   559
    Rendering.error_pri -> JEdit_Lib.load_icon(options.string("gutter_error_icon")))
wenzelm@49356
   560
wenzelm@56495
   561
  def gutter_icon(range: Text.Range): Option[Icon] =
wenzelm@49356
   562
  {
wenzelm@56495
   563
    val pris =
wenzelm@55651
   564
      snapshot.cumulate[Int](range, 0, Rendering.gutter_elements, _ =>
wenzelm@49356
   565
        {
wenzelm@56495
   566
          case (pri, Text.Info(_, msg @ XML.Elem(Markup(_, Markup.Serial(serial)), _))) =>
wenzelm@56495
   567
            Some(pri max gutter_message_pri(msg))
wenzelm@52889
   568
          case _ => None
wenzelm@56495
   569
        }).map(_.info)
wenzelm@56495
   570
wenzelm@56495
   571
    gutter_icons.get((0 /: pris)(_ max _))
wenzelm@49356
   572
  }
wenzelm@49356
   573
wenzelm@49356
   574
wenzelm@55626
   575
  /* squiggly underline */
wenzelm@55626
   576
wenzelm@55647
   577
  private lazy val squiggly_colors = Map(
wenzelm@50199
   578
    Rendering.writeln_pri -> writeln_color,
wenzelm@52650
   579
    Rendering.information_pri -> information_color,
wenzelm@50199
   580
    Rendering.warning_pri -> warning_color,
wenzelm@50199
   581
    Rendering.error_pri -> error_color)
wenzelm@49356
   582
wenzelm@52900
   583
  def squiggly_underline(range: Text.Range): List[Text.Info[Color]] =
wenzelm@49356
   584
  {
wenzelm@49356
   585
    val results =
wenzelm@55651
   586
      snapshot.cumulate[Int](range, 0, Rendering.squiggly_elements, _ =>
wenzelm@49356
   587
        {
wenzelm@52890
   588
          case (pri, Text.Info(_, elem)) =>
wenzelm@52890
   589
            if (Protocol.is_information(elem))
wenzelm@52889
   590
              Some(pri max Rendering.information_pri)
wenzelm@55620
   591
            else
wenzelm@52890
   592
              Some(pri max Rendering.message_pri(elem.name))
wenzelm@49356
   593
        })
wenzelm@49356
   594
    for {
wenzelm@49356
   595
      Text.Info(r, pri) <- results
wenzelm@49356
   596
      color <- squiggly_colors.get(pri)
wenzelm@49356
   597
    } yield Text.Info(r, color)
wenzelm@49356
   598
  }
wenzelm@49356
   599
wenzelm@49474
   600
wenzelm@55626
   601
  /* message output */
wenzelm@55626
   602
wenzelm@55647
   603
  private lazy val message_colors = Map(
wenzelm@50199
   604
    Rendering.writeln_pri -> writeln_message_color,
wenzelm@52650
   605
    Rendering.information_pri -> information_message_color,
wenzelm@50199
   606
    Rendering.tracing_pri -> tracing_message_color,
wenzelm@50199
   607
    Rendering.warning_pri -> warning_message_color,
wenzelm@50199
   608
    Rendering.error_pri -> error_message_color)
wenzelm@49474
   609
wenzelm@49473
   610
  def line_background(range: Text.Range): Option[(Color, Boolean)] =
wenzelm@49473
   611
  {
wenzelm@49474
   612
    val results =
wenzelm@55651
   613
      snapshot.cumulate[Int](range, 0, Rendering.line_background_elements, _ =>
wenzelm@49473
   614
        {
wenzelm@52890
   615
          case (pri, Text.Info(_, elem)) =>
wenzelm@55623
   616
            if (elem.name == Markup.INFORMATION)
wenzelm@52890
   617
              Some(pri max Rendering.information_pri)
wenzelm@55623
   618
            else
wenzelm@55623
   619
              Some(pri max Rendering.message_pri(elem.name))
wenzelm@49474
   620
        })
wenzelm@49474
   621
    val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
wenzelm@49474
   622
wenzelm@55623
   623
    val is_separator =
wenzelm@55623
   624
      pri > 0 &&
wenzelm@55651
   625
      snapshot.cumulate[Boolean](range, false, Rendering.separator_elements, _ =>
wenzelm@49473
   626
        {
wenzelm@55623
   627
          case _ => Some(true)
wenzelm@49473
   628
        }).exists(_.info)
wenzelm@49473
   629
wenzelm@49474
   630
    message_colors.get(pri).map((_, is_separator))
wenzelm@49473
   631
  }
wenzelm@49356
   632
wenzelm@56299
   633
  def output_messages(results: Command.Results): List[XML.Tree] =
wenzelm@57691
   634
  {
wenzelm@57691
   635
    val (states, other) =
wenzelm@57691
   636
      results.iterator.map(_._2).filterNot(Protocol.is_result(_)).toList
wenzelm@57691
   637
        .partition(Protocol.is_state(_))
wenzelm@57691
   638
    states ::: other
wenzelm@57691
   639
  }
wenzelm@50500
   640
wenzelm@50500
   641
wenzelm@55626
   642
  /* text background */
wenzelm@55626
   643
wenzelm@55790
   644
  def background(range: Text.Range): List[Text.Info[Color]] =
wenzelm@49356
   645
  {
wenzelm@56176
   646
    if (snapshot.is_outdated && snapshot.is_loaded) List(Text.Info(range, outdated_color))
wenzelm@49356
   647
    else
wenzelm@49356
   648
      for {
wenzelm@49356
   649
        Text.Info(r, result) <-
wenzelm@56352
   650
          snapshot.cumulate[(List[Markup], Option[Color])](
wenzelm@56352
   651
            range, (List(Markup.Empty), None), Rendering.background_elements,
wenzelm@56354
   652
            command_states =>
wenzelm@55647
   653
              {
wenzelm@56352
   654
                case (((status, color), Text.Info(_, XML.Elem(markup, _))))
wenzelm@56395
   655
                if !status.isEmpty && Protocol.proper_status_elements(markup.name) =>
wenzelm@56352
   656
                  Some((markup :: status, color))
wenzelm@55647
   657
                case (_, Text.Info(_, XML.Elem(Markup(Markup.BAD, _), _))) =>
wenzelm@56352
   658
                  Some((Nil, Some(bad_color)))
wenzelm@55647
   659
                case (_, Text.Info(_, XML.Elem(Markup(Markup.INTENSIFY, _), _))) =>
wenzelm@56352
   660
                  Some((Nil, Some(intensify_color)))
wenzelm@55647
   661
                case (acc, Text.Info(_, Protocol.Dialog(_, serial, result))) =>
wenzelm@56354
   662
                  command_states.collectFirst(
wenzelm@56354
   663
                    { case st if st.results.defined(serial) => st.results.get(serial).get }) match
wenzelm@56354
   664
                  {
wenzelm@55647
   665
                    case Some(Protocol.Dialog_Result(res)) if res == result =>
wenzelm@56352
   666
                      Some((Nil, Some(active_result_color)))
wenzelm@55647
   667
                    case _ =>
wenzelm@56352
   668
                      Some((Nil, Some(active_color)))
wenzelm@55647
   669
                  }
wenzelm@55647
   670
                case (_, Text.Info(_, elem)) =>
wenzelm@56352
   671
                  if (Rendering.active_elements(elem.name)) Some((Nil, Some(active_color)))
wenzelm@55647
   672
                  else None
wenzelm@55647
   673
              })
wenzelm@49356
   674
        color <-
wenzelm@49356
   675
          (result match {
wenzelm@56352
   676
            case (markups, opt_color) if !markups.isEmpty =>
wenzelm@56359
   677
              val status = Protocol.Status.make(markups.iterator)
wenzelm@49356
   678
              if (status.is_unprocessed) Some(unprocessed1_color)
wenzelm@49356
   679
              else if (status.is_running) Some(running1_color)
wenzelm@49356
   680
              else opt_color
wenzelm@50500
   681
            case (_, opt_color) => opt_color
wenzelm@49356
   682
          })
wenzelm@49356
   683
      } yield Text.Info(r, color)
wenzelm@49356
   684
  }
wenzelm@49356
   685
wenzelm@49356
   686
wenzelm@55626
   687
  /* text foreground */
wenzelm@51574
   688
wenzelm@52900
   689
  def foreground(range: Text.Range): List[Text.Info[Color]] =
wenzelm@55651
   690
    snapshot.select(range, Rendering.foreground_elements, _ =>
wenzelm@49356
   691
      {
wenzelm@52890
   692
        case Text.Info(_, elem) =>
wenzelm@55620
   693
          if (elem.name == Markup.ANTIQUOTED) Some(antiquoted_color) else Some(quoted_color)
wenzelm@49356
   694
      })
wenzelm@49356
   695
wenzelm@49356
   696
wenzelm@55626
   697
  /* text color */
wenzelm@55626
   698
wenzelm@55647
   699
  private lazy val text_colors: Map[String, Color] = Map(
wenzelm@50201
   700
      Markup.KEYWORD1 -> keyword1_color,
wenzelm@50201
   701
      Markup.KEYWORD2 -> keyword2_color,
wenzelm@55765
   702
      Markup.KEYWORD3 -> keyword3_color,
wenzelm@55919
   703
      Markup.QUASI_KEYWORD -> quasi_keyword_color,
wenzelm@56202
   704
      Markup.IMPROPER -> improper_color,
wenzelm@56064
   705
      Markup.OPERATOR -> operator_color,
wenzelm@50201
   706
      Markup.STRING -> Color.BLACK,
wenzelm@59081
   707
      Markup.ALT_STRING -> Color.BLACK,
wenzelm@50201
   708
      Markup.VERBATIM -> Color.BLACK,
wenzelm@55514
   709
      Markup.CARTOUCHE -> Color.BLACK,
wenzelm@50201
   710
      Markup.LITERAL -> keyword1_color,
wenzelm@50201
   711
      Markup.DELIMITER -> Color.BLACK,
wenzelm@50201
   712
      Markup.TFREE -> tfree_color,
wenzelm@50201
   713
      Markup.TVAR -> tvar_color,
wenzelm@50201
   714
      Markup.FREE -> free_color,
wenzelm@50201
   715
      Markup.SKOLEM -> skolem_color,
wenzelm@50201
   716
      Markup.BOUND -> bound_color,
wenzelm@50201
   717
      Markup.VAR -> var_color,
wenzelm@50201
   718
      Markup.INNER_STRING -> inner_quoted_color,
wenzelm@55033
   719
      Markup.INNER_CARTOUCHE -> inner_cartouche_color,
wenzelm@50201
   720
      Markup.INNER_COMMENT -> inner_comment_color,
wenzelm@50201
   721
      Markup.DYNAMIC_FACT -> dynamic_color,
wenzelm@55526
   722
      Markup.ANTIQUOTE -> antiquote_color,
wenzelm@55505
   723
      Markup.ML_KEYWORD1 -> keyword1_color,
wenzelm@55505
   724
      Markup.ML_KEYWORD2 -> keyword2_color,
wenzelm@55505
   725
      Markup.ML_KEYWORD3 -> keyword3_color,
wenzelm@50201
   726
      Markup.ML_DELIMITER -> Color.BLACK,
wenzelm@50201
   727
      Markup.ML_NUMERAL -> inner_numeral_color,
wenzelm@50201
   728
      Markup.ML_CHAR -> inner_quoted_color,
wenzelm@50201
   729
      Markup.ML_STRING -> inner_quoted_color,
wenzelm@59112
   730
      Markup.ML_CARTOUCHE -> inner_cartouche_color,
wenzelm@56278
   731
      Markup.ML_COMMENT -> inner_comment_color,
wenzelm@56278
   732
      Markup.SML_STRING -> inner_quoted_color,
wenzelm@56278
   733
      Markup.SML_COMMENT -> inner_comment_color)
wenzelm@49356
   734
wenzelm@55820
   735
  private lazy val text_color_elements =
wenzelm@56743
   736
    Markup.Elements(text_colors.keySet)
wenzelm@49356
   737
wenzelm@52900
   738
  def text_color(range: Text.Range, color: Color): List[Text.Info[Color]] =
wenzelm@49356
   739
  {
wenzelm@52900
   740
    if (color == Token_Markup.hidden_color) List(Text.Info(range, color))
wenzelm@50196
   741
    else
wenzelm@55651
   742
      snapshot.cumulate(range, color, text_color_elements, _ =>
wenzelm@50196
   743
        {
wenzelm@52890
   744
          case (_, Text.Info(_, elem)) => text_colors.get(elem.name)
wenzelm@50196
   745
        })
wenzelm@49356
   746
  }
wenzelm@50542
   747
wenzelm@50542
   748
wenzelm@55626
   749
  /* virtual bullets */
wenzelm@55626
   750
wenzelm@55626
   751
  def bullet(range: Text.Range): List[Text.Info[Color]] =
wenzelm@55651
   752
    snapshot.select(range, Rendering.bullet_elements, _ => _ => Some(bullet_color))
wenzelm@55626
   753
wenzelm@55626
   754
wenzelm@55626
   755
  /* text folds */
wenzelm@50542
   756
wenzelm@52900
   757
  def fold_depth(range: Text.Range): List[Text.Info[Int]] =
wenzelm@55651
   758
    snapshot.cumulate[Int](range, 0, Rendering.fold_depth_elements, _ =>
wenzelm@50542
   759
      {
wenzelm@55620
   760
        case (depth, _) => Some(depth + 1)
wenzelm@50542
   761
      })
wenzelm@49356
   762
}