src/Pure/ProofGeneral/proof_general_pgip.ML
author aspinall
Wed, 24 Jan 2007 13:15:16 +0100
changeset 22171 58f554f51f0d
parent 22163 a586b0af857e
child 22216 c3f5aa951a68
permissions -rw-r--r--
Let <loadfile> execute even while a file is open interactively.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     1
(*  Title:      Pure/ProofGeneral/proof_general_pgip.ML
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     2
    ID:         $Id$
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     3
    Author:     David Aspinall and Markus Wenzel
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     4
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     5
Isabelle configuration for Proof General using PGIP protocol.
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
     6
See http://proofgeneral.inf.ed.ac.uk/kit
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     7
*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     8
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     9
signature PROOF_GENERAL_PGIP =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    10
sig
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    11
  val init_pgip: bool -> unit             (* main PGIP loop with true; fail with false *)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents: 21637
diff changeset
    12
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
    13
  (* These two are just to support the semi-PGIP Emacs mode *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    14
  val init_pgip_channel: (string -> unit) -> unit
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    15
  val process_pgip: string -> unit
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
    16
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
    17
  (* Yet more message functions... *)
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
    18
  val nonfatal_error : string -> unit     (* recoverable error *)
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
    19
  val log_msg : string -> unit	          (* for internal log messages *)
22163
a586b0af857e Expose currently open file
aspinall
parents: 22159
diff changeset
    20
  val error_with_pos : PgipTypes.fatality -> Position.T -> string -> unit
22159
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
    21
22163
a586b0af857e Expose currently open file
aspinall
parents: 22159
diff changeset
    22
  val get_currently_open_file : unit -> Path.T option  (* interface focus *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    23
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    24
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    25
structure ProofGeneralPgip : PROOF_GENERAL_PGIP  =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    26
struct
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    27
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    28
open Pgip;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    29
21949
046e0482f0a1 removed obsolete context_thy etc.;
wenzelm
parents: 21940
diff changeset
    30
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    31
(* print modes *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    32
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    33
val proof_generalN = "ProofGeneral";  (*token markup (colouring vars, etc.)*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    34
val pgmlN = "PGML";                   (*XML escapes and PGML symbol elements*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    35
val pgmlatomsN = "PGMLatoms";         (*variable kind decorations*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    36
val thm_depsN = "thm_deps";           (*meta-information about theorem deps*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    37
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    38
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    39
(* text output: print modes for xsymbol and PGML *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    40
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    41
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    42
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    43
fun xsym_output "\\" = "\\\\"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    44
  | xsym_output s = if Symbol.is_raw s then Symbol.decode_raw s else s;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    45
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    46
fun xsymbols_output s =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    47
  if Output.has_mode Symbol.xsymbolsN andalso exists_string (equal "\\") s then
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    48
    let val syms = Symbol.explode s
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    49
    in (implode (map xsym_output syms), real (Symbol.length syms)) end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    50
  else Symbol.default_output s;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    51
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    52
(* XML immediately rendered pretty printer. Take care not to double escape *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    53
fun pgml_sym s =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    54
  (case Symbol.decode s of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    55
    Symbol.Char s => XML.text s
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    56
  | Symbol.Sym sn => XML.element "sym" [("name", sn)] [XML.text s]
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    57
  | Symbol.Ctrl sn => XML.element "ctrl" [("name", sn)] [XML.text s] (* FIXME: no such PGML! *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    58
  | Symbol.Raw s => s);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    59
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    60
fun pgml_output str =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    61
  let val syms = Symbol.explode str
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    62
  in (implode (map pgml_sym syms), real (Symbol.length syms)) end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    63
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    64
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    65
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    66
fun setup_xsymbols_output () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    67
  Output.add_mode Symbol.xsymbolsN
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    68
    (xsymbols_output, K xsymbols_output, Symbol.default_indent, Symbol.encode_raw);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    69
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    70
fun setup_pgml_output () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    71
  Output.add_mode pgmlN
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    72
    (pgml_output, K pgml_output, Symbol.default_indent, Symbol.encode_raw);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    73
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    74
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    75
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    76
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    77
(* token translations *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    78
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    79
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    80
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    81
val class_tag = "class"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    82
val tfree_tag = "tfree"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    83
val tvar_tag = "tvar"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    84
val free_tag = "free"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    85
val bound_tag = "bound"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    86
val var_tag = "var"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    87
val skolem_tag = "skolem"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    88
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    89
fun xml_atom kind x = XML.element "atom" [("kind", kind)] [XML.text x];
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    90
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
    91
fun tagit kind x =
21949
046e0482f0a1 removed obsolete context_thy etc.;
wenzelm
parents: 21940
diff changeset
    92
  (xml_atom kind x, real (Symbol.length (Symbol.explode x)));
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    93
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    94
fun free_or_skolem x =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    95
  (case try Name.dest_skolem x of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    96
    NONE => tagit free_tag x
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    97
  | SOME x' => tagit skolem_tag x');
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    98
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    99
fun var_or_skolem s =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   100
  (case Syntax.read_variable s of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   101
    SOME (x, i) =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   102
      (case try Name.dest_skolem x of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   103
        NONE => tagit var_tag s
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   104
      | SOME x' => tagit skolem_tag
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   105
          (setmp show_question_marks true Syntax.string_of_vname (x', i)))
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   106
  | NONE => tagit var_tag s);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   107
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   108
val proof_general_trans =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   109
 Syntax.tokentrans_mode proof_generalN
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   110
  [("class", tagit class_tag),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   111
   ("tfree", tagit tfree_tag),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   112
   ("tvar", tagit tvar_tag),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   113
   ("free", free_or_skolem),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   114
   ("bound", tagit bound_tag),
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   115
   ("var", var_or_skolem)];
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   116
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   117
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   118
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   119
val _ = Context.add_setup (Theory.add_tokentrfuns proof_general_trans);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   120
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   121
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   122
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   123
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   124
(** assembling and issuing PGIP packets **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   125
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   126
val pgip_refid  = ref NONE: string option ref;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   127
val pgip_refseq = ref NONE: int option ref;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   128
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   129
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   130
  val pgip_class  = "pg"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   131
  val pgip_tag = "Isabelle/Isar"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   132
  val pgip_id = ref ""
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   133
  val pgip_seq = ref 0
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   134
  fun pgip_serial () = inc pgip_seq
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   135
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   136
  fun assemble_pgips pgips =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   137
    Pgip { tag = SOME pgip_tag,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   138
           class = pgip_class,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   139
           seq = pgip_serial(),
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   140
           id = !pgip_id,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   141
           destid = !pgip_refid,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   142
           (* destid=refid since Isabelle only communicates back to sender *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   143
           refid  = !pgip_refid,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   144
           refseq = !pgip_refseq,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   145
           content = pgips }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   146
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   147
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   148
fun init_pgip_session_id () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   149
    pgip_id := getenv "HOSTNAME" ^ "/" ^ getenv "USER" ^ "/" ^
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   150
               getenv "ISABELLE_PID" ^ "/" ^ Time.toString (Time.now ())
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   151
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   152
fun matching_pgip_id id = (id = !pgip_id)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   153
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   154
val output_xml_fn = ref writeln_default
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   155
fun output_xml s = (!output_xml_fn) (XML.string_of_tree s);  (* TODO: string buffer *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   156
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   157
fun issue_pgip_rawtext str =
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   158
    output_xml (PgipOutput.output (assemble_pgips [XML.Rawtext str]))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   159
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   160
fun issue_pgips pgipops =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   161
    output_xml (PgipOutput.output (assemble_pgips (map PgipOutput.output pgipops)));
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   162
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   163
fun issue_pgip pgipop =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   164
    output_xml (PgipOutput.output (assemble_pgips [PgipOutput.output pgipop]));
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   165
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   166
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   167
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   168
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   169
(** messages and notification **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   170
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   171
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   172
    val delay_msgs = ref false   (*true: accumulate messages*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   173
    val delayed_msgs = ref []
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   174
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   175
    fun queue_or_issue pgip =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   176
        if ! delay_msgs then
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   177
            delayed_msgs := pgip :: ! delayed_msgs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   178
        else issue_pgip pgip
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   179
in
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   180
    (* Normal responses are messages for the user *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   181
    fun normalmsg area cat urgent s =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   182
        let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   183
            val content = XML.Elem("pgmltext",[],[XML.Rawtext s])
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   184
            val pgip = Normalresponse {area=area,messagecategory=cat,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   185
                                       urgent=urgent,content=[content] }
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   186
        in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   187
            queue_or_issue pgip
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   188
        end
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   189
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   190
    (* Error responses are error messages for the user, or system-level messages *)
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   191
    fun errormsg fatality s =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   192
        let
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   193
              val content = XML.Elem("pgmltext",[],[XML.Rawtext s])
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   194
              val pgip = Errorresponse {area=NONE,fatality=fatality,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   195
                                        content=[content],
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   196
                                        location=NONE}
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   197
        in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   198
            queue_or_issue pgip
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   199
        end
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   200
22159
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   201
    (* Error responses with useful locations *)
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   202
    fun error_with_pos fatality pos s =
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   203
        let
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   204
              val content = XML.Elem("pgmltext",[],[XML.Rawtext s])
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   205
              val pgip = Errorresponse {area=NONE,fatality=fatality,
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   206
                                        content=[content],
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   207
                                        location=SOME (PgipIsabelle.location_of_position pos)}
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   208
        in
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   209
            queue_or_issue pgip
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   210
        end
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   211
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   212
    fun start_delay_msgs () = (set delay_msgs; delayed_msgs := [])
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   213
    fun end_delayed_msgs () = (reset delay_msgs; ! delayed_msgs)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   214
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   215
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   216
(* NB: all of the standard error/message functions now expect already-escaped text.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   217
   FIXME: this may cause us problems now we're generating trees; on the other
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   218
   hand the output functions were tuned some time ago, so it ought to be
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   219
   enough to use Rawtext always above. *)
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   220
(* NB 2: all of standard functions print strings terminated with new lines, but we don't
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   221
   add new lines explicitly in PGIP: they are left implicit.  It means that PGIP messages 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   222
   can't be written without newlines. *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   223
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   224
fun setup_messages () =
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   225
 (writeln_fn := (fn s => normalmsg Message Normal false s);
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   226
  priority_fn := (fn s => normalmsg Message Normal true s);
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   227
  tracing_fn := (fn s => normalmsg  Message Tracing false s);
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   228
  info_fn := (fn s => errormsg Info s);
22001
d79a84789875 Use warning fatality
aspinall
parents: 21986
diff changeset
   229
  warning_fn := (fn s => errormsg Warning s);
22014
4b70cbd96007 removed Toplevel.print_exn hook -- existing error_msg_fn does the job;
wenzelm
parents: 22001
diff changeset
   230
  error_fn := (fn s => errormsg Fatal s);
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   231
  panic_fn := (fn s => errormsg Panic s);
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   232
  debug_fn := (fn s => errormsg Debug s));
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   233
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   234
fun nonfatal_error s = errormsg Nonfatal s;
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   235
fun log_msg s = errormsg Log s;
21983
9fb029d1189b Use Isar toplevel print_exn_fn for generating error responses instead of Output.error_msg.
aspinall
parents: 21972
diff changeset
   236
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   237
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   238
(* immediate messages *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   239
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   240
fun tell_clear_goals ()      = issue_pgip (Cleardisplay {area=Display})
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   241
fun tell_clear_response ()   = issue_pgip (Cleardisplay {area=Message})
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   242
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   243
fun tell_file_loaded completed path   = 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   244
    issue_pgip (Informfileloaded {url=PgipTypes.pgipurl_of_path path,
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   245
				  completed=completed})
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   246
fun tell_file_outdated completed path   = 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   247
    issue_pgip (Informfileoutdated {url=PgipTypes.pgipurl_of_path path,
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   248
				    completed=completed})
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   249
fun tell_file_retracted completed path = 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   250
    issue_pgip (Informfileretracted {url=PgipTypes.pgipurl_of_path path,
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   251
				     completed=completed})
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   252
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   253
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   254
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   255
(** theory / proof state output **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   256
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   257
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   258
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   259
fun statedisplay prts =
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   260
    let 
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   261
        val display = Pretty.output (Pretty.chunks prts)
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   262
        (* TODO: add extra PGML markup for allow proof state navigation *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   263
        val statedisplay = XML.Elem("statedisplay",[], [XML.Rawtext display])
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   264
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   265
        issue_pgip (Proofstate {pgml=[XML.Elem("pgml",[],[statedisplay])]})
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   266
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   267
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   268
fun print_current_goals n m st =
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   269
  case (Display.pretty_current_goals n m st) of 
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   270
   [] => tell_clear_goals()
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   271
 | prts => statedisplay prts
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   272
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   273
fun print_state b st =
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   274
  case (Toplevel.pretty_state b st) of 
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   275
   [] => tell_clear_goals() 
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   276
  | prts => statedisplay prts
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   277
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   278
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   279
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   280
fun setup_state () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   281
  (Display.print_current_goals_fn := print_current_goals;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   282
   Toplevel.print_state_fn := print_state);
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   283
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   284
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   285
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   286
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   287
(* theory loader actions *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   288
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   289
local
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   290
  (* da: TODO: PGIP has a completed flag so the prover can indicate to the 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   291
     interface which files are busy performing a particular action. 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   292
     To make use of this we need to adjust the hook in thy_info.ML
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   293
     (may actually be difficult to tell the interface *which* action is in 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   294
      progress, but we could add a generic "Lock" action which uses
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   295
      informfileloaded: the broker/UI should not infer too much from incomplete
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   296
      operations).
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   297
   *)     
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   298
fun trace_action action name =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   299
  if action = ThyInfo.Update then
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   300
    List.app (tell_file_loaded true) (ThyInfo.loaded_files name) 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   301
  else if action = ThyInfo.Outdate then
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   302
    List.app (tell_file_outdated true) (ThyInfo.loaded_files name)
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   303
  else if action = ThyInfo.Remove then
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   304
      List.app (tell_file_retracted true) (ThyInfo.loaded_files name) 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   305
  else ()
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   306
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   307
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   308
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   309
  fun setup_thy_loader () = ThyInfo.add_hook trace_action;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   310
  fun sync_thy_loader () = List.app (trace_action ThyInfo.Update) (ThyInfo.names ());
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   311
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   312
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   313
21949
046e0482f0a1 removed obsolete context_thy etc.;
wenzelm
parents: 21940
diff changeset
   314
(* get informed about files *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   315
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   316
val thy_name = Path.implode o #1 o Path.split_ext o Path.base;
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   317
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   318
val inform_file_retracted = ThyInfo.if_known_thy ThyInfo.remove_thy o thy_name;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   319
val inform_file_processed = ThyInfo.if_known_thy ThyInfo.touch_child_thys o thy_name;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   320
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   321
fun proper_inform_file_processed path state =
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   322
  let val name = thy_name path in
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   323
    if Toplevel.is_toplevel state andalso ThyInfo.known_thy name then
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   324
     (ThyInfo.touch_child_thys name;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   325
      ThyInfo.pretend_use_thy_only name handle ERROR msg =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   326
       (warning msg; warning ("Failed to register theory: " ^ quote name);
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   327
        tell_file_retracted true (Path.base path)))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   328
    else raise Toplevel.UNDEF
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   329
  end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   330
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   331
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   332
(* restart top-level loop (keeps most state information) *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   333
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   334
val welcome = priority o Session.welcome;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   335
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   336
fun restart () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   337
    (sync_thy_loader ();
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   338
     tell_clear_goals ();
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   339
     tell_clear_response ();
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   340
     welcome ();
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   341
     raise Toplevel.RESTART)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   342
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   343
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   344
(* theorem dependency output *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   345
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   346
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   347
val spaces_quote = space_implode " " o map quote;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   348
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   349
fun thm_deps_message (thms, deps) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   350
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   351
        val valuethms = XML.Elem("value",[("name", "thms")],[XML.Text thms])
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   352
        val valuedeps = XML.Elem("value",[("name", "deps")],[XML.Text deps])
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   353
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   354
        issue_pgip (Metainforesponse {attrs=[("infotype", "isabelle_theorem_dependencies")],
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   355
                                      content=[valuethms,valuedeps]})
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   356
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   357
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   358
(* FIXME: check this uses non-transitive closure function here *)
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   359
fun tell_thm_deps ths =
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   360
  if Output.has_mode thm_depsN then
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   361
    let
22159
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   362
      val names = filter_out (equal "") (map PureThy.get_name_hint ths); (* da: HAS THIS NOW BECOME "??.unknown"? *)
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   363
      val deps = filter_out (equal "")
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   364
        (Symtab.keys (fold Proofterm.thms_of_proof
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   365
          (map Thm.proof_of ths) Symtab.empty));
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   366
    in
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   367
      if null names orelse null deps then ()
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   368
      else thm_deps_message (spaces_quote names, spaces_quote deps)
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   369
    end
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   370
  else ();
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   371
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   372
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   373
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   374
fun setup_present_hook () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   375
  Present.add_hook (fn _ => fn res => tell_thm_deps (maps #2 res));
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   376
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   377
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   378
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   379
(** lexicalstructure element with keywords (PGIP version of elisp keywords file) **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   380
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   381
fun lexicalstructure_keywords () =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   382
    let val commands = OuterSyntax.dest_keywords ()
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   383
        fun category_of k = if k mem commands then "major" else "minor"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   384
         (* NB: we might filter to only include words like elisp case (OuterSyntax.is_keyword). *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   385
        fun keyword_elt (keyword,help,kind,_) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   386
            XML.Elem("keyword", [("word", keyword), ("category", category_of kind)],
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   387
                     [XML.Elem("shorthelp", [], [XML.Text help])])
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   388
        in
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   389
            (* Also, note we don't call init_outer_syntax here to add interface commands,
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   390
            but they should never appear in scripts anyway so it shouldn't matter *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   391
            Lexicalstructure {content = map keyword_elt (OuterSyntax.dest_parsers()) }
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   392
        end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   393
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   394
(* TODO: we can issue a lexicalstructure/keyword when the syntax gets extended dynamically;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   395
   hooks needed in outer_syntax.ML to do that. *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   396
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   397
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   398
(* Configuration: GUI config, proverinfo messages *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   399
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   400
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   401
    val isabellewww = "http://isabelle.in.tum.de/"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   402
    val staticconfig = "~~/lib/ProofGeneral/pgip_isar.xml"
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   403
    fun orenv v d = case getenv v of "" => d  | s => s
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   404
    fun config_file()  = orenv "ISABELLE_PGIPCONFIG" staticconfig
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   405
    fun isabelle_www() = orenv "ISABELLE_HOMEPAGE" isabellewww
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   406
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   407
fun send_pgip_config () =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   408
    let
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21655
diff changeset
   409
        val path = Path.explode (config_file())
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   410
        val ex = File.exists path
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   411
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   412
        val wwwpage =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   413
            (Url.explode (isabelle_www()))
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   414
            handle ERROR _ =>
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   415
                   (Output.panic
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   416
                        ("Error in URL in environment variable ISABELLE_HOMEPAGE.");
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   417
                        Url.explode isabellewww)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   418
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   419
        val proverinfo =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   420
            Proverinfo { name = "Isabelle",
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   421
                         version = version,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   422
                         instance = Session.name(),
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   423
                         descr = "The Isabelle/Isar theorem prover",
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   424
                         url = wwwpage,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   425
                         filenameextns = ".thy;" }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   426
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   427
        if ex then
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   428
            (issue_pgip proverinfo;
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   429
             issue_pgip_rawtext (File.read path);
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   430
             issue_pgip (lexicalstructure_keywords()))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   431
        else Output.panic ("PGIP configuration file \"" ^ config_file() ^ "\" not found")
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   432
    end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   433
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   434
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   435
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   436
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   437
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   438
(* Sending commands to Isar *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   439
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   440
fun isarcmd s =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   441
    s |> OuterSyntax.scan |> OuterSyntax.read
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   442
      (*|> map (Toplevel.position (Position.name "PGIP message") o #3)*)
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   443
      |> map #3
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   444
      |> Toplevel.>>>;
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   445
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   446
(* TODO:
21885
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   447
    - apply a command given a transition function, e.g. IsarCmd.undo.
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   448
    - fix position from path of currently open file [line numbers risk garbling though].
5a11263bd8cf Remove obsolete prefixes from error and warning messages.
aspinall
parents: 21867
diff changeset
   449
*)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   450
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   451
(* load an arbitrary file (must be .thy or .ML) *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   452
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   453
fun use_thy_or_ml_file file =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   454
    let
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21655
diff changeset
   455
        val (path,extn) = Path.split_ext (Path.explode file)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   456
    in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   457
        case extn of
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   458
            "" => isarcmd ("use_thy " ^ quote (Path.implode path))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   459
          | "thy" => isarcmd ("use_thy " ^ quote (Path.implode path))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   460
          | "ML" => isarcmd ("use " ^ quote file)
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   461
          | other => error ("Don't know how to read a file with extension " ^ quote other)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   462
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   463
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   464
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   465
(******* PGIP actions *******)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   466
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   467
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   468
(* Responses to each of the PGIP input commands.
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   469
   These are programmed uniformly for extensibility. *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   470
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   471
fun askpgip (Askpgip vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   472
    issue_pgip
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   473
        (Usespgip { version = PgipIsabelle.isabelle_pgip_version_supported,
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   474
                    pgipelems = PgipIsabelle.accepted_inputs })
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   475
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   476
fun askpgml (Askpgml vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   477
    issue_pgip
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   478
        (Usespgml { version = PgipIsabelle.isabelle_pgml_version_supported })
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   479
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   480
fun askprefs (Askprefs vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   481
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   482
        fun preference_of {name, descr, default, pgiptype, get, set } =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   483
            { name = name, descr = SOME descr, default = SOME default,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   484
              pgiptype = pgiptype }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   485
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   486
        List.app (fn (prefcat, prefs) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   487
                     issue_pgip (Hasprefs {prefcategory=SOME prefcat,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   488
                                           prefs=map preference_of prefs}))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   489
                 Preferences.preferences
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   490
    end
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   491
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   492
fun askconfig (Askconfig vs) = () (* TODO: add config response *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   493
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   494
local
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   495
    fun lookuppref pref =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   496
        case AList.lookup (op =)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   497
                          (map (fn p => (#name p,p))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   498
                               (maps snd Preferences.preferences)) pref of
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   499
            NONE => error ("Unknown prover preference: " ^ quote pref)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   500
          | SOME p => p
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   501
in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   502
fun setpref (Setpref vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   503
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   504
        val name = #name vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   505
        val value = #value vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   506
        val set = #set (lookuppref name)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   507
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   508
        set value
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   509
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   510
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   511
fun getpref (Getpref vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   512
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   513
        val name = #name vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   514
        val get = #get (lookuppref name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   515
    in
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   516
        issue_pgip (Prefval {name=name, value=get ()})
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   517
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   518
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   519
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   520
fun proverinit vs = restart ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   521
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   522
fun proverexit vs = isarcmd "quit"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   523
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   524
fun startquiet vs = isarcmd "disable_pr"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   525
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   526
fun stopquiet vs = isarcmd "enable_pr"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   527
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   528
fun pgmlsymbolson vs =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   529
    change print_mode (fn mode =>
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   530
                          remove (op =) Symbol.xsymbolsN mode @ [Symbol.xsymbolsN])
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   531
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   532
fun pgmlsymbolsoff vs =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   533
    change print_mode (remove (op =) Symbol.xsymbolsN)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   534
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   535
fun dostep (Dostep vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   536
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   537
        val text = #text vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   538
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   539
        isarcmd text
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   540
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   541
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   542
fun undostep (Undostep vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   543
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   544
        val times = #times vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   545
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   546
        isarcmd ("undos_proof " ^ Int.toString times)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   547
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   548
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   549
fun redostep vs = isarcmd "redo"
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   550
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   551
fun abortgoal vs = isarcmd "kill" (* was: ProofGeneral.kill_proof *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   552
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   553
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   554
(*** PGIP identifier tables ***)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   555
22159
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   556
(* TODO: these ones should be triggered by hooks after a 
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   557
   declaration addition/removal, to be sent automatically. *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   558
22159
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   559
fun addids t  = issue_pgip (Addids {idtables = [t]})
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   560
fun delids t  = issue_pgip (Delids {idtables = [t]})
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   561
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   562
fun askids (Askids vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   563
    let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   564
        val url = #url vs            (* ask for identifiers within a file *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   565
        val thyname = #thyname vs    (* ask for identifiers within a theory *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   566
        val objtype = #objtype vs    (* ask for identifiers of a particular type *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   567
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   568
        fun idtable ty ctx ids = {objtype=ty,context=ctx,ids=ids}
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   569
22159
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   570
	fun setids t  = issue_pgip (Setids {idtables = [t]})
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   571
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   572
        val thms_of_thy = map fst o PureThy.thms_of o ThyInfo.get_theory
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   573
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   574
(*      case (url_attr,thyname,objtype) of
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   575
            (NONE,NONE,NONE) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   576
*)          (* top-level: return *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   577
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   578
        (* TODO: add askids for "file" here, which returns single theory with same name *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   579
        (* FIXME: objtypes on both sides *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   580
        case (thyname,objtype) of
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   581
           (* only files known in top context *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   582
           (NONE, NONE)               => setids (idtable ObjFile NONE (ThyInfo.names())) (*FIXME: uris?*)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   583
         | (NONE, SOME ObjFile)        => setids (idtable ObjFile NONE (ThyInfo.names())) (* ditto *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   584
         | (SOME fi, SOME ObjFile)     => setids (idtable ObjTheory (SOME fi) [fi]) (* FIXME: lookup file *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   585
         | (NONE, SOME ObjTheory)      => setids (idtable ObjTheory NONE (ThyInfo.names()))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   586
         | (SOME thy, SOME ObjTheory)  => setids (idtable ObjTheory (SOME thy) (ThyInfo.get_preds thy))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   587
         | (SOME thy, SOME ObjTheorem) => setids (idtable ObjTheorem (SOME thy) (thms_of_thy thy))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   588
         (* next case is both of above.  FIXME: cleanup this *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   589
         | (SOME thy, NONE) => (setids (idtable ObjTheory (SOME thy) (ThyInfo.get_preds thy));
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   590
                                setids (idtable ObjTheorem (SOME thy) (thms_of_thy thy)))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   591
         | (_, SOME ot) => error ("No objects of type "^(PgipTypes.name_of_objtype ot)^" are available here.")
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   592
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   593
22159
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   594
fun askrefs (Askrefs vs) =
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   595
    let
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   596
        val url = #url vs            (* ask for references of a file (i.e. immediate pre-requisites) *)
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   597
        val thyname = #thyname vs    (* ask for references of a theory (other theories) *)
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   598
        val objtype = #objtype vs    (* ask for references of a particular type... *)
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   599
        val name = #name vs          (*   ... with this name *)
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   600
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   601
        fun idtable ty ctx ids = {objtype=ty,context=ctx,ids=ids}
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   602
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   603
        val thms_of_thy = map fst o PureThy.thms_of o ThyInfo.get_theory
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   604
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   605
	val thy_name = Path.implode o #1 o Path.split_ext o Path.base
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   606
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   607
	fun filerefs f = 
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   608
	    let val thy = thy_name f
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   609
		val (_,filerefs) = OuterSyntax.deps_thy thy true f (* (Path.unpack f); *)
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   610
	    in 
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   611
		issue_pgip (Setrefs {url=url, thyname=NONE, objtype=SOME PgipTypes.ObjFile,
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   612
				     name=NONE, idtables=[], fileurls=filerefs})
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   613
	    end
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   614
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   615
	fun thyrefs thy = 
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   616
	    let val ml_path = ThyLoad.ml_path thy
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   617
		val (thyrefs,_) = OuterSyntax.deps_thy thy true ml_path (* (Path.unpack f); *)
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   618
	    in 
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   619
		issue_pgip (Setrefs {url=url, thyname=thyname, objtype=SOME PgipTypes.ObjTheory,
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   620
				     name=NONE, idtables=[{context=NONE, objtype=PgipTypes.ObjTheory,
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   621
							   ids=thyrefs}], fileurls=[]})
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   622
	    end
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   623
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   624
	fun thmrefs thmname = 
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   625
	    let
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   626
		(* TODO: interim: this is probably not right.  
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   627
		   What we want is mapping onto simple PGIP name/context model. *)
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   628
		val ctx = Toplevel.context_of (Toplevel.get_state()) (* NB: raises UNDEF *)
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   629
		val thy = Context.theory_of_proof ctx
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   630
		val ths = [PureThy.get_thm thy (PureThy.Name thmname)]
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   631
		val deps = filter_out (equal "")
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   632
				      (Symtab.keys (fold Proofterm.thms_of_proof
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   633
							 (map Thm.proof_of ths) Symtab.empty))
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   634
	    in
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   635
		if null deps then ()
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   636
		else issue_pgip (Setrefs {url=url, thyname=thyname, name=name,
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   637
					  objtype=SOME PgipTypes.ObjTheorem,
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   638
					  idtables=[{context=NONE, objtype=PgipTypes.ObjTheorem,
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   639
						     ids=deps}], fileurls=[]})
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   640
	    end 
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   641
    in
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   642
        case (url,thyname,objtype,name) of
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   643
	    (SOME file, NONE, _, _)  => filerefs file           
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   644
	  | (_,SOME thy,_,_)         => thyrefs thy
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   645
	  | (_,_,SOME PgipTypes.ObjTheorem,SOME thmname) => thmrefs thmname
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   646
          | _  => error ("Unimplemented/invalid case of <askrefs>")
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   647
    end
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   648
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   649
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   650
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   651
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   652
  (* accumulate printed output in a single PGIP response (inside <pgmltext>) *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   653
  fun with_displaywrap pgipfn dispfn =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   654
      let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   655
          val lines = ref ([]: string list);
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   656
          fun wlgrablines s = lines := s :: ! lines;
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   657
      in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   658
          setmp writeln_fn wlgrablines dispfn ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   659
          issue_pgip (pgipfn (!lines))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   660
      end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   661
in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   662
fun showid (Showid vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   663
    let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   664
        val thyname = #thyname vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   665
        val objtype = #objtype vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   666
        val name = #name vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   667
        val topthy = Toplevel.theory_of o Toplevel.get_state
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   668
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   669
        fun idvalue objtype name strings =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   670
            Idvalue { name=name, objtype=objtype,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   671
                      text=[XML.Elem("pgmltext",[],map XML.Text strings)] }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   672
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   673
        fun pthm thy name = print_thm (get_thm thy (Name name))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   674
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   675
        case (thyname, objtype) of
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   676
            (_,ObjTheory) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   677
            with_displaywrap (idvalue ObjTheory name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   678
                             (fn ()=>(print_theory (ThyInfo.get_theory name)))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   679
          | (SOME thy, ObjTheorem) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   680
            with_displaywrap (idvalue ObjTheorem name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   681
                             (fn ()=>(pthm (ThyInfo.get_theory thy) name))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   682
          | (NONE, ObjTheorem) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   683
            with_displaywrap (idvalue ObjTheorem name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   684
                             (fn ()=>pthm (topthy()) name)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   685
          | (_, ot) => error ("Cannot show objects of type "^(PgipTypes.name_of_objtype ot))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   686
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   687
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   688
(*** Inspecting state ***)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   689
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   690
(* The file which is currently being processed interactively.
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   691
   In the pre-PGIP code, this was informed to Isabelle and the theory loader
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   692
   on completion, but that allows for circularity in case we read
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   693
   ourselves.  So PGIP opens the filename at the start of a script.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   694
   We ought to prevent problems by modifying the theory loader to know
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   695
   about this special status, but for now we just keep a local reference.
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   696
*)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   697
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   698
val currently_open_file = ref (NONE : pgipurl option)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   699
22163
a586b0af857e Expose currently open file
aspinall
parents: 22159
diff changeset
   700
fun get_currently_open_file () = ! currently_open_file;
a586b0af857e Expose currently open file
aspinall
parents: 22159
diff changeset
   701
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   702
fun askguise vs =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   703
    (* The "guise" is the PGIP abstraction of the prover's state.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   704
       The <informguise> message is merely used for consistency checking. *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   705
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   706
        val openfile = !currently_open_file
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   707
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   708
        val topthy = Toplevel.theory_of o Toplevel.get_state
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   709
        val topthy_name = Context.theory_name o topthy
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   710
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   711
        val opentheory = SOME (topthy_name()) handle Toplevel.UNDEF => NONE
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   712
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   713
        fun topproofpos () = try Toplevel.proof_position_of (Isar.state ());
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   714
        val openproofpos = topproofpos()
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   715
    in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   716
        issue_pgip (Informguise { file = openfile,
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   717
                                  theory = opentheory,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   718
                                  (* would be nice to get thm name... *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   719
                                  theorem = NONE,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   720
                                  proofpos = openproofpos })
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   721
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   722
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   723
fun parsescript (Parsescript vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   724
    let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   725
        val text = #text vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   726
        val systemdata = #systemdata vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   727
        val location = #location vs   (* TODO: extract position *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   728
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   729
        val _ = start_delay_msgs ()   (* gather parsing errs/warns *)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   730
        val doc = PgipParser.pgip_parser text
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   731
        val errs = end_delayed_msgs ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   732
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   733
        val sysattrs = PgipTypes.opt_attr "systemdata" systemdata
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   734
        val locattrs = PgipTypes.attrs_of_location location
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   735
     in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   736
        issue_pgip (Parseresult { attrs= sysattrs@locattrs,
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   737
                                  doc = doc,
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   738
                                  errs = map PgipOutput.output errs })
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   739
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   740
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   741
fun showproofstate vs = isarcmd "pr"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   742
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   743
fun showctxt vs = isarcmd "print_context"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   744
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   745
fun searchtheorems (Searchtheorems vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   746
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   747
        val arg = #arg vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   748
    in
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   749
        isarcmd ("find_theorems " ^ arg)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   750
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   751
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   752
fun setlinewidth (Setlinewidth vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   753
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   754
        val width = #width vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   755
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   756
        isarcmd ("pretty_setmargin " ^ Int.toString width) (* FIXME: conversion back/forth! *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   757
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   758
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   759
fun viewdoc (Viewdoc vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   760
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   761
        val arg = #arg vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   762
    in
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   763
        isarcmd ("print_" ^ arg)   (* FIXME: isatool doc?.  Return URLs, maybe? *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   764
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   765
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   766
(*** Theory ***)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   767
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   768
fun doitem (Doitem vs) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   769
    let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   770
        val text = #text vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   771
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   772
        isarcmd text
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   773
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   774
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   775
fun undoitem vs =
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   776
    isarcmd "undo"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   777
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   778
fun redoitem vs =
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   779
    isarcmd "redo"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   780
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   781
fun aborttheory vs =
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
   782
    isarcmd "kill"  (* was: "init_toplevel" *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   783
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   784
fun retracttheory (Retracttheory vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   785
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   786
        val thyname = #thyname vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   787
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   788
        isarcmd ("kill_thy " ^ quote thyname)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   789
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   790
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   791
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   792
(*** Files ***)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   793
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   794
(* Path management: we allow theory files to have dependencies in
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   795
   their own directory, but when we change directory for a new file we
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   796
   remove the path.  Leaving it there can cause confusion with
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   797
   difference in batch mode.
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   798
   NB: PGIP does not assume that the prover has a load path.
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   799
*)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   800
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   801
local
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   802
    val current_working_dir = ref (NONE : string option)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   803
in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   804
fun changecwd_dir newdirpath =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   805
   let
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   806
       val newdir = File.platform_path newdirpath
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   807
   in
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   808
       (case (!current_working_dir) of
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   809
            NONE => ()
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   810
          | SOME dir => ThyLoad.del_path dir;
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   811
        ThyLoad.add_path newdir;
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   812
        current_working_dir := SOME newdir)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   813
   end
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   814
end
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   815
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   816
fun changecwd (Changecwd vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   817
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   818
        val url = #url vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   819
        val newdir = PgipTypes.path_of_pgipurl url
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   820
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   821
        changecwd_dir url
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   822
    end
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   823
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   824
fun openfile (Openfile vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   825
  let
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   826
      val url = #url vs
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   827
      val filepath = PgipTypes.path_of_pgipurl url
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   828
      val filedir = Path.dir filepath
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   829
      val thy_name = Path.implode o #1 o Path.split_ext o Path.base
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   830
      val openfile_retract = Output.no_warnings (ThyInfo.if_known_thy ThyInfo.remove_thy) o thy_name;
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   831
  in
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   832
      case !currently_open_file of
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   833
          SOME f => raise PGIP ("<openfile> when a file is already open!\nCurrently open file: " ^
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   834
				PgipTypes.string_of_pgipurl url)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   835
        | NONE => (openfile_retract filepath;
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   836
                   changecwd_dir filedir;
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   837
		   priority ("Working in file: " ^ PgipTypes.string_of_pgipurl url);
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   838
                   currently_open_file := SOME url)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   839
  end
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   840
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   841
fun closefile vs =
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   842
    case !currently_open_file of
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   843
        SOME f => (proper_inform_file_processed f (Isar.state());
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   844
		   priority ("Finished working in file: " ^ PgipTypes.string_of_pgipurl f);
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   845
                   currently_open_file := NONE)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   846
      | NONE => raise PGIP ("<closefile> when no file is open!")
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   847
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   848
fun loadfile (Loadfile vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   849
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   850
        val url = #url vs
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   851
    in
22171
58f554f51f0d Let <loadfile> execute even while a file is open interactively.
aspinall
parents: 22163
diff changeset
   852
        (* da: this doesn't seem to cause a problem, batch loading uses
58f554f51f0d Let <loadfile> execute even while a file is open interactively.
aspinall
parents: 22163
diff changeset
   853
           a different state context.  Of course confusion is still possible,
58f554f51f0d Let <loadfile> execute even while a file is open interactively.
aspinall
parents: 22163
diff changeset
   854
           e.g. file loaded depends on open file which is not yet saved. *)
58f554f51f0d Let <loadfile> execute even while a file is open interactively.
aspinall
parents: 22163
diff changeset
   855
        (* case !currently_open_file of
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   856
            SOME f => raise PGIP ("<loadfile> when a file is open!\nCurrently open file: " ^
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   857
				  PgipTypes.string_of_pgipurl url)
22171
58f554f51f0d Let <loadfile> execute even while a file is open interactively.
aspinall
parents: 22163
diff changeset
   858
          | NONE => *)
58f554f51f0d Let <loadfile> execute even while a file is open interactively.
aspinall
parents: 22163
diff changeset
   859
	use_thy_or_ml_file (File.platform_path url)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   860
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   861
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   862
fun abortfile vs =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   863
    case !currently_open_file of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   864
        SOME f => (isarcmd "init_toplevel";
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   865
		   priority ("Aborted working in file: " ^ 
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   866
			     PgipTypes.string_of_pgipurl f);
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   867
                   currently_open_file := NONE)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   868
      | NONE => raise PGIP ("<abortfile> when no file is open!")
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   869
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   870
fun retractfile (Retractfile vs) =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   871
    let
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   872
        val url = #url vs
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   873
    in
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   874
        case !currently_open_file of
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   875
            SOME f => raise PGIP ("<retractfile> when a file is open!")
22028
c13f6b5bf2b8 Be more chatty in PGIP file operations.
aspinall
parents: 22014
diff changeset
   876
          | NONE => (priority ("Retracting file: " ^ PgipTypes.string_of_pgipurl url);
22042
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   877
		     (* TODO: next should be in thy loader, here just for testing *)
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   878
		     let 
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   879
			 val name = thy_name url
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   880
		     in List.app (tell_file_retracted false) (ThyInfo.loaded_files name) end;
64f8f5433f30 Cleanup message model: add info fatality level. Add informfileoutdated and some use of completed flag.
aspinall
parents: 22028
diff changeset
   881
		     inform_file_retracted url)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   882
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   883
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   884
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   885
(*** System ***)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   886
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   887
fun systemcmd (Systemcmd vs) =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   888
  let
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   889
      val arg = #arg vs
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   890
  in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   891
      isarcmd arg
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   892
  end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   893
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   894
exception PGIP_QUIT;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   895
fun quitpgip vs = raise PGIP_QUIT
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   896
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   897
fun process_input inp = case inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   898
 of Pgip.Askpgip _          => askpgip inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   899
  | Pgip.Askpgml _          => askpgml inp
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   900
  | Pgip.Askprefs _         => askprefs inp
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   901
  | Pgip.Askconfig _        => askconfig inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   902
  | Pgip.Getpref _          => getpref inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   903
  | Pgip.Setpref _          => setpref inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   904
  | Pgip.Proverinit _       => proverinit inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   905
  | Pgip.Proverexit _       => proverexit inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   906
  | Pgip.Startquiet _       => startquiet inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   907
  | Pgip.Stopquiet _        => stopquiet inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   908
  | Pgip.Pgmlsymbolson _    => pgmlsymbolson inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   909
  | Pgip.Pgmlsymbolsoff _   => pgmlsymbolsoff inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   910
  | Pgip.Dostep _           => dostep inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   911
  | Pgip.Undostep _         => undostep inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   912
  | Pgip.Redostep _         => redostep inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   913
  | Pgip.Forget _           => error "<forget> not implemented"
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   914
  | Pgip.Restoregoal _      => error "<restoregoal> not implemented"
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   915
  | Pgip.Abortgoal _        => abortgoal inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   916
  | Pgip.Askids _           => askids inp
22159
0cf0d3912239 Comment
aspinall
parents: 22042
diff changeset
   917
  | Pgip.Askrefs _          => askrefs inp
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   918
  | Pgip.Showid _           => showid inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   919
  | Pgip.Askguise _         => askguise inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   920
  | Pgip.Parsescript _      => parsescript inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   921
  | Pgip.Showproofstate _   => showproofstate inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   922
  | Pgip.Showctxt _         => showctxt inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   923
  | Pgip.Searchtheorems _   => searchtheorems inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   924
  | Pgip.Setlinewidth _     => setlinewidth inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   925
  | Pgip.Viewdoc _          => viewdoc inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   926
  | Pgip.Doitem _           => doitem inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   927
  | Pgip.Undoitem _         => undoitem inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   928
  | Pgip.Redoitem _         => redoitem inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   929
  | Pgip.Aborttheory _      => aborttheory inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   930
  | Pgip.Retracttheory _    => retracttheory inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   931
  | Pgip.Loadfile _         => loadfile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   932
  | Pgip.Openfile _         => openfile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   933
  | Pgip.Closefile _        => closefile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   934
  | Pgip.Abortfile _        => abortfile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   935
  | Pgip.Retractfile _      => retractfile inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   936
  | Pgip.Changecwd _        => changecwd inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   937
  | Pgip.Systemcmd _        => systemcmd inp
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21885
diff changeset
   938
  | Pgip.Quitpgip _         => quitpgip inp
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   939
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   940
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   941
fun process_pgip_element pgipxml =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   942
    case pgipxml of
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   943
        xml as (XML.Elem elem) =>
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   944
        (case Pgip.input elem of
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   945
             NONE => warning ("Unrecognized PGIP command, ignored: \n" ^
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   946
                              (XML.string_of_tree xml))
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   947
           | SOME inp => (process_input inp)) (* errors later; packet discarded *)
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   948
      | XML.Text t => ignored_text_warning t
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   949
      | XML.Rawtext t => ignored_text_warning t
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   950
and ignored_text_warning t =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   951
    if size (Symbol.strip_blanks t) > 0 then
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   952
           warning ("Ignored text in PGIP packet: \n" ^ t)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   953
    else ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   954
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   955
fun process_pgip_tree xml =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   956
    (pgip_refid := NONE;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   957
     pgip_refseq := NONE;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   958
     (case xml of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   959
          XML.Elem ("pgip", attrs, pgips) =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   960
          (let
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   961
               val class = PgipTypes.get_attr "class" attrs
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   962
               val dest  = PgipTypes.get_attr_opt "destid" attrs
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   963
               val seq = PgipTypes.read_pgipnat (PgipTypes.get_attr "seq" attrs)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   964
               (* Respond to prover broadcasts, or messages for us. Ignore rest *)
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   965
               val processit =
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   966
                   case dest of
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   967
                       NONE =>    class = "pa"
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   968
                     | SOME id => matching_pgip_id id
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   969
           in if processit then
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   970
                  (pgip_refid :=  PgipTypes.get_attr_opt "id" attrs;
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   971
                   pgip_refseq := SOME seq;
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   972
                   List.app process_pgip_element pgips;
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   973
                   (* return true to indicate <ready/> *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   974
                   true)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   975
              else
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   976
                  (* no response to ignored messages. *)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   977
                  false
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   978
           end)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   979
        | _ => raise PGIP "Invalid PGIP packet received")
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   980
     handle PGIP msg =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   981
            (Output.error_msg ((msg ^ "\nPGIP error occured in XML text below:\n") ^
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   982
                               (XML.string_of_tree xml));
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   983
             true))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   984
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   985
(* External input *)
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   986
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
   987
val process_pgip_plain = K () o process_pgip_tree o XML.tree_of_string
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   988
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   989
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   990
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   991
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   992
(* PGIP loop: process PGIP input only *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   993
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   994
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   995
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   996
exception XML_PARSE
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   997
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   998
fun loop ready src =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   999
    let
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1000
        val _ = if ready then issue_pgip (Ready ()) else ()
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1001
        val pgipo =
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1002
          (case try Source.get_single src of
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1003
            SOME pgipo => pgipo
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1004
          | NONE => raise XML_PARSE)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1005
    in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1006
        case pgipo of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1007
             NONE  => ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1008
           | SOME (pgip,src') =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1009
             let
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1010
                 val ready' = (process_pgip_tree pgip)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1011
                                handle e => (handler (e,SOME src'); true)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1012
             in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1013
                 loop ready' src'
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1014
             end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1015
    end handle e => handler (e,SOME src)  (* error in XML parse or Ready issue *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1016
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1017
and handler (e,srco) =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1018
    case (e,srco) of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1019
        (XML_PARSE,SOME src) =>
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1020
        Output.panic "Invalid XML input, aborting"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1021
      | (PGIP_QUIT,_) => ()
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1022
      | (Interrupt,SOME src) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1023
        (Output.error_msg "Interrupt during PGIP processing"; loop true src)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1024
      | (Toplevel.UNDEF,SOME src) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1025
        (Output.error_msg "No working context defined"; loop true src)
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1026
      | (e,SOME src) =>
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1027
        (Output.error_msg (Toplevel.exn_message e); loop true src)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1028
      | (_,NONE) => ()
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1029
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1030
  (* TODO: add socket interface *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1031
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1032
  val xmlP = XML.scan_comment_whspc |-- XML.parse_elem >> single
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1033
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1034
  val tty_src = Source.set_prompt "" (Source.source Symbol.stopper xmlP NONE Source.tty)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1035
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1036
  fun pgip_toplevel x = loop true x
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1037
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1038
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1039
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
  1040
local
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
  1041
(* Extra command for embedding prover-control inside document (obscure/debug usage). *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1042
22014
4b70cbd96007 removed Toplevel.print_exn hook -- existing error_msg_fn does the job;
wenzelm
parents: 22001
diff changeset
  1043
val process_pgipP =
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
  1044
  OuterSyntax.improper_command "ProofGeneral.process_pgip" "(internal)" OuterKeyword.control
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
  1045
    (OuterParse.text >> (Toplevel.no_timing oo
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1046
      (fn txt => Toplevel.imperative (fn () => process_pgip_plain txt))));
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1047
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
  1048
in
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1049
21972
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
  1050
 fun init_outer_syntax () = OuterSyntax.add_parsers [process_pgipP];
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
  1051
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
  1052
end
1b68312c4cf0 Initialise parser at startup. Remove some obsolete ProofGeneral.XXX outer syntax, mapping PGIP commands directly to Isar.
aspinall
parents: 21970
diff changeset
  1053
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1054
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1055
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1056
(* init *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1057
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1058
val initialized = ref false;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1059
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1060
fun init_pgip false =
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1061
      Output.panic "No Proof General interface support for Isabelle/classic mode."
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1062
  | init_pgip true =
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1063
      (! initialized orelse
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1064
        (setmp warning_fn (K ()) init_outer_syntax ();
22014
4b70cbd96007 removed Toplevel.print_exn hook -- existing error_msg_fn does the job;
wenzelm
parents: 22001
diff changeset
  1065
          PgipParser.init ();
21969
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1066
          setup_xsymbols_output ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1067
          setup_pgml_output ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1068
          setup_messages ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1069
          setup_state ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1070
          setup_thy_loader ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1071
          setup_present_hook ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1072
          init_pgip_session_id ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1073
          welcome ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1074
          set initialized);
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1075
        sync_thy_loader ();
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1076
       change print_mode (cons proof_generalN o remove (op =) proof_generalN);
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1077
       change print_mode (append [pgmlN, pgmlatomsN] o subtract (op =) [pgmlN, pgmlatomsN]);
a8bf1106cb7c removed conditional combinator;
wenzelm
parents: 21959
diff changeset
  1078
       pgip_toplevel tty_src);
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1079
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1080
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1081
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1082
(** Out-of-loop PGIP commands (for Emacs hybrid mode) **)
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1083
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1084
local
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1085
    val pgip_output_channel = ref writeln_default
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1086
in
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1087
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1088
(* Set recipient for PGIP results *)
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1089
fun init_pgip_channel writefn =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1090
    (init_pgip_session_id();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1091
     pgip_output_channel := writefn)
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1092
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1093
(* Process a PGIP command.
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
  1094
   This works for preferences but not generally guaranteed
21649
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1095
   because we haven't done full setup here (e.g., no pgml mode)  *)
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1096
fun process_pgip str =
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1097
     setmp output_xml_fn (!pgip_output_channel) process_pgip_plain str
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1098
40e6fdd26f82 Support PGIP communication for preferences in Emacs mode.
aspinall
parents: 21646
diff changeset
  1099
end
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1100
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1101
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
  1102