src/Tools/jEdit/src/jedit_rendering.scala
author wenzelm
Mon Jan 09 20:26:59 2017 +0100 (2017-01-09)
changeset 64854 f5aa712e6250
parent 64831 4792ee012e94
child 64877 31e9920a0dc1
permissions -rw-r--r--
tuned signature;
wenzelm@64622
     1
/*  Title:      Tools/jEdit/src/jedit_rendering.scala
wenzelm@39178
     2
    Author:     Makarius
wenzelm@39178
     3
wenzelm@64622
     4
Isabelle/jEdit-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@61175
    17
import org.gjt.sp.jedit.jEdit
wenzelm@39178
    18
wenzelm@45460
    19
import scala.collection.immutable.SortedMap
wenzelm@45460
    20
wenzelm@39178
    21
wenzelm@64621
    22
object JEdit_Rendering
wenzelm@39178
    23
{
wenzelm@64621
    24
  def apply(snapshot: Document.Snapshot, options: Options): JEdit_Rendering =
wenzelm@64621
    25
    new JEdit_Rendering(snapshot, options)
wenzelm@39178
    26
wenzelm@49356
    27
wenzelm@53230
    28
  /* popup window bounds */
wenzelm@53230
    29
wenzelm@53230
    30
  def popup_bounds: Double = (PIDE.options.real("jedit_popup_bounds") max 0.2) min 0.8
wenzelm@53230
    31
wenzelm@53230
    32
wenzelm@55501
    33
  /* Isabelle/Isar token markup */
wenzelm@39179
    34
wenzelm@39179
    35
  private val command_style: Map[String, Byte] =
wenzelm@39179
    36
  {
wenzelm@43414
    37
    import JEditToken._
wenzelm@39179
    38
    Map[String, Byte](
wenzelm@39179
    39
      Keyword.THY_END -> KEYWORD2,
wenzelm@39179
    40
      Keyword.PRF_ASM -> KEYWORD3,
wenzelm@59125
    41
      Keyword.PRF_ASM_GOAL -> KEYWORD3
wenzelm@39179
    42
    ).withDefaultValue(KEYWORD1)
wenzelm@39179
    43
  }
wenzelm@39179
    44
wenzelm@43414
    45
  private val token_style: Map[Token.Kind.Value, Byte] =
wenzelm@39179
    46
  {
wenzelm@43414
    47
    import JEditToken._
wenzelm@43414
    48
    Map[Token.Kind.Value, Byte](
wenzelm@43414
    49
      Token.Kind.KEYWORD -> KEYWORD2,
wenzelm@43414
    50
      Token.Kind.IDENT -> NULL,
wenzelm@43414
    51
      Token.Kind.LONG_IDENT -> NULL,
wenzelm@43414
    52
      Token.Kind.SYM_IDENT -> NULL,
wenzelm@43414
    53
      Token.Kind.VAR -> NULL,
wenzelm@43414
    54
      Token.Kind.TYPE_IDENT -> NULL,
wenzelm@43414
    55
      Token.Kind.TYPE_VAR -> NULL,
wenzelm@43414
    56
      Token.Kind.NAT -> NULL,
wenzelm@43414
    57
      Token.Kind.FLOAT -> NULL,
wenzelm@59081
    58
      Token.Kind.SPACE -> NULL,
wenzelm@43431
    59
      Token.Kind.STRING -> LITERAL1,
wenzelm@43431
    60
      Token.Kind.ALT_STRING -> LITERAL2,
wenzelm@43414
    61
      Token.Kind.VERBATIM -> COMMENT3,
wenzelm@55033
    62
      Token.Kind.CARTOUCHE -> COMMENT4,
wenzelm@43414
    63
      Token.Kind.COMMENT -> COMMENT1,
wenzelm@48754
    64
      Token.Kind.ERROR -> INVALID
wenzelm@39179
    65
    ).withDefaultValue(NULL)
wenzelm@39179
    66
  }
wenzelm@39179
    67
wenzelm@43414
    68
  def token_markup(syntax: Outer_Syntax, token: Token): Byte =
wenzelm@63441
    69
    if (token.is_command) command_style(syntax.keywords.kinds.getOrElse(token.content, ""))
wenzelm@61579
    70
    else if (token.is_keyword && token.source == Symbol.comment_decoded) JEditToken.NULL
wenzelm@55505
    71
    else if (token.is_delimiter) JEditToken.OPERATOR
wenzelm@43414
    72
    else token_style(token.kind)
wenzelm@55500
    73
wenzelm@55501
    74
wenzelm@55501
    75
  /* Isabelle/ML token markup */
wenzelm@55501
    76
wenzelm@55500
    77
  private val ml_token_style: Map[ML_Lex.Kind.Value, Byte] =
wenzelm@55500
    78
  {
wenzelm@55500
    79
    import JEditToken._
wenzelm@55500
    80
    Map[ML_Lex.Kind.Value, Byte](
wenzelm@55505
    81
      ML_Lex.Kind.KEYWORD -> NULL,
wenzelm@55500
    82
      ML_Lex.Kind.IDENT -> NULL,
wenzelm@55500
    83
      ML_Lex.Kind.LONG_IDENT -> NULL,
wenzelm@55500
    84
      ML_Lex.Kind.TYPE_VAR -> NULL,
wenzelm@55503
    85
      ML_Lex.Kind.WORD -> DIGIT,
wenzelm@55503
    86
      ML_Lex.Kind.INT -> DIGIT,
wenzelm@55503
    87
      ML_Lex.Kind.REAL -> DIGIT,
wenzelm@55500
    88
      ML_Lex.Kind.CHAR -> LITERAL2,
wenzelm@55500
    89
      ML_Lex.Kind.STRING -> LITERAL1,
wenzelm@55500
    90
      ML_Lex.Kind.SPACE -> NULL,
wenzelm@55500
    91
      ML_Lex.Kind.COMMENT -> COMMENT1,
wenzelm@55512
    92
      ML_Lex.Kind.ANTIQ -> NULL,
wenzelm@55512
    93
      ML_Lex.Kind.ANTIQ_START -> LITERAL4,
wenzelm@55512
    94
      ML_Lex.Kind.ANTIQ_STOP -> LITERAL4,
wenzelm@55512
    95
      ML_Lex.Kind.ANTIQ_OTHER -> NULL,
wenzelm@55514
    96
      ML_Lex.Kind.ANTIQ_STRING -> NULL,
wenzelm@55514
    97
      ML_Lex.Kind.ANTIQ_ALT_STRING -> NULL,
wenzelm@55514
    98
      ML_Lex.Kind.ANTIQ_CARTOUCHE -> NULL,
wenzelm@55500
    99
      ML_Lex.Kind.ERROR -> INVALID
wenzelm@55500
   100
    ).withDefaultValue(NULL)
wenzelm@55500
   101
  }
