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