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