wenzelm@55500
   102
wenzelm@55500
   103
  def ml_token_markup(token: ML_Lex.Token): Byte =
wenzelm@55501
   104
    if (!token.is_keyword) ml_token_style(token.kind)
wenzelm@55505
   105
    else if (token.is_delimiter) JEditToken.OPERATOR
wenzelm@55505
   106
    else if (ML_Lex.keywords2(token.source)) JEditToken.KEYWORD2
wenzelm@55505
   107
    else if (ML_Lex.keywords3(token.source)) JEditToken.KEYWORD3
wenzelm@55501
   108
    else JEditToken.KEYWORD1
wenzelm@55647
   109
wenzelm@55647
   110
wenzelm@55647
   111
  /* markup elements */
wenzelm@55647
   112
wenzelm@63474
   113
  private val indentation_elements =
wenzelm@63474
   114
    Markup.Elements(Markup.Command_Indent.name)
wenzelm@63474
   115
wenzelm@56173
   116
  private val semantic_completion_elements =
wenzelm@56743
   117
    Markup.Elements(Markup.COMPLETION, Markup.NO_COMPLETION)
wenzelm@55674
   118
wenzelm@56173
   119
  private val language_context_elements =
wenzelm@59081
   120
    Markup.Elements(Markup.STRING, Markup.ALT_STRING, Markup.VERBATIM,
wenzelm@55647
   121
      Markup.CARTOUCHE, Markup.COMMENT, Markup.LANGUAGE,
wenzelm@61598
   122
      Markup.ML_STRING, Markup.ML_COMMENT)
wenzelm@55647
   123
wenzelm@56843
   124
  private val language_elements = Markup.Elements(Markup.LANGUAGE)
wenzelm@56843
   125
wenzelm@58592
   126
  private val citation_elements = Markup.Elements(Markup.CITATION)
wenzelm@58592
   127
wenzelm@60878
   128
  private val breakpoint_elements = Markup.Elements(Markup.ML_BREAKPOINT)
wenzelm@60878
   129
wenzelm@55647
   130
  private val highlight_elements =
wenzelm@58545
   131
    Markup.Elements(Markup.EXPRESSION, Markup.CITATION, Markup.LANGUAGE, Markup.ML_TYPING,
wenzelm@61718
   132
      Markup.TOKEN_RANGE, Markup.ENTITY, Markup.PATH, Markup.DOC, Markup.URL, Markup.SORTING,
wenzelm@63347
   133
      Markup.TYPING, Markup.CLASS_PARAMETER, Markup.FREE, Markup.SKOLEM, Markup.BOUND,
wenzelm@61450
   134
      Markup.VAR, Markup.TFREE, Markup.TVAR, Markup.ML_BREAKPOINT,
wenzelm@61450
   135
      Markup.MARKDOWN_PARAGRAPH, Markup.Markdown_List.name)
wenzelm@55647
   136
wenzelm@55647
   137
  private val hyperlink_elements =
wenzelm@61660
   138
    Markup.Elements(Markup.ENTITY, Markup.PATH, Markup.DOC, Markup.POSITION,
wenzelm@61660
   139
      Markup.CITATION, Markup.URL)
wenzelm@55647
   140
wenzelm@55647
   141
  private val active_elements =
wenzelm@56743
   142
    Markup.Elements(Markup.DIALOG, Markup.BROWSER, Markup.GRAPHVIEW,
wenzelm@63681
   143
      Markup.SENDBACK, Markup.JEDIT_ACTION, Markup.SIMP_TRACE_PANEL)
wenzelm@55647
   144
wenzelm@55647
   145
  private val tooltip_message_elements =
wenzelm@59203
   146
    Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR,
wenzelm@59203
   147
      Markup.BAD)
wenzelm@55647
   148
wenzelm@55647
   149
  private val gutter_elements =
wenzelm@59203
   150
    Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR)
wenzelm@55647
   151
wenzelm@55647
   152
  private val squiggly_elements =
wenzelm@59203
   153
    Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR)
wenzelm@55647
   154
wenzelm@55647
   155
  private val line_background_elements =
wenzelm@59184
   156
    Markup.Elements(Markup.WRITELN_MESSAGE, Markup.STATE_MESSAGE, Markup.INFORMATION_MESSAGE,
wenzelm@59203
   157
      Markup.TRACING_MESSAGE, Markup.WARNING_MESSAGE, Markup.LEGACY_MESSAGE,
wenzelm@59203
   158
      Markup.ERROR_MESSAGE)
wenzelm@55647
   159
wenzelm@55820
   160
  private val separator_elements =
wenzelm@56743
   161
    Markup.Elements(Markup.SEPARATOR)
wenzelm@55647
   162
wenzelm@55790
   163
  private val background_elements =
wenzelm@56395
   164
    Protocol.proper_status_elements + Markup.WRITELN_MESSAGE +
wenzelm@59184
   165
      Markup.STATE_MESSAGE + Markup.INFORMATION_MESSAGE +
wenzelm@55647
   166
      Markup.TRACING_MESSAGE + Markup.WARNING_MESSAGE +
wenzelm@59203
   167
      Markup.LEGACY_MESSAGE + Markup.ERROR_MESSAGE +
wenzelm@62986
   168
      Markup.BAD + Markup.INTENSIFY + Markup.ENTITY +
wenzelm@62986
   169
      Markup.Markdown_Item.name ++ active_elements
wenzelm@55647
   170
wenzelm@55647
   171
  private val foreground_elements =
wenzelm@59081
   172
    Markup.Elements(Markup.STRING, Markup.ALT_STRING, Markup.VERBATIM,
wenzelm@55647
   173
      Markup.CARTOUCHE, Markup.ANTIQUOTED)
