src/Tools/jEdit/src/rendering.scala
author wenzelm
Thu Feb 20 13:23:49 2014 +0100 (2014-02-20 ago)
changeset 55616 25a7a998852a
parent 55615 bf4bbe72f740
child 55619 c5aeeacdd2b1
permissions -rw-r--r--
default completion context via outer syntax;
no symbol completion for ML files;
tuned;
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@39178
   149
}
wenzelm@49356
   150
wenzelm@49356
   151
wenzelm@50199
   152
class Rendering private(val snapshot: Document.Snapshot, val options: Options)
wenzelm@49356
   153
{
wenzelm@49356
   154
  /* colors */
wenzelm@49356
   155
wenzelm@49356
   156
  def color_value(s: String): Color = Color_Value(options.string(s))
wenzelm@49356
   157
wenzelm@49356
   158
  val outdated_color = color_value("outdated_color")
wenzelm@49356
   159
  val unprocessed_color = color_value("unprocessed_color")
wenzelm@49356
   160
  val unprocessed1_color = color_value("unprocessed1_color")
wenzelm@49356
   161
  val running_color = color_value("running_color")
wenzelm@49356
   162
  val running1_color = color_value("running1_color")
wenzelm@49356
   163
  val light_color = color_value("light_color")
wenzelm@51574
   164
  val bullet_color = color_value("bullet_color")
wenzelm@49706
   165
  val tooltip_color = color_value("tooltip_color")
wenzelm@49356
   166
  val writeln_color = color_value("writeln_color")
wenzelm@52650
   167
  val information_color = color_value("information_color")
wenzelm@49356
   168
  val warning_color = color_value("warning_color")
wenzelm@49356
   169
  val error_color = color_value("error_color")
wenzelm@49356
   170
  val error1_color = color_value("error1_color")
wenzelm@49418
   171
  val writeln_message_color = color_value("writeln_message_color")
wenzelm@52650
   172
  val information_message_color = color_value("information_message_color")
wenzelm@49418
   173
  val tracing_message_color = color_value("tracing_message_color")
wenzelm@49418
   174
  val warning_message_color = color_value("warning_message_color")
wenzelm@49418
   175
  val error_message_color = color_value("error_message_color")
wenzelm@49356
   176
  val bad_color = color_value("bad_color")
wenzelm@49358
   177
  val intensify_color = color_value("intensify_color")
wenzelm@49356
   178
  val quoted_color = color_value("quoted_color")
wenzelm@52101
   179
  val antiquoted_color = color_value("antiquoted_color")
wenzelm@55526
   180
  val antiquote_color = color_value("antiquote_color")
wenzelm@49358
   181
  val highlight_color = color_value("highlight_color")
wenzelm@49356
   182
  val hyperlink_color = color_value("hyperlink_color")
wenzelm@50450
   183
  val active_color = color_value("active_color")
wenzelm@50450
   184
  val active_hover_color = color_value("active_hover_color")
wenzelm@50498
   185
  val active_result_color = color_value("active_result_color")
wenzelm@49356
   186
  val keyword1_color = color_value("keyword1_color")
wenzelm@49356
   187
  val keyword2_color = color_value("keyword2_color")
wenzelm@55505
   188
  val keyword3_color = color_value("keyword3_color")
wenzelm@49356
   189
wenzelm@49356
   190
  val tfree_color = color_value("tfree_color")
wenzelm@49356
   191
  val tvar_color = color_value("tvar_color")
wenzelm@49356
   192
  val free_color = color_value("free_color")
wenzelm@49356
   193
  val skolem_color = color_value("skolem_color")
wenzelm@49356
   194
  val bound_color = color_value("bound_color")
wenzelm@49356
   195
  val var_color = color_value("var_color")
wenzelm@49356
   196
  val inner_numeral_color = color_value("inner_numeral_color")
wenzelm@49356
   197
  val inner_quoted_color = color_value("inner_quoted_color")
wenzelm@55033
   198
  val inner_cartouche_color = color_value("inner_cartouche_color")
wenzelm@49356
   199
  val inner_comment_color = color_value("inner_comment_color")
wenzelm@49356
   200
  val dynamic_color = color_value("dynamic_color")
wenzelm@49356
   201
wenzelm@49356
   202
wenzelm@55615
   203
  /* completion context */
wenzelm@55615
   204
wenzelm@55615
   205
  private val completion_elements =
wenzelm@55615
   206
    Set(Markup.STRING, Markup.ALTSTRING, Markup.VERBATIM, Markup.CARTOUCHE,
wenzelm@55615
   207
      Markup.COMMENT, Markup.LANGUAGE)
wenzelm@55615
   208
wenzelm@55616
   209
  def completion_context(caret: Text.Offset): Option[Completion.Context] =
wenzelm@55615
   210
    if (caret > 0) {
wenzelm@55615
   211
      val result =
wenzelm@55615
   212
        snapshot.select_markup(Text.Range(caret - 1, caret + 1), Some(completion_elements), _ =>
wenzelm@55615
   213
          {
wenzelm@55615
   214
            case Text.Info(_, XML.Elem(Markup.Language(language, symbols), _)) =>
wenzelm@55615
   215
              Some(Completion.Context(language, symbols))
wenzelm@55615
   216
            case Text.Info(_, XML.Elem(markup, _)) =>
wenzelm@55616
   217
              if (completion_elements(markup.name))
wenzelm@55616
   218
                Some(Completion.Context(Markup.Language.UNKNOWN, true))
wenzelm@55615
   219
              else None
wenzelm@55615
   220
          })
wenzelm@55615
   221
      result match {
wenzelm@55616
   222
        case Text.Info(_, context) :: _ => Some(context)
wenzelm@55616
   223
        case Nil => None
wenzelm@55615
   224
      }
wenzelm@55615
   225
    }
wenzelm@55616
   226
    else None
wenzelm@55615
   227
wenzelm@55615
   228
wenzelm@49356
   229
  /* command overview */
wenzelm@49356
   230
wenzelm@49969
   231
  val overview_limit = options.int("jedit_text_overview_limit")
wenzelm@49969
   232
wenzelm@50547
   233
  private val overview_include = Protocol.command_status_markup + Markup.WARNING + Markup.ERROR
wenzelm@50547
   234
wenzelm@49356
   235
  def overview_color(range: Text.Range): Option[Color] =
wenzelm@49356
   236
  {
wenzelm@49356
   237
    if (snapshot.is_outdated) None
wenzelm@49356
   238
    else {
wenzelm@49356
   239
      val results =
wenzelm@49356
   240
        snapshot.cumulate_markup[(Protocol.Status, Int)](
wenzelm@50547
   241
          range, (Protocol.Status.init, 0), Some(overview_include), _ =>
wenzelm@49356
   242
          {
wenzelm@52890
   243
            case ((status, pri), Text.Info(_, elem)) =>
wenzelm@52890
   244
              if (elem.name == Markup.WARNING || elem.name == Markup.ERROR)
wenzelm@52890
   245
                Some((status, pri max Rendering.message_pri(elem.name)))
wenzelm@52890
   246
              else if (overview_include(elem.name))
wenzelm@52890
   247
                Some((Protocol.command_status(status, elem.markup), pri))
wenzelm@52889
   248
              else None
wenzelm@49356
   249
          })
wenzelm@49356
   250
      if (results.isEmpty) None
wenzelm@49356
   251
      else {
wenzelm@49356
   252
        val (status, pri) =
wenzelm@49356
   253
          ((Protocol.Status.init, 0) /: results) {
wenzelm@49356
   254
            case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) }
wenzelm@49356
   255
wenzelm@50895
   256
        if (status.is_running) Some(running_color)
wenzelm@50895
   257
        else if (pri == Rendering.warning_pri) Some(warning_color)
wenzelm@50199
   258
        else if (pri == Rendering.error_pri) Some(error_color)
wenzelm@49356
   259
        else if (status.is_unprocessed) Some(unprocessed_color)
wenzelm@49356
   260
        else if (status.is_failed) Some(error_color)
wenzelm@49356
   261
        else None
wenzelm@49356
   262
      }
wenzelm@49356
   263
    }
wenzelm@49356
   264
  }
