src/Pure/ProofGeneral/proof_general_emacs.ML
author wenzelm
Mon, 09 Jul 2007 11:44:23 +0200
changeset 23662 91d06b04951f
parent 23641 d6f9d3acffaa
child 23702 58ca991e0702
permissions -rw-r--r--
simplified writeln_fn;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     1
(*  Title:      Pure/ProofGeneral/proof_general_emacs.ML
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     2
    ID:         $Id$
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     3
    Author:     David Aspinall and Markus Wenzel
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     4
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     5
Isabelle/Isar configuration for Emacs Proof General.
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     6
See http://proofgeneral.inf.ed.ac.uk
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     7
*)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     8
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     9
signature PROOF_GENERAL =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    10
sig
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    11
  val init: bool -> unit
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    12
  val write_keywords: string -> unit
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    13
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    14
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    15
structure ProofGeneral: PROOF_GENERAL =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    16
struct
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    17
21945
wenzelm
parents: 21940
diff changeset
    18
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    19
(* print modes *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    20
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    21
val proof_generalN = "ProofGeneralEmacs";  (*token markup (colouring vars, etc.)*)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    22
val pgasciiN = "PGASCII";                  (*plain 7-bit ASCII communication*)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    23
val thm_depsN = "thm_deps";                (*meta-information about theorem deps*)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    24
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    25
fun special oct =
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
    26
  if print_mode_active pgasciiN then chr 1 ^ chr (ord (oct_char oct) - 167)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    27
  else oct_char oct;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    28
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    29
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    30
(* text output: print modes for xsymbol *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    31
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    32
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    33
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    34
fun xsym_output "\\" = "\\\\"
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    35
  | xsym_output s = if Symbol.is_raw s then Symbol.decode_raw s else s;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    36
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    37
fun xsymbols_output s =
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
    38
  if print_mode_active Symbol.xsymbolsN andalso exists_string (equal "\\") s then
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    39
    let val syms = Symbol.explode s
23621
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22699
diff changeset
    40
    in (implode (map xsym_output syms), Symbol.length syms) end
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22699
diff changeset
    41
  else Output.default_output s;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    42
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    43
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    44
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    45
fun setup_xsymbols_output () =
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
    46
  Output.add_mode Symbol.xsymbolsN xsymbols_output Symbol.encode_raw;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    47
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    48
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    49
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    50
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    51
(* token translations *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    52
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    53
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    54
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    55
fun end_tag () = special "350";
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    56
val class_tag = ("class", fn () => special "351");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    57
val tfree_tag = ("tfree", fn () => special "352");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    58
val tvar_tag = ("tvar", fn () => special "353");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    59
val free_tag = ("free", fn () => special "354");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    60
val bound_tag = ("bound", fn () => special "355");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    61
val var_tag = ("var", fn () => special "356");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    62
val skolem_tag = ("skolem", fn () => special "357");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    63
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    64
fun xml_atom kind x = XML.element "atom" [("kind", kind)] [XML.text x];
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    65
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    66
fun tagit (kind, bg_tag) x =
23621
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22699
diff changeset
    67
  (bg_tag () ^ x ^ end_tag (), Symbol.length (Symbol.explode x));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    68
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    69
fun free_or_skolem x =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    70
  (case try Name.dest_skolem x of
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    71
    NONE => tagit free_tag x
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    72
  | SOME x' => tagit skolem_tag x');
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    73
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    74
fun var_or_skolem s =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    75
  (case Syntax.read_variable s of
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    76
    SOME (x, i) =>
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    77
      (case try Name.dest_skolem x of
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    78
        NONE => tagit var_tag s
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    79
      | SOME x' => tagit skolem_tag
22678
23963361278c Term.string_of_vname;
wenzelm
parents: 22590
diff changeset
    80
          (setmp show_question_marks true Term.string_of_vname (x', i)))
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    81
  | NONE => tagit var_tag s);
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    82
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    83
val proof_general_trans =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    84
 Syntax.tokentrans_mode proof_generalN
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    85
  [("class", tagit class_tag),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    86
   ("tfree", tagit tfree_tag),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    87
   ("tvar", tagit tvar_tag),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    88
   ("free", free_or_skolem),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    89
   ("bound", tagit bound_tag),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    90
   ("var", var_or_skolem)];
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    91
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    92
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    93
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    94
val _ = Context.add_setup (Theory.add_tokentrfuns proof_general_trans);
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    95
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    96
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    97
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    98
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
    99
(* common markup *)
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   100
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   101
fun proof_general_markup (name, props) =
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   102
  (if name = Markup.promptN then ("", special "372")
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   103
    else if name = Markup.no_stateN orelse name = Markup.stateN
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   104
    then (special "366" ^ "\n", "\n" ^ special "367")
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   105
    else ("", ""))
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   106
  |> (name <> Markup.promptN andalso print_mode_active "test_markup") ?
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   107
    (fn (bg, en) =>
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   108
      (bg ^ enclose "<" ">" (space_implode " " (name :: map XML.attribute props)),
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   109
        enclose "</" ">" name ^ en));
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   110
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   111
val _ = Pretty.add_mode proof_generalN Pretty.default_indent proof_general_markup;
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   112
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   113
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   114
(* messages and notification *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   115
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   116
fun decorate bg en prfx =
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   117
  Output.writeln_default o enclose bg en o prefix_lines prfx;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   118
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   119
fun setup_messages () =
23662
91d06b04951f simplified writeln_fn;
wenzelm
parents: 23641
diff changeset
   120
 (Output.writeln_fn := Output.writeln_default;
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   121
  Output.priority_fn := (fn s => decorate (special "360") (special "361") "" s);
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   122
  Output.tracing_fn := (fn s => decorate (special "360" ^ special "375") (special "361") "" s);
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   123
  Output.debug_fn := (fn s => decorate (special "362") (special "363") "+++ " s);
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   124
  Output.warning_fn := (fn s => decorate (special "362") (special "363") "### " s);
22699
938c1011ac94 removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents: 22678
diff changeset
   125
  Output.error_fn := (fn s => decorate (special "364") (special "365") "*** " s));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   126
22699
938c1011ac94 removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents: 22678
diff changeset
   127
fun panic s =
938c1011ac94 removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents: 22678
diff changeset
   128
  (decorate (special "364") (special "365") "!!! " ("## SYSTEM EXIT ##\n" ^ s); exit 1);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   129
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   130
fun emacs_notify s = decorate (special "360") (special "361") "" s;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   131
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   132
fun tell_clear_goals () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   133
  emacs_notify "Proof General, please clear the goals buffer.";
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   134
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   135
fun tell_clear_response () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   136
  emacs_notify "Proof General, please clear the response buffer.";
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   137
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   138
fun tell_file_loaded path =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   139
  emacs_notify ("Proof General, this file is loaded: " ^ quote (File.platform_path path));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   140
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   141
fun tell_file_retracted path =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   142
  emacs_notify ("Proof General, you can unlock the file " ^ quote (File.platform_path path));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   143
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   144
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   145
(* theory loader actions *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   146
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   147
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   148
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   149
fun trace_action action name =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   150
  if action = ThyInfo.Update then
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   151
    List.app tell_file_loaded (ThyInfo.loaded_files name)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   152
  else if action = ThyInfo.Outdate orelse action = ThyInfo.Remove then
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   153
    List.app tell_file_retracted (ThyInfo.loaded_files name)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   154
  else ();
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   155
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   156
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   157
  fun setup_thy_loader () = ThyInfo.add_hook trace_action;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   158
  fun sync_thy_loader () = List.app (trace_action ThyInfo.Update) (ThyInfo.names ());
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   159
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   160
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   161
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   162
(* get informed about files *)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   163
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21649
diff changeset
   164
val thy_name = Path.implode o #1 o Path.split_ext o Path.base o Path.explode;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   165
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   166
val inform_file_retracted = ThyInfo.if_known_thy ThyInfo.remove_thy o thy_name;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   167
val inform_file_processed = ThyInfo.if_known_thy ThyInfo.touch_child_thys o thy_name;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   168
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   169
fun proper_inform_file_processed file state =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   170
  let val name = thy_name file in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   171
    if Toplevel.is_toplevel state andalso ThyInfo.known_thy name then
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   172
     (ThyInfo.touch_child_thys name;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   173
      ThyInfo.pretend_use_thy_only name handle ERROR msg =>
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   174
       (warning msg; warning ("Failed to register theory: " ^ quote name);
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21649
diff changeset
   175
        tell_file_retracted (Path.base (Path.explode file))))
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   176
    else raise Toplevel.UNDEF
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   177
  end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   178
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   179
fun vacuous_inform_file_processed file state =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   180
 (warning ("No theory " ^ quote (thy_name file));
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21649
diff changeset
   181
  tell_file_retracted (Path.base (Path.explode file)));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   182
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   183
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   184
(* restart top-level loop (keeps most state information) *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   185
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   186
val welcome = priority o Session.welcome;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   187
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   188
fun restart () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   189
 (sync_thy_loader ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   190
  tell_clear_goals ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   191
  tell_clear_response ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   192
  welcome ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   193
  raise Toplevel.RESTART);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   194
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   195
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   196
(* theorem dependency output *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   197
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   198
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   199
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   200
val spaces_quote = space_implode " " o map quote;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   201
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   202
fun thm_deps_message (thms, deps) =
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   203
  emacs_notify ("Proof General, theorem dependencies of " ^ thms ^ " are " ^ deps);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   204
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   205
fun tell_thm_deps ths =
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   206
  if print_mode_active thm_depsN then
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   207
    let
22228
7c27195a4afc proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents: 22225
diff changeset
   208
      val names = map PureThy.get_name_hint (filter PureThy.has_name_hint ths);
22225
30ab97554602 Fix tell_thm_deps to match changse in PureThy.
aspinall
parents: 22159
diff changeset
   209
      val deps = Symtab.keys (fold Proofterm.thms_of_proof'
30ab97554602 Fix tell_thm_deps to match changse in PureThy.
aspinall
parents: 22159
diff changeset
   210
				   (map Thm.proof_of ths) Symtab.empty);
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   211
    in
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   212
      if null names orelse null deps then ()
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   213
      else thm_deps_message (spaces_quote names, spaces_quote deps)
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   214
    end
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   215
  else ();
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   216
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   217
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   218
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   219
fun setup_present_hook () =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   220
  Present.add_hook (fn _ => fn res => tell_thm_deps (maps #2 res));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   221
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   222
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   223
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   224
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   225
(* additional outer syntax for Isar *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   226
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   227
local structure P = OuterParse and K = OuterKeyword in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   228
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   229
val undoP = (*undo without output*)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   230
  OuterSyntax.improper_command "ProofGeneral.undo" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   231
    (Scan.succeed (Toplevel.no_timing o IsarCmd.undo));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   232
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   233
val restartP =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   234
  OuterSyntax.improper_command "ProofGeneral.restart" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   235
    (P.opt_unit >> (Toplevel.no_timing oo K (Toplevel.imperative restart)));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   236
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   237
val kill_proofP =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   238
  OuterSyntax.improper_command "ProofGeneral.kill_proof" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   239
    (Scan.succeed (Toplevel.no_timing o IsarCmd.kill_proof_notify tell_clear_goals));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   240
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   241
val inform_file_processedP =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   242
  OuterSyntax.improper_command "ProofGeneral.inform_file_processed" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   243
    (P.name >> (fn file => Toplevel.no_timing o
21959
b50182aff75f inform_file_processed: Toplevel.init_empty;
wenzelm
parents: 21948
diff changeset
   244
      Toplevel.init_empty (vacuous_inform_file_processed file) o
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   245
      Toplevel.kill o
21959
b50182aff75f inform_file_processed: Toplevel.init_empty;
wenzelm
parents: 21948
diff changeset
   246
      Toplevel.init_empty (proper_inform_file_processed file)));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   247
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   248
val inform_file_retractedP =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   249
  OuterSyntax.improper_command "ProofGeneral.inform_file_retracted" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   250
    (P.name >> (Toplevel.no_timing oo
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   251
      (fn file => Toplevel.imperative (fn () => inform_file_retracted file))));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   252
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   253
val process_pgipP =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   254
  OuterSyntax.improper_command "ProofGeneral.process_pgip" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   255
    (P.text >> (Toplevel.no_timing oo
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   256
      (fn txt => Toplevel.imperative (fn () => ProofGeneralPgip.process_pgip txt))));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   257
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   258
fun init_outer_syntax () = OuterSyntax.add_parsers
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   259
 [undoP, restartP, kill_proofP, inform_file_processedP, inform_file_retractedP, process_pgipP];
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   260
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   261
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   262
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   263
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   264
(* init *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   265
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   266
val initialized = ref false;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   267
22699
938c1011ac94 removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents: 22678
diff changeset
   268
fun init false = panic "No Proof General interface support for Isabelle/classic mode."
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   269
  | init true =
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   270
      (! initialized orelse
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   271
        (Output.no_warnings init_outer_syntax ();
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   272
          setup_xsymbols_output ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   273
          setup_messages ();
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   274
          ProofGeneralPgip.init_pgip_channel (! Output.priority_fn);
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   275
          setup_thy_loader ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   276
          setup_present_hook ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   277
          set initialized);
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   278
        sync_thy_loader ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   279
       change print_mode (cons proof_generalN o remove (op =) proof_generalN);
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   280
       Isar.sync_main ());
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   281
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   282
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   283
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   284
 (** generate elisp file for keyword classification **)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   285
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   286
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   287
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   288
val regexp_meta = member (op =) (explode ".*+?[]^$");
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   289
val regexp_quote = translate_string (fn c => if regexp_meta c then "\\\\" ^ c else c);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   290
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   291
fun defconst name strs =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   292
  "\n(defconst isar-keywords-" ^ name ^
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   293
  "\n  '(" ^ space_implode "\n    " (map (quote o regexp_quote) strs) ^ "))\n";
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   294
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   295
fun make_elisp_commands commands kind = defconst kind
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   296
  (commands |> map_filter (fn (c, _, k, _) => if k = kind then SOME c else NONE));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   297
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   298
fun make_elisp_syntax (keywords, commands) =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   299
  ";;\n\
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   300
  \;; Keyword classification tables for Isabelle/Isar.\n\
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   301
  \;; This file was generated by " ^ Session.name () ^ " -- DO NOT EDIT!\n\
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   302
  \;;\n\
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   303
  \;; $" ^ "Id$\n\
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   304
  \;;\n" ^
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   305
  defconst "major" (map #1 commands) ^
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   306
  defconst "minor" (filter Syntax.is_identifier keywords) ^
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   307
  implode (map (make_elisp_commands commands) OuterKeyword.kinds) ^
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   308
  "\n(provide 'isar-keywords)\n";
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   309
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   310
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   311
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   312
fun write_keywords s =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   313
 (init_outer_syntax ();
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21649
diff changeset
   314
  File.write (Path.explode ("isar-keywords" ^ (if s = "" then "" else "-" ^ s) ^".el"))
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   315
    (make_elisp_syntax (OuterSyntax.dest_keywords (), OuterSyntax.dest_parsers ())));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   316
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   317
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   318
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   319
end;