wenzelm@55647
   174
wenzelm@55820
   175
  private val bullet_elements =
wenzelm@60913
   176
    Markup.Elements(Markup.BULLET, Markup.ML_BREAKPOINT)
wenzelm@55647
   177
wenzelm@55647
   178
  private val fold_depth_elements =
wenzelm@56743
   179
    Markup.Elements(Markup.TEXT_FOLD, Markup.GOAL, Markup.SUBGOAL)
wenzelm@39178
   180
}
wenzelm@49356
   181
wenzelm@49356
   182
wenzelm@64622
   183
class JEdit_Rendering(snapshot: Document.Snapshot, options: Options)
wenzelm@64622
   184
  extends Rendering(snapshot, options, PIDE.resources)
wenzelm@49356
   185
{
wenzelm@49356
   186
  /* colors */
wenzelm@49356
   187
wenzelm@49356
   188
  def color_value(s: String): Color = Color_Value(options.string(s))
wenzelm@49356
   189
wenzelm@49356
   190
  val outdated_color = color_value("outdated_color")
wenzelm@49356
   191
  val unprocessed_color = color_value("unprocessed_color")
wenzelm@49356
   192
  val unprocessed1_color = color_value("unprocessed1_color")
wenzelm@49356
   193
  val running_color = color_value("running_color")
wenzelm@49356
   194
  val running1_color = color_value("running1_color")
wenzelm@51574
   195
  val bullet_color = color_value("bullet_color")
wenzelm@49706
   196
  val tooltip_color = color_value("tooltip_color")
wenzelm@49356
   197
  val writeln_color = color_value("writeln_color")
wenzelm@52650
   198
  val information_color = color_value("information_color")
wenzelm@49356
   199
  val warning_color = color_value("warning_color")
wenzelm@59203
   200
  val legacy_color = color_value("legacy_color")
wenzelm@49356
   201
  val error_color = color_value("error_color")
wenzelm@49418
   202
  val writeln_message_color = color_value("writeln_message_color")
wenzelm@52650
   203
  val information_message_color = color_value("information_message_color")
wenzelm@49418
   204
  val tracing_message_color = color_value("tracing_message_color")
wenzelm@49418
   205
  val warning_message_color = color_value("warning_message_color")
wenzelm@59203
   206
  val legacy_message_color = color_value("legacy_message_color")
wenzelm@49418
   207
  val error_message_color = color_value("error_message_color")
wenzelm@56550
   208
  val spell_checker_color = color_value("spell_checker_color")
wenzelm@49356
   209
  val bad_color = color_value("bad_color")
wenzelm@49358
   210
  val intensify_color = color_value("intensify_color")
wenzelm@62988
   211
  val entity_color = color_value("entity_color")
wenzelm@62991
   212
  val entity_ref_color = color_value("entity_ref_color")
wenzelm@60913
   213
  val breakpoint_disabled_color = color_value("breakpoint_disabled_color")
wenzelm@60913
   214
  val breakpoint_enabled_color = color_value("breakpoint_enabled_color")
wenzelm@61011
   215
  val caret_debugger_color = color_value("caret_debugger_color")
wenzelm@49356
   216
  val quoted_color = color_value("quoted_color")
wenzelm@52101
   217
  val antiquoted_color = color_value("antiquoted_color")
wenzelm@55526
   218
  val antiquote_color = color_value("antiquote_color")
wenzelm@49358
   219
  val highlight_color = color_value("highlight_color")
wenzelm@49356
   220
  val hyperlink_color = color_value("hyperlink_color")
wenzelm@50450
   221
  val active_color = color_value("active_color")
wenzelm@50450
   222
  val active_hover_color = color_value("active_hover_color")
wenzelm@50498
   223
  val active_result_color = color_value("active_result_color")
wenzelm@49356
   224
  val keyword1_color = color_value("keyword1_color")
wenzelm@49356
   225
  val keyword2_color = color_value("keyword2_color")
wenzelm@55505
   226
  val keyword3_color = color_value("keyword3_color")
wenzelm@55919
   227
  val quasi_keyword_color = color_value("quasi_keyword_color")
wenzelm@56202
   228
  val improper_color = color_value("improper_color")
wenzelm@56064
   229
  val operator_color = color_value("operator_color")
wenzelm@55713
   230
  val caret_invisible_color = color_value("caret_invisible_color")
wenzelm@55747
   231
  val completion_color = color_value("completion_color")
wenzelm@56883
   232
  val search_color = color_value("search_color")
wenzelm@49356
   233
wenzelm@49356
   234
  val tfree_color = color_value("tfree_color")
wenzelm@49356
   235
  val tvar_color = color_value("tvar_color")
wenzelm@49356
   236
  val free_color = color_value("free_color")
wenzelm@49356
   237
  val skolem_color = color_value("skolem_color")
wenzelm@49356
   238
  val bound_color = color_value("bound_color")
wenzelm@49356
   239
  val var_color = color_value("var_color")
wenzelm@49356
   240
  val inner_numeral_color = color_value("inner_numeral_color")
wenzelm@49356
   241
  val inner_quoted_color = color_value("inner_quoted_color")
wenzelm@55033
   242
  val inner_cartouche_color = color_value("inner_cartouche_color")
wenzelm@49356
   243
  val inner_comment_color = color_value("inner_comment_color")
wenzelm@49356
   244
  val dynamic_color = color_value("dynamic_color")
wenzelm@63347
   245
  val class_parameter_color = color_value("class_parameter_color")
wenzelm@49356
   246
wenzelm@61449
   247
  val markdown_item_color1 = color_value("markdown_item_color1")
wenzelm@61449
   248
  val markdown_item_color2 = color_value("markdown_item_color2")
wenzelm@61449
   249
  val markdown_item_color3 = color_value("markdown_item_color3")
wenzelm@61449
   250
  val markdown_item_color4 = color_value("markdown_item_color4")
wenzelm@61449
   251
wenzelm@49356
   252
wenzelm@63474
   253
  /* indentation */
wenzelm@63474
   254
wenzelm@63474
   255
  def indentation(range: Text.Range): Int =
wenzelm@64621
   256
    snapshot.select(range, JEdit_Rendering.indentation_elements, _ =>
wenzelm@63474
   257
      {
wenzelm@63474
   258
        case Text.Info(_, XML.Elem(Markup.Command_Indent(i), _)) => Some(i)
wenzelm@63474
   259
        case _ => None
wenzelm@63474
   260
      }).headOption.map(_.info).getOrElse(0)
wenzelm@63474
   261
wenzelm@63474
   262
wenzelm@55674
   263
  /* completion */
wenzelm@55674
   264
wenzelm@61601
   265
  def semantic_completion(completed_range: Option[Text.Range], range: Text.Range)
wenzelm@61601
   266
      : Option[Text.Info[Completion.Semantic]] =
wenzelm@55690
   267
    if (snapshot.is_outdated) None
wenzelm@55690
   268
    else {
wenzelm@64621
   269
      snapshot.select(range, JEdit_Rendering.semantic_completion_elements, _ =>
wenzelm@55688
   270
        {
wenzelm@61601
   271
          case Completion.Semantic.Info(info) =>
wenzelm@61601
   272
            completed_range match {
wenzelm@61601
   273
              case Some(range0) if range0.contains(info.range) && range0 != info.range => None
wenzelm@61601
   274
              case _ => Some(info)
wenzelm@61601
   275
            }
wenzelm@55688
   276
          case _ => None
wenzelm@55688
   277
        }).headOption.map(_.info)
wenzelm@55674
   278
    }
wenzelm@55615
   279
wenzelm@56173
   280
  def language_context(range: Text.Range): Option[Completion.Language_Context] =
wenzelm@64621
   281
    snapshot.select(range, JEdit_Rendering.language_context_elements, _ =>
wenzelm@55690
   282
      {
wenzelm@55828
   283
        case Text.Info(_, XML.Elem(Markup.Language(language, symbols, antiquotes, delimited), _)) =>
wenzelm@55828
   284
          if (delimited) Some(Completion.Language_Context(language, symbols, antiquotes))
wenzelm@55828
   285
          else None
wenzelm@55690
   286
        case Text.Info(_, elem)
wenzelm@61598
   287
        if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT =>
wenzelm@55749
   288
          Some(Completion.Language_Context.ML_inner)
wenzelm@55690
   289
        case Text.Info(_, _) =>
wenzelm@55749
   290
          Some(Completion.Language_Context.inner)
wenzelm@55690
   291
      }).headOption.map(_.info)
wenzelm@55615
   292
wenzelm@56843
   293
  def language_path(range: Text.Range): Option[Text.Range] =
wenzelm@64621
   294
    snapshot.select(range, JEdit_Rendering.language_elements, _ =>
wenzelm@56843
   295
      {
wenzelm@56843
   296
        case Text.Info(info_range, XML.Elem(Markup.Language(Markup.Language.PATH, _, _, _), _)) =>
wenzelm@56843
   297
          Some(snapshot.convert(info_range))
wenzelm@56843
   298
        case _ => None
wenzelm@56843
   299
      }).headOption.map(_.info)
wenzelm@56843
   300
wenzelm@58592
   301
  def citation(range: Text.Range): Option[Text.Info[String]] =
wenzelm@64621
   302
    snapshot.select(range, JEdit_Rendering.citation_elements, _ =>
wenzelm@58592
   303
      {
wenzelm@58592
   304
        case Text.Info(info_range, XML.Elem(Markup.Citation(name), _)) =>
wenzelm@58592
   305
          Some(Text.Info(snapshot.convert(info_range), name))
wenzelm@58592
   306
        case _ => None
wenzelm@58592
   307
      }).headOption.map(_.info)
wenzelm@58592
   308
wenzelm@55615
   309
wenzelm@56551
   310
  /* spell checker */
wenzelm@56548
   311
wenzelm@56551
   312
  private lazy val spell_checker_elements =
wenzelm@56743
   313
    Markup.Elements(space_explode(',', options.string("spell_checker_elements")): _*)
wenzelm@56551
   314
wenzelm@56551
   315
  def spell_checker_ranges(range: Text.Range): List[Text.Range] =
wenzelm@56551
   316
    snapshot.select(range, spell_checker_elements, _ => _ => Some(())).map(_.range)
wenzelm@56548
   317
wenzelm@56564
   318
  def spell_checker_point(range: Text.Range): Option[Text.Range] =
wenzelm@56564
   319
    snapshot.select(range, spell_checker_elements, _ =>
wenzelm@56564
   320
      {
wenzelm@56564
   321
        case info => Some(snapshot.convert(info.range))
wenzelm@56564
   322
      }).headOption.map(_.info)
wenzelm@56564
   323
wenzelm@56548
   324
wenzelm@60878
   325
  /* breakpoints */
wenzelm@60878
   326
wenzelm@60880
   327
  def breakpoint(range: Text.Range): Option[(Command, Long)] =
wenzelm@60880
   328
    if (snapshot.is_outdated) None
wenzelm@60880
   329
    else
wenzelm@64621
   330
      snapshot.select(range, JEdit_Rendering.breakpoint_elements, command_states =>
wenzelm@60880
   331
        {
wenzelm@60882
   332
          case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) =>
wenzelm@60880
   333
            command_states match {
wenzelm@60882
   334
              case st :: _ => Some((st.command, breakpoint))
wenzelm@60880
   335
              case _ => None
wenzelm@60880
   336
            }
wenzelm@60880
   337
          case _ => None
wenzelm@60880
   338
        }).headOption.map(_.info)