wenzelm@49356
   265
wenzelm@49356
   266
wenzelm@49356
   267
  /* markup selectors */
wenzelm@49356
   268
wenzelm@49358
   269
  private val highlight_include =
wenzelm@55552
   270
    Set(Markup.LANGUAGE, Markup.ML_TYPING, Markup.TOKEN_RANGE,
wenzelm@55552
   271
      Markup.ENTITY, Markup.PATH, Markup.URL, Markup.SORTING,
wenzelm@55552
   272
      Markup.TYPING, Markup.FREE, Markup.SKOLEM, Markup.BOUND,
wenzelm@55552
   273
      Markup.VAR, Markup.TFREE, Markup.TVAR)
wenzelm@49356
   274
wenzelm@49358
   275
  def highlight(range: Text.Range): Option[Text.Info[Color]] =
wenzelm@49356
   276
  {
wenzelm@50500
   277
    snapshot.select_markup(range, Some(highlight_include), _ =>
wenzelm@49356
   278
        {
wenzelm@52890
   279
          case Text.Info(info_range, elem) =>
wenzelm@52890
   280
            if (highlight_include(elem.name))
wenzelm@52889
   281
              Some(Text.Info(snapshot.convert(info_range), highlight_color))
wenzelm@52889
   282
            else None
wenzelm@52900
   283
        }) match { case Text.Info(_, info) :: _ => Some(info) case _ => None }
wenzelm@49356
   284
  }
wenzelm@49356
   285
wenzelm@49356
   286
wenzelm@55547
   287
  private val hyperlink_include = Set(Markup.ENTITY, Markup.PATH, Markup.POSITION, Markup.URL)
wenzelm@55547
   288
wenzelm@55547
   289
  private def hyperlink_file(line: Int, name: String): Option[PIDE.editor.Hyperlink] =
wenzelm@55547
   290
    if (Path.is_ok(name))
wenzelm@55547
   291
      Isabelle_System.source_file(Path.explode(name)).map(path =>
wenzelm@55547
   292
        PIDE.editor.hyperlink_file(Isabelle_System.platform_path(path), line))
