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