src/Pure/PIDE/isar_document.ML
author wenzelm
Thu Jan 27 12:24:00 2011 +0100 (2011-01-27 ago)
changeset 41634 28d94383249c
parent 38567 b670faa807c9
child 43665 573d1272f36d
permissions -rw-r--r--
cancel document execution before editing, to improve reactivity on systems with few cores;
wenzelm@38483
     1
(*  Title:      Pure/PIDE/isar_document.ML
wenzelm@38412
     2
    Author:     Makarius
wenzelm@38412
     3
wenzelm@38567
     4
Protocol message formats for interactive Isar documents.
wenzelm@38412
     5
*)
wenzelm@38412
     6
wenzelm@38412
     7
structure Isar_Document: sig end =
wenzelm@38412
     8
struct
wenzelm@38412
     9
wenzelm@38420
    10
val global_state = Synchronized.var "Isar_Document" Document.init_state;
wenzelm@38420
    11
val change_state = Synchronized.change global_state;
wenzelm@38412
    12
wenzelm@38418
    13
val _ =
wenzelm@38418
    14
  Isabelle_Process.add_command "Isar_Document.define_command"
wenzelm@38418
    15
    (fn [id, text] => change_state (Document.define_command (Document.parse_id id) text));
wenzelm@38412
    16
wenzelm@38418
    17
val _ =
wenzelm@38418
    18
  Isabelle_Process.add_command "Isar_Document.edit_version"
wenzelm@38418
    19
    (fn [old_id_string, new_id_string, edits_yxml] => change_state (fn state =>
wenzelm@38418
    20
      let
wenzelm@38418
    21
        val old_id = Document.parse_id old_id_string;
wenzelm@38418
    22
        val new_id = Document.parse_id new_id_string;
wenzelm@38418
    23
        val edits =
wenzelm@38448
    24
          XML_Data.dest_list
wenzelm@38448
    25
            (XML_Data.dest_pair
wenzelm@38448
    26
              XML_Data.dest_string
wenzelm@38448
    27
              (XML_Data.dest_option
wenzelm@38448
    28
                (XML_Data.dest_list
wenzelm@38448
    29
                  (XML_Data.dest_pair
wenzelm@38448
    30
                    (XML_Data.dest_option XML_Data.dest_int)
wenzelm@38448
    31
                    (XML_Data.dest_option XML_Data.dest_int))))) (YXML.parse_body edits_yxml);
wenzelm@38412
    32
wenzelm@41634
    33
      val _ = Document.cancel state;
wenzelm@38418
    34
      val (updates, state') = Document.edit old_id new_id edits state;
wenzelm@38418
    35
      val _ =
wenzelm@38418
    36
        implode (map (fn (id, exec_id) => Markup.markup (Markup.edit id exec_id) "") updates)
wenzelm@38418
    37
        |> Markup.markup (Markup.assign new_id)
wenzelm@38418
    38
        |> Output.status;
wenzelm@38418
    39
      val state'' = Document.execute new_id state';
wenzelm@38418
    40
    in state'' end));
wenzelm@38412
    41
wenzelm@38412
    42
end;
wenzelm@38412
    43