wenzelm@55547
   293
    else None
wenzelm@55547
   294
wenzelm@55547
   295
  private def hyperlink_command(id: Document_ID.Generic, offset: Text.Offset)
wenzelm@55547
   296
      : Option[PIDE.editor.Hyperlink] =
wenzelm@55547
   297
    snapshot.state.find_command(snapshot.version, id) match {
wenzelm@55547
   298
      case Some((node, command)) =>
wenzelm@55547
   299
        PIDE.editor.hyperlink_command(snapshot, command, offset)
wenzelm@55547
   300
      case None => None
wenzelm@55547
   301
    }
wenzelm@49356
   302
wenzelm@52980
   303
  def hyperlink(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] =
wenzelm@49356
   304
  {
wenzelm@52980
   305
    snapshot.cumulate_markup[List[Text.Info[PIDE.editor.Hyperlink]]](
wenzelm@52980
   306
      range, Nil, Some(hyperlink_include), _ =>
wenzelm@49356
   307
        {
wenzelm@50201
   308
          case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _)))
wenzelm@49356
   309
          if Path.is_ok(name) =>
wenzelm@54515
   310
            val jedit_file = PIDE.thy_load.append(snapshot.node_name.master_dir, Path.explode(name))
wenzelm@52980
   311
            val link = PIDE.editor.hyperlink_file(jedit_file)
wenzelm@52980
   312
            Some(Text.Info(snapshot.convert(info_range), link) :: links)
wenzelm@49356
   313
wenzelm@54702
   314
          case (links, Text.Info(info_range, XML.Elem(Markup.Url(name), _))) =>
wenzelm@54702
   315
            val link = PIDE.editor.hyperlink_url(name)
wenzelm@54702
   316
            Some(Text.Info(snapshot.convert(info_range), link) :: links)
wenzelm@54702
   317
wenzelm@50201
   318
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _)))
wenzelm@49815
   319
          if !props.exists(
wenzelm@50201
   320
            { case (Markup.KIND, Markup.ML_OPEN) => true
wenzelm@50201
   321
              case (Markup.KIND, Markup.ML_STRUCT) => true
wenzelm@49815
   322
              case _ => false }) =>
wenzelm@49356
   323
wenzelm@55547
   324
            val opt_link =
wenzelm@55547
   325
              props match {
wenzelm@55547
   326
                case Position.Def_Line_File(line, name) => hyperlink_file(line, name)
wenzelm@55547
   327
                case Position.Def_Id_Offset(id, offset) => hyperlink_command(id, offset)
wenzelm@55547
   328
                case _ => None
wenzelm@55547
   329
              }
wenzelm@55547
   330
            opt_link.map(link => (Text.Info(snapshot.convert(info_range), link) :: links))
wenzelm@49356
   331
wenzelm@55547
   332
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.POSITION, props), _))) =>
wenzelm@55547
   333
            val opt_link =
wenzelm@55547
   334
              props match {
wenzelm@55547
   335
                case Position.Line_File(line, name) => hyperlink_file(line, name)
wenzelm@55547
   336
                case Position.Id_Offset(id, offset) => hyperlink_command(id, offset)
wenzelm@55547
   337
                case _ => None
wenzelm@55547
   338
              }
wenzelm@55547
   339
            opt_link.map(link => (Text.Info(snapshot.convert(info_range), link) :: links))
wenzelm@52889
   340
wenzelm@52889
   341
          case _ => None
wenzelm@52900
   342
        }) match { case Text.Info(_, info :: _) :: _ => Some(info) case _ => None }
wenzelm@49356
   343
  }
wenzelm@49356
   344
wenzelm@49356
   345
wenzelm@50715
   346
  private val active_include =
lars@55316
   347
    Set(Markup.BROWSER, Markup.GRAPHVIEW, Markup.SENDBACK, Markup.DIALOG, Markup.SIMP_TRACE)
wenzelm@50450
   348
wenzelm@50450
   349
  def active(range: Text.Range): Option[Text.Info[XML.Elem]] =
wenzelm@50500
   350
    snapshot.select_markup(range, Some(active_include), command_state =>
wenzelm@50501
   351
        {
wenzelm@50501
   352
          case Text.Info(info_range, elem @ Protocol.Dialog(_, serial, _))
wenzelm@50507
   353
          if !command_state.results.defined(serial) =>
wenzelm@52889
   354
            Some(Text.Info(snapshot.convert(info_range), elem))
wenzelm@52890
   355
          case Text.Info(info_range, elem) =>
wenzelm@52890
   356
            if (elem.name == Markup.BROWSER ||
wenzelm@52890
   357
                elem.name == Markup.GRAPHVIEW ||
lars@55316
   358
                elem.name == Markup.SENDBACK ||
lars@55316
   359
                elem.name == Markup.SIMP_TRACE)
wenzelm@52889
   360
              Some(Text.Info(snapshot.convert(info_range), elem))
wenzelm@52889
   361
            else None
wenzelm@52900
   362
        }) match { case Text.Info(_, info) :: _ => Some(info) case _ => None }
wenzelm@49492
   363
wenzelm@49492
   364
wenzelm@50502
   365
  def command_results(range: Text.Range): Command.Results =
