src/Tools/jEdit/src/jedit_rendering.scala
changeset 64621 7116f2634e32
parent 63681 d2448471ffba
child 64622 529bbb8977c7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Tools/jEdit/src/jedit_rendering.scala	Tue Dec 20 21:35:56 2016 +0100
     1.3 @@ -0,0 +1,923 @@
     1.4 +/*  Title:      Tools/jEdit/src/rendering.scala
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +Isabelle-specific implementation of quasi-abstract rendering and
     1.8 +markup interpretation.
     1.9 +*/
    1.10 +
    1.11 +package isabelle.jedit
    1.12 +
    1.13 +
    1.14 +import isabelle._
    1.15 +
    1.16 +import java.awt.Color
    1.17 +import javax.swing.Icon
    1.18 +
    1.19 +import org.gjt.sp.jedit.syntax.{Token => JEditToken}
    1.20 +import org.gjt.sp.jedit.jEdit
    1.21 +
    1.22 +import scala.collection.immutable.SortedMap
    1.23 +
    1.24 +
    1.25 +object JEdit_Rendering
    1.26 +{
    1.27 +  def apply(snapshot: Document.Snapshot, options: Options): JEdit_Rendering =
    1.28 +    new JEdit_Rendering(snapshot, options)
    1.29 +
    1.30 +
    1.31 +  /* message priorities */
    1.32 +
    1.33 +  private val state_pri = 1
    1.34 +  private val writeln_pri = 2
    1.35 +  private val information_pri = 3
    1.36 +  private val tracing_pri = 4
    1.37 +  private val warning_pri = 5
    1.38 +  private val legacy_pri = 6
    1.39 +  private val error_pri = 7
    1.40 +
    1.41 +  private val message_pri = Map(
    1.42 +    Markup.STATE -> state_pri,
    1.43 +    Markup.STATE_MESSAGE -> state_pri,
    1.44 +    Markup.WRITELN -> writeln_pri,
    1.45 +    Markup.WRITELN_MESSAGE -> writeln_pri,
    1.46 +    Markup.INFORMATION -> information_pri,
    1.47 +    Markup.INFORMATION_MESSAGE -> information_pri,
    1.48 +    Markup.TRACING -> tracing_pri,
    1.49 +    Markup.TRACING_MESSAGE -> tracing_pri,
    1.50 +    Markup.WARNING -> warning_pri,
    1.51 +    Markup.WARNING_MESSAGE -> warning_pri,
    1.52 +    Markup.LEGACY -> legacy_pri,
    1.53 +    Markup.LEGACY_MESSAGE -> legacy_pri,
    1.54 +    Markup.ERROR -> error_pri,
    1.55 +    Markup.ERROR_MESSAGE -> error_pri)
    1.56 +
    1.57 +
    1.58 +  /* popup window bounds */
    1.59 +
    1.60 +  def popup_bounds: Double = (PIDE.options.real("jedit_popup_bounds") max 0.2) min 0.8
    1.61 +
    1.62 +
    1.63 +  /* Isabelle/Isar token markup */
    1.64 +
    1.65 +  private val command_style: Map[String, Byte] =
    1.66 +  {
    1.67 +    import JEditToken._
    1.68 +    Map[String, Byte](
    1.69 +      Keyword.THY_END -> KEYWORD2,
    1.70 +      Keyword.PRF_ASM -> KEYWORD3,
    1.71 +      Keyword.PRF_ASM_GOAL -> KEYWORD3
    1.72 +    ).withDefaultValue(KEYWORD1)
    1.73 +  }
    1.74 +
    1.75 +  private val token_style: Map[Token.Kind.Value, Byte] =
    1.76 +  {
    1.77 +    import JEditToken._
    1.78 +    Map[Token.Kind.Value, Byte](
    1.79 +      Token.Kind.KEYWORD -> KEYWORD2,
    1.80 +      Token.Kind.IDENT -> NULL,
    1.81 +      Token.Kind.LONG_IDENT -> NULL,
    1.82 +      Token.Kind.SYM_IDENT -> NULL,
    1.83 +      Token.Kind.VAR -> NULL,
    1.84 +      Token.Kind.TYPE_IDENT -> NULL,
    1.85 +      Token.Kind.TYPE_VAR -> NULL,
    1.86 +      Token.Kind.NAT -> NULL,
    1.87 +      Token.Kind.FLOAT -> NULL,
    1.88 +      Token.Kind.SPACE -> NULL,
    1.89 +      Token.Kind.STRING -> LITERAL1,
    1.90 +      Token.Kind.ALT_STRING -> LITERAL2,
    1.91 +      Token.Kind.VERBATIM -> COMMENT3,
    1.92 +      Token.Kind.CARTOUCHE -> COMMENT4,
    1.93 +      Token.Kind.COMMENT -> COMMENT1,
    1.94 +      Token.Kind.ERROR -> INVALID
    1.95 +    ).withDefaultValue(NULL)
    1.96 +  }
    1.97 +
    1.98 +  def token_markup(syntax: Outer_Syntax, token: Token): Byte =
    1.99 +    if (token.is_command) command_style(syntax.keywords.kinds.getOrElse(token.content, ""))
   1.100 +    else if (token.is_keyword && token.source == Symbol.comment_decoded) JEditToken.NULL
   1.101 +    else if (token.is_delimiter) JEditToken.OPERATOR
   1.102 +    else token_style(token.kind)
   1.103 +
   1.104 +
   1.105 +  /* Isabelle/ML token markup */
   1.106 +
   1.107 +  private val ml_token_style: Map[ML_Lex.Kind.Value, Byte] =
   1.108 +  {
   1.109 +    import JEditToken._
   1.110 +    Map[ML_Lex.Kind.Value, Byte](
   1.111 +      ML_Lex.Kind.KEYWORD -> NULL,
   1.112 +      ML_Lex.Kind.IDENT -> NULL,
   1.113 +      ML_Lex.Kind.LONG_IDENT -> NULL,
   1.114 +      ML_Lex.Kind.TYPE_VAR -> NULL,
   1.115 +      ML_Lex.Kind.WORD -> DIGIT,
   1.116 +      ML_Lex.Kind.INT -> DIGIT,
   1.117 +      ML_Lex.Kind.REAL -> DIGIT,
   1.118 +      ML_Lex.Kind.CHAR -> LITERAL2,
   1.119 +      ML_Lex.Kind.STRING -> LITERAL1,
   1.120 +      ML_Lex.Kind.SPACE -> NULL,
   1.121 +      ML_Lex.Kind.COMMENT -> COMMENT1,
   1.122 +      ML_Lex.Kind.ANTIQ -> NULL,
   1.123 +      ML_Lex.Kind.ANTIQ_START -> LITERAL4,
   1.124 +      ML_Lex.Kind.ANTIQ_STOP -> LITERAL4,
   1.125 +      ML_Lex.Kind.ANTIQ_OTHER -> NULL,
   1.126 +      ML_Lex.Kind.ANTIQ_STRING -> NULL,
   1.127 +      ML_Lex.Kind.ANTIQ_ALT_STRING -> NULL,
   1.128 +      ML_Lex.Kind.ANTIQ_CARTOUCHE -> NULL,
   1.129 +      ML_Lex.Kind.ERROR -> INVALID
   1.130 +    ).withDefaultValue(NULL)
   1.131 +  }
   1.132 +
   1.133 +  def ml_token_markup(token: ML_Lex.Token): Byte =
   1.134 +    if (!token.is_keyword) ml_token_style(token.kind)
   1.135 +    else if (token.is_delimiter) JEditToken.OPERATOR
   1.136 +    else if (ML_Lex.keywords2(token.source)) JEditToken.KEYWORD2
   1.137 +    else if (ML_Lex.keywords3(token.source)) JEditToken.KEYWORD3
   1.138 +    else JEditToken.KEYWORD1
   1.139 +
   1.140 +
   1.141 +  /* markup elements */
   1.142 +
   1.143 +  private val indentation_elements =
   1.144 +    Markup.Elements(Markup.Command_Indent.name)
   1.145 +
   1.146 +  private val semantic_completion_elements =
   1.147 +    Markup.Elements(Markup.COMPLETION, Markup.NO_COMPLETION)
   1.148 +
   1.149 +  private val language_context_elements =
   1.150 +    Markup.Elements(Markup.STRING, Markup.ALT_STRING, Markup.VERBATIM,
   1.151 +      Markup.CARTOUCHE, Markup.COMMENT, Markup.LANGUAGE,
   1.152 +      Markup.ML_STRING, Markup.ML_COMMENT)
   1.153 +
   1.154 +  private val language_elements = Markup.Elements(Markup.LANGUAGE)
   1.155 +
   1.156 +  private val citation_elements = Markup.Elements(Markup.CITATION)
   1.157 +
   1.158 +  private val breakpoint_elements = Markup.Elements(Markup.ML_BREAKPOINT)
   1.159 +
   1.160 +  private val caret_focus_elements = Markup.Elements(Markup.ENTITY)
   1.161 +
   1.162 +  private val highlight_elements =
   1.163 +    Markup.Elements(Markup.EXPRESSION, Markup.CITATION, Markup.LANGUAGE, Markup.ML_TYPING,
   1.164 +      Markup.TOKEN_RANGE, Markup.ENTITY, Markup.PATH, Markup.DOC, Markup.URL, Markup.SORTING,
   1.165 +      Markup.TYPING, Markup.CLASS_PARAMETER, Markup.FREE, Markup.SKOLEM, Markup.BOUND,
   1.166 +      Markup.VAR, Markup.TFREE, Markup.TVAR, Markup.ML_BREAKPOINT,
   1.167 +      Markup.MARKDOWN_PARAGRAPH, Markup.Markdown_List.name)
   1.168 +
   1.169 +  private val hyperlink_elements =
   1.170 +    Markup.Elements(Markup.ENTITY, Markup.PATH, Markup.DOC, Markup.POSITION,
   1.171 +      Markup.CITATION, Markup.URL)
   1.172 +
   1.173 +  private val active_elements =
   1.174 +    Markup.Elements(Markup.DIALOG, Markup.BROWSER, Markup.GRAPHVIEW,
   1.175 +      Markup.SENDBACK, Markup.JEDIT_ACTION, Markup.SIMP_TRACE_PANEL)
   1.176 +
   1.177 +  private val tooltip_message_elements =
   1.178 +    Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR,
   1.179 +      Markup.BAD)
   1.180 +
   1.181 +  private val tooltip_descriptions =
   1.182 +    Map(
   1.183 +      Markup.CITATION -> "citation",
   1.184 +      Markup.TOKEN_RANGE -> "inner syntax token",
   1.185 +      Markup.FREE -> "free variable",
   1.186 +      Markup.SKOLEM -> "skolem variable",
   1.187 +      Markup.BOUND -> "bound variable",
   1.188 +      Markup.VAR -> "schematic variable",
   1.189 +      Markup.TFREE -> "free type variable",
   1.190 +      Markup.TVAR -> "schematic type variable")
   1.191 +
   1.192 +  private val tooltip_elements =
   1.193 +    Markup.Elements(Markup.LANGUAGE, Markup.EXPRESSION, Markup.TIMING, Markup.ENTITY,
   1.194 +      Markup.SORTING, Markup.TYPING, Markup.CLASS_PARAMETER, Markup.ML_TYPING,
   1.195 +      Markup.ML_BREAKPOINT, Markup.PATH, Markup.DOC, Markup.URL, Markup.MARKDOWN_PARAGRAPH,
   1.196 +      Markup.Markdown_List.name) ++ Markup.Elements(tooltip_descriptions.keySet)
   1.197 +
   1.198 +  private val gutter_elements =
   1.199 +    Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR)
   1.200 +
   1.201 +  private val squiggly_elements =
   1.202 +    Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR)
   1.203 +
   1.204 +  private val line_background_elements =
   1.205 +    Markup.Elements(Markup.WRITELN_MESSAGE, Markup.STATE_MESSAGE, Markup.INFORMATION_MESSAGE,
   1.206 +      Markup.TRACING_MESSAGE, Markup.WARNING_MESSAGE, Markup.LEGACY_MESSAGE,
   1.207 +      Markup.ERROR_MESSAGE)
   1.208 +
   1.209 +  private val separator_elements =
   1.210 +    Markup.Elements(Markup.SEPARATOR)
   1.211 +
   1.212 +  private val background_elements =
   1.213 +    Protocol.proper_status_elements + Markup.WRITELN_MESSAGE +
   1.214 +      Markup.STATE_MESSAGE + Markup.INFORMATION_MESSAGE +
   1.215 +      Markup.TRACING_MESSAGE + Markup.WARNING_MESSAGE +
   1.216 +      Markup.LEGACY_MESSAGE + Markup.ERROR_MESSAGE +
   1.217 +      Markup.BAD + Markup.INTENSIFY + Markup.ENTITY +
   1.218 +      Markup.Markdown_Item.name ++ active_elements
   1.219 +
   1.220 +  private val foreground_elements =
   1.221 +    Markup.Elements(Markup.STRING, Markup.ALT_STRING, Markup.VERBATIM,
   1.222 +      Markup.CARTOUCHE, Markup.ANTIQUOTED)
   1.223 +
   1.224 +  private val bullet_elements =
   1.225 +    Markup.Elements(Markup.BULLET, Markup.ML_BREAKPOINT)
   1.226 +
   1.227 +  private val fold_depth_elements =
   1.228 +    Markup.Elements(Markup.TEXT_FOLD, Markup.GOAL, Markup.SUBGOAL)
   1.229 +}
   1.230 +
   1.231 +
   1.232 +class JEdit_Rendering private(val snapshot: Document.Snapshot, val options: Options)
   1.233 +{
   1.234 +  override def toString: String = "Rendering(" + snapshot.toString + ")"
   1.235 +
   1.236 +
   1.237 +  /* colors */
   1.238 +
   1.239 +  def color_value(s: String): Color = Color_Value(options.string(s))
   1.240 +
   1.241 +  val outdated_color = color_value("outdated_color")
   1.242 +  val unprocessed_color = color_value("unprocessed_color")
   1.243 +  val unprocessed1_color = color_value("unprocessed1_color")
   1.244 +  val running_color = color_value("running_color")
   1.245 +  val running1_color = color_value("running1_color")
   1.246 +  val bullet_color = color_value("bullet_color")
   1.247 +  val tooltip_color = color_value("tooltip_color")
   1.248 +  val writeln_color = color_value("writeln_color")
   1.249 +  val information_color = color_value("information_color")
   1.250 +  val warning_color = color_value("warning_color")
   1.251 +  val legacy_color = color_value("legacy_color")
   1.252 +  val error_color = color_value("error_color")
   1.253 +  val writeln_message_color = color_value("writeln_message_color")
   1.254 +  val information_message_color = color_value("information_message_color")
   1.255 +  val tracing_message_color = color_value("tracing_message_color")
   1.256 +  val warning_message_color = color_value("warning_message_color")
   1.257 +  val legacy_message_color = color_value("legacy_message_color")
   1.258 +  val error_message_color = color_value("error_message_color")
   1.259 +  val spell_checker_color = color_value("spell_checker_color")
   1.260 +  val bad_color = color_value("bad_color")
   1.261 +  val intensify_color = color_value("intensify_color")
   1.262 +  val entity_color = color_value("entity_color")
   1.263 +  val entity_ref_color = color_value("entity_ref_color")
   1.264 +  val breakpoint_disabled_color = color_value("breakpoint_disabled_color")
   1.265 +  val breakpoint_enabled_color = color_value("breakpoint_enabled_color")
   1.266 +  val caret_debugger_color = color_value("caret_debugger_color")
   1.267 +  val quoted_color = color_value("quoted_color")
   1.268 +  val antiquoted_color = color_value("antiquoted_color")
   1.269 +  val antiquote_color = color_value("antiquote_color")
   1.270 +  val highlight_color = color_value("highlight_color")
   1.271 +  val hyperlink_color = color_value("hyperlink_color")
   1.272 +  val active_color = color_value("active_color")
   1.273 +  val active_hover_color = color_value("active_hover_color")
   1.274 +  val active_result_color = color_value("active_result_color")
   1.275 +  val keyword1_color = color_value("keyword1_color")
   1.276 +  val keyword2_color = color_value("keyword2_color")
   1.277 +  val keyword3_color = color_value("keyword3_color")
   1.278 +  val quasi_keyword_color = color_value("quasi_keyword_color")
   1.279 +  val improper_color = color_value("improper_color")
   1.280 +  val operator_color = color_value("operator_color")
   1.281 +  val caret_invisible_color = color_value("caret_invisible_color")
   1.282 +  val completion_color = color_value("completion_color")
   1.283 +  val search_color = color_value("search_color")
   1.284 +
   1.285 +  val tfree_color = color_value("tfree_color")
   1.286 +  val tvar_color = color_value("tvar_color")
   1.287 +  val free_color = color_value("free_color")
   1.288 +  val skolem_color = color_value("skolem_color")
   1.289 +  val bound_color = color_value("bound_color")
   1.290 +  val var_color = color_value("var_color")
   1.291 +  val inner_numeral_color = color_value("inner_numeral_color")
   1.292 +  val inner_quoted_color = color_value("inner_quoted_color")
   1.293 +  val inner_cartouche_color = color_value("inner_cartouche_color")
   1.294 +  val inner_comment_color = color_value("inner_comment_color")
   1.295 +  val dynamic_color = color_value("dynamic_color")
   1.296 +  val class_parameter_color = color_value("class_parameter_color")
   1.297 +
   1.298 +  val markdown_item_color1 = color_value("markdown_item_color1")
   1.299 +  val markdown_item_color2 = color_value("markdown_item_color2")
   1.300 +  val markdown_item_color3 = color_value("markdown_item_color3")
   1.301 +  val markdown_item_color4 = color_value("markdown_item_color4")
   1.302 +
   1.303 +
   1.304 +  /* indentation */
   1.305 +
   1.306 +  def indentation(range: Text.Range): Int =
   1.307 +    snapshot.select(range, JEdit_Rendering.indentation_elements, _ =>
   1.308 +      {
   1.309 +        case Text.Info(_, XML.Elem(Markup.Command_Indent(i), _)) => Some(i)
   1.310 +        case _ => None
   1.311 +      }).headOption.map(_.info).getOrElse(0)
   1.312 +
   1.313 +
   1.314 +  /* completion */
   1.315 +
   1.316 +  def semantic_completion(completed_range: Option[Text.Range], range: Text.Range)
   1.317 +      : Option[Text.Info[Completion.Semantic]] =
   1.318 +    if (snapshot.is_outdated) None
   1.319 +    else {
   1.320 +      snapshot.select(range, JEdit_Rendering.semantic_completion_elements, _ =>
   1.321 +        {
   1.322 +          case Completion.Semantic.Info(info) =>
   1.323 +            completed_range match {
   1.324 +              case Some(range0) if range0.contains(info.range) && range0 != info.range => None
   1.325 +              case _ => Some(info)
   1.326 +            }
   1.327 +          case _ => None
   1.328 +        }).headOption.map(_.info)
   1.329 +    }
   1.330 +
   1.331 +  def language_context(range: Text.Range): Option[Completion.Language_Context] =
   1.332 +    snapshot.select(range, JEdit_Rendering.language_context_elements, _ =>
   1.333 +      {
   1.334 +        case Text.Info(_, XML.Elem(Markup.Language(language, symbols, antiquotes, delimited), _)) =>
   1.335 +          if (delimited) Some(Completion.Language_Context(language, symbols, antiquotes))
   1.336 +          else None
   1.337 +        case Text.Info(_, elem)
   1.338 +        if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT =>
   1.339 +          Some(Completion.Language_Context.ML_inner)
   1.340 +        case Text.Info(_, _) =>
   1.341 +          Some(Completion.Language_Context.inner)
   1.342 +      }).headOption.map(_.info)
   1.343 +
   1.344 +  def language_path(range: Text.Range): Option[Text.Range] =
   1.345 +    snapshot.select(range, JEdit_Rendering.language_elements, _ =>
   1.346 +      {
   1.347 +        case Text.Info(info_range, XML.Elem(Markup.Language(Markup.Language.PATH, _, _, _), _)) =>
   1.348 +          Some(snapshot.convert(info_range))
   1.349 +        case _ => None
   1.350 +      }).headOption.map(_.info)
   1.351 +
   1.352 +  def citation(range: Text.Range): Option[Text.Info[String]] =
   1.353 +    snapshot.select(range, JEdit_Rendering.citation_elements, _ =>
   1.354 +      {
   1.355 +        case Text.Info(info_range, XML.Elem(Markup.Citation(name), _)) =>
   1.356 +          Some(Text.Info(snapshot.convert(info_range), name))
   1.357 +        case _ => None
   1.358 +      }).headOption.map(_.info)
   1.359 +
   1.360 +
   1.361 +  /* spell checker */
   1.362 +
   1.363 +  private lazy val spell_checker_elements =
   1.364 +    Markup.Elements(space_explode(',', options.string("spell_checker_elements")): _*)
   1.365 +
   1.366 +  def spell_checker_ranges(range: Text.Range): List[Text.Range] =
   1.367 +    snapshot.select(range, spell_checker_elements, _ => _ => Some(())).map(_.range)
   1.368 +
   1.369 +  def spell_checker_point(range: Text.Range): Option[Text.Range] =
   1.370 +    snapshot.select(range, spell_checker_elements, _ =>
   1.371 +      {
   1.372 +        case info => Some(snapshot.convert(info.range))
   1.373 +      }).headOption.map(_.info)
   1.374 +
   1.375 +
   1.376 +  /* breakpoints */
   1.377 +
   1.378 +  def breakpoint(range: Text.Range): Option[(Command, Long)] =
   1.379 +    if (snapshot.is_outdated) None
   1.380 +    else
   1.381 +      snapshot.select(range, JEdit_Rendering.breakpoint_elements, command_states =>
   1.382 +        {
   1.383 +          case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) =>
   1.384 +            command_states match {
   1.385 +              case st :: _ => Some((st.command, breakpoint))
   1.386 +              case _ => None
   1.387 +            }
   1.388 +          case _ => None
   1.389 +        }).headOption.map(_.info)
   1.390 +
   1.391 +
   1.392 +  /* command status overview */
   1.393 +
   1.394 +  def overview_color(range: Text.Range): Option[Color] =
   1.395 +  {
   1.396 +    if (snapshot.is_outdated) None
   1.397 +    else {
   1.398 +      val results =
   1.399 +        snapshot.cumulate[List[Markup]](range, Nil, Protocol.liberal_status_elements, _ =>
   1.400 +          {
   1.401 +            case (status, Text.Info(_, elem)) => Some(elem.markup :: status)
   1.402 +          }, status = true)
   1.403 +      if (results.isEmpty) None
   1.404 +      else {
   1.405 +        val status = Protocol.Status.make(results.iterator.flatMap(_.info))
   1.406 +
   1.407 +        if (status.is_running) Some(running_color)
   1.408 +        else if (status.is_failed) Some(error_color)
   1.409 +        else if (status.is_warned) Some(warning_color)
   1.410 +        else if (status.is_unprocessed) Some(unprocessed_color)
   1.411 +        else None
   1.412 +      }
   1.413 +    }
   1.414 +  }
   1.415 +
   1.416 +
   1.417 +  /* caret focus */
   1.418 +
   1.419 +  def entity_focus(range: Text.Range,
   1.420 +    check: (Boolean, Long) => Boolean = (is_def: Boolean, i: Long) => is_def): Set[Long] =
   1.421 +  {
   1.422 +    val results =
   1.423 +      snapshot.cumulate[Set[Long]](range, Set.empty, JEdit_Rendering.caret_focus_elements, _ =>
   1.424 +          {
   1.425 +            case (serials, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
   1.426 +              props match {
   1.427 +                case Markup.Entity.Def(i) if check(true, i) => Some(serials + i)
   1.428 +                case Markup.Entity.Ref(i) if check(false, i) => Some(serials + i)
   1.429 +                case _ => None
   1.430 +              }
   1.431 +            case _ => None
   1.432 +          })
   1.433 +    (Set.empty[Long] /: results){ case (s1, Text.Info(_, s2)) => s1 ++ s2 }
   1.434 +  }
   1.435 +
   1.436 +  def caret_focus(caret_range: Text.Range, visible_range: Text.Range): Set[Long] =
   1.437 +  {
   1.438 +    val focus_defs = entity_focus(caret_range)
   1.439 +    if (focus_defs.nonEmpty) focus_defs
   1.440 +    else {
   1.441 +      val visible_defs = entity_focus(visible_range)
   1.442 +      entity_focus(caret_range, (is_def: Boolean, i: Long) => !is_def && visible_defs.contains(i))
   1.443 +    }
   1.444 +  }
   1.445 +
   1.446 +  def caret_focus_ranges(caret_range: Text.Range, visible_range: Text.Range): List[Text.Range] =
   1.447 +  {
   1.448 +    val focus = caret_focus(caret_range, visible_range)
   1.449 +    if (focus.nonEmpty) {
   1.450 +      val results =
   1.451 +        snapshot.cumulate[Boolean](visible_range, false, JEdit_Rendering.caret_focus_elements, _ =>
   1.452 +          {
   1.453 +            case (_, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
   1.454 +              props match {
   1.455 +                case Markup.Entity.Def(i) if focus(i) => Some(true)
   1.456 +                case Markup.Entity.Ref(i) if focus(i) => Some(true)
   1.457 +                case _ => None
   1.458 +              }
   1.459 +          })
   1.460 +      for (info <- results if info.info) yield info.range
   1.461 +    }
   1.462 +    else Nil
   1.463 +  }
   1.464 +
   1.465 +  def entity_ref(range: Text.Range, focus: Set[Long]): List[Text.Info[Color]] =
   1.466 +    snapshot.select(range, JEdit_Rendering.caret_focus_elements, _ =>
   1.467 +      {
   1.468 +        case Text.Info(_, XML.Elem(Markup(Markup.ENTITY, Markup.Entity.Ref(i)), _)) if focus(i) =>
   1.469 +          Some(entity_ref_color)
   1.470 +        case _ => None
   1.471 +      })
   1.472 +
   1.473 +
   1.474 +  /* highlighted area */
   1.475 +
   1.476 +  def highlight(range: Text.Range): Option[Text.Info[Color]] =
   1.477 +    snapshot.select(range, JEdit_Rendering.highlight_elements, _ =>
   1.478 +      {
   1.479 +        case info => Some(Text.Info(snapshot.convert(info.range), highlight_color))
   1.480 +      }).headOption.map(_.info)
   1.481 +
   1.482 +
   1.483 +  /* hyperlinks */
   1.484 +
   1.485 +  private def jedit_file(name: String): String =
   1.486 +    if (Path.is_valid(name))
   1.487 +      PIDE.resources.append(snapshot.node_name.master_dir, Path.explode(name))
   1.488 +    else name
   1.489 +
   1.490 +  def hyperlink(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] =
   1.491 +  {
   1.492 +    snapshot.cumulate[Vector[Text.Info[PIDE.editor.Hyperlink]]](
   1.493 +      range, Vector.empty, JEdit_Rendering.hyperlink_elements, _ =>
   1.494 +        {
   1.495 +          case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _))) =>
   1.496 +            val link = PIDE.editor.hyperlink_file(true, jedit_file(name))
   1.497 +            Some(links :+ Text.Info(snapshot.convert(info_range), link))
   1.498 +
   1.499 +          case (links, Text.Info(info_range, XML.Elem(Markup.Doc(name), _))) =>
   1.500 +            PIDE.editor.hyperlink_doc(name).map(link =>
   1.501 +              (links :+ Text.Info(snapshot.convert(info_range), link)))
   1.502 +
   1.503 +          case (links, Text.Info(info_range, XML.Elem(Markup.Url(name), _))) =>
   1.504 +            val link = PIDE.editor.hyperlink_url(name)
   1.505 +            Some(links :+ Text.Info(snapshot.convert(info_range), link))
   1.506 +
   1.507 +          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _)))
   1.508 +          if !props.exists(
   1.509 +            { case (Markup.KIND, Markup.ML_OPEN) => true
   1.510 +              case (Markup.KIND, Markup.ML_STRUCTURE) => true
   1.511 +              case _ => false }) =>
   1.512 +            val opt_link = PIDE.editor.hyperlink_def_position(true, snapshot, props)
   1.513 +            opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link))
   1.514 +
   1.515 +          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.POSITION, props), _))) =>
   1.516 +            val opt_link = PIDE.editor.hyperlink_position(true, snapshot, props)
   1.517 +            opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link))
   1.518 +
   1.519 +          case (links, Text.Info(info_range, XML.Elem(Markup.Citation(name), _))) =>
   1.520 +            val opt_link =
   1.521 +              Bibtex_JEdit.entries_iterator.collectFirst(
   1.522 +                { case (a, buffer, offset) if a == name =>
   1.523 +                    PIDE.editor.hyperlink_buffer(true, buffer, offset) })
   1.524 +            opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link))
   1.525 +
   1.526 +          case _ => None
   1.527 +        }) match { case Text.Info(_, _ :+ info) :: _ => Some(info) case _ => None }
   1.528 +  }
   1.529 +
   1.530 +
   1.531 +  /* active elements */
   1.532 +
   1.533 +  def active(range: Text.Range): Option[Text.Info[XML.Elem]] =
   1.534 +    snapshot.select(range, JEdit_Rendering.active_elements, command_states =>
   1.535 +      {
   1.536 +        case Text.Info(info_range, elem) =>
   1.537 +          if (elem.name == Markup.DIALOG) {
   1.538 +            elem match {
   1.539 +              case Protocol.Dialog(_, serial, _)
   1.540 +              if !command_states.exists(st => st.results.defined(serial)) =>
   1.541 +                Some(Text.Info(snapshot.convert(info_range), elem))
   1.542 +              case _ => None
   1.543 +            }
   1.544 +          }
   1.545 +          else Some(Text.Info(snapshot.convert(info_range), elem))
   1.546 +      }).headOption.map(_.info)
   1.547 +
   1.548 +  def command_results(range: Text.Range): Command.Results =
   1.549 +    Command.State.merge_results(
   1.550 +      snapshot.select[List[Command.State]](range, Markup.Elements.full, command_states =>
   1.551 +        { case _ => Some(command_states) }).flatMap(_.info))
   1.552 +
   1.553 +
   1.554 +  /* tooltip messages */
   1.555 +
   1.556 +  def tooltip_message(range: Text.Range): Option[Text.Info[XML.Body]] =
   1.557 +  {
   1.558 +    val results =
   1.559 +      snapshot.cumulate[List[Text.Info[Command.Results.Entry]]](
   1.560 +        range, Nil, JEdit_Rendering.tooltip_message_elements, _ =>
   1.561 +        {
   1.562 +          case (msgs, Text.Info(info_range, msg @ XML.Elem(Markup(Markup.BAD, _), body)))
   1.563 +          if body.nonEmpty =>
   1.564 +            val entry: Command.Results.Entry = (Document_ID.make(), msg)
   1.565 +            Some(Text.Info(snapshot.convert(info_range), entry) :: msgs)
   1.566 +
   1.567 +          case (msgs, Text.Info(info_range,
   1.568 +            XML.Elem(Markup(name, props @ Markup.Serial(serial)), body))) =>
   1.569 +            val entry: Command.Results.Entry =
   1.570 +              serial -> XML.Elem(Markup(Markup.message(name), props), body)
   1.571 +            Some(Text.Info(snapshot.convert(info_range), entry) :: msgs)
   1.572 +
   1.573 +          case _ => None
   1.574 +        }).flatMap(_.info)
   1.575 +    if (results.isEmpty) None
   1.576 +    else {
   1.577 +      val r = Text.Range(results.head.range.start, results.last.range.stop)
   1.578 +      val msgs = Command.Results.make(results.map(_.info))
   1.579 +      Some(Text.Info(r, Pretty.separate(msgs.iterator.map(_._2).toList)))
   1.580 +    }
   1.581 +  }
   1.582 +
   1.583 +
   1.584 +  /* tooltips */
   1.585 +
   1.586 +  private def pretty_typing(kind: String, body: XML.Body): XML.Tree =
   1.587 +    Pretty.block(XML.Text(kind) :: Pretty.brk(1) :: body)
   1.588 +
   1.589 +  private def timing_threshold: Double = options.real("jedit_timing_threshold")
   1.590 +
   1.591 +  def tooltip(range: Text.Range): Option[Text.Info[XML.Body]] =
   1.592 +  {
   1.593 +    def add(prev: Text.Info[(Timing, Vector[(Boolean, XML.Tree)])],
   1.594 +      r0: Text.Range, p: (Boolean, XML.Tree)): Text.Info[(Timing, Vector[(Boolean, XML.Tree)])] =
   1.595 +    {
   1.596 +      val r = snapshot.convert(r0)
   1.597 +      val (t, info) = prev.info
   1.598 +      if (prev.range == r)
   1.599 +        Text.Info(r, (t, info :+ p))
   1.600 +      else Text.Info(r, (t, Vector(p)))
   1.601 +    }
   1.602 +
   1.603 +    val results =
   1.604 +      snapshot.cumulate[Text.Info[(Timing, Vector[(Boolean, XML.Tree)])]](
   1.605 +        range, Text.Info(range, (Timing.zero, Vector.empty)), JEdit_Rendering.tooltip_elements, _ =>
   1.606 +        {
   1.607 +          case (Text.Info(r, (t1, info)), Text.Info(_, XML.Elem(Markup.Timing(t2), _))) =>
   1.608 +            Some(Text.Info(r, (t1 + t2, info)))
   1.609 +
   1.610 +          case (prev, Text.Info(r, XML.Elem(Markup.Entity(kind, name), _)))
   1.611 +          if kind != "" &&
   1.612 +            kind != Markup.ML_DEF &&
   1.613 +            kind != Markup.ML_OPEN &&
   1.614 +            kind != Markup.ML_STRUCTURE =>
   1.615 +            val kind1 = Word.implode(Word.explode('_', kind))
   1.616 +            val txt1 =
   1.617 +              if (name == "") kind1
   1.618 +              else if (kind1 == "") quote(name)
   1.619 +              else kind1 + " " + quote(name)
   1.620 +            val t = prev.info._1
   1.621 +            val txt2 =
   1.622 +              if (kind == Markup.COMMAND && t.elapsed.seconds >= timing_threshold)
   1.623 +                "\n" + t.message
   1.624 +              else ""
   1.625 +            Some(add(prev, r, (true, XML.Text(txt1 + txt2))))
   1.626 +
   1.627 +          case (prev, Text.Info(r, XML.Elem(Markup.Path(name), _))) =>
   1.628 +            val file = jedit_file(name)
   1.629 +            val text =
   1.630 +              if (name == file) "file " + quote(file)
   1.631 +              else "path " + quote(name) + "\nfile " + quote(file)
   1.632 +            Some(add(prev, r, (true, XML.Text(text))))
   1.633 +
   1.634 +          case (prev, Text.Info(r, XML.Elem(Markup.Doc(name), _))) =>
   1.635 +            val text = "doc " + quote(name)
   1.636 +            Some(add(prev, r, (true, XML.Text(text))))
   1.637 +
   1.638 +          case (prev, Text.Info(r, XML.Elem(Markup.Url(name), _))) =>
   1.639 +            Some(add(prev, r, (true, XML.Text("URL " + quote(name)))))
   1.640 +
   1.641 +          case (prev, Text.Info(r, XML.Elem(Markup(name, _), body)))
   1.642 +          if name == Markup.SORTING || name == Markup.TYPING =>
   1.643 +            Some(add(prev, r, (true, pretty_typing("::", body))))
   1.644 +
   1.645 +          case (prev, Text.Info(r, XML.Elem(Markup(Markup.CLASS_PARAMETER, _), body))) =>
   1.646 +            Some(add(prev, r, (true, Pretty.block(0, body))))
   1.647 +
   1.648 +          case (prev, Text.Info(r, XML.Elem(Markup(Markup.ML_TYPING, _), body))) =>
   1.649 +            Some(add(prev, r, (false, pretty_typing("ML:", body))))
   1.650 +
   1.651 +          case (prev, Text.Info(r, Protocol.ML_Breakpoint(breakpoint))) =>
   1.652 +            val text =
   1.653 +              if (Debugger.breakpoint_state(breakpoint)) "breakpoint (enabled)"
   1.654 +              else "breakpoint (disabled)"
   1.655 +            Some(add(prev, r, (true, XML.Text(text))))
   1.656 +
   1.657 +          case (prev, Text.Info(r, XML.Elem(Markup.Language(language, _, _, _), _))) =>
   1.658 +            val lang = Word.implode(Word.explode('_', language))
   1.659 +            Some(add(prev, r, (true, XML.Text("language: " + lang))))
   1.660 +
   1.661 +          case (prev, Text.Info(r, XML.Elem(Markup.Expression(kind), _))) =>
   1.662 +            val descr = if (kind == "") "expression" else "expression: " + kind
   1.663 +            Some(add(prev, r, (true, XML.Text(descr))))
   1.664 +
   1.665 +          case (prev, Text.Info(r, XML.Elem(Markup(Markup.MARKDOWN_PARAGRAPH, _), _))) =>
   1.666 +            Some(add(prev, r, (true, XML.Text("Markdown: paragraph"))))
   1.667 +          case (prev, Text.Info(r, XML.Elem(Markup.Markdown_List(kind), _))) =>
   1.668 +            Some(add(prev, r, (true, XML.Text("Markdown: " + kind))))
   1.669 +
   1.670 +          case (prev, Text.Info(r, XML.Elem(Markup(name, _), _))) =>
   1.671 +            JEdit_Rendering.tooltip_descriptions.get(name).
   1.672 +              map(descr => add(prev, r, (true, XML.Text(descr))))
   1.673 +        }).map(_.info)
   1.674 +
   1.675 +    results.map(_.info).flatMap(res => res._2.toList) match {
   1.676 +      case Nil => None
   1.677 +      case tips =>
   1.678 +        val r = Text.Range(results.head.range.start, results.last.range.stop)
   1.679 +        val all_tips = (tips.filter(_._1) ++ tips.filter(!_._1).lastOption.toList).map(_._2)
   1.680 +        Some(Text.Info(r, Library.separate(Pretty.fbrk, all_tips)))
   1.681 +    }
   1.682 +  }
   1.683 +
   1.684 +  def tooltip_margin: Int = options.int("jedit_tooltip_margin")
   1.685 +
   1.686 +  lazy val tooltip_close_icon = JEdit_Lib.load_icon(options.string("tooltip_close_icon"))
   1.687 +  lazy val tooltip_detach_icon = JEdit_Lib.load_icon(options.string("tooltip_detach_icon"))
   1.688 +
   1.689 +
   1.690 +  /* gutter */
   1.691 +
   1.692 +  private def gutter_message_pri(msg: XML.Tree): Int =
   1.693 +    if (Protocol.is_error(msg)) JEdit_Rendering.error_pri
   1.694 +    else if (Protocol.is_legacy(msg)) JEdit_Rendering.legacy_pri
   1.695 +    else if (Protocol.is_warning(msg)) JEdit_Rendering.warning_pri
   1.696 +    else if (Protocol.is_information(msg)) JEdit_Rendering.information_pri
   1.697 +    else 0
   1.698 +
   1.699 +  private lazy val gutter_message_content = Map(
   1.700 +    JEdit_Rendering.information_pri ->
   1.701 +      (JEdit_Lib.load_icon(options.string("gutter_information_icon")), information_message_color),
   1.702 +    JEdit_Rendering.warning_pri ->
   1.703 +      (JEdit_Lib.load_icon(options.string("gutter_warning_icon")), warning_message_color),
   1.704 +    JEdit_Rendering.legacy_pri ->
   1.705 +      (JEdit_Lib.load_icon(options.string("gutter_legacy_icon")), warning_message_color),
   1.706 +    JEdit_Rendering.error_pri ->
   1.707 +      (JEdit_Lib.load_icon(options.string("gutter_error_icon")), error_message_color))
   1.708 +
   1.709 +  def gutter_content(range: Text.Range): Option[(Icon, Color)] =
   1.710 +  {
   1.711 +    val pris =
   1.712 +      snapshot.cumulate[Int](range, 0, JEdit_Rendering.gutter_elements, _ =>
   1.713 +        {
   1.714 +          case (pri, Text.Info(_, msg @ XML.Elem(Markup(_, Markup.Serial(serial)), _))) =>
   1.715 +            Some(pri max gutter_message_pri(msg))
   1.716 +          case _ => None
   1.717 +        }).map(_.info)
   1.718 +
   1.719 +    gutter_message_content.get((0 /: pris)(_ max _))
   1.720 +  }
   1.721 +
   1.722 +
   1.723 +  /* squiggly underline */
   1.724 +
   1.725 +  private lazy val squiggly_colors = Map(
   1.726 +    JEdit_Rendering.writeln_pri -> writeln_color,
   1.727 +    JEdit_Rendering.information_pri -> information_color,
   1.728 +    JEdit_Rendering.warning_pri -> warning_color,
   1.729 +    JEdit_Rendering.legacy_pri -> legacy_color,
   1.730 +    JEdit_Rendering.error_pri -> error_color)
   1.731 +
   1.732 +  def squiggly_underline(range: Text.Range): List[Text.Info[Color]] =
   1.733 +  {
   1.734 +    val results =
   1.735 +      snapshot.cumulate[Int](range, 0, JEdit_Rendering.squiggly_elements, _ =>
   1.736 +        {
   1.737 +          case (pri, Text.Info(_, elem)) => Some(pri max JEdit_Rendering.message_pri(elem.name))
   1.738 +        })
   1.739 +    for {
   1.740 +      Text.Info(r, pri) <- results
   1.741 +      color <- squiggly_colors.get(pri)
   1.742 +    } yield Text.Info(r, color)
   1.743 +  }
   1.744 +
   1.745 +
   1.746 +  /* message output */
   1.747 +
   1.748 +  private lazy val message_colors = Map(
   1.749 +    JEdit_Rendering.writeln_pri -> writeln_message_color,
   1.750 +    JEdit_Rendering.information_pri -> information_message_color,
   1.751 +    JEdit_Rendering.tracing_pri -> tracing_message_color,
   1.752 +    JEdit_Rendering.warning_pri -> warning_message_color,
   1.753 +    JEdit_Rendering.legacy_pri -> legacy_message_color,
   1.754 +    JEdit_Rendering.error_pri -> error_message_color)
   1.755 +
   1.756 +  def line_background(range: Text.Range): Option[(Color, Boolean)] =
   1.757 +  {
   1.758 +    val results =
   1.759 +      snapshot.cumulate[Int](range, 0, JEdit_Rendering.line_background_elements, _ =>
   1.760 +        {
   1.761 +          case (pri, Text.Info(_, elem)) => Some(pri max JEdit_Rendering.message_pri(elem.name))
   1.762 +        })
   1.763 +    val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
   1.764 +
   1.765 +    message_colors.get(pri).map(message_color =>
   1.766 +      {
   1.767 +        val is_separator =
   1.768 +          snapshot.cumulate[Boolean](range, false, JEdit_Rendering.separator_elements, _ =>
   1.769 +            {
   1.770 +              case _ => Some(true)
   1.771 +            }).exists(_.info)
   1.772 +        (message_color, is_separator)
   1.773 +      })
   1.774 +  }
   1.775 +
   1.776 +  def output_messages(results: Command.Results): List[XML.Tree] =
   1.777 +  {
   1.778 +    val (states, other) =
   1.779 +      results.iterator.map(_._2).filterNot(Protocol.is_result(_)).toList
   1.780 +        .partition(Protocol.is_state(_))
   1.781 +    states ::: other
   1.782 +  }
   1.783 +
   1.784 +
   1.785 +  /* text background */
   1.786 +
   1.787 +  def background(range: Text.Range, focus: Set[Long]): List[Text.Info[Color]] =
   1.788 +  {
   1.789 +    for {
   1.790 +      Text.Info(r, result) <-
   1.791 +        snapshot.cumulate[(List[Markup], Option[Color])](
   1.792 +          range, (List(Markup.Empty), None), JEdit_Rendering.background_elements,
   1.793 +          command_states =>
   1.794 +            {
   1.795 +              case (((status, color), Text.Info(_, XML.Elem(markup, _))))
   1.796 +              if status.nonEmpty && Protocol.proper_status_elements(markup.name) =>
   1.797 +                Some((markup :: status, color))
   1.798 +              case (_, Text.Info(_, XML.Elem(Markup(Markup.BAD, _), _))) =>
   1.799 +                Some((Nil, Some(bad_color)))
   1.800 +              case (_, Text.Info(_, XML.Elem(Markup(Markup.INTENSIFY, _), _))) =>
   1.801 +                Some((Nil, Some(intensify_color)))
   1.802 +              case (_, Text.Info(_, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
   1.803 +                props match {
   1.804 +                  case Markup.Entity.Def(i) if focus(i) => Some((Nil, Some(entity_color)))
   1.805 +                  case Markup.Entity.Ref(i) if focus(i) => Some((Nil, Some(entity_color)))
   1.806 +                  case _ => None
   1.807 +                }
   1.808 +              case (_, Text.Info(_, XML.Elem(Markup.Markdown_Item(depth), _))) =>
   1.809 +                val color =
   1.810 +                  depth match {
   1.811 +                    case 1 => markdown_item_color1
   1.812 +                    case 2 => markdown_item_color2
   1.813 +                    case 3 => markdown_item_color3
   1.814 +                    case _ => markdown_item_color4
   1.815 +                  }
   1.816 +                Some((Nil, Some(color)))
   1.817 +              case (acc, Text.Info(_, Protocol.Dialog(_, serial, result))) =>
   1.818 +                command_states.collectFirst(
   1.819 +                  { case st if st.results.defined(serial) => st.results.get(serial).get }) match
   1.820 +                {
   1.821 +                  case Some(Protocol.Dialog_Result(res)) if res == result =>
   1.822 +                    Some((Nil, Some(active_result_color)))
   1.823 +                  case _ =>
   1.824 +                    Some((Nil, Some(active_color)))
   1.825 +                }
   1.826 +              case (_, Text.Info(_, elem)) =>
   1.827 +                if (JEdit_Rendering.active_elements(elem.name)) Some((Nil, Some(active_color)))
   1.828 +                else None
   1.829 +            })
   1.830 +      color <-
   1.831 +        (result match {
   1.832 +          case (markups, opt_color) if markups.nonEmpty =>
   1.833 +            val status = Protocol.Status.make(markups.iterator)
   1.834 +            if (status.is_unprocessed) Some(unprocessed1_color)
   1.835 +            else if (status.is_running) Some(running1_color)
   1.836 +            else opt_color
   1.837 +          case (_, opt_color) => opt_color
   1.838 +        })
   1.839 +    } yield Text.Info(r, color)
   1.840 +  }
   1.841 +
   1.842 +
   1.843 +  /* text foreground */
   1.844 +
   1.845 +  def foreground(range: Text.Range): List[Text.Info[Color]] =
   1.846 +    snapshot.select(range, JEdit_Rendering.foreground_elements, _ =>
   1.847 +      {
   1.848 +        case Text.Info(_, elem) =>
   1.849 +          if (elem.name == Markup.ANTIQUOTED) Some(antiquoted_color) else Some(quoted_color)
   1.850 +      })
   1.851 +
   1.852 +
   1.853 +  /* text color */
   1.854 +
   1.855 +  val foreground_color = jEdit.getColorProperty("view.fgColor")
   1.856 +
   1.857 +  private lazy val text_colors: Map[String, Color] = Map(
   1.858 +      Markup.KEYWORD1 -> keyword1_color,
   1.859 +      Markup.KEYWORD2 -> keyword2_color,
   1.860 +      Markup.KEYWORD3 -> keyword3_color,
   1.861 +      Markup.QUASI_KEYWORD -> quasi_keyword_color,
   1.862 +      Markup.IMPROPER -> improper_color,
   1.863 +      Markup.OPERATOR -> operator_color,
   1.864 +      Markup.STRING -> foreground_color,
   1.865 +      Markup.ALT_STRING -> foreground_color,
   1.866 +      Markup.VERBATIM -> foreground_color,
   1.867 +      Markup.CARTOUCHE -> foreground_color,
   1.868 +      Markup.LITERAL -> keyword1_color,
   1.869 +      Markup.DELIMITER -> foreground_color,
   1.870 +      Markup.TFREE -> tfree_color,
   1.871 +      Markup.TVAR -> tvar_color,
   1.872 +      Markup.FREE -> free_color,
   1.873 +      Markup.SKOLEM -> skolem_color,
   1.874 +      Markup.BOUND -> bound_color,
   1.875 +      Markup.VAR -> var_color,
   1.876 +      Markup.INNER_STRING -> inner_quoted_color,
   1.877 +      Markup.INNER_CARTOUCHE -> inner_cartouche_color,
   1.878 +      Markup.INNER_COMMENT -> inner_comment_color,
   1.879 +      Markup.DYNAMIC_FACT -> dynamic_color,
   1.880 +      Markup.CLASS_PARAMETER -> class_parameter_color,
   1.881 +      Markup.ANTIQUOTE -> antiquote_color,
   1.882 +      Markup.ML_KEYWORD1 -> keyword1_color,
   1.883 +      Markup.ML_KEYWORD2 -> keyword2_color,
   1.884 +      Markup.ML_KEYWORD3 -> keyword3_color,
   1.885 +      Markup.ML_DELIMITER -> foreground_color,
   1.886 +      Markup.ML_NUMERAL -> inner_numeral_color,
   1.887 +      Markup.ML_CHAR -> inner_quoted_color,
   1.888 +      Markup.ML_STRING -> inner_quoted_color,
   1.889 +      Markup.ML_COMMENT -> inner_comment_color,
   1.890 +      Markup.SML_STRING -> inner_quoted_color,
   1.891 +      Markup.SML_COMMENT -> inner_comment_color)
   1.892 +
   1.893 +  private lazy val text_color_elements =
   1.894 +    Markup.Elements(text_colors.keySet)
   1.895 +
   1.896 +  def text_color(range: Text.Range, color: Color): List[Text.Info[Color]] =
   1.897 +  {
   1.898 +    if (color == Token_Markup.hidden_color) List(Text.Info(range, color))
   1.899 +    else
   1.900 +      snapshot.cumulate(range, color, text_color_elements, _ =>
   1.901 +        {
   1.902 +          case (_, Text.Info(_, elem)) => text_colors.get(elem.name)
   1.903 +        })
   1.904 +  }
   1.905 +
   1.906 +
   1.907 +  /* virtual bullets */
   1.908 +
   1.909 +  def bullet(range: Text.Range): List[Text.Info[Color]] =
   1.910 +    snapshot.select(range, JEdit_Rendering.bullet_elements, _ =>
   1.911 +      {
   1.912 +        case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) =>
   1.913 +          Debugger.active_breakpoint_state(breakpoint).map(b =>
   1.914 +            if (b) breakpoint_enabled_color else breakpoint_disabled_color)
   1.915 +        case _ => Some(bullet_color)
   1.916 +      })
   1.917 +
   1.918 +
   1.919 +  /* text folds */
   1.920 +
   1.921 +  def fold_depth(range: Text.Range): List[Text.Info[Int]] =
   1.922 +    snapshot.cumulate[Int](range, 0, JEdit_Rendering.fold_depth_elements, _ =>
   1.923 +      {
   1.924 +        case (depth, _) => Some(depth + 1)
   1.925 +      })
   1.926 +}