src/Tools/jEdit/src/jedit_rendering.scala
author wenzelm
Mon, 06 Mar 2017 17:10:37 +0100
changeset 65132 60e7072b8dbe
parent 65129 06a7c2d316cf
child 65139 0a2c0712e432
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64622
529bbb8977c7 more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents: 64621
diff changeset
     1
/*  Title:      Tools/jEdit/src/jedit_rendering.scala
39178
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
     3
64622
529bbb8977c7 more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents: 64621
diff changeset
     4
Isabelle/jEdit-specific implementation of quasi-abstract rendering and
50199
6d04e2422769 quasi-abstract module Rendering, with Isabelle-specific implementation;
wenzelm
parents: 50196
diff changeset
     5
markup interpretation.
39178
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
     6
*/
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
     7
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
     8
package isabelle.jedit
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
     9
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
    10
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
    11
import isabelle._
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
    12
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
    13
import java.awt.Color
46227
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46224
diff changeset
    14
import javax.swing.Icon
39178
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
    15
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    16
import org.gjt.sp.jedit.syntax.{Token => JEditToken}
61175
1d9c121cbe4d avoid hardwired colors;
wenzelm
parents: 61011
diff changeset
    17
import org.gjt.sp.jedit.jEdit
39178
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
    18
45460
dcd02d1a25d7 more tooltip content;
wenzelm
parents: 45454
diff changeset
    19
import scala.collection.immutable.SortedMap
dcd02d1a25d7 more tooltip content;
wenzelm
parents: 45454
diff changeset
    20
39178
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
    21
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
    22