wenzelm@50502
   366
  {
wenzelm@50502
   367
    val results =
wenzelm@50502
   368
      snapshot.select_markup[Command.Results](range, None, command_state =>
wenzelm@52889
   369
        { case _ => Some(command_state.results) }).map(_.info)
wenzelm@50507
   370
    (Command.Results.empty /: results)(_ ++ _)
wenzelm@50502
   371
  }
wenzelm@50502
   372
wenzelm@51496
   373
  def tooltip_message(range: Text.Range): Option[Text.Info[XML.Body]] =
wenzelm@49356
   374
  {
wenzelm@51496
   375
    val results =
wenzelm@51496
   376
      snapshot.cumulate_markup[List[Text.Info[Command.Results.Entry]]](range, Nil,
wenzelm@51496
   377
        Some(Set(Markup.WRITELN, Markup.WARNING, Markup.ERROR, Markup.BAD)), _ =>
wenzelm@51496
   378
        {
wenzelm@51496
   379
          case (msgs, Text.Info(info_range,
wenzelm@51496
   380
            XML.Elem(Markup(name, props @ Markup.Serial(serial)), body)))
wenzelm@51496
   381
          if name == Markup.WRITELN || name == Markup.WARNING || name == Markup.ERROR =>
wenzelm@51496
   382
            val entry: Command.Results.Entry =
wenzelm@51496
   383
              (serial -> XML.Elem(Markup(Markup.message(name), props), body))
wenzelm@52889
   384
            Some(Text.Info(snapshot.convert(info_range), entry) :: msgs)
wenzelm@51496
   385
wenzelm@51496
   386
          case (msgs, Text.Info(info_range, msg @ XML.Elem(Markup(Markup.BAD, _), body)))
wenzelm@51496
   387
          if !body.isEmpty =>
wenzelm@52530
   388
            val entry: Command.Results.Entry = (Document_ID.make(), msg)
wenzelm@52889
   389
            Some(Text.Info(snapshot.convert(info_range), entry) :: msgs)
wenzelm@52889
   390
wenzelm@52889
   391
          case _ => None
wenzelm@52900
   392
        }).flatMap(_.info)
wenzelm@51496
   393
    if (results.isEmpty) None
wenzelm@51496
   394
    else {
wenzelm@51496
   395
      val r = Text.Range(results.head.range.start, results.last.range.stop)
wenzelm@51496
   396
      val msgs = Command.Results.make(results.map(_.info))
wenzelm@51496
   397
      Some(Text.Info(r, Pretty.separate(msgs.entries.map(_._2).toList)))
wenzelm@51496
   398
    }
wenzelm@49356
   399
  }
wenzelm@49356
   400
wenzelm@49356
   401
wenzelm@49356
   402
  private val tooltips: Map[String, String] =
wenzelm@49356
   403
    Map(
wenzelm@50201
   404
      Markup.TOKEN_RANGE -> "inner syntax token",
wenzelm@50201
   405
      Markup.FREE -> "free variable",
wenzelm@50201
   406
      Markup.SKOLEM -> "skolem variable",
wenzelm@50201
   407
      Markup.BOUND -> "bound variable",
wenzelm@50201
   408
      Markup.VAR -> "schematic variable",
wenzelm@50201
   409
      Markup.TFREE -> "free type variable",
wenzelm@55552
   410
      Markup.TVAR -> "schematic type variable")
wenzelm@49356
   411
wenzelm@49356
   412
  private val tooltip_elements =
wenzelm@55552
   413
    Set(Markup.LANGUAGE, Markup.TIMING, Markup.ENTITY, Markup.SORTING,
wenzelm@55552
   414
      Markup.TYPING, Markup.ML_TYPING, Markup.PATH, Markup.URL) ++
wenzelm@55552
   415
      tooltips.keys
wenzelm@49356
   416
wenzelm@49700
   417
  private def pretty_typing(kind: String, body: XML.Body): XML.Tree =
wenzelm@49700
   418
    Pretty.block(XML.Text(kind) :: Pretty.Break(1) :: body)
wenzelm@49356
   419
wenzelm@51588
   420
  private val timing_threshold: Double = options.real("jedit_timing_threshold")
wenzelm@51588
   421
wenzelm@51496
   422
  def tooltip(range: Text.Range): Option[Text.Info[XML.Body]] =
