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