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