wenzelm@49356
   423
  {
wenzelm@51588
   424
    def add(prev: Text.Info[(Timing, List[(Boolean, XML.Tree)])],
wenzelm@51588
   425
      r0: Text.Range, p: (Boolean, XML.Tree)): Text.Info[(Timing, List[(Boolean, XML.Tree)])] =
wenzelm@51496
   426
    {
wenzelm@51496
   427
      val r = snapshot.convert(r0)
wenzelm@51588
   428
      val (t, info) = prev.info
wenzelm@51588
   429
      if (prev.range == r) Text.Info(r, (t, p :: info)) else Text.Info(r, (t, List(p)))
wenzelm@51496
   430
    }
wenzelm@49356
   431
wenzelm@51496
   432
    val results =
wenzelm@51588
   433
      snapshot.cumulate_markup[Text.Info[(Timing, List[(Boolean, XML.Tree)])]](
wenzelm@51588
   434
        range, Text.Info(range, (Timing.zero, Nil)), Some(tooltip_elements), _ =>
wenzelm@49356
   435
        {
wenzelm@51588
   436
          case (Text.Info(r, (t1, info)), Text.Info(_, XML.Elem(Markup.Timing(t2), _))) =>
wenzelm@52889
   437
            Some(Text.Info(r, (t1 + t2, info)))
wenzelm@50201
   438
          case (prev, Text.Info(r, XML.Elem(Markup.Entity(kind, name), _))) =>
wenzelm@49356
   439
            val kind1 = space_explode('_', kind).mkString(" ")
wenzelm@51588
   440
            val txt1 = kind1 + " " + quote(name)
wenzelm@51588
   441
            val t = prev.info._1
wenzelm@51588
   442
            val txt2 =
wenzelm@51588
   443
              if (kind == Markup.COMMAND && t.elapsed.seconds >= timing_threshold)
wenzelm@51588
   444
                "\n" + t.message
wenzelm@51588
   445
              else ""
wenzelm@52889
   446
            Some(add(prev, r, (true, XML.Text(txt1 + txt2))))
wenzelm@50201
   447
          case (prev, Text.Info(r, XML.Elem(Markup.Path(name), _)))
wenzelm@49356
   448
          if Path.is_ok(name) =>
wenzelm@54515
   449
            val jedit_file = PIDE.thy_load.append(snapshot.node_name.master_dir, Path.explode(name))
wenzelm@52889
   450
            Some(add(prev, r, (true, XML.Text("file " + quote(jedit_file)))))
wenzelm@54702
   451
          case (prev, Text.Info(r, XML.Elem(Markup.Url(name), _))) =>
wenzelm@54702
   452
            Some(add(prev, r, (true, XML.Text("URL " + quote(name)))))
wenzelm@49674
   453
          case (prev, Text.Info(r, XML.Elem(Markup(name, _), body)))
wenzelm@50201
   454
          if name == Markup.SORTING || name == Markup.TYPING =>
wenzelm@52889
   455
            Some(add(prev, r, (true, pretty_typing("::", body))))
wenzelm@50201
   456
          case (prev, Text.Info(r, XML.Elem(Markup(Markup.ML_TYPING, _), body))) =>
wenzelm@52889
   457
            Some(add(prev, r, (false, pretty_typing("ML:", body))))
wenzelm@55615
   458
          case (prev, Text.Info(r, XML.Elem(Markup.Language(language, _), _))) =>
wenzelm@55615
   459
            Some(add(prev, r, (true, XML.Text("language: " + language))))
wenzelm@52889
   460
          case (prev, Text.Info(r, XML.Elem(Markup(name, _), _))) =>
wenzelm@52889
   461
            if (tooltips.isDefinedAt(name))
wenzelm@52889
   462
              Some(add(prev, r, (true, XML.Text(tooltips(name)))))
wenzelm@52889
   463
            else None
wenzelm@52900
   464
        }).map(_.info)
wenzelm@49356
   465
wenzelm@51588
   466
    results.map(_.info).flatMap(_._2) match {
wenzelm@51496
   467
      case Nil => None
wenzelm@51496
   468
      case tips =>
wenzelm@51496
   469
        val r = Text.Range(results.head.range.start, results.last.range.stop)
wenzelm@51496
   470
        val all_tips = (tips.filter(_._1) ++ tips.filter(!_._1).lastOption.toList).map(_._2)
wenzelm@51496
   471
        Some(Text.Info(r, Library.separate(Pretty.FBreak, all_tips)))
wenzelm@51496
   472
    }
wenzelm@49356
   473
  }
wenzelm@49356
   474
wenzelm@50554
   475
  val tooltip_margin: Int = options.int("jedit_tooltip_margin")
wenzelm@50554
   476
wenzelm@52873
   477
  lazy val tooltip_close_icon = JEdit_Lib.load_icon(options.string("tooltip_close_icon"))
wenzelm@52873
   478
  lazy val tooltip_detach_icon = JEdit_Lib.load_icon(options.string("tooltip_detach_icon"))
wenzelm@52472
   479
wenzelm@52472
   480
wenzelm@52472
   481
  private lazy val gutter_icons = Map(
wenzelm@52873
   482
    Rendering.information_pri -> JEdit_Lib.load_icon(options.string("gutter_information_icon")),
wenzelm@52873
   483
    Rendering.warning_pri -> JEdit_Lib.load_icon(options.string("gutter_warning_icon")),
wenzelm@52873
   484
    Rendering.legacy_pri -> JEdit_Lib.load_icon(options.string("gutter_legacy_icon")),
wenzelm@52873
   485
    Rendering.error_pri -> JEdit_Lib.load_icon(options.string("gutter_error_icon")))
wenzelm@49356
   486
wenzelm@52644
   487
  private val gutter_elements = Set(Markup.WRITELN, Markup.WARNING, Markup.ERROR)
wenzelm@52644
   488
wenzelm@49356
   489
  def gutter_message(range: Text.Range): Option[Icon] =