wenzelm@60878
   339
wenzelm@60878
   340
wenzelm@55626
   341
  /* command status overview */
wenzelm@49356
   342
wenzelm@49356
   343
  def overview_color(range: Text.Range): Option[Color] =
wenzelm@49356
   344
  {
wenzelm@49356
   345
    if (snapshot.is_outdated) None
wenzelm@49356
   346
    else {
wenzelm@49356
   347
      val results =
wenzelm@56395
   348
        snapshot.cumulate[List[Markup]](range, Nil, Protocol.liberal_status_elements, _ =>
wenzelm@49356
   349
          {
wenzelm@56395
   350
            case (status, Text.Info(_, elem)) => Some(elem.markup :: status)
wenzelm@55651
   351
          }, status = true)
wenzelm@49356
   352
      if (results.isEmpty) None
wenzelm@49356
   353
      else {
wenzelm@56395
   354
        val status = Protocol.Status.make(results.iterator.flatMap(_.info))
wenzelm@49356
   355
wenzelm@50895
   356
        if (status.is_running) Some(running_color)
wenzelm@56980
   357
        else if (status.is_failed) Some(error_color)
wenzelm@56395
   358
        else if (status.is_warned) Some(warning_color)
wenzelm@49356
   359
        else if (status.is_unprocessed) Some(unprocessed_color)
wenzelm@49356
   360
        else None
wenzelm@49356
   361
      }
wenzelm@49356
   362
    }
wenzelm@49356
   363
  }
