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