wenzelm@49356
   490
  {
wenzelm@49356
   491
    val results =
wenzelm@52644
   492
      snapshot.cumulate_markup[Int](range, 0, Some(gutter_elements), _ =>
wenzelm@49356
   493
        {
wenzelm@52644
   494
          case (pri, Text.Info(_, XML.Elem(Markup(Markup.WRITELN, _),
wenzelm@52644
   495
              List(XML.Elem(Markup(Markup.INFORMATION, _), _))))) =>
wenzelm@52889
   496
            Some(pri max Rendering.information_pri)
wenzelm@50201
   497
          case (pri, Text.Info(_, XML.Elem(Markup(Markup.WARNING, _), body))) =>
wenzelm@49356
   498
            body match {
wenzelm@50201
   499
              case List(XML.Elem(Markup(Markup.LEGACY, _), _)) =>
wenzelm@52889
   500
                Some(pri max Rendering.legacy_pri)
wenzelm@52889
   501
              case _ =>
wenzelm@52889
   502
                Some(pri max Rendering.warning_pri)
wenzelm@49356
   503
            }
wenzelm@50201
   504
          case (pri, Text.Info(_, XML.Elem(Markup(Markup.ERROR, _), _))) =>
wenzelm@52889
   505
            Some(pri max Rendering.error_pri)
wenzelm@52889
   506
          case _ => None
wenzelm@49356
   507
        })
wenzelm@49356
   508
    val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
wenzelm@52472
   509
    gutter_icons.get(pri)
wenzelm@49356
   510
  }
wenzelm@49356
   511
wenzelm@49356
   512
wenzelm@49356
   513
  private val squiggly_colors = Map(
wenzelm@50199
   514
    Rendering.writeln_pri -> writeln_color,
wenzelm@52650
   515
    Rendering.information_pri -> information_color,
wenzelm@50199
   516
    Rendering.warning_pri -> warning_color,
wenzelm@50199
   517
    Rendering.error_pri -> error_color)
wenzelm@49356
   518
wenzelm@52889
   519
  private val squiggly_include = Set(Markup.WRITELN, Markup.WARNING, Markup.ERROR)
wenzelm@52644
   520
wenzelm@52900
   521
  def squiggly_underline(range: Text.Range): List[Text.Info[Color]] =
wenzelm@49356
   522
  {
wenzelm@49356
   523
    val results =
wenzelm@52889
   524
      snapshot.cumulate_markup[Int](range, 0, Some(squiggly_include), _ =>
wenzelm@49356
   525
        {
wenzelm@52890
   526
          case (pri, Text.Info(_, elem)) =>
wenzelm@52890
   527
            if (Protocol.is_information(elem))
wenzelm@52889
   528
              Some(pri max Rendering.information_pri)
wenzelm@52890
   529
            else if (squiggly_include.contains(elem.name))
wenzelm@52890
   530
              Some(pri max Rendering.message_pri(elem.name))
wenzelm@52889
   531
            else None
wenzelm@49356
   532
        })
wenzelm@49356
   533
    for {
wenzelm@49356
   534
      Text.Info(r, pri) <- results
wenzelm@49356
   535
      color <- squiggly_colors.get(pri)
wenzelm@49356
   536
    } yield Text.Info(r, color)
wenzelm@49356
   537
  }
wenzelm@49356
   538
wenzelm@49474
   539
wenzelm@49474
   540
  private val message_colors = Map(
wenzelm@50199
   541
    Rendering.writeln_pri -> writeln_message_color,
wenzelm@52650
   542
    Rendering.information_pri -> information_message_color,
wenzelm@50199
   543
    Rendering.tracing_pri -> tracing_message_color,
wenzelm@50199
   544
    Rendering.warning_pri -> warning_message_color,
wenzelm@50199
   545
    Rendering.error_pri -> error_message_color)
wenzelm@49474
   546
wenzelm@52650
   547
  private val line_background_elements =
wenzelm@52650
   548
    Set(Markup.WRITELN_MESSAGE, Markup.TRACING_MESSAGE, Markup.WARNING_MESSAGE,
wenzelm@52650
   549
      Markup.ERROR_MESSAGE, Markup.INFORMATION)
wenzelm@52650
   550
wenzelm@49473
   551
  def line_background(range: Text.Range): Option[(Color, Boolean)] =
wenzelm@49473
   552
  {
wenzelm@49474
   553
    val results =
wenzelm@52650
   554
      snapshot.cumulate_markup[Int](range, 0, Some(line_background_elements), _ =>
wenzelm@49473
   555
        {
wenzelm@52890
   556
          case (pri, Text.Info(_, elem)) =>
wenzelm@52890
   557
            val name = elem.name
wenzelm@52890
   558
            if (name == Markup.INFORMATION)
wenzelm@52890
   559
              Some(pri max Rendering.information_pri)
wenzelm@52890
   560
            else if (name == Markup.WRITELN_MESSAGE || name == Markup.TRACING_MESSAGE ||
wenzelm@52890
   561
                elem.name == Markup.WARNING_MESSAGE || name == Markup.ERROR_MESSAGE)
wenzelm@52889
   562
              Some(pri max Rendering.message_pri(name))
wenzelm@52889
   563
            else None
wenzelm@49474
   564
        })
wenzelm@49474
   565
    val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
wenzelm@49474
   566
wenzelm@49474
   567
    val is_separator = pri > 0 &&
wenzelm@50500
   568
      snapshot.cumulate_markup[Boolean](range, false, Some(Set(Markup.SEPARATOR)), _ =>
wenzelm@49473
   569
        {
wenzelm@52890
   570
          case (_, Text.Info(_, elem)) =>
wenzelm@52890
   571
            if (elem.name == Markup.SEPARATOR) Some(true) else None
wenzelm@49473
   572
        }).exists(_.info)
wenzelm@49473
   573
wenzelm@49474
   574
    message_colors.get(pri).map((_, is_separator))
wenzelm@49473
   575
  }