wenzelm@49356
   364
wenzelm@49356
   365
wenzelm@62986
   366
  /* caret focus */
wenzelm@62986
   367
wenzelm@62991
   368
  def entity_ref(range: Text.Range, focus: Set[Long]): List[Text.Info[Color]] =
wenzelm@64767
   369
    snapshot.select(range, Rendering.caret_focus_elements, _ =>
wenzelm@62988
   370
      {
wenzelm@62991
   371
        case Text.Info(_, XML.Elem(Markup(Markup.ENTITY, Markup.Entity.Ref(i)), _)) if focus(i) =>
wenzelm@62991
   372
          Some(entity_ref_color)
wenzelm@62988
   373
        case _ => None
wenzelm@62988
   374
      })
wenzelm@62988
   375
wenzelm@62986
   376
wenzelm@55626
   377
  /* highlighted area */
wenzelm@49356
   378
wenzelm@49358
   379
  def highlight(range: Text.Range): Option[Text.Info[Color]] =
wenzelm@64621
   380
    snapshot.select(range, JEdit_Rendering.highlight_elements, _ =>
wenzelm@55620
   381
      {
wenzelm@55620
   382
        case info => Some(Text.Info(snapshot.convert(info.range), highlight_color))
wenzelm@55689
   383
      }).headOption.map(_.info)
wenzelm@49356
   384
wenzelm@49356
   385
wenzelm@55626
   386
  /* hyperlinks */
wenzelm@55626
   387
wenzelm@52980
   388
  def hyperlink(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] =
wenzelm@49356
   389
  {
wenzelm@55651
   390
    snapshot.cumulate[Vector[Text.Info[PIDE.editor.Hyperlink]]](
wenzelm@64621
   391
      range, Vector.empty, JEdit_Rendering.hyperlink_elements, _ =>
wenzelm@49356
   392
        {
wenzelm@56458
   393
          case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _))) =>
wenzelm@64654
   394
            val file = resources.append_file(snapshot.node_name.master_dir, name)
wenzelm@64654
   395
            val link = PIDE.editor.hyperlink_file(true, file)
wenzelm@55622
   396
            Some(links :+ Text.Info(snapshot.convert(info_range), link))
wenzelm@49356
   397
wenzelm@61660
   398
          case (links, Text.Info(info_range, XML.Elem(Markup.Doc(name), _))) =>
wenzelm@61660
   399
            PIDE.editor.hyperlink_doc(name).map(link =>
wenzelm@61660
   400
              (links :+ Text.Info(snapshot.convert(info_range), link)))
wenzelm@61660
   401
wenzelm@54702
   402
          case (links, Text.Info(info_range, XML.Elem(Markup.Url(name), _))) =>
wenzelm@54702
   403
            val link = PIDE.editor.hyperlink_url(name)
wenzelm@55622
   404
            Some(links :+ Text.Info(snapshot.convert(info_range), link))
wenzelm@54702
   405
wenzelm@64660
   406
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
wenzelm@60893
   407
            val opt_link = PIDE.editor.hyperlink_def_position(true, snapshot, props)
wenzelm@60215
   408
            opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link))
wenzelm@49356
   409
wenzelm@55545
   410
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.POSITION, props), _))) =>
wenzelm@60893
   411
            val opt_link = PIDE.editor.hyperlink_position(true, snapshot, props)
wenzelm@60215
   412
            opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link))
wenzelm@52889
   413
wenzelm@58545
   414
          case (links, Text.Info(info_range, XML.Elem(Markup.Citation(name), _))) =>
wenzelm@58545
   415
            val opt_link =
wenzelm@64829
   416
              Document_Model.bibtex_entries_iterator.collectFirst(
wenzelm@64831
   417
                { case Text.Info(entry_range, (entry, model)) if entry == name =>
wenzelm@64831
   418
                    PIDE.editor.hyperlink_model(true, model, entry_range.start) })
wenzelm@60215
   419
            opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link))
wenzelm@58545
   420
wenzelm@52889
   421
          case _ => None
wenzelm@55622
   422
        }) match { case Text.Info(_, _ :+ info) :: _ => Some(info) case _ => None }
wenzelm@49356
   423
  }
wenzelm@49356
   424
wenzelm@49356
   425
wenzelm@55626
   426
  /* active elements */
wenzelm@55626
   427
wenzelm@50450
   428
  def active(range: Text.Range): Option[Text.Info[XML.Elem]] =
wenzelm@64621
   429
    snapshot.select(range, JEdit_Rendering.active_elements, command_states =>
wenzelm@55620
   430
      {
wenzelm@55620
   431
        case Text.Info(info_range, elem) =>
wenzelm@55623
   432
          if (elem.name == Markup.DIALOG) {
wenzelm@55623
   433
            elem match {
wenzelm@55623
   434
              case Protocol.Dialog(_, serial, _)
wenzelm@56354
   435
              if !command_states.exists(st => st.results.defined(serial)) =>
wenzelm@55623
   436
                Some(Text.Info(snapshot.convert(info_range), elem))
wenzelm@55623
   437
              case _ => None
wenzelm@55623
   438
            }
wenzelm@55623
   439
          }
wenzelm@55623
   440
          else Some(Text.Info(snapshot.convert(info_range), elem))
wenzelm@55689
   441
      }).headOption.map(_.info)
wenzelm@49492
   442
wenzelm@50502
   443
  def command_results(range: Text.Range): Command.Results =