object JEdit_Rendering
39178
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
    23
{
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
    24
  def apply(snapshot: Document.Snapshot, options: Options): JEdit_Rendering =
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
    25
    new JEdit_Rendering(snapshot, options)
39178
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
    26
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
    27
53230
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 52980
diff changeset
    28
  /* popup window bounds */
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 52980
diff changeset
    29
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 52980
diff changeset
    30
  def popup_bounds: Double = (PIDE.options.real("jedit_popup_bounds") max 0.2) min 0.8
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 52980
diff changeset
    31
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 52980
diff changeset
    32
55501
fdde1d62e1fb refined ML keyword styles;
wenzelm
parents: 55500
diff changeset
    33
  /* Isabelle/Isar token markup */
39179
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    34
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    35
  private val command_style: Map[String, Byte] =
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    36
  {
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    37
    import JEditToken._
39179
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    38
    Map[String, Byte](
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    39
      Keyword.THY_END -> KEYWORD2,
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    40
      Keyword.PRF_ASM -> KEYWORD3,
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59118
diff changeset
    41
      Keyword.PRF_ASM_GOAL -> KEYWORD3
39179
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    42
    ).withDefaultValue(KEYWORD1)
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    43
  }
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    44
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    45
  private val token_style: Map[Token.Kind.Value, Byte] =
39179
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    46
  {
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    47
    import JEditToken._
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    48
    Map[Token.Kind.Value, Byte](
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    49
      Token.Kind.KEYWORD -> KEYWORD2,
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    50
      Token.Kind.IDENT -> NULL,
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    51
      Token.Kind.LONG_IDENT -> NULL,
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    52
      Token.Kind.SYM_IDENT -> NULL,
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    53
      Token.Kind.VAR -> NULL,
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    54
      Token.Kind.TYPE_IDENT -> NULL,
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    55
      Token.Kind.TYPE_VAR -> NULL,
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    56
      Token.Kind.NAT -> NULL,
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    57
      Token.Kind.FLOAT -> NULL,
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 58901
diff changeset
    58
      Token.Kind.SPACE -> NULL,
43431
f3d5cecfecdc tuned markup;
wenzelm
parents: 43430
diff changeset
    59
      Token.Kind.STRING -> LITERAL1,
f3d5cecfecdc tuned markup;
wenzelm
parents: 43430
diff changeset
    60
      Token.Kind.ALT_STRING -> LITERAL2,
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    61
      Token.Kind.VERBATIM -> COMMENT3,
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54702
diff changeset
    62
      Token.Kind.CARTOUCHE -> COMMENT4,
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    63
      Token.Kind.COMMENT -> COMMENT1,
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48751
diff changeset
    64
      Token.Kind.ERROR -> INVALID
39179
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    65
    ).withDefaultValue(NULL)
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    66
  }
591bbab9ef59 moved token markup tables to isabelle_markup.scala;
wenzelm
parents: 39178
diff changeset
    67
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    68
  def token_markup(syntax: Outer_Syntax, token: Token): Byte =
63441
4c3fa4dba79f explicit kind "before_command";
wenzelm
parents: 63347
diff changeset
    69
    if (token.is_command) command_style(syntax.keywords.kinds.getOrElse(token.content, ""))
61579
634cd44bb1d3 symbolic syntax "\<comment> text";
wenzelm
parents: 61450
diff changeset
    70
    else if (token.is_keyword && token.source == Symbol.comment_decoded) JEditToken.NULL
55505
2a1ca7f6607b more uniform ML keyword markup;
wenzelm
parents: 55503
diff changeset
    71
    else if (token.is_delimiter) JEditToken.OPERATOR
43414
f0770743b7ec static token markup, based on outer syntax only;
wenzelm
parents: 43394
diff changeset
    72
    else token_style(token.kind)
55500
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    73
55501
fdde1d62e1fb refined ML keyword styles;
wenzelm
parents: 55500
diff changeset
    74
fdde1d62e1fb refined ML keyword styles;
wenzelm
parents: 55500
diff changeset
    75
  /* Isabelle/ML token markup */
fdde1d62e1fb refined ML keyword styles;
wenzelm
parents: 55500
diff changeset
    76
55500
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    77
  private val ml_token_style: Map[ML_Lex.Kind.Value, Byte] =
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    78
  {
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    79
    import JEditToken._
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    80
    Map[ML_Lex.Kind.Value, Byte](
55505
2a1ca7f6607b more uniform ML keyword markup;
wenzelm
parents: 55503
diff changeset
    81
      ML_Lex.Kind.KEYWORD -> NULL,
55500
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    82
      ML_Lex.Kind.IDENT -> NULL,
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    83
      ML_Lex.Kind.LONG_IDENT -> NULL,
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    84
      ML_Lex.Kind.TYPE_VAR -> NULL,
55503
wenzelm
parents: 55501
diff changeset
    85
      ML_Lex.Kind.WORD -> DIGIT,
wenzelm
parents: 55501
diff changeset
    86
      ML_Lex.Kind.INT -> DIGIT,
wenzelm
parents: 55501
diff changeset
    87
      ML_Lex.Kind.REAL -> DIGIT,
55500
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    88
      ML_Lex.Kind.CHAR -> LITERAL2,
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    89
      ML_Lex.Kind.STRING -> LITERAL1,
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    90
      ML_Lex.Kind.SPACE -> NULL,
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    91
      ML_Lex.Kind.COMMENT -> COMMENT1,
55512
75c68e05f9ea support ML antiquotations in Scala;
wenzelm
parents: 55505
diff changeset
    92
      ML_Lex.Kind.ANTIQ -> NULL,
75c68e05f9ea support ML antiquotations in Scala;
wenzelm
parents: 55505
diff changeset
    93
      ML_Lex.Kind.ANTIQ_START -> LITERAL4,
75c68e05f9ea support ML antiquotations in Scala;
wenzelm
parents: 55505
diff changeset
    94
      ML_Lex.Kind.ANTIQ_STOP -> LITERAL4,
75c68e05f9ea support ML antiquotations in Scala;
wenzelm
parents: 55505
diff changeset
    95
      ML_Lex.Kind.ANTIQ_OTHER -> NULL,
55514
8ef781e282d9 more uniform rendering of text that is formally interpreted: avoid clash with inner markup;
wenzelm
parents: 55512
diff changeset
    96
      ML_Lex.Kind.ANTIQ_STRING -> NULL,
8ef781e282d9 more uniform rendering of text that is formally interpreted: avoid clash with inner markup;
wenzelm
parents: 55512
diff changeset
    97
      ML_Lex.Kind.ANTIQ_ALT_STRING -> NULL,
8ef781e282d9 more uniform rendering of text that is formally interpreted: avoid clash with inner markup;
wenzelm
parents: 55512
diff changeset
    98
      ML_Lex.Kind.ANTIQ_CARTOUCHE -> NULL,
55500
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    99
      ML_Lex.Kind.ERROR -> INVALID
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
   100
    ).withDefaultValue(NULL)
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
   101
  }
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
   102
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
   103
  def ml_token_markup(token: ML_Lex.Token): Byte =
55501
fdde1d62e1fb refined ML keyword styles;
wenzelm
parents: 55500
diff changeset
   104
    if (!token.is_keyword) ml_token_style(token.kind)
55505
2a1ca7f6607b more uniform ML keyword markup;
wenzelm
parents: 55503
diff changeset
   105
    else if (token.is_delimiter) JEditToken.OPERATOR
2a1ca7f6607b more uniform ML keyword markup;
wenzelm
parents: 55503
diff changeset
   106
    else if (ML_Lex.keywords2(token.source)) JEditToken.KEYWORD2
2a1ca7f6607b more uniform ML keyword markup;
wenzelm
parents: 55503
diff changeset
   107
    else if (ML_Lex.keywords3(token.source)) JEditToken.KEYWORD3
55501
fdde1d62e1fb refined ML keyword styles;
wenzelm
parents: 55500
diff changeset
   108
    else JEditToken.KEYWORD1
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   109
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   110
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   111
  /* markup elements */
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   112
63474
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   113
  private val indentation_elements =
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   114
    Markup.Elements(Markup.Command_Indent.name)
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   115
56173
62f10624339a tuned signature;
wenzelm
parents: 56146
diff changeset
   116
  private val language_context_elements =
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 58901
diff changeset
   117
    Markup.Elements(Markup.STRING, Markup.ALT_STRING, Markup.VERBATIM,
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   118
      Markup.CARTOUCHE, Markup.COMMENT, Markup.LANGUAGE,
61598
ed4dad8823a4 less confusing markup;
wenzelm
parents: 61596
diff changeset
   119
      Markup.ML_STRING, Markup.ML_COMMENT)
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   120
56843
b2bfcd8cda80 support for path completion based on file-system content;
wenzelm
parents: 56743
diff changeset
   121
  private val language_elements = Markup.Elements(Markup.LANGUAGE)
b2bfcd8cda80 support for path completion based on file-system content;
wenzelm
parents: 56743
diff changeset
   122
58592
b0fff34d3247 completion for bibtex entries;
wenzelm
parents: 58545
diff changeset
   123
  private val citation_elements = Markup.Elements(Markup.CITATION)
b0fff34d3247 completion for bibtex entries;
wenzelm
parents: 58545
diff changeset
   124
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
   125
  private val breakpoint_elements = Markup.Elements(Markup.ML_BREAKPOINT)
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
   126
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   127
  private val highlight_elements =
58545
30b75b7958d6 citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents: 58464
diff changeset
   128
    Markup.Elements(Markup.EXPRESSION, Markup.CITATION, Markup.LANGUAGE, Markup.ML_TYPING,
61718
309c20b21451 clarified rendering of Markup.DOC: like Markup.PATH / Markup.URL;
wenzelm
parents: 61660
diff changeset
   129
      Markup.TOKEN_RANGE, Markup.ENTITY, Markup.PATH, Markup.DOC, Markup.URL, Markup.SORTING,
63347
e344dc82f6c2 report class parameters within instantiation;
wenzelm
parents: 63340
diff changeset
   130
      Markup.TYPING, Markup.CLASS_PARAMETER, Markup.FREE, Markup.SKOLEM, Markup.BOUND,
61450
239a04ec2d4c more markup;
wenzelm
parents: 61449
diff changeset
   131
      Markup.VAR, Markup.TFREE, Markup.TVAR, Markup.ML_BREAKPOINT,
239a04ec2d4c more markup;
wenzelm
parents: 61449
diff changeset
   132
      Markup.MARKDOWN_PARAGRAPH, Markup.Markdown_List.name)
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   133
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   134
  private val hyperlink_elements =
61660
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61603
diff changeset
   135
    Markup.Elements(Markup.ENTITY, Markup.PATH, Markup.DOC, Markup.POSITION,
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61603
diff changeset
   136
      Markup.CITATION, Markup.URL)
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   137
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   138
  private val gutter_elements =
59203
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   139
    Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR)
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   140
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   141
  private val squiggly_elements =
59203
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   142
    Markup.Elements(Markup.WRITELN, Markup.INFORMATION, Markup.WARNING, Markup.LEGACY, Markup.ERROR)
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   143
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   144
  private val line_background_elements =
59184
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59129
diff changeset
   145
    Markup.Elements(Markup.WRITELN_MESSAGE, Markup.STATE_MESSAGE, Markup.INFORMATION_MESSAGE,
59203
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   146
      Markup.TRACING_MESSAGE, Markup.WARNING_MESSAGE, Markup.LEGACY_MESSAGE,
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   147
      Markup.ERROR_MESSAGE)
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   148
55820
61869776ce1f tuned signature -- more explicit Document.Elements;
wenzelm
parents: 55790
diff changeset
   149
  private val separator_elements =
56743
81370dfadb1d tuned signature;
wenzelm
parents: 56600
diff changeset
   150
    Markup.Elements(Markup.SEPARATOR)
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   151
55820
61869776ce1f tuned signature -- more explicit Document.Elements;
wenzelm
parents: 55790
diff changeset
   152
  private val bullet_elements =
60913
7432d6bb4195 clarified breakpoint rendering;
wenzelm
parents: 60893
diff changeset
   153
    Markup.Elements(Markup.BULLET, Markup.ML_BREAKPOINT)
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   154
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   155
  private val fold_depth_elements =
56743
81370dfadb1d tuned signature;
wenzelm
parents: 56600
diff changeset
   156
    Markup.Elements(Markup.TEXT_FOLD, Markup.GOAL, Markup.SUBGOAL)