wenzelm@49356
   576
wenzelm@49492
   577
wenzelm@50500
   578
  def output_messages(st: Command.State): List[XML.Tree] =
wenzelm@50507
   579
    st.results.entries.map(_._2).filterNot(Protocol.is_result(_)).toList
wenzelm@50500
   580
wenzelm@50500
   581
wenzelm@49492
   582
  private val background1_include =
wenzelm@50201
   583
    Protocol.command_status_markup + Markup.WRITELN_MESSAGE + Markup.TRACING_MESSAGE +
wenzelm@52650
   584
      Markup.WARNING_MESSAGE + Markup.ERROR_MESSAGE + Markup.BAD + Markup.INTENSIFY ++
wenzelm@52650
   585
      active_include
wenzelm@49492
   586
wenzelm@52900
   587
  def background1(range: Text.Range): List[Text.Info[Color]] =
wenzelm@49356
   588
  {
wenzelm@52900
   589
    if (snapshot.is_outdated) List(Text.Info(range, outdated_color))
wenzelm@49356
   590
    else
wenzelm@49356
   591
      for {
wenzelm@49356
   592
        Text.Info(r, result) <-
wenzelm@50500
   593
          snapshot.cumulate_markup[(Option[Protocol.Status], Option[Color])](
wenzelm@50500
   594
            range, (Some(Protocol.Status.init), None), Some(background1_include), command_state =>
wenzelm@49356
   595
            {
wenzelm@50500
   596
              case (((Some(status), color), Text.Info(_, XML.Elem(markup, _))))
wenzelm@49356
   597
              if (Protocol.command_status_markup(markup.name)) =>
wenzelm@52889
   598
                Some((Some(Protocol.command_status(status, markup)), color))
wenzelm@50500
   599
              case (_, Text.Info(_, XML.Elem(Markup(Markup.BAD, _), _))) =>
wenzelm@52889
   600
                Some((None, Some(bad_color)))
wenzelm@50500
   601
              case (_, Text.Info(_, XML.Elem(Markup(Markup.INTENSIFY, _), _))) =>
wenzelm@52889
   602
                Some((None, Some(intensify_color)))
wenzelm@52081
   603
              case (acc, Text.Info(_, Protocol.Dialog(_, serial, result))) =>
wenzelm@52081
   604
                command_state.results.get(serial) match {
wenzelm@52081
   605
                  case Some(Protocol.Dialog_Result(res)) if res == result =>
wenzelm@52889
   606
                    Some((None, Some(active_result_color)))
wenzelm@52081
   607
                  case _ =>
wenzelm@52889
   608
                    Some((None, Some(active_color)))
wenzelm@50500
   609
                }
wenzelm@52890
   610
              case (_, Text.Info(_, elem)) =>
wenzelm@52890
   611
                if (active_include(elem.name)) Some((None, Some(active_color)))
wenzelm@52889
   612
                else None
wenzelm@49356
   613
            })
wenzelm@49356
   614
        color <-
wenzelm@49356
   615
          (result match {
wenzelm@50500
   616
            case (Some(status), opt_color) =>
wenzelm@49356
   617
              if (status.is_unprocessed) Some(unprocessed1_color)
wenzelm@49356
   618
              else if (status.is_running) Some(running1_color)
wenzelm@49356
   619
              else opt_color
wenzelm@50500
   620
            case (_, opt_color) => opt_color
wenzelm@49356
   621
          })
wenzelm@49356
   622
      } yield Text.Info(r, color)
wenzelm@49356
   623
  }
wenzelm@49356
   624
wenzelm@49356
   625
wenzelm@52900
   626
  def background2(range: Text.Range): List[Text.Info[Color]] =
wenzelm@50500
   627
    snapshot.select_markup(range, Some(Set(Markup.TOKEN_RANGE)), _ =>
wenzelm@49356
   628
      {
wenzelm@52890
   629
        case Text.Info(_, elem) =>
wenzelm@52890
   630
          if (elem.name == Markup.TOKEN_RANGE) Some(light_color) else None
wenzelm@49356
   631
      })
wenzelm@49356
   632
wenzelm@49356
   633
wenzelm@52900
   634
  def bullet(range: Text.Range): List[Text.Info[Color]] =
wenzelm@51574
   635
    snapshot.select_markup(range, Some(Set(Markup.BULLET)), _ =>
wenzelm@51574
   636
      {
wenzelm@52890
   637
        case Text.Info(_, elem) =>
wenzelm@52890
   638
          if (elem.name == Markup.BULLET) Some(bullet_color) else None
wenzelm@51574
   639
      })