wenzelm@56354
   444
    Command.State.merge_results(
wenzelm@56743
   445
      snapshot.select[List[Command.State]](range, Markup.Elements.full, command_states =>
wenzelm@56354
   446
        { case _ => Some(command_states) }).flatMap(_.info))
wenzelm@50502
   447
wenzelm@55626
   448
wenzelm@55626
   449
  /* tooltip messages */
wenzelm@55626
   450
wenzelm@51496
   451
  def tooltip_message(range: Text.Range): Option[Text.Info[XML.Body]] =
wenzelm@49356
   452
  {
wenzelm@51496
   453
    val results =
wenzelm@55651
   454
      snapshot.cumulate[List[Text.Info[Command.Results.Entry]]](
wenzelm@64621
   455
        range, Nil, JEdit_Rendering.tooltip_message_elements, _ =>
wenzelm@51496
   456
        {
wenzelm@64677
   457
          case (msgs, Text.Info(info_range,
wenzelm@64677
   458
            XML.Elem(Markup(name, props @ Markup.Serial(serial)), body)))
wenzelm@59319
   459
          if body.nonEmpty =>
wenzelm@59184
   460
            val entry: Command.Results.Entry =
wenzelm@60215
   461
              serial -> XML.Elem(Markup(Markup.message(name), props), body)
wenzelm@59184
   462
            Some(Text.Info(snapshot.convert(info_range), entry) :: msgs)
wenzelm@59184
   463
wenzelm@52889
   464
          case _ => None
wenzelm@52900
   465
        }).flatMap(_.info)
wenzelm@51496
   466
    if (results.isEmpty) None
wenzelm@51496
   467
    else {
wenzelm@51496
   468
      val r = Text.Range(results.head.range.start, results.last.range.stop)
wenzelm@51496
   469
      val msgs = Command.Results.make(results.map(_.info))
wenzelm@56372
   470
      Some(Text.Info(r, Pretty.separate(msgs.iterator.map(_._2).toList)))
wenzelm@51496
   471
    }
wenzelm@49356
   472
  }
wenzelm@49356
   473
wenzelm@49356
   474
wenzelm@55626
   475
  /* tooltips */
wenzelm@55626
   476
wenzelm@55647
   477
  def tooltip_margin: Int = options.int("jedit_tooltip_margin")
wenzelm@64622
   478
  def timing_threshold: Double = options.real("jedit_timing_threshold")
wenzelm@50554
   479
wenzelm@64748
   480
  def tooltip(range: Text.Range): Option[Text.Info[XML.Body]] =
wenzelm@64748
   481
    tooltips(range).map({ case Text.Info(r, all_tips) =>
wenzelm@64748
   482
      Text.Info(r, Library.separate(Pretty.fbrk, all_tips)) })
wenzelm@64748
   483
wenzelm@52873
   484
  lazy val tooltip_close_icon = JEdit_Lib.load_icon(options.string("tooltip_close_icon"))
wenzelm@52873
   485
  lazy val tooltip_detach_icon = JEdit_Lib.load_icon(options.string("tooltip_detach_icon"))
wenzelm@52472
   486
wenzelm@52472
   487
wenzelm@56495
   488
  /* gutter */
wenzelm@56495
   489
wenzelm@56495
   490
  private def gutter_message_pri(msg: XML.Tree): Int =
wenzelm@64676
   491
    if (Protocol.is_error(msg)) Rendering.error_pri
wenzelm@64676
   492
    else if (Protocol.is_legacy(msg)) Rendering.legacy_pri
wenzelm@64676
   493
    else if (Protocol.is_warning(msg)) Rendering.warning_pri
wenzelm@64676
   494
    else if (Protocol.is_information(msg)) Rendering.information_pri
wenzelm@56495
   495
    else 0
wenzelm@55626
   496
wenzelm@59129
   497
  private lazy val gutter_message_content = Map(
wenzelm@64676
   498
    Rendering.information_pri ->
wenzelm@59129
   499
      (JEdit_Lib.load_icon(options.string("gutter_information_icon")), information_message_color),
wenzelm@64676
   500
    Rendering.warning_pri ->
wenzelm@59129
   501
      (JEdit_Lib.load_icon(options.string("gutter_warning_icon")), warning_message_color),
wenzelm@64676
   502
    Rendering.legacy_pri ->
wenzelm@59129
   503
      (JEdit_Lib.load_icon(options.string("gutter_legacy_icon")), warning_message_color),
wenzelm@64676
   504
    Rendering.error_pri ->
wenzelm@59129
   505
      (JEdit_Lib.load_icon(options.string("gutter_error_icon")), error_message_color))
wenzelm@49356
   506
wenzelm@59129
   507
  def gutter_content(range: Text.Range): Option[(Icon, Color)] =
wenzelm@49356
   508
  {
wenzelm@56495
   509
    val pris =
wenzelm@64621
   510
      snapshot.cumulate[Int](range, 0, JEdit_Rendering.gutter_elements, _ =>
wenzelm@49356
   511
        {
wenzelm@56495
   512
          case (pri, Text.Info(_, msg @ XML.Elem(Markup(_, Markup.Serial(serial)), _))) =>
wenzelm@56495
   513
            Some(pri max gutter_message_pri(msg))
wenzelm@52889
   514
          case _ => None
wenzelm@56495
   515
        }).map(_.info)
wenzelm@56495
   516
wenzelm@59129
   517
    gutter_message_content.get((0 /: pris)(_ max _))
wenzelm@49356
   518
  }
wenzelm@49356
   519
wenzelm@49356
   520
wenzelm@55626
   521
  /* squiggly underline */
wenzelm@55626
   522
wenzelm@55647
   523
  private lazy val squiggly_colors = Map(
wenzelm@64676
   524
    Rendering.writeln_pri -> writeln_color,
wenzelm@64676
   525
    Rendering.information_pri -> information_color,
wenzelm@64676
   526
    Rendering.warning_pri -> warning_color,
wenzelm@64676
   527
    Rendering.legacy_pri -> legacy_color,
wenzelm@64676
   528
    Rendering.error_pri -> error_color)
wenzelm@49356
   529
wenzelm@52900
   530
  def squiggly_underline(range: Text.Range): List[Text.Info[Color]] =