39178
83e9f3ccea9f concentrate Isabelle specific physical rendering markup selection in isabelle_markup.scala;
wenzelm
parents:
diff changeset
   157
}
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   158
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   159
64622
529bbb8977c7 more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents: 64621
diff changeset
   160
class JEdit_Rendering(snapshot: Document.Snapshot, options: Options)
529bbb8977c7 more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents: 64621
diff changeset
   161
  extends Rendering(snapshot, options, PIDE.resources)
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   162
{
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   163
  /* colors */
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   164
65102
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   165
  def color(s: String): Color = Color_Value(options.string(s))
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   166
65101
4263b2a201b3 symbolic Rendering.Color;
wenzelm
parents: 65100
diff changeset
   167
  lazy val _rendering_colors: Map[Rendering.Color.Value, Color] =
65102
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   168
    Rendering.Color.values.iterator.map(c => c -> color(c.toString + "_color")).toMap
65101
4263b2a201b3 symbolic Rendering.Color;
wenzelm
parents: 65100
diff changeset
   169
4263b2a201b3 symbolic Rendering.Color;
wenzelm
parents: 65100
diff changeset
   170
  def color(c: Rendering.Color.Value): Color = _rendering_colors(c)
4263b2a201b3 symbolic Rendering.Color;
wenzelm
parents: 65100
diff changeset
   171
65102
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   172
  val outdated_color = color("outdated_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   173
  val unprocessed_color = color("unprocessed_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   174
  val running_color = color("running_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   175
  val bullet_color = color("bullet_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   176
  val tooltip_color = color("tooltip_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   177
  val warning_color = color("warning_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   178
  val error_color = color("error_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   179
  val spell_checker_color = color("spell_checker_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   180
  val entity_ref_color = color("entity_ref_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   181
  val breakpoint_disabled_color = color("breakpoint_disabled_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   182
  val breakpoint_enabled_color = color("breakpoint_enabled_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   183
  val caret_debugger_color = color("caret_debugger_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   184
  val antiquote_color = color("antiquote_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   185
  val highlight_color = color("highlight_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   186
  val hyperlink_color = color("hyperlink_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   187
  val active_hover_color = color("active_hover_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   188
  val keyword1_color = color("keyword1_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   189
  val keyword2_color = color("keyword2_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   190
  val keyword3_color = color("keyword3_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   191
  val quasi_keyword_color = color("quasi_keyword_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   192
  val improper_color = color("improper_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   193
  val operator_color = color("operator_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   194
  val caret_invisible_color = color("caret_invisible_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   195
  val completion_color = color("completion_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   196
  val search_color = color("search_color")
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   197
65102
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   198
  val tfree_color = color("tfree_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   199
  val tvar_color = color("tvar_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   200
  val free_color = color("free_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   201
  val skolem_color = color("skolem_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   202
  val bound_color = color("bound_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   203
  val var_color = color("var_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   204
  val inner_numeral_color = color("inner_numeral_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   205
  val inner_quoted_color = color("inner_quoted_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   206
  val inner_cartouche_color = color("inner_cartouche_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   207
  val inner_comment_color = color("inner_comment_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   208
  val dynamic_color = color("dynamic_color")
136b620b11af tuned signature;
wenzelm
parents: 65101
diff changeset
   209
  val class_parameter_color = color("class_parameter_color")
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   210
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   211
63474
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   212
  /* indentation */
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   213
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   214
  def indentation(range: Text.Range): Int =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   215
    snapshot.select(range, JEdit_Rendering.indentation_elements, _ =>
63474
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   216
      {
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   217
        case Text.Info(_, XML.Elem(Markup.Command_Indent(i), _)) => Some(i)
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   218
        case _ => None
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   219
      }).headOption.map(_.info).getOrElse(0)
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   220
f66e3c3b0fb1 semantic indentation for unstructured proof scripts;
wenzelm
parents: 63441
diff changeset
   221
55674
8a213ab0e78a support for semantic completion on Scala side;
wenzelm
parents: 55666
diff changeset
   222
  /* completion */
8a213ab0e78a support for semantic completion on Scala side;
wenzelm
parents: 55666
diff changeset
   223
56173
62f10624339a tuned signature;
wenzelm
parents: 56146
diff changeset
   224
  def language_context(range: Text.Range): Option[Completion.Language_Context] =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   225
    snapshot.select(range, JEdit_Rendering.language_context_elements, _ =>
55690
d73949233c2e clarified stretch_point_range wrt. UTF-16 surrogates;
wenzelm
parents: 55689
diff changeset
   226
      {
55828
42ac3cfb89f6 clarified language markup: added "delimited" property;
wenzelm
parents: 55825
diff changeset
   227
        case Text.Info(_, XML.Elem(Markup.Language(language, symbols, antiquotes, delimited), _)) =>
42ac3cfb89f6 clarified language markup: added "delimited" property;
wenzelm
parents: 55825
diff changeset
   228
          if (delimited) Some(Completion.Language_Context(language, symbols, antiquotes))
42ac3cfb89f6 clarified language markup: added "delimited" property;
wenzelm
parents: 55825
diff changeset
   229
          else None
55690
d73949233c2e clarified stretch_point_range wrt. UTF-16 surrogates;
wenzelm
parents: 55689
diff changeset
   230
        case Text.Info(_, elem)
61598
ed4dad8823a4 less confusing markup;
wenzelm
parents: 61596
diff changeset
   231
        if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT =>
55749
75a48dc4383e tuned signature;
wenzelm
parents: 55747
diff changeset
   232
          Some(Completion.Language_Context.ML_inner)
55690
d73949233c2e clarified stretch_point_range wrt. UTF-16 surrogates;
wenzelm
parents: 55689
diff changeset
   233
        case Text.Info(_, _) =>
55749
75a48dc4383e tuned signature;
wenzelm
parents: 55747
diff changeset
   234
          Some(Completion.Language_Context.inner)
55690
d73949233c2e clarified stretch_point_range wrt. UTF-16 surrogates;
wenzelm
parents: 55689
diff changeset
   235
      }).headOption.map(_.info)
55615
bf4bbe72f740 completion of keywords and symbols based on language context;
wenzelm
parents: 55550
diff changeset
   236
56843
b2bfcd8cda80 support for path completion based on file-system content;
wenzelm
parents: 56743
diff changeset
   237
  def language_path(range: Text.Range): Option[Text.Range] =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   238
    snapshot.select(range, JEdit_Rendering.language_elements, _ =>
56843
b2bfcd8cda80 support for path completion based on file-system content;
wenzelm
parents: 56743
diff changeset
   239
      {
b2bfcd8cda80 support for path completion based on file-system content;
wenzelm
parents: 56743
diff changeset
   240
        case Text.Info(info_range, XML.Elem(Markup.Language(Markup.Language.PATH, _, _, _), _)) =>
b2bfcd8cda80 support for path completion based on file-system content;
wenzelm
parents: 56743
diff changeset
   241
          Some(snapshot.convert(info_range))
b2bfcd8cda80 support for path completion based on file-system content;
wenzelm
parents: 56743
diff changeset
   242
        case _ => None
b2bfcd8cda80 support for path completion based on file-system content;
wenzelm
parents: 56743
diff changeset
   243
      }).headOption.map(_.info)
b2bfcd8cda80 support for path completion based on file-system content;
wenzelm
parents: 56743
diff changeset
   244
58592
b0fff34d3247 completion for bibtex entries;
wenzelm
parents: 58545
diff changeset
   245
  def citation(range: Text.Range): Option[Text.Info[String]] =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   246
    snapshot.select(range, JEdit_Rendering.citation_elements, _ =>
58592
b0fff34d3247 completion for bibtex entries;
wenzelm
parents: 58545
diff changeset
   247
      {
b0fff34d3247 completion for bibtex entries;
wenzelm
parents: 58545
diff changeset
   248
        case Text.Info(info_range, XML.Elem(Markup.Citation(name), _)) =>
b0fff34d3247 completion for bibtex entries;
wenzelm
parents: 58545
diff changeset
   249
          Some(Text.Info(snapshot.convert(info_range), name))
b0fff34d3247 completion for bibtex entries;
wenzelm
parents: 58545
diff changeset
   250
        case _ => None
b0fff34d3247 completion for bibtex entries;
wenzelm
parents: 58545
diff changeset
   251
      }).headOption.map(_.info)
b0fff34d3247 completion for bibtex entries;
wenzelm
parents: 58545
diff changeset
   252
55615
bf4bbe72f740 completion of keywords and symbols based on language context;
wenzelm
parents: 55550
diff changeset
   253
56551
d4da2b11c729 more general spell_checker_elements;
wenzelm
parents: 56550
diff changeset
   254
  /* spell checker */
56548
ae6870efc28d markup for prose words within formal comments;
wenzelm
parents: 56495
diff changeset
   255
56551
d4da2b11c729 more general spell_checker_elements;
wenzelm
parents: 56550
diff changeset
   256
  private lazy val spell_checker_elements =
56743
81370dfadb1d tuned signature;
wenzelm
parents: 56600
diff changeset
   257
    Markup.Elements(space_explode(',', options.string("spell_checker_elements")): _*)
56551
d4da2b11c729 more general spell_checker_elements;
wenzelm
parents: 56550
diff changeset
   258
d4da2b11c729 more general spell_checker_elements;
wenzelm
parents: 56550
diff changeset
   259
  def spell_checker_ranges(range: Text.Range): List[Text.Range] =
d4da2b11c729 more general spell_checker_elements;
wenzelm
parents: 56550
diff changeset
   260
    snapshot.select(range, spell_checker_elements, _ => _ => Some(())).map(_.range)
56548
ae6870efc28d markup for prose words within formal comments;
wenzelm
parents: 56495
diff changeset
   261
56564
94c55cc73747 added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents: 56551
diff changeset
   262
  def spell_checker_point(range: Text.Range): Option[Text.Range] =
94c55cc73747 added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents: 56551
diff changeset
   263
    snapshot.select(range, spell_checker_elements, _ =>
94c55cc73747 added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents: 56551
diff changeset
   264
      {
94c55cc73747 added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents: 56551
diff changeset
   265
        case info => Some(snapshot.convert(info.range))
94c55cc73747 added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents: 56551
diff changeset
   266
      }).headOption.map(_.info)
94c55cc73747 added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents: 56551
diff changeset
   267
56548
ae6870efc28d markup for prose words within formal comments;
wenzelm
parents: 56495
diff changeset
   268
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
   269
  /* breakpoints */
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
   270
60880
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
   271
  def breakpoint(range: Text.Range): Option[(Command, Long)] =
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
   272
    if (snapshot.is_outdated) None
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
   273
    else
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   274
      snapshot.select(range, JEdit_Rendering.breakpoint_elements, command_states =>
60880
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
   275
        {
60882
45bfd18835f1 tuned signature;
wenzelm
parents: 60880
diff changeset
   276
          case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) =>
60880
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
   277
            command_states match {
60882
45bfd18835f1 tuned signature;
wenzelm
parents: 60880
diff changeset
   278
              case st :: _ => Some((st.command, breakpoint))
60880
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
   279
              case _ => None
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
   280
            }
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
   281
          case _ => None
fa958e24ff24 set breakpoint state on ML side, relying on stable situation within the PIDE editing queue;
wenzelm
parents: 60878
diff changeset
   282
        }).headOption.map(_.info)
60878
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
   283
1f0d2bbcf38b added action to toggle breakpoints (on editor side);
wenzelm
parents: 60876
diff changeset
   284
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   285
  /* command status overview */
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   286
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   287
  def overview_color(range: Text.Range): Option[Color] =
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   288
  {
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   289
    if (snapshot.is_outdated) None
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   290
    else {
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   291
      val results =
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   292
        snapshot.cumulate[List[Markup]](range, Nil, Protocol.liberal_status_elements, _ =>
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   293
          {
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   294
            case (status, Text.Info(_, elem)) => Some(elem.markup :: status)
55651
fa42cf3fe79b tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents: 55649
diff changeset
   295
          }, status = true)
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   296
      if (results.isEmpty) None
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   297
      else {
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   298
        val status = Protocol.Status.make(results.iterator.flatMap(_.info))
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   299
50895
3a1edaa0dc6d more prominent status ticks;
wenzelm
parents: 50715
diff changeset
   300
        if (status.is_running) Some(running_color)
56980
9c5220e05e04 proper priority for error over warning, which got mixed up in 0546e036d1c0 and 4df2727a0b5f;
wenzelm
parents: 56883
diff changeset
   301
        else if (status.is_failed) Some(error_color)
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   302
        else if (status.is_warned) Some(warning_color)
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   303
        else if (status.is_unprocessed) Some(unprocessed_color)
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   304
        else None
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   305
      }
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   306
    }
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   307
  }
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   308
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   309
62986
9d2fae6b31cc background color for entity def/ref focus;
wenzelm
parents: 62806
diff changeset
   310
  /* caret focus */
9d2fae6b31cc background color for entity def/ref focus;
wenzelm
parents: 62806
diff changeset
   311
62991
35f1475e9ced clarified rendering wrt. hyperlinks;
wenzelm
parents: 62989
diff changeset
   312
  def entity_ref(range: Text.Range, focus: Set[Long]): List[Text.Info[Color]] =
64767
f5c4ffdb1124 support VSCode DocumentHighlights;
wenzelm
parents: 64748
diff changeset
   313
    snapshot.select(range, Rendering.caret_focus_elements, _ =>
62988
224e8d8a4fb8 tuned rendering;
wenzelm
parents: 62986
diff changeset
   314
      {
62991
35f1475e9ced clarified rendering wrt. hyperlinks;
wenzelm
parents: 62989
diff changeset
   315
        case Text.Info(_, XML.Elem(Markup(Markup.ENTITY, Markup.Entity.Ref(i)), _)) if focus(i) =>
35f1475e9ced clarified rendering wrt. hyperlinks;
wenzelm
parents: 62989
diff changeset
   316
          Some(entity_ref_color)
62988
224e8d8a4fb8 tuned rendering;
wenzelm
parents: 62986
diff changeset
   317
        case _ => None
224e8d8a4fb8 tuned rendering;
wenzelm
parents: 62986
diff changeset
   318
      })
224e8d8a4fb8 tuned rendering;
wenzelm
parents: 62986
diff changeset
   319
62986
9d2fae6b31cc background color for entity def/ref focus;
wenzelm
parents: 62806
diff changeset
   320
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   321
  /* highlighted area */
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   322
49358
0fa351b1bd14 clarified markup names;
wenzelm
parents: 49356
diff changeset
   323
  def highlight(range: Text.Range): Option[Text.Info[Color]] =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   324
    snapshot.select(range, JEdit_Rendering.highlight_elements, _ =>
55620
19dffae33cde cumulate/select wrt. precise elements guard;
wenzelm
parents: 55619
diff changeset
   325
      {
19dffae33cde cumulate/select wrt. precise elements guard;
wenzelm
parents: 55619
diff changeset
   326
        case info => Some(Text.Info(snapshot.convert(info.range), highlight_color))
55689
wenzelm
parents: 55688
diff changeset
   327
      }).headOption.map(_.info)
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   328
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   329
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   330
  /* hyperlinks */
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   331
52980
28f59ca8ce78 manage hyperlinks via PIDE editor interface;
wenzelm
parents: 52900
diff changeset
   332
  def hyperlink(range: Text.Range): Option[Text.Info[PIDE.editor.Hyperlink]] =
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   333
  {
55651
fa42cf3fe79b tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents: 55649
diff changeset
   334
    snapshot.cumulate[Vector[Text.Info[PIDE.editor.Hyperlink]]](
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   335
      range, Vector.empty, JEdit_Rendering.hyperlink_elements, _ =>
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   336
        {
56458
a8d960baa5c2 simplified blob again (amending 1e77ed11f2f7): only store file node name, i.e. the raw editor file name;
wenzelm
parents: 56395
diff changeset
   337
          case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _))) =>
64654
31b681e38c70 clarified signature;
wenzelm
parents: 64622
diff changeset
   338
            val file = resources.append_file(snapshot.node_name.master_dir, name)
31b681e38c70 clarified signature;
wenzelm
parents: 64622
diff changeset
   339
            val link = PIDE.editor.hyperlink_file(true, file)
55622
ce575c2212fc clarified markup cumulation order (see also 25306d92f4ad and 0009a6ebc83b), e.g. relevant for completion_context;
wenzelm
parents: 55620
diff changeset
   340
            Some(links :+ Text.Info(snapshot.convert(info_range), link))
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   341
61660
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61603
diff changeset
   342
          case (links, Text.Info(info_range, XML.Elem(Markup.Doc(name), _))) =>
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61603
diff changeset
   343
            PIDE.editor.hyperlink_doc(name).map(link =>
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61603
diff changeset
   344
              (links :+ Text.Info(snapshot.convert(info_range), link)))
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61603
diff changeset
   345
54702
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54515
diff changeset
   346
          case (links, Text.Info(info_range, XML.Elem(Markup.Url(name), _))) =>
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54515
diff changeset
   347
            val link = PIDE.editor.hyperlink_url(name)
55622
ce575c2212fc clarified markup cumulation order (see also 25306d92f4ad and 0009a6ebc83b), e.g. relevant for completion_context;
wenzelm
parents: 55620
diff changeset
   348
            Some(links :+ Text.Info(snapshot.convert(info_range), link))
54702
3daeba5130f0 added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
wenzelm
parents: 54515
diff changeset
   349
64660
ef85bb6491b3 omit unused markup;
wenzelm
parents: 64654
diff changeset
   350
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.ENTITY, props), _))) =>
60893
3c8b9b4b577c support hyperlinks with optional focus change;
wenzelm
parents: 60882
diff changeset
   351
            val opt_link = PIDE.editor.hyperlink_def_position(true, snapshot, props)
60215
5fb4990dfc73 misc tuning, based on warnings by IntelliJ IDEA;
wenzelm
parents: 59319
diff changeset
   352
            opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link))
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   353
55545
4a9f76263ece hyperlink for visible positions;
wenzelm
parents: 55526
diff changeset
   354
          case (links, Text.Info(info_range, XML.Elem(Markup(Markup.POSITION, props), _))) =>
60893
3c8b9b4b577c support hyperlinks with optional focus change;
wenzelm
parents: 60882
diff changeset
   355
            val opt_link = PIDE.editor.hyperlink_position(true, snapshot, props)
60215
5fb4990dfc73 misc tuning, based on warnings by IntelliJ IDEA;
wenzelm
parents: 59319
diff changeset
   356
            opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link))
52889
ea3338812e67 more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents: 52873
diff changeset
   357
58545
30b75b7958d6 citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents: 58464
diff changeset
   358
          case (links, Text.Info(info_range, XML.Elem(Markup.Citation(name), _))) =>
30b75b7958d6 citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents: 58464
diff changeset
   359
            val opt_link =
64829
07f209e957bc refer to bibtex entries via general Document_Model, instead of editor buffers;
wenzelm
parents: 64767
diff changeset
   360
              Document_Model.bibtex_entries_iterator.collectFirst(
64831
4792ee012e94 tuned signature;
wenzelm
parents: 64829
diff changeset
   361
                { case Text.Info(entry_range, (entry, model)) if entry == name =>
4792ee012e94 tuned signature;
wenzelm
parents: 64829
diff changeset
   362
                    PIDE.editor.hyperlink_model(true, model, entry_range.start) })
60215
5fb4990dfc73 misc tuning, based on warnings by IntelliJ IDEA;
wenzelm
parents: 59319
diff changeset
   363
            opt_link.map(link => links :+ Text.Info(snapshot.convert(info_range), link))
58545
30b75b7958d6 citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents: 58464
diff changeset
   364
52889
ea3338812e67 more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents: 52873
diff changeset
   365
          case _ => None
55622
ce575c2212fc clarified markup cumulation order (see also 25306d92f4ad and 0009a6ebc83b), e.g. relevant for completion_context;
wenzelm
parents: 55620
diff changeset
   366
        }) match { case Text.Info(_, _ :+ info) :: _ => Some(info) case _ => None }
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   367
  }
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   368
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   369
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   370
  /* active elements */
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   371
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50215
diff changeset
   372
  def active(range: Text.Range): Option[Text.Info[XML.Elem]] =
65101
4263b2a201b3 symbolic Rendering.Color;
wenzelm
parents: 65100
diff changeset
   373
    snapshot.select(range, Rendering.active_elements, command_states =>
55620
19dffae33cde cumulate/select wrt. precise elements guard;
wenzelm
parents: 55619
diff changeset
   374
      {
19dffae33cde cumulate/select wrt. precise elements guard;
wenzelm
parents: 55619
diff changeset
   375
        case Text.Info(info_range, elem) =>
55623
wenzelm
parents: 55622
diff changeset
   376
          if (elem.name == Markup.DIALOG) {
wenzelm
parents: 55622
diff changeset
   377
            elem match {
wenzelm
parents: 55622
diff changeset
   378
              case Protocol.Dialog(_, serial, _)
56354
a6f8c3566560 more direct command states -- merge_results is hardly ever needed;
wenzelm
parents: 56352
diff changeset
   379
              if !command_states.exists(st => st.results.defined(serial)) =>
55623
wenzelm
parents: 55622
diff changeset
   380
                Some(Text.Info(snapshot.convert(info_range), elem))
wenzelm
parents: 55622
diff changeset
   381
              case _ => None
wenzelm
parents: 55622
diff changeset
   382
            }
wenzelm
parents: 55622
diff changeset
   383
          }
wenzelm
parents: 55622
diff changeset
   384
          else Some(Text.Info(snapshot.convert(info_range), elem))
55689
wenzelm
parents: 55688
diff changeset
   385
      }).headOption.map(_.info)
49492
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents: 49476
diff changeset
   386
50502
51408dde956f include command results in tooltip as well;
wenzelm
parents: 50501
diff changeset
   387
  def command_results(range: Text.Range): Command.Results =
56354
a6f8c3566560 more direct command states -- merge_results is hardly ever needed;
wenzelm
parents: 56352
diff changeset
   388
    Command.State.merge_results(
56743
81370dfadb1d tuned signature;
wenzelm
parents: 56600
diff changeset
   389
      snapshot.select[List[Command.State]](range, Markup.Elements.full, command_states =>
56354
a6f8c3566560 more direct command states -- merge_results is hardly ever needed;
wenzelm
parents: 56352
diff changeset
   390
        { case _ => Some(command_states) }).flatMap(_.info))
50502
51408dde956f include command results in tooltip as well;
wenzelm
parents: 50501
diff changeset
   391
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   392
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   393
  /* tooltips */
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   394
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   395
  def tooltip_margin: Int = options.int("jedit_tooltip_margin")
64622
529bbb8977c7 more uniform rendering for Isabelle/jEdit and Isabelle/VSCode;
wenzelm
parents: 64621
diff changeset
   396
  def timing_threshold: Double = options.real("jedit_timing_threshold")
50554
0493efcc97e9 more general handling of graphics configurations, to increase chance of proper positioning of tooltips in multi-screen environment;
wenzelm
parents: 50547
diff changeset
   397
64748
155bf8632104 clarified multiple tooltips;
wenzelm
parents: 64677
diff changeset
   398
  def tooltip(range: Text.Range): Option[Text.Info[XML.Body]] =
65132
wenzelm
parents: 65129
diff changeset
   399
    tooltips(Rendering.tooltip_elements, range).map(info => info.map(Pretty.fbreaks(_)))
65129
06a7c2d316cf more general tooltips, with uniform info range handling;
wenzelm
parents: 65128
diff changeset
   400
06a7c2d316cf more general tooltips, with uniform info range handling;
wenzelm
parents: 65128
diff changeset
   401
  def tooltip_message(range: Text.Range): Option[Text.Info[XML.Body]] =
65132
wenzelm
parents: 65129
diff changeset
   402
    tooltips(Rendering.tooltip_message_elements, range).map(info => info.map(Pretty.fbreaks(_)))
64748
155bf8632104 clarified multiple tooltips;
wenzelm
parents: 64677
diff changeset
   403
52873
9e934d4fff00 tuned signature;
wenzelm
parents: 52650
diff changeset
   404
  lazy val tooltip_close_icon = JEdit_Lib.load_icon(options.string("tooltip_close_icon"))
9e934d4fff00 tuned signature;
wenzelm
parents: 52650
diff changeset
   405
  lazy val tooltip_detach_icon = JEdit_Lib.load_icon(options.string("tooltip_detach_icon"))
52472
3a43a8b1ecb0 load icons via options -- prefer IntelliJ IDEA for now;
wenzelm
parents: 52471
diff changeset
   406
3a43a8b1ecb0 load icons via options -- prefer IntelliJ IDEA for now;
wenzelm
parents: 52471
diff changeset
   407
56495
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56458
diff changeset
   408
  /* gutter */
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56458
diff changeset
   409
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56458
diff changeset
   410
  private def gutter_message_pri(msg: XML.Tree): Int =
64676
fd2df1ea3bb4 clarified modules;
wenzelm
parents: 64660
diff changeset
   411
    if (Protocol.is_error(msg)) Rendering.error_pri
fd2df1ea3bb4 clarified modules;
wenzelm
parents: 64660
diff changeset
   412
    else if (Protocol.is_legacy(msg)) Rendering.legacy_pri
fd2df1ea3bb4 clarified modules;
wenzelm
parents: 64660
diff changeset
   413
    else if (Protocol.is_warning(msg)) Rendering.warning_pri
fd2df1ea3bb4 clarified modules;
wenzelm
parents: 64660
diff changeset
   414
    else if (Protocol.is_information(msg)) Rendering.information_pri
56495
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56458
diff changeset
   415
    else 0
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   416
59129
6959ceb53ac8 more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents: 59125
diff changeset
   417
  private lazy val gutter_message_content = Map(
64676
fd2df1ea3bb4 clarified modules;
wenzelm
parents: 64660
diff changeset
   418
    Rendering.information_pri ->
65127
ce8b8f979afd more generic colors;
wenzelm
parents: 65125
diff changeset
   419
      (JEdit_Lib.load_icon(options.string("gutter_information_icon")),
ce8b8f979afd more generic colors;
wenzelm
parents: 65125
diff changeset
   420
        color(Rendering.Color.information_message)),
64676
fd2df1ea3bb4 clarified modules;
wenzelm
parents: 64660
diff changeset
   421
    Rendering.warning_pri ->
65127
ce8b8f979afd more generic colors;
wenzelm
parents: 65125
diff changeset
   422
      (JEdit_Lib.load_icon(options.string("gutter_warning_icon")),
ce8b8f979afd more generic colors;
wenzelm
parents: 65125
diff changeset
   423
        color(Rendering.Color.warning_message)),
64676
fd2df1ea3bb4 clarified modules;
wenzelm
parents: 64660
diff changeset
   424
    Rendering.legacy_pri ->
65127
ce8b8f979afd more generic colors;
wenzelm
parents: 65125
diff changeset
   425
      (JEdit_Lib.load_icon(options.string("gutter_legacy_icon")),
ce8b8f979afd more generic colors;
wenzelm
parents: 65125
diff changeset
   426
        color(Rendering.Color.legacy_message)),
64676
fd2df1ea3bb4 clarified modules;
wenzelm
parents: 64660
diff changeset
   427
    Rendering.error_pri ->
65127
ce8b8f979afd more generic colors;
wenzelm
parents: 65125
diff changeset
   428
      (JEdit_Lib.load_icon(options.string("gutter_error_icon")),
ce8b8f979afd more generic colors;
wenzelm
parents: 65125
diff changeset
   429
        color(Rendering.Color.error_message)))
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   430
59129
6959ceb53ac8 more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents: 59125
diff changeset
   431
  def gutter_content(range: Text.Range): Option[(Icon, Color)] =
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   432
  {
56495
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56458
diff changeset
   433
    val pris =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   434
      snapshot.cumulate[Int](range, 0, JEdit_Rendering.gutter_elements, _ =>
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   435
        {
56495
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56458
diff changeset
   436
          case (pri, Text.Info(_, msg @ XML.Elem(Markup(_, Markup.Serial(serial)), _))) =>
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56458
diff changeset
   437
            Some(pri max gutter_message_pri(msg))
52889
ea3338812e67 more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents: 52873
diff changeset
   438
          case _ => None
56495
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56458
diff changeset
   439
        }).map(_.info)
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56458
diff changeset
   440
59129
6959ceb53ac8 more informative gutter content: fall-back on background color, e.g. when line numbers are enabled;
wenzelm
parents: 59125
diff changeset
   441
    gutter_message_content.get((0 /: pris)(_ max _))
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   442
  }
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   443
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   444
65128
wenzelm
parents: 65127
diff changeset
   445
  /* message output */
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   446
65121
12c6774a8f65 more generic rendering;
wenzelm
parents: 65102
diff changeset
   447
  def squiggly_underline(range: Text.Range): List[Text.Info[Rendering.Color.Value]] =
12c6774a8f65 more generic rendering;
wenzelm
parents: 65102
diff changeset
   448
    message_underline_color(JEdit_Rendering.squiggly_elements, range)
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   449
65124
759c64c39a6f more generic colors;
wenzelm
parents: 65121
diff changeset
   450
  def line_background(range: Text.Range): Option[(Rendering.Color.Value, Boolean)] =
49473
ca7e2c21b104 tuned rendering;
wenzelm
parents: 49423
diff changeset
   451
  {
49474
e7ff10e1a155 clarified message background;
wenzelm
parents: 49473
diff changeset
   452
    val results =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   453
      snapshot.cumulate[Int](range, 0, JEdit_Rendering.line_background_elements, _ =>
49473
ca7e2c21b104 tuned rendering;
wenzelm
parents: 49423
diff changeset
   454
        {
64676
fd2df1ea3bb4 clarified modules;
wenzelm
parents: 64660
diff changeset
   455
          case (pri, Text.Info(_, elem)) => Some(pri max Rendering.message_pri(elem.name))
49474
e7ff10e1a155 clarified message background;
wenzelm
parents: 49473
diff changeset
   456
        })
e7ff10e1a155 clarified message background;
wenzelm
parents: 49473
diff changeset
   457
    val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
e7ff10e1a155 clarified message background;
wenzelm
parents: 49473
diff changeset
   458
65124
759c64c39a6f more generic colors;
wenzelm
parents: 65121
diff changeset
   459
    Rendering.message_background_color.get(pri).map(message_color =>
61719
318f324d41f5 less intrusive rendering, notably for State dockable;
wenzelm
parents: 61718
diff changeset
   460
      {
318f324d41f5 less intrusive rendering, notably for State dockable;
wenzelm
parents: 61718
diff changeset
   461
        val is_separator =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   462
          snapshot.cumulate[Boolean](range, false, JEdit_Rendering.separator_elements, _ =>
61719
318f324d41f5 less intrusive rendering, notably for State dockable;
wenzelm
parents: 61718
diff changeset
   463
            {
318f324d41f5 less intrusive rendering, notably for State dockable;
wenzelm
parents: 61718
diff changeset
   464
              case _ => Some(true)
318f324d41f5 less intrusive rendering, notably for State dockable;
wenzelm
parents: 61718
diff changeset
   465
            }).exists(_.info)
318f324d41f5 less intrusive rendering, notably for State dockable;
wenzelm
parents: 61718
diff changeset
   466
        (message_color, is_separator)
318f324d41f5 less intrusive rendering, notably for State dockable;
wenzelm
parents: 61718
diff changeset
   467
      })
49473
ca7e2c21b104 tuned rendering;
wenzelm
parents: 49423
diff changeset
   468
  }
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   469
56299
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56298
diff changeset
   470
  def output_messages(results: Command.Results): List[XML.Tree] =
57691
9616643a3032 output state first -- avoid fluctuation wrt. warnings, errors, etc.;
wenzelm
parents: 57595
diff changeset
   471
  {
9616643a3032 output state first -- avoid fluctuation wrt. warnings, errors, etc.;
wenzelm
parents: 57595
diff changeset
   472
    val (states, other) =
9616643a3032 output state first -- avoid fluctuation wrt. warnings, errors, etc.;
wenzelm
parents: 57595
diff changeset
   473
      results.iterator.map(_._2).filterNot(Protocol.is_result(_)).toList
9616643a3032 output state first -- avoid fluctuation wrt. warnings, errors, etc.;
wenzelm
parents: 57595
diff changeset
   474
        .partition(Protocol.is_state(_))
61727
6f1a84d78865 reverted 2abbe7d700e9: "state" output is not necessarily proof state;
wenzelm
parents: 61722
diff changeset
   475
    states ::: other
57691
9616643a3032 output state first -- avoid fluctuation wrt. warnings, errors, etc.;
wenzelm
parents: 57595
diff changeset
   476
  }
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50499
diff changeset
   477
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50499
diff changeset
   478
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   479
  /* text color */
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   480
61175
1d9c121cbe4d avoid hardwired colors;
wenzelm
parents: 61011
diff changeset
   481
  val foreground_color = jEdit.getColorProperty("view.fgColor")
1d9c121cbe4d avoid hardwired colors;
wenzelm
parents: 61011
diff changeset
   482
55647
106a57dec7af more lightweight Rendering;
wenzelm
parents: 55646
diff changeset
   483
  private lazy val text_colors: Map[String, Color] = Map(
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   484
      Markup.KEYWORD1 -> keyword1_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   485
      Markup.KEYWORD2 -> keyword2_color,
55765
ec7ca5388dea markup for method combinators;
wenzelm
parents: 55749
diff changeset
   486
      Markup.KEYWORD3 -> keyword3_color,
55919
2eb8c13339a5 more explicit quasi_keyword markup, for Args.$$$ material, which is somewhere in between of outer and inner syntax;
wenzelm
parents: 55914
diff changeset
   487
      Markup.QUASI_KEYWORD -> quasi_keyword_color,
56202
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56176
diff changeset
   488
      Markup.IMPROPER -> improper_color,
56064
7658489047e3 clarified Markup.operator vs. Markup.delimiter;
wenzelm
parents: 56063
diff changeset
   489
      Markup.OPERATOR -> operator_color,
61175
1d9c121cbe4d avoid hardwired colors;
wenzelm
parents: 61011
diff changeset
   490
      Markup.STRING -> foreground_color,
1d9c121cbe4d avoid hardwired colors;
wenzelm
parents: 61011
diff changeset
   491
      Markup.ALT_STRING -> foreground_color,
1d9c121cbe4d avoid hardwired colors;
wenzelm
parents: 61011
diff changeset
   492
      Markup.VERBATIM -> foreground_color,
1d9c121cbe4d avoid hardwired colors;
wenzelm
parents: 61011
diff changeset
   493
      Markup.CARTOUCHE -> foreground_color,
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   494
      Markup.LITERAL -> keyword1_color,
61175
1d9c121cbe4d avoid hardwired colors;
wenzelm
parents: 61011
diff changeset
   495
      Markup.DELIMITER -> foreground_color,
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   496
      Markup.TFREE -> tfree_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   497
      Markup.TVAR -> tvar_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   498
      Markup.FREE -> free_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   499
      Markup.SKOLEM -> skolem_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   500
      Markup.BOUND -> bound_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   501
      Markup.VAR -> var_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   502
      Markup.INNER_STRING -> inner_quoted_color,
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 54702
diff changeset
   503
      Markup.INNER_CARTOUCHE -> inner_cartouche_color,
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   504
      Markup.INNER_COMMENT -> inner_comment_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   505
      Markup.DYNAMIC_FACT -> dynamic_color,
63347
e344dc82f6c2 report class parameters within instantiation;
wenzelm
parents: 63340
diff changeset
   506
      Markup.CLASS_PARAMETER -> class_parameter_color,
55526
39708e59f4b0 more markup;
wenzelm
parents: 55514
diff changeset
   507
      Markup.ANTIQUOTE -> antiquote_color,
55505
2a1ca7f6607b more uniform ML keyword markup;
wenzelm
parents: 55503
diff changeset
   508
      Markup.ML_KEYWORD1 -> keyword1_color,
2a1ca7f6607b more uniform ML keyword markup;
wenzelm
parents: 55503
diff changeset
   509
      Markup.ML_KEYWORD2 -> keyword2_color,
2a1ca7f6607b more uniform ML keyword markup;
wenzelm
parents: 55503
diff changeset
   510
      Markup.ML_KEYWORD3 -> keyword3_color,
61175
1d9c121cbe4d avoid hardwired colors;
wenzelm
parents: 61011
diff changeset
   511
      Markup.ML_DELIMITER -> foreground_color,
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   512
      Markup.ML_NUMERAL -> inner_numeral_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   513
      Markup.ML_CHAR -> inner_quoted_color,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50200
diff changeset
   514
      Markup.ML_STRING -> inner_quoted_color,
56278
2576d3a40ed6 separate tokenization and language context for SML: no symbols, no antiquotes;
wenzelm
parents: 56208
diff changeset
   515
      Markup.ML_COMMENT -> inner_comment_color,
2576d3a40ed6 separate tokenization and language context for SML: no symbols, no antiquotes;
wenzelm
parents: 56208
diff changeset
   516
      Markup.SML_STRING -> inner_quoted_color,
2576d3a40ed6 separate tokenization and language context for SML: no symbols, no antiquotes;
wenzelm
parents: 56208
diff changeset
   517
      Markup.SML_COMMENT -> inner_comment_color)
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   518
55820
61869776ce1f tuned signature -- more explicit Document.Elements;
wenzelm
parents: 55790
diff changeset
   519
  private lazy val text_color_elements =
56743
81370dfadb1d tuned signature;
wenzelm
parents: 56600
diff changeset
   520
    Markup.Elements(text_colors.keySet)
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   521
52900
d29bf6db8a2d more elementary list structures for markup tree traversal;
wenzelm
parents: 52890
diff changeset
   522
  def text_color(range: Text.Range, color: Color): List[Text.Info[Color]] =
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   523
  {
52900
d29bf6db8a2d more elementary list structures for markup tree traversal;
wenzelm
parents: 52890
diff changeset
   524
    if (color == Token_Markup.hidden_color) List(Text.Info(range, color))
50196
94886ebf090f retain hidden_color (i.e. transparent white) instead of replacing it by semantic text color, to make control symbols more hidden and avoid "dirty" lines with some fonts;
wenzelm
parents: 50164
diff changeset
   525
    else
55651
fa42cf3fe79b tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents: 55649
diff changeset
   526
      snapshot.cumulate(range, color, text_color_elements, _ =>
50196
94886ebf090f retain hidden_color (i.e. transparent white) instead of replacing it by semantic text color, to make control symbols more hidden and avoid "dirty" lines with some fonts;
wenzelm
parents: 50164
diff changeset
   527
        {
52890
36e2c0c308eb tuned signature;
wenzelm
parents: 52889
diff changeset
   528
          case (_, Text.Info(_, elem)) => text_colors.get(elem.name)
50196
94886ebf090f retain hidden_color (i.e. transparent white) instead of replacing it by semantic text color, to make control symbols more hidden and avoid "dirty" lines with some fonts;
wenzelm
parents: 50164
diff changeset
   529
        })
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   530
  }
50542
58bd88159f8f fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents: 50507
diff changeset
   531
58bd88159f8f fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents: 50507
diff changeset
   532
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   533
  /* virtual bullets */
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   534
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   535
  def bullet(range: Text.Range): List[Text.Info[Color]] =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   536
    snapshot.select(range, JEdit_Rendering.bullet_elements, _ =>
60913
7432d6bb4195 clarified breakpoint rendering;
wenzelm
parents: 60893
diff changeset
   537
      {
7432d6bb4195 clarified breakpoint rendering;
wenzelm
parents: 60893
diff changeset
   538
        case Text.Info(_, Protocol.ML_Breakpoint(breakpoint)) =>
7432d6bb4195 clarified breakpoint rendering;
wenzelm
parents: 60893
diff changeset
   539
          Debugger.active_breakpoint_state(breakpoint).map(b =>
7432d6bb4195 clarified breakpoint rendering;
wenzelm
parents: 60893
diff changeset
   540
            if (b) breakpoint_enabled_color else breakpoint_disabled_color)
7432d6bb4195 clarified breakpoint rendering;
wenzelm
parents: 60893
diff changeset
   541
        case _ => Some(bullet_color)
7432d6bb4195 clarified breakpoint rendering;
wenzelm
parents: 60893
diff changeset
   542
      })
55626
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   543
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   544
0e2b7f04c944 tuned comments;
wenzelm
parents: 55625
diff changeset
   545
  /* text folds */
50542
58bd88159f8f fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents: 50507
diff changeset
   546
52900
d29bf6db8a2d more elementary list structures for markup tree traversal;
wenzelm
parents: 52890
diff changeset
   547
  def fold_depth(range: Text.Range): List[Text.Info[Int]] =
64621
7116f2634e32 clarified module name;
wenzelm
parents: 63681
diff changeset
   548
    snapshot.cumulate[Int](range, 0, JEdit_Rendering.fold_depth_elements, _ =>
50542
58bd88159f8f fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents: 50507
diff changeset
   549
      {
55620
19dffae33cde cumulate/select wrt. precise elements guard;
wenzelm
parents: 55619
diff changeset
   550
        case (depth, _) => Some(depth + 1)
50542
58bd88159f8f fold handling within Pretty_Text_Area, based on formal document content, which is static here;
wenzelm
parents: 50507
diff changeset
   551
      })
49356
6e0c0ffb6ec7 more static handling of rendering options;
wenzelm
parents: 49355
diff changeset
   552
}