wenzelm@51574
   640
wenzelm@51574
   641
wenzelm@52890
   642
  private val foreground_include =
wenzelm@55526
   643
    Set(Markup.STRING, Markup.ALTSTRING, Markup.VERBATIM, Markup.CARTOUCHE, Markup.ANTIQUOTED)
wenzelm@52101
   644
wenzelm@52900
   645
  def foreground(range: Text.Range): List[Text.Info[Color]] =
wenzelm@52890
   646
    snapshot.select_markup(range, Some(foreground_include), _ =>
wenzelm@49356
   647
      {
wenzelm@52890
   648
        case Text.Info(_, elem) =>
wenzelm@55526
   649
          if (elem.name == Markup.ANTIQUOTED) Some(antiquoted_color)
wenzelm@52890
   650
          else if (foreground_include.contains(elem.name)) Some(quoted_color)
wenzelm@52890
   651
          else None
wenzelm@49356
   652
      })
wenzelm@49356
   653
wenzelm@49356
   654
wenzelm@49356
   655
  private val text_colors: Map[String, Color] = Map(
wenzelm@50201
   656
      Markup.KEYWORD1 -> keyword1_color,
wenzelm@50201
   657
      Markup.KEYWORD2 -> keyword2_color,
wenzelm@50201
   658
      Markup.STRING -> Color.BLACK,
wenzelm@50201
   659
      Markup.ALTSTRING -> Color.BLACK,
wenzelm@50201
   660
      Markup.VERBATIM -> Color.BLACK,
wenzelm@55514
   661
      Markup.CARTOUCHE -> Color.BLACK,
wenzelm@50201
   662
      Markup.LITERAL -> keyword1_color,
wenzelm@50201
   663
      Markup.DELIMITER -> Color.BLACK,
wenzelm@50201
   664
      Markup.TFREE -> tfree_color,
wenzelm@50201
   665
      Markup.TVAR -> tvar_color,
wenzelm@50201
   666
      Markup.FREE -> free_color,
wenzelm@50201
   667
      Markup.SKOLEM -> skolem_color,
wenzelm@50201
   668
      Markup.BOUND -> bound_color,
wenzelm@50201
   669
      Markup.VAR -> var_color,
wenzelm@50201
   670
      Markup.INNER_STRING -> inner_quoted_color,
wenzelm@55033
   671
      Markup.INNER_CARTOUCHE -> inner_cartouche_color,
wenzelm@50201
   672
      Markup.INNER_COMMENT -> inner_comment_color,
wenzelm@50201
   673
      Markup.DYNAMIC_FACT -> dynamic_color,
wenzelm@55526
   674
      Markup.ANTIQUOTE -> antiquote_color,
wenzelm@55505
   675
      Markup.ML_KEYWORD1 -> keyword1_color,
wenzelm@55505
   676
      Markup.ML_KEYWORD2 -> keyword2_color,
wenzelm@55505
   677
      Markup.ML_KEYWORD3 -> keyword3_color,
wenzelm@50201
   678
      Markup.ML_DELIMITER -> Color.BLACK,
wenzelm@50201
   679
      Markup.ML_NUMERAL -> inner_numeral_color,
wenzelm@50201
   680
      Markup.ML_CHAR -> inner_quoted_color,
wenzelm@50201
   681
      Markup.ML_STRING -> inner_quoted_color,
wenzelm@52101
   682
      Markup.ML_COMMENT -> inner_comment_color)
wenzelm@49356
   683
wenzelm@52102
   684
  private val text_color_elements = text_colors.keySet
wenzelm@49356
   685
wenzelm@52900
   686
  def text_color(range: Text.Range, color: Color): List[Text.Info[Color]] =
wenzelm@49356
   687
  {
wenzelm@52900
   688
    if (color == Token_Markup.hidden_color) List(Text.Info(range, color))
wenzelm@50196
   689
    else
wenzelm@50500
   690
      snapshot.cumulate_markup(range, color, Some(text_color_elements), _ =>
wenzelm@50196
   691
        {
wenzelm@52890
   692
          case (_, Text.Info(_, elem)) => text_colors.get(elem.name)
wenzelm@50196
   693
        })
wenzelm@49356
   694
  }
wenzelm@50542
   695
wenzelm@50542
   696
wenzelm@50542
   697
  /* nested text structure -- folds */
wenzelm@50542
   698
wenzelm@50545
   699
  private val fold_depth_include = Set(Markup.TEXT_FOLD, Markup.GOAL, Markup.SUBGOAL)
wenzelm@50542
   700
wenzelm@52900
   701
  def fold_depth(range: Text.Range): List[Text.Info[Int]] =
wenzelm@50542
   702
    snapshot.cumulate_markup[Int](range, 0, Some(fold_depth_include), _ =>
wenzelm@50542
   703
      {
wenzelm@52890
   704
        case (depth, Text.Info(_, elem)) =>
wenzelm@52890
   705
          if (fold_depth_include(elem.name)) Some(depth + 1) else None
wenzelm@50542
   706
      })
wenzelm@49356
   707
}