wenzelm@49356
   531
  {
wenzelm@49356
   532
    val results =
wenzelm@64621
   533
      snapshot.cumulate[Int](range, 0, JEdit_Rendering.squiggly_elements, _ =>
wenzelm@49356
   534
        {
wenzelm@64676
   535
          case (pri, Text.Info(_, elem)) => Some(pri max Rendering.message_pri(elem.name))
wenzelm@49356
   536
        })
wenzelm@49356
   537
    for {
wenzelm@49356
   538
      Text.Info(r, pri) <- results
wenzelm@49356
   539
      color <- squiggly_colors.get(pri)
wenzelm@49356
   540
    } yield Text.Info(r, color)
wenzelm@49356
   541
  }
wenzelm@49356
   542
wenzelm@49474
   543
wenzelm@55626
   544
  /* message output */
wenzelm@55626
   545
wenzelm@55647
   546
  private lazy val message_colors = Map(
wenzelm@64676
   547
    Rendering.writeln_pri -> writeln_message_color,
wenzelm@64676
   548
    Rendering.information_pri -> information_message_color,
wenzelm@64676
   549
    Rendering.tracing_pri -> tracing_message_color,
wenzelm@64676
   550
    Rendering.warning_pri -> warning_message_color,
wenzelm@64676
   551
    Rendering.legacy_pri -> legacy_message_color,
wenzelm@64676
   552
    Rendering.error_pri -> error_message_color)
wenzelm@49474
   553
wenzelm@49473
   554
  def line_background(range: Text.Range): Option[(Color, Boolean)] =
wenzelm@49473
   555
  {
wenzelm@49474
   556
    val results =
wenzelm@64621
   557
      snapshot.cumulate[Int](range, 0, JEdit_Rendering.line_background_elements, _ =>
wenzelm@49473
   558
        {
wenzelm@64676
   559
          case (pri, Text.Info(_, elem)) => Some(pri max Rendering.message_pri(elem.name))
wenzelm@49474
   560
        })
wenzelm@49474
   561
    val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
wenzelm@49474
   562
wenzelm@61719
   563
    message_colors.get(pri).map(message_color =>
wenzelm@61719
   564
      {
wenzelm@61719
   565
        val is_separator =
wenzelm@64621
   566
          snapshot.cumulate[Boolean](range, false, JEdit_Rendering.separator_elements, _ =>
wenzelm@61719
   567
            {
wenzelm@61719
   568
              case _ => Some(true)
wenzelm@61719
   569
            }).exists(_.info)
wenzelm@61719
   570
        (message_color, is_separator)
wenzelm@61719
   571
      })
wenzelm@49473
   572
  }
wenzelm@49356
   573
wenzelm@56299
   574
  def output_messages(results: Command.Results): List[XML.Tree] =
wenzelm@57691
   575
  {
wenzelm@57691
   576
    val (states, other) =
wenzelm@57691
   577
      results.iterator.map(_._2).filterNot(Protocol.is_result(_)).toList
wenzelm@57691
   578
        .partition(Protocol.is_state(_))
wenzelm@61727
   579
    states ::: other
wenzelm@57691
   580
  }
wenzelm@50500
   581
wenzelm@50500
   582
wenzelm@55626
   583
  /* text background */
wenzelm@55626
   584
wenzelm@62986
   585
  def background(range: Text.Range, focus: Set[Long]): List[Text.Info[Color]] =
