src/Pure/PIDE/markup.ML
author wenzelm
Sun May 06 22:15:52 2018 +0200 (15 months ago)
changeset 68090 7c8ed28dd40a
parent 68089 d934bbfeac32
child 68101 0699a0bacc50
permissions -rw-r--r--
tuned signature;
clarified modules;
     1 (*  Title:      Pure/PIDE/markup.ML
     2     Author:     Makarius
     3 
     4 Quasi-abstract markup elements.
     5 *)
     6 
     7 signature MARKUP =
     8 sig
     9   type T = string * Properties.T
    10   val empty: T
    11   val is_empty: T -> bool
    12   val properties: Properties.T -> T -> T
    13   val nameN: string
    14   val name: string -> T -> T
    15   val kindN: string
    16   val serialN: string
    17   val serial_properties: int -> Properties.T
    18   val instanceN: string
    19   val languageN: string
    20   val symbolsN: string
    21   val delimitedN: string
    22   val is_delimited: Properties.T -> bool
    23   val language: {name: string, symbols: bool, antiquotes: bool, delimited: bool} -> T
    24   val language': {name: string, symbols: bool, antiquotes: bool} -> bool -> T
    25   val language_Isar: bool -> T
    26   val language_method: T
    27   val language_attribute: T
    28   val language_sort: bool -> T
    29   val language_type: bool -> T
    30   val language_term: bool -> T
    31   val language_prop: bool -> T
    32   val language_ML: bool -> T
    33   val language_SML: bool -> T
    34   val language_document: bool -> T
    35   val language_antiquotation: T
    36   val language_text: bool -> T
    37   val language_verbatim: bool -> T
    38   val language_latex: bool -> T
    39   val language_rail: T
    40   val language_path: T
    41   val language_mixfix: T
    42   val bindingN: string val binding: T
    43   val entityN: string val entity: string -> string -> T
    44   val get_entity_kind: T -> string option
    45   val defN: string
    46   val refN: string
    47   val completionN: string val completion: T
    48   val no_completionN: string val no_completion: T
    49   val lineN: string
    50   val end_lineN: string
    51   val offsetN: string
    52   val end_offsetN: string
    53   val fileN: string
    54   val idN: string
    55   val position_properties': string list
    56   val position_properties: string list
    57   val positionN: string val position: T
    58   val expressionN: string val expression: string -> T
    59   val citationN: string val citation: string -> T
    60   val pathN: string val path: string -> T
    61   val urlN: string val url: string -> T
    62   val docN: string val doc: string -> T
    63   val markupN: string
    64   val consistentN: string
    65   val unbreakableN: string
    66   val block_properties: string list
    67   val indentN: string
    68   val widthN: string
    69   val blockN: string val block: bool -> int -> T
    70   val breakN: string val break: int -> int -> T
    71   val fbreakN: string val fbreak: T
    72   val itemN: string val item: T
    73   val wordsN: string val words: T
    74   val no_wordsN: string val no_words: T
    75   val hiddenN: string val hidden: T
    76   val system_optionN: string
    77   val sessionN: string
    78   val theoryN: string
    79   val classN: string
    80   val type_nameN: string
    81   val constantN: string
    82   val fixedN: string val fixed: string -> T
    83   val caseN: string val case_: string -> T
    84   val dynamic_factN: string val dynamic_fact: string -> T
    85   val literal_factN: string val literal_fact: string -> T
    86   val method_modifierN: string
    87   val tfreeN: string val tfree: T
    88   val tvarN: string val tvar: T
    89   val freeN: string val free: T
    90   val skolemN: string val skolem: T
    91   val boundN: string val bound: T
    92   val varN: string val var: T
    93   val numeralN: string val numeral: T
    94   val literalN: string val literal: T
    95   val delimiterN: string val delimiter: T
    96   val inner_stringN: string val inner_string: T
    97   val inner_cartoucheN: string val inner_cartouche: T
    98   val inner_commentN: string val inner_comment: T
    99   val token_rangeN: string val token_range: T
   100   val sortingN: string val sorting: T
   101   val typingN: string val typing: T
   102   val class_parameterN: string val class_parameter: T
   103   val ML_keyword1N: string val ML_keyword1: T
   104   val ML_keyword2N: string val ML_keyword2: T
   105   val ML_keyword3N: string val ML_keyword3: T
   106   val ML_delimiterN: string val ML_delimiter: T
   107   val ML_tvarN: string val ML_tvar: T
   108   val ML_numeralN: string val ML_numeral: T
   109   val ML_charN: string val ML_char: T
   110   val ML_stringN: string val ML_string: T
   111   val ML_commentN: string val ML_comment: T
   112   val SML_stringN: string val SML_string: T
   113   val SML_commentN: string val SML_comment: T
   114   val ML_defN: string
   115   val ML_openN: string
   116   val ML_structureN: string
   117   val ML_typingN: string val ML_typing: T
   118   val ML_breakpointN: string val ML_breakpoint: int -> T
   119   val antiquotedN: string val antiquoted: T
   120   val antiquoteN: string val antiquote: T
   121   val ML_antiquotationN: string
   122   val document_antiquotationN: string
   123   val document_antiquotation_optionN: string
   124   val paragraphN: string val paragraph: T
   125   val text_foldN: string val text_fold: T
   126   val markdown_paragraphN: string val markdown_paragraph: T
   127   val markdown_itemN: string val markdown_item: T
   128   val markdown_bulletN: string val markdown_bullet: int -> T
   129   val markdown_listN: string val markdown_list: string -> T
   130   val itemizeN: string
   131   val enumerateN: string
   132   val descriptionN: string
   133   val inputN: string val input: bool -> Properties.T -> T
   134   val command_keywordN: string val command_keyword: T
   135   val commandN: string val command_properties: T -> T
   136   val keywordN: string val keyword_properties: T -> T
   137   val stringN: string val string: T
   138   val alt_stringN: string val alt_string: T
   139   val verbatimN: string val verbatim: T
   140   val cartoucheN: string val cartouche: T
   141   val commentN: string val comment: T
   142   val keyword1N: string val keyword1: T
   143   val keyword2N: string val keyword2: T
   144   val keyword3N: string val keyword3: T
   145   val quasi_keywordN: string val quasi_keyword: T
   146   val improperN: string val improper: T
   147   val operatorN: string val operator: T
   148   val elapsedN: string
   149   val cpuN: string
   150   val gcN: string
   151   val timing_properties: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> Properties.T
   152   val parse_timing_properties: Properties.T -> {elapsed: Time.time, cpu: Time.time, gc: Time.time}
   153   val command_timingN: string
   154   val command_timing_properties:
   155     {file: string, offset: int, name: string} -> Time.time -> Properties.T
   156   val parse_command_timing_properties:
   157     Properties.T -> ({file: string, offset: int, name: string} * Time.time) option
   158   val timingN: string val timing: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> T
   159   val command_indentN: string val command_indent: int -> T
   160   val goalN: string val goal: T
   161   val subgoalN: string val subgoal: string -> T
   162   val taskN: string
   163   val acceptedN: string val accepted: T
   164   val forkedN: string val forked: T
   165   val joinedN: string val joined: T
   166   val runningN: string val running: T
   167   val finishedN: string val finished: T
   168   val failedN: string val failed: T
   169   val consolidatedN: string val consolidated: T
   170   val exec_idN: string
   171   val initN: string
   172   val statusN: string val status: T
   173   val resultN: string val result: T
   174   val writelnN: string val writeln: T
   175   val stateN: string val state: T
   176   val informationN: string val information: T
   177   val tracingN: string val tracing: T
   178   val warningN: string val warning: T
   179   val legacyN: string val legacy: T
   180   val errorN: string val error: T
   181   val systemN: string val system: T
   182   val protocolN: string
   183   val reportN: string val report: T
   184   val no_reportN: string val no_report: T
   185   val badN: string val bad: unit -> T
   186   val intensifyN: string val intensify: T
   187   val browserN: string
   188   val graphviewN: string
   189   val sendbackN: string
   190   val paddingN: string
   191   val padding_line: Properties.entry
   192   val padding_command: Properties.entry
   193   val dialogN: string val dialog: serial -> string -> T
   194   val jedit_actionN: string
   195   val functionN: string
   196   val assign_update: Properties.T
   197   val removed_versions: Properties.T
   198   val protocol_handler: string -> Properties.T
   199   val invoke_scala: string -> string -> Properties.T
   200   val cancel_scala: string -> Properties.T
   201   val ML_statistics: Properties.entry
   202   val task_statistics: Properties.entry
   203   val command_timing: Properties.entry
   204   val theory_timing: Properties.entry
   205   val exportN: string
   206   type export_args = {id: string option, theory_name: string, name: string, compress: bool}
   207   val export: export_args -> Properties.T
   208   val loading_theory: string -> Properties.T
   209   val dest_loading_theory: Properties.T -> string option
   210   val build_session_finished: Properties.T
   211   val print_operationsN: string
   212   val print_operations: Properties.T
   213   val debugger_state: string -> Properties.T
   214   val debugger_output: string -> Properties.T
   215   val simp_trace_panelN: string
   216   val simp_trace_logN: string
   217   val simp_trace_stepN: string
   218   val simp_trace_recurseN: string
   219   val simp_trace_hintN: string
   220   val simp_trace_ignoreN: string
   221   val simp_trace_cancel: serial -> Properties.T
   222   val no_output: Output.output * Output.output
   223   val add_mode: string -> (T -> Output.output * Output.output) -> unit
   224   val output: T -> Output.output * Output.output
   225   val enclose: T -> Output.output -> Output.output
   226   val markup: T -> string -> string
   227   val markups: T list -> string -> string
   228   val markup_only: T -> string
   229   val markup_report: string -> string
   230 end;
   231 
   232 structure Markup: MARKUP =
   233 struct
   234 
   235 (** markup elements **)
   236 
   237 (* basic markup *)
   238 
   239 type T = string * Properties.T;
   240 
   241 val empty = ("", []);
   242 
   243 fun is_empty ("", _) = true
   244   | is_empty _ = false;
   245 
   246 
   247 fun properties more_props ((elem, props): T) =
   248   (elem, fold_rev Properties.put more_props props);
   249 
   250 fun markup_elem name = (name, (name, []): T);
   251 fun markup_string name prop = (name, fn s => (name, [(prop, s)]): T);
   252 fun markup_int name prop = (name, fn i => (name, [(prop, Value.print_int i)]): T);
   253 
   254 
   255 (* misc properties *)
   256 
   257 val nameN = "name";
   258 fun name a = properties [(nameN, a)];
   259 
   260 val kindN = "kind";
   261 
   262 val serialN = "serial";
   263 fun serial_properties i = [(serialN, Value.print_int i)];
   264 
   265 val instanceN = "instance";
   266 
   267 
   268 (* embedded languages *)
   269 
   270 val languageN = "language";
   271 val symbolsN = "symbols";
   272 val antiquotesN = "antiquotes";
   273 val delimitedN = "delimited"
   274 
   275 fun is_delimited props =
   276   Properties.get props delimitedN = SOME "true";
   277 
   278 fun language {name, symbols, antiquotes, delimited} =
   279   (languageN,
   280    [(nameN, name),
   281     (symbolsN, Value.print_bool symbols),
   282     (antiquotesN, Value.print_bool antiquotes),
   283     (delimitedN, Value.print_bool delimited)]);
   284 
   285 fun language' {name, symbols, antiquotes} delimited =
   286   language {name = name, symbols = symbols, antiquotes = antiquotes, delimited = delimited};
   287 
   288 val language_Isar = language' {name = "Isar", symbols = true, antiquotes = false};
   289 val language_method =
   290   language {name = "method", symbols = true, antiquotes = false, delimited = false};
   291 val language_attribute =
   292   language {name = "attribute", symbols = true, antiquotes = false, delimited = false};
   293 val language_sort = language' {name = "sort", symbols = true, antiquotes = false};
   294 val language_type = language' {name = "type", symbols = true, antiquotes = false};
   295 val language_term = language' {name = "term", symbols = true, antiquotes = false};
   296 val language_prop = language' {name = "prop", symbols = true, antiquotes = false};
   297 val language_ML = language' {name = "ML", symbols = false, antiquotes = true};
   298 val language_SML = language' {name = "SML", symbols = false, antiquotes = false};
   299 val language_document = language' {name = "document", symbols = false, antiquotes = true};
   300 val language_antiquotation =
   301   language {name = "antiquotation", symbols = true, antiquotes = false, delimited = true};
   302 val language_text = language' {name = "text", symbols = true, antiquotes = false};
   303 val language_verbatim = language' {name = "verbatim_text", symbols = true, antiquotes = false};
   304 val language_latex = language' {name = "latex", symbols = false, antiquotes = false};
   305 val language_rail = language {name = "rail", symbols = true, antiquotes = true, delimited = true};
   306 val language_path = language {name = "path", symbols = false, antiquotes = false, delimited = true};
   307 val language_mixfix =
   308   language {name = "mixfix_annotation", symbols = true, antiquotes = false, delimited = true};
   309 
   310 
   311 (* formal entities *)
   312 
   313 val (bindingN, binding) = markup_elem "binding";
   314 
   315 val entityN = "entity";
   316 fun entity kind name =
   317   (entityN,
   318     (if name = "" then [] else [(nameN, name)]) @ (if kind = "" then [] else [(kindN, kind)]));
   319 
   320 fun get_entity_kind (name, props) =
   321   if name = entityN then Properties.get props kindN
   322   else NONE;
   323 
   324 val defN = "def";
   325 val refN = "ref";
   326 
   327 
   328 (* completion *)
   329 
   330 val (completionN, completion) = markup_elem "completion";
   331 val (no_completionN, no_completion) = markup_elem "no_completion";
   332 
   333 
   334 (* position *)
   335 
   336 val lineN = "line";
   337 val end_lineN = "end_line";
   338 
   339 val offsetN = "offset";
   340 val end_offsetN = "end_offset";
   341 
   342 val fileN = "file";
   343 val idN = "id";
   344 
   345 val position_properties' = [fileN, idN];
   346 val position_properties = [lineN, offsetN, end_offsetN] @ position_properties';
   347 
   348 val (positionN, position) = markup_elem "position";
   349 
   350 
   351 (* expression *)
   352 
   353 val expressionN = "expression";
   354 fun expression kind = (expressionN, if kind = "" then [] else [(kindN, kind)]);
   355 
   356 
   357 (* citation *)
   358 
   359 val (citationN, citation) = markup_string "citation" nameN;
   360 
   361 
   362 (* external resources *)
   363 
   364 val (pathN, path) = markup_string "path" nameN;
   365 val (urlN, url) = markup_string "url" nameN;
   366 val (docN, doc) = markup_string "doc" nameN;
   367 
   368 
   369 (* pretty printing *)
   370 
   371 val markupN = "markup";
   372 val consistentN = "consistent";
   373 val unbreakableN = "unbreakable";
   374 val indentN = "indent";
   375 
   376 val block_properties = [markupN, consistentN, unbreakableN, indentN];
   377 
   378 val widthN = "width";
   379 
   380 val blockN = "block";
   381 fun block c i =
   382   (blockN,
   383     (if c then [(consistentN, Value.print_bool c)] else []) @
   384     (if i <> 0 then [(indentN, Value.print_int i)] else []));
   385 
   386 val breakN = "break";
   387 fun break w i =
   388   (breakN,
   389     (if w <> 0 then [(widthN, Value.print_int w)] else []) @
   390     (if i <> 0 then [(indentN, Value.print_int i)] else []));
   391 
   392 val (fbreakN, fbreak) = markup_elem "fbreak";
   393 
   394 val (itemN, item) = markup_elem "item";
   395 
   396 
   397 (* text properties *)
   398 
   399 val (wordsN, words) = markup_elem "words";
   400 val (no_wordsN, no_words) = markup_elem "no_words";
   401 
   402 val (hiddenN, hidden) = markup_elem "hidden";
   403 
   404 
   405 (* misc entities *)
   406 
   407 val system_optionN = "system_option";
   408 
   409 val sessionN = "session";
   410 
   411 val theoryN = "theory";
   412 val classN = "class";
   413 val type_nameN = "type_name";
   414 val constantN = "constant";
   415 
   416 val (fixedN, fixed) = markup_string "fixed" nameN;
   417 val (caseN, case_) = markup_string "case" nameN;
   418 val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" nameN;
   419 val (literal_factN, literal_fact) = markup_string "literal_fact" nameN;
   420 
   421 val method_modifierN = "method_modifier";
   422 
   423 
   424 (* inner syntax *)
   425 
   426 val (tfreeN, tfree) = markup_elem "tfree";
   427 val (tvarN, tvar) = markup_elem "tvar";
   428 val (freeN, free) = markup_elem "free";
   429 val (skolemN, skolem) = markup_elem "skolem";
   430 val (boundN, bound) = markup_elem "bound";
   431 val (varN, var) = markup_elem "var";
   432 val (numeralN, numeral) = markup_elem "numeral";
   433 val (literalN, literal) = markup_elem "literal";
   434 val (delimiterN, delimiter) = markup_elem "delimiter";
   435 val (inner_stringN, inner_string) = markup_elem "inner_string";
   436 val (inner_cartoucheN, inner_cartouche) = markup_elem "inner_cartouche";
   437 val (inner_commentN, inner_comment) = markup_elem "inner_comment";
   438 
   439 val (token_rangeN, token_range) = markup_elem "token_range";
   440 
   441 val (sortingN, sorting) = markup_elem "sorting";
   442 val (typingN, typing) = markup_elem "typing";
   443 val (class_parameterN, class_parameter) = markup_elem "class_parameter";
   444 
   445 
   446 (* ML *)
   447 
   448 val (ML_keyword1N, ML_keyword1) = markup_elem "ML_keyword1";
   449 val (ML_keyword2N, ML_keyword2) = markup_elem "ML_keyword2";
   450 val (ML_keyword3N, ML_keyword3) = markup_elem "ML_keyword3";
   451 val (ML_delimiterN, ML_delimiter) = markup_elem "ML_delimiter";
   452 val (ML_tvarN, ML_tvar) = markup_elem "ML_tvar";
   453 val (ML_numeralN, ML_numeral) = markup_elem "ML_numeral";
   454 val (ML_charN, ML_char) = markup_elem "ML_char";
   455 val (ML_stringN, ML_string) = markup_elem "ML_string";
   456 val (ML_commentN, ML_comment) = markup_elem "ML_comment";
   457 val (SML_stringN, SML_string) = markup_elem "SML_string";
   458 val (SML_commentN, SML_comment) = markup_elem "SML_comment";
   459 
   460 val ML_defN = "ML_def";
   461 val ML_openN = "ML_open";
   462 val ML_structureN = "ML_structure";
   463 val (ML_typingN, ML_typing) = markup_elem "ML_typing";
   464 
   465 val (ML_breakpointN, ML_breakpoint) = markup_int "ML_breakpoint" serialN;
   466 
   467 
   468 (* antiquotations *)
   469 
   470 val (antiquotedN, antiquoted) = markup_elem "antiquoted";
   471 val (antiquoteN, antiquote) = markup_elem "antiquote";
   472 
   473 val ML_antiquotationN = "ML_antiquotation";
   474 val document_antiquotationN = "document_antiquotation";
   475 val document_antiquotation_optionN = "document_antiquotation_option";
   476 
   477 
   478 (* text structure *)
   479 
   480 val (paragraphN, paragraph) = markup_elem "paragraph";
   481 val (text_foldN, text_fold) = markup_elem "text_fold";
   482 
   483 
   484 (* Markdown document structure *)
   485 
   486 val (markdown_paragraphN, markdown_paragraph) = markup_elem "markdown_paragraph";
   487 val (markdown_itemN, markdown_item) = markup_elem "markdown_item";
   488 val (markdown_bulletN, markdown_bullet) = markup_int "markdown_bullet" "depth";
   489 val (markdown_listN, markdown_list) = markup_string "markdown_list" kindN;
   490 
   491 val itemizeN = "itemize";
   492 val enumerateN = "enumerate";
   493 val descriptionN = "description";
   494 
   495 
   496 (* formal input *)
   497 
   498 val inputN = "input";
   499 fun input delimited props = (inputN, (delimitedN, Value.print_bool delimited) :: props);
   500 
   501 
   502 (* outer syntax *)
   503 
   504 val (command_keywordN, command_keyword) = markup_elem "command_keyword";
   505 
   506 val commandN = "command"; val command_properties = properties [(kindN, commandN)];
   507 val keywordN = "keyword"; val keyword_properties = properties [(kindN, keywordN)];
   508 
   509 val (keyword1N, keyword1) = markup_elem "keyword1";
   510 val (keyword2N, keyword2) = markup_elem "keyword2";
   511 val (keyword3N, keyword3) = markup_elem "keyword3";
   512 val (quasi_keywordN, quasi_keyword) = markup_elem "quasi_keyword";
   513 val (improperN, improper) = markup_elem "improper";
   514 val (operatorN, operator) = markup_elem "operator";
   515 val (stringN, string) = markup_elem "string";
   516 val (alt_stringN, alt_string) = markup_elem "alt_string";
   517 val (verbatimN, verbatim) = markup_elem "verbatim";
   518 val (cartoucheN, cartouche) = markup_elem "cartouche";
   519 val (commentN, comment) = markup_elem "comment";
   520 
   521 
   522 (* timing *)
   523 
   524 val elapsedN = "elapsed";
   525 val cpuN = "cpu";
   526 val gcN = "gc";
   527 
   528 fun timing_properties {elapsed, cpu, gc} =
   529  [(elapsedN, Value.print_time elapsed),
   530   (cpuN, Value.print_time cpu),
   531   (gcN, Value.print_time gc)];
   532 
   533 fun parse_timing_properties props =
   534  {elapsed = Properties.seconds props elapsedN,
   535   cpu = Properties.seconds props cpuN,
   536   gc = Properties.seconds props gcN};
   537 
   538 val timingN = "timing";
   539 fun timing t = (timingN, timing_properties t);
   540 
   541 
   542 (* command timing *)
   543 
   544 val command_timingN = "command_timing";
   545 
   546 fun command_timing_properties {file, offset, name} elapsed =
   547  [(fileN, file), (offsetN, Value.print_int offset),
   548   (nameN, name), (elapsedN, Value.print_time elapsed)];
   549 
   550 fun parse_command_timing_properties props =
   551   (case (Properties.get props fileN, Properties.get props offsetN, Properties.get props nameN) of
   552     (SOME file, SOME offset, SOME name) =>
   553       SOME ({file = file, offset = Value.parse_int offset, name = name},
   554         Properties.seconds props elapsedN)
   555   | _ => NONE);
   556 
   557 
   558 (* indentation *)
   559 
   560 val (command_indentN, command_indent) = markup_int "command_indent" indentN;
   561 
   562 
   563 (* goals *)
   564 
   565 val (goalN, goal) = markup_elem "goal";
   566 val (subgoalN, subgoal) = markup_string "subgoal" nameN;
   567 
   568 
   569 (* command status *)
   570 
   571 val taskN = "task";
   572 
   573 val (acceptedN, accepted) = markup_elem "accepted";
   574 val (forkedN, forked) = markup_elem "forked";
   575 val (joinedN, joined) = markup_elem "joined";
   576 val (runningN, running) = markup_elem "running";
   577 val (finishedN, finished) = markup_elem "finished";
   578 val (failedN, failed) = markup_elem "failed";
   579 val (consolidatedN, consolidated) = markup_elem "consolidated";
   580 
   581 
   582 (* messages *)
   583 
   584 val exec_idN = "exec_id";
   585 
   586 val initN = "init";
   587 val (statusN, status) = markup_elem "status";
   588 val (resultN, result) = markup_elem "result";
   589 val (writelnN, writeln) = markup_elem "writeln";
   590 val (stateN, state) = markup_elem "state"
   591 val (informationN, information) = markup_elem "information";
   592 val (tracingN, tracing) = markup_elem "tracing";
   593 val (warningN, warning) = markup_elem "warning";
   594 val (legacyN, legacy) = markup_elem "legacy";
   595 val (errorN, error) = markup_elem "error";
   596 val (systemN, system) = markup_elem "system";
   597 val protocolN = "protocol";
   598 
   599 val (reportN, report) = markup_elem "report";
   600 val (no_reportN, no_report) = markup_elem "no_report";
   601 
   602 val badN = "bad";
   603 fun bad () = (badN, serial_properties (serial ()));
   604 
   605 val (intensifyN, intensify) = markup_elem "intensify";
   606 
   607 
   608 (* active areas *)
   609 
   610 val browserN = "browser"
   611 val graphviewN = "graphview";
   612 
   613 val sendbackN = "sendback";
   614 val paddingN = "padding";
   615 val padding_line = (paddingN, "line");
   616 val padding_command = (paddingN, "command");
   617 
   618 val dialogN = "dialog";
   619 fun dialog i result = (dialogN, [(serialN, Value.print_int i), (resultN, result)]);
   620 
   621 val jedit_actionN = "jedit_action";
   622 
   623 
   624 (* protocol message functions *)
   625 
   626 val functionN = "function"
   627 
   628 val assign_update = [(functionN, "assign_update")];
   629 val removed_versions = [(functionN, "removed_versions")];
   630 
   631 fun protocol_handler name = [(functionN, "protocol_handler"), (nameN, name)];
   632 
   633 fun invoke_scala name id = [(functionN, "invoke_scala"), (nameN, name), (idN, id)];
   634 fun cancel_scala id = [(functionN, "cancel_scala"), (idN, id)];
   635 
   636 val ML_statistics = (functionN, "ML_statistics");
   637 
   638 val task_statistics = (functionN, "task_statistics");
   639 
   640 val command_timing = (functionN, "command_timing");
   641 
   642 val theory_timing = (functionN, "theory_timing");
   643 
   644 val exportN = "export";
   645 type export_args = {id: string option, theory_name: string, name: string, compress: bool}
   646 fun export ({id, theory_name, name, compress}: export_args) =
   647   [(functionN, exportN), (idN, the_default "" id),
   648     ("theory_name", theory_name), (nameN, name), ("compress", Value.print_bool compress)];
   649 
   650 fun loading_theory name = [("function", "loading_theory"), ("name", name)];
   651 
   652 fun dest_loading_theory [("function", "loading_theory"), ("name", name)] = SOME name
   653   | dest_loading_theory _ = NONE;
   654 
   655 val build_session_finished = [("function", "build_session_finished")];
   656 
   657 val print_operationsN = "print_operations";
   658 val print_operations = [(functionN, print_operationsN)];
   659 
   660 
   661 (* debugger *)
   662 
   663 fun debugger_state name = [(functionN, "debugger_state"), (nameN, name)];
   664 fun debugger_output name = [(functionN, "debugger_output"), (nameN, name)];
   665 
   666 
   667 (* simplifier trace *)
   668 
   669 val simp_trace_panelN = "simp_trace_panel";
   670 
   671 val simp_trace_logN = "simp_trace_log";
   672 val simp_trace_stepN = "simp_trace_step";
   673 val simp_trace_recurseN = "simp_trace_recurse";
   674 val simp_trace_hintN = "simp_trace_hint";
   675 val simp_trace_ignoreN = "simp_trace_ignore";
   676 
   677 fun simp_trace_cancel i = [(functionN, "simp_trace_cancel"), (serialN, Value.print_int i)];
   678 
   679 
   680 
   681 (** print mode operations **)
   682 
   683 val no_output = ("", "");
   684 
   685 local
   686   val default = {output = Output_Primitives.markup_fn};
   687   val modes = Synchronized.var "Markup.modes" (Symtab.make [("", default)]);
   688 in
   689   fun add_mode name output =
   690     Synchronized.change modes (fn tab =>
   691       (if not (Symtab.defined tab name) then ()
   692        else Output.warning ("Redefining markup mode " ^ quote name);
   693        Symtab.update (name, {output = output}) tab));
   694   fun get_mode () =
   695     the_default default
   696       (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ()));
   697 end;
   698 
   699 fun output m = if is_empty m then no_output else #output (get_mode ()) m;
   700 
   701 val enclose = output #-> Library.enclose;
   702 
   703 fun markup m =
   704   let val (bg, en) = output m
   705   in Library.enclose (Output.escape bg) (Output.escape en) end;
   706 
   707 val markups = fold_rev markup;
   708 
   709 fun markup_only m = markup m "";
   710 
   711 fun markup_report "" = ""
   712   | markup_report txt = markup report txt;
   713 
   714 end;