wenzelm@49356
   586
  {
wenzelm@61722
   587
    for {
wenzelm@61722
   588
      Text.Info(r, result) <-
wenzelm@61722
   589
        snapshot.cumulate[(List[Markup], Option[Color])](
wenzelm@64621
   590
          range, (List(Markup.Empty), None), JEdit_Rendering.background_elements,
wenzelm@61722
   591
          command_states =>
wenzelm@61722
   592
            {
wenzelm@61722
   593
              case (((status, color), Text.Info(_, XML.Elem(markup, _))))
wenzelm@61722
   594
              if status.nonEmpty && Protocol.proper_status_elements(markup.name) =>
wenzelm@61722
   595
                Some((markup :: status, color))
wenzelm@61722
   596
              case (_, Text.Info(_, XML.Elem(Markup(Markup.BAD, _), _))) =>
wenzelm@61722
   597
                Some((Nil, Some(bad_color)))
wenzelm@61722
   598
              case (_, Text.Info(_, XML.Elem(Markup(Markup.INTENSIFY, _), _))) =>
wenzelm@61722
   599
                Some((Nil, Some(intensify_color)))
wenzelm@62986
   600
              case (_, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
wenzelm@62986
   601
                props match {
wenzelm@62988
   602
                  case Markup.Entity.Def(i) if focus(i) => Some((Nil, Some(entity_color)))
wenzelm@62988
   603
                  case Markup.Entity.Ref(i) if focus(i) => Some((Nil, Some(entity_color)))
wenzelm@62986
   604
                  case _ => None
wenzelm@62986
   605
                }
wenzelm@61722
   606
              case (_, Text.Info(_, XML.Elem(Markup.Markdown_Item(depth), _))) =>
wenzelm@61722
   607
                val color =
wenzelm@61722
   608
                  depth match {
wenzelm@61722
   609
                    case 1 => markdown_item_color1
wenzelm@61722
   610
                    case 2 => markdown_item_color2
wenzelm@61722
   611
                    case 3 => markdown_item_color3
wenzelm@61722
   612
                    case _ => markdown_item_color4
wenzelm@55647
   613
                  }
wenzelm@61722
   614
                Some((Nil, Some(color)))
wenzelm@61722
   615
              case (acc, Text.Info(_, Protocol.Dialog(_, serial, result))) =>
wenzelm@61722
   616
                command_states.collectFirst(
wenzelm@61722
   617
                  { case st if st.results.defined(serial) => st.results.get(serial).get }) match
wenzelm@61722
   618
                {
wenzelm@61722
   619
                  case Some(Protocol.Dialog_Result(res)) if res == result =>
wenzelm@61722
   620
                    Some((Nil, Some(active_result_color)))
wenzelm@61722
   621
                  case _ =>
wenzelm@61722
   622
                    Some((Nil, Some(active_color)))
wenzelm@61722
   623
                }
wenzelm@61722
   624
              case (_, Text.Info(_, elem)) =>
wenzelm@64621
   625
                if (JEdit_Rendering.active_elements(elem.name)) Some((Nil, Some(active_color)))
wenzelm@61722
   626
                else None
wenzelm@61722
   627
            })
wenzelm@61722
   628
      color <-
wenzelm@61722
   629
        (result match {
wenzelm@61722
   630
          case (markups, opt_color) if markups.nonEmpty =>
wenzelm@61722
   631
            val status = Protocol.Status.make(markups.iterator)
wenzelm@61722
   632
            if (status.is_unprocessed) Some(unprocessed1_color)
wenzelm@61722
   633
            else if (status.is_running) Some(running1_color)
wenzelm@61722
   634
            else opt_color
wenzelm@61722
   635
          case (_, opt_color) => opt_color
wenzelm@61722
   636
        })
wenzelm@61722
   637
    } yield Text.Info(r, color)
wenzelm@49356
   638
  }
wenzelm@49356
   639
wenzelm@49356
   640
wenzelm@55626
   641
  /* text foreground */
wenzelm@51574
   642
wenzelm@52900
   643
  def foreground(range: Text.Range): List[Text.Info[Color]] =
wenzelm@64621
   644
    snapshot.select(range, JEdit_Rendering.foreground_elements, _ =>
wenzelm@49356
   645
      {
wenzelm@52890
   646
        case Text.Info(_, elem) =>
wenzelm@55620
   647
          if (elem.name == Markup.ANTIQUOTED) Some(antiquoted_color) else Some(quoted_color)
wenzelm@49356
   648
      })
wenzelm@49356
   649
wenzelm@49356
   650
wenzelm@55626
   651
  /* text color */
wenzelm@55626
   652
wenzelm@61175
   653
  val foreground_color = jEdit.getColorProperty("view.fgColor")
wenzelm@61175
   654
wenzelm@55647
   655
  private lazy val text_colors: Map[String, Color] = Map(
wenzelm@50201
   656
      Markup.KEYWORD1 -> keyword1_color,
wenzelm@50201
   657
      Markup.KEYWORD2 -> keyword2_color,
wenzelm@55765
   658
      Markup.KEYWORD3 -> keyword3_color,
wenzelm@55919
   659
      Markup.QUASI_KEYWORD -> quasi_keyword_color,
wenzelm@56202
   660
      Markup.IMPROPER -> improper_color,
wenzelm@56064
   661
      Markup.OPERATOR -> operator_color,
wenzelm@61175
   662
      Markup.STRING -> foreground_color,
wenzelm@61175
   663
      Markup.ALT_STRING -> foreground_color,
wenzelm@61175
   664
      Markup.VERBATIM -> foreground_color,
wenzelm@61175
   665
      Markup.CARTOUCHE -> foreground_color,
wenzelm@50201
   666
      Markup.LITERAL -> keyword1_color,
wenzelm@61175
   667
      Markup.DELIMITER -> foreground_color,
wenzelm@50201
   668
      Markup.TFREE -> tfree_color,
wenzelm@50201
   669
      Markup.TVAR -> tvar_color,
wenzelm@50201
   670
      Markup.FREE -> free_color,
wenzelm@50201
   671
      Markup.SKOLEM -> skolem_color,
wenzelm@50201
   672
      Markup.BOUND -> bound_color,
wenzelm@50201
   673
      Markup.VAR -> var_color,
wenzelm@50201
   674
      Markup.INNER_STRING -> inner_quoted_color,
wenzelm@55033
   675
      Markup.INNER_CARTOUCHE -> inner_cartouche_color,
wenzelm@50201
   676
      Markup.INNER_COMMENT -> inner_comment_color,
wenzelm@50201
   677
      Markup.DYNAMIC_FACT -> dynamic_color,
wenzelm@63347
   678
      Markup.CLASS_PARAMETER -> class_parameter_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@61175
   683
      Markup.ML_DELIMITER -> foreground_color,
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@56278
   687
      Markup.ML_COMMENT -> inner_comment_color,
wenzelm@56278
   688
      Markup.SML_STRING -> inner_quoted_color,
wenzelm@56278
   689
      Markup.SML_COMMENT -> inner_comment_color)
wenzelm@49356
   690
wenzelm@55820
   691
  private lazy val text_color_elements =
wenzelm@56743
   692
    Markup.Elements(text_colors.keySet)
wenzelm@49356
   693
wenzelm@52900
   694
  def text_color(range: Text.Range, color: Color): List[Text.Info[Color]] =
wenzelm@49356
   695
  {
wenzelm@52900
   696
    if (color == Token_Markup.hidden_color) List(Text.Info(range, color))
wenzelm@50196
   697
    else
wenzelm@55651
   698
      snapshot.cumulate(range, color, text_color_elements, _ =>
wenzelm@50196
   699
        {
wenzelm@52890
   700
          case (_, Text.Info(_, elem)) => text_colors.get(elem.name)
wenzelm@50196
   701
        })
wenzelm@49356
   702
  }
wenzelm@50542
   703
wenzelm@50542
   704
wenzelm@55626
   705
  /* virtual bullets */
wenzelm@55626
   706
wenzelm@55626
   707
  def bullet(range: Text.Range): List[Text.Info[Color]] =
wenzelm@64621
   708
    snapshot.select(range, JEdit_Rendering.bullet_elements, _ =>
wenzelm@60913
   709
      {
wenzelm@60913
   710
        case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) =>
wenzelm@60913
   711
          Debugger.active_breakpoint_state(breakpoint).map(b =>
wenzelm@60913
   712
            if (b) breakpoint_enabled_color else breakpoint_disabled_color)
wenzelm@60913
   713
        case _ => Some(bullet_color)
wenzelm@60913
   714
      })
wenzelm@55626
   715
wenzelm@55626
   716
wenzelm@55626
   717
  /* text folds */
wenzelm@50542
   718
wenzelm@52900
   719
  def fold_depth(range: Text.Range): List[Text.Info[Int]] =
wenzelm@64621
   720
    snapshot.cumulate[Int](range, 0, JEdit_Rendering.fold_depth_elements, _ =>
wenzelm@50542
   721
      {
wenzelm@55620
   722
        case (depth, _) => Some(depth + 1)
wenzelm@50542
   723
      })
wenzelm@49356
   724
}