src/Pure/ProofGeneral/proof_general_emacs.ML
author wenzelm
Mon, 14 Apr 2008 14:28:47 +0200
changeset 26643 99f5407c05ef
parent 26613 725a3d9011d1
child 26706 4ea64590d28b
permissions -rw-r--r--
Isar.toplevel_loop: separate init/welcome flag;
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.
26549
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
     6
See also http://proofgeneral.inf.ed.ac.uk
21642
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
26549
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
    11
  val test_markupN: string
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    12
  val init: bool -> unit
24874
e4400a70eeaa export init_outer_syntax;
wenzelm
parents: 24873
diff changeset
    13
  val init_outer_syntax: unit -> unit
24289
bfd59eb6e24e added sendback;
wenzelm
parents: 24244
diff changeset
    14
  val sendback: string -> Pretty.T list -> unit
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    15
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    16
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    17
structure ProofGeneral: PROOF_GENERAL =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    18
struct
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    19
21945
wenzelm
parents: 21940
diff changeset
    20
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    21
(* print modes *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    22
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    23
val proof_generalN = "ProofGeneralEmacs";  (*token markup (colouring vars, etc.)*)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    24
val pgasciiN = "PGASCII";                  (*plain 7-bit ASCII communication*)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    25
val thm_depsN = "thm_deps";                (*meta-information about theorem deps*)
26549
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
    26
val test_markupN = "test_markup";          (*XML markup for everything*)
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
    27
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
    28
val _ = Markup.add_mode test_markupN XML.output_markup;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    29
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    30
fun special oct =
26526
d1557acb9ef9 Symbol.SOH;
wenzelm
parents: 26463
diff changeset
    31
  if print_mode_active pgasciiN then Symbol.SOH ^ chr (ord (oct_char oct) - 167)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    32
  else oct_char oct;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    33
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    34
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    35
(* text output: print modes for xsymbol *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    36
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    37
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    38
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    39
fun xsym_output "\\" = "\\\\"
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    40
  | 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
    41
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    42
fun xsymbols_output s =
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
    43
  if print_mode_active Symbol.xsymbolsN andalso exists_string (equal "\\") s then
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    44
    let val syms = Symbol.explode s
23621
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22699
diff changeset
    45
    in (implode (map xsym_output syms), Symbol.length syms) end
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22699
diff changeset
    46
  else Output.default_output s;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    47
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    48
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    49
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    50
fun setup_xsymbols_output () =
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
    51
  Output.add_mode Symbol.xsymbolsN xsymbols_output Symbol.encode_raw;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    52
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    53
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    54
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    55
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    56
(* token translations *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    57
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    58
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    59
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    60
fun end_tag () = special "350";
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    61
val class_tag = ("class", fn () => special "351");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    62
val tfree_tag = ("tfree", fn () => special "352");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    63
val tvar_tag = ("tvar", fn () => special "353");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    64
val free_tag = ("free", fn () => special "354");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    65
val bound_tag = ("bound", fn () => special "355");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    66
val var_tag = ("var", fn () => special "356");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    67
val skolem_tag = ("skolem", fn () => special "357");
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    68
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    69
fun xml_atom kind x = XML.element "atom" [("kind", kind)] [XML.text x];
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    70
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    71
fun tagit (kind, bg_tag) x =
23621
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22699
diff changeset
    72
  (bg_tag () ^ x ^ end_tag (), Symbol.length (Symbol.explode x));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    73
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    74
fun free_or_skolem x =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    75
  (case try Name.dest_skolem x of
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    76
    NONE => tagit free_tag x
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    77
  | SOME x' => tagit skolem_tag x');
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    78
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    79
fun var_or_skolem s =
24244
d7ee11ba1534 Lexicon.read_indexname/nat/variable;
wenzelm
parents: 24079
diff changeset
    80
  (case Lexicon.read_variable s of
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    81
    SOME (x, i) =>
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    82
      (case try Name.dest_skolem x of
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    83
        NONE => tagit var_tag s
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    84
      | SOME x' => tagit skolem_tag
22678
23963361278c Term.string_of_vname;
wenzelm
parents: 22590
diff changeset
    85
          (setmp show_question_marks true Term.string_of_vname (x', i)))
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    86
  | NONE => tagit var_tag s);
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    87
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    88
val proof_general_trans =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    89
 Syntax.tokentrans_mode proof_generalN
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    90
  [("class", tagit class_tag),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    91
   ("tfree", tagit tfree_tag),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    92
   ("tvar", tagit tvar_tag),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    93
   ("free", free_or_skolem),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    94
   ("bound", tagit bound_tag),
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    95
   ("var", var_or_skolem)];
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    96
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    97
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    98
26463
9283b4185fdf Context.>> : operate on Context.generic;
wenzelm
parents: 26435
diff changeset
    99
val _ = Context.>> (Context.map_theory (Sign.add_tokentrfuns proof_general_trans));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   100
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   101
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   102
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   103
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   104
(* common markup *)
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   105
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   106
fun proof_general_markup (name, props) =
25630
wenzelm
parents: 25553
diff changeset
   107
  let
wenzelm
parents: 25553
diff changeset
   108
    val (bg1, en1) =
25848
fb998d0bf175 replaced prompt markup by prompt channel setup;
wenzelm
parents: 25749
diff changeset
   109
      if name = Markup.stateN then (special "366" ^ "\n", "\n" ^ special "367")
25630
wenzelm
parents: 25553
diff changeset
   110
      else if name = Markup.sendbackN then (special "376", special "377")
wenzelm
parents: 25553
diff changeset
   111
      else if name = Markup.hiliteN then (special "327", special "330")
wenzelm
parents: 25553
diff changeset
   112
      else ("", "");
wenzelm
parents: 25553
diff changeset
   113
    val (bg2, en2) =
26549
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
   114
      if print_mode_active test_markupN
26542
ffc1f97ab5fc XML.output_markup;
wenzelm
parents: 26526
diff changeset
   115
      then XML.output_markup (name, props)
25630
wenzelm
parents: 25553
diff changeset
   116
      else ("", "");
wenzelm
parents: 25553
diff changeset
   117
  in (bg1 ^ bg2, en2 ^ en1) end;
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   118
23702
58ca991e0702 removed no_state markup -- produce empty state;
wenzelm
parents: 23662
diff changeset
   119
val _ = Markup.add_mode proof_generalN proof_general_markup;
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   120
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   121
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   122
(* messages and notification *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   123
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   124
fun decorate bg en prfx =
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   125
  Output.writeln_default o enclose bg en o prefix_lines prfx;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   126
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   127
fun setup_messages () =
23662
91d06b04951f simplified writeln_fn;
wenzelm
parents: 23641
diff changeset
   128
 (Output.writeln_fn := Output.writeln_default;
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   129
  Output.priority_fn := (fn s => decorate (special "360") (special "361") "" s);
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   130
  Output.tracing_fn := (fn s => decorate (special "360" ^ special "375") (special "361") "" s);
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   131
  Output.debug_fn := (fn s => decorate (special "362") (special "363") "+++ " s);
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   132
  Output.warning_fn := (fn s => decorate (special "362") (special "363") "### " s);
25848
fb998d0bf175 replaced prompt markup by prompt channel setup;
wenzelm
parents: 25749
diff changeset
   133
  Output.error_fn := (fn s => decorate (special "364") (special "365") "*** " s);
fb998d0bf175 replaced prompt markup by prompt channel setup;
wenzelm
parents: 25749
diff changeset
   134
  Output.prompt_fn := (fn s => Output.std_output (s ^ special "372")));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   135
22699
938c1011ac94 removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents: 22678
diff changeset
   136
fun panic s =
938c1011ac94 removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents: 22678
diff changeset
   137
  (decorate (special "364") (special "365") "!!! " ("## SYSTEM EXIT ##\n" ^ s); exit 1);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   138
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   139
fun emacs_notify s = decorate (special "360") (special "361") "" s;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   140
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   141
fun tell_clear_goals () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   142
  emacs_notify "Proof General, please clear the goals buffer.";
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   143
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   144
fun tell_clear_response () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   145
  emacs_notify "Proof General, please clear the response buffer.";
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   146
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   147
fun tell_file_loaded path =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   148
  emacs_notify ("Proof General, this file is loaded: " ^ quote (File.platform_path path));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   149
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   150
fun tell_file_retracted path =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   151
  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
   152
24289
bfd59eb6e24e added sendback;
wenzelm
parents: 24244
diff changeset
   153
fun sendback heading prts =
bfd59eb6e24e added sendback;
wenzelm
parents: 24244
diff changeset
   154
  Pretty.writeln (Pretty.big_list heading [Pretty.markup Markup.sendback prts]);
bfd59eb6e24e added sendback;
wenzelm
parents: 24244
diff changeset
   155
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   156
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   157
(* theory loader actions *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   158
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   159
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   160
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   161
fun trace_action action name =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   162
  if action = ThyInfo.Update then
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   163
    List.app tell_file_loaded (ThyInfo.loaded_files name)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   164
  else if action = ThyInfo.Outdate orelse action = ThyInfo.Remove then
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   165
    List.app tell_file_retracted (ThyInfo.loaded_files name)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   166
  else ();
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   167
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   168
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   169
  fun setup_thy_loader () = ThyInfo.add_hook trace_action;
26613
725a3d9011d1 ThyInfo.get_names;
wenzelm
parents: 26607
diff changeset
   170
  fun sync_thy_loader () = List.app (trace_action ThyInfo.Update) (ThyInfo.get_names ());
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   171
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   172
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   173
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   174
(* get informed about files *)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   175
25442
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   176
local
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   177
25442
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   178
(*liberal low-level version*)
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   179
val thy_name = perhaps (try (unsuffix ".thy")) o List.last o space_explode "/";
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   180
val thy_path = ThyLoad.thy_path o thy_name;
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   181
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   182
in
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   183
25443
1af14e8f225b inform_file_processed: made even more robust against bad file specs;
wenzelm
parents: 25442
diff changeset
   184
fun check_thy "" = false
1af14e8f225b inform_file_processed: made even more robust against bad file specs;
wenzelm
parents: 25442
diff changeset
   185
  | check_thy file = ThyInfo.check_known_thy (thy_name file);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   186
23913
fcfacb6670ed inform_file_processed: tuned msg, no state;
wenzelm
parents: 23702
diff changeset
   187
fun proper_inform_file_processed file () =
25442
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   188
  let
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   189
    val name = thy_name file;
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   190
    val _ = ThyInfo.touch_child_thys name;
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   191
    val _ = ThyInfo.register_thy name handle ERROR msg =>
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   192
      (warning (cat_lines [msg, "Failed to register theory: " ^ quote name]);
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   193
        tell_file_retracted (thy_path file));
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   194
  in () end;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   195
25442
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   196
fun vacuous_inform_file_processed file () = tell_file_retracted (thy_path file);
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   197
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   198
val inform_file_retracted = ThyInfo.if_known_thy ThyInfo.remove_thy o thy_name;
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   199
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   200
end;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   201
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   202
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   203
(* restart top-level loop (keeps most state information) *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   204
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   205
val welcome = priority o Session.welcome;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   206
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   207
fun restart () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   208
 (sync_thy_loader ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   209
  tell_clear_goals ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   210
  tell_clear_response ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   211
  welcome ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   212
  raise Toplevel.RESTART);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   213
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   214
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   215
(* theorem dependency output *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   216
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   217
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   218
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   219
val spaces_quote = space_implode " " o map quote;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   220
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   221
fun thm_deps_message (thms, deps) =
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   222
  emacs_notify ("Proof General, theorem dependencies of " ^ thms ^ " are " ^ deps);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   223
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   224
fun tell_thm_deps ths =
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   225
  if print_mode_active thm_depsN then
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   226
    let
22228
7c27195a4afc proper use of PureThy.has_name_hint instead of hard-wired string'';
wenzelm
parents: 22225
diff changeset
   227
      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
   228
      val deps = Symtab.keys (fold Proofterm.thms_of_proof'
30ab97554602 Fix tell_thm_deps to match changse in PureThy.
aspinall
parents: 22159
diff changeset
   229
				   (map Thm.proof_of ths) Symtab.empty);
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   230
    in
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   231
      if null names orelse null deps then ()
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   232
      else thm_deps_message (spaces_quote names, spaces_quote deps)
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   233
    end
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   234
  else ();
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   235
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   236
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   237
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   238
fun setup_present_hook () =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   239
  Present.add_hook (fn _ => fn res => tell_thm_deps (maps #2 res));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   240
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   241
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   242
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   243
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   244
(* additional outer syntax for Isar *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   245
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   246
local structure P = OuterParse and K = OuterKeyword in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   247
25192
b568f8c5d5ca made command 'undo' silent ('ProofGeneral.undo' becomes a historical relic);
wenzelm
parents: 24882
diff changeset
   248
fun undoP () = (*undo without output -- historical*)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   249
  OuterSyntax.improper_command "ProofGeneral.undo" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   250
    (Scan.succeed (Toplevel.no_timing o IsarCmd.undo));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   251
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   252
fun restartP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   253
  OuterSyntax.improper_command "ProofGeneral.restart" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   254
    (P.opt_unit >> (Toplevel.no_timing oo K (Toplevel.imperative restart)));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   255
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   256
fun kill_proofP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   257
  OuterSyntax.improper_command "ProofGeneral.kill_proof" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   258
    (Scan.succeed (Toplevel.no_timing o IsarCmd.kill_proof_notify tell_clear_goals));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   259
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   260
fun inform_file_processedP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   261
  OuterSyntax.improper_command "ProofGeneral.inform_file_processed" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   262
    (P.name >> (fn file => Toplevel.no_timing o
25443
1af14e8f225b inform_file_processed: made even more robust against bad file specs;
wenzelm
parents: 25442
diff changeset
   263
      Toplevel.imperative (fn () => error "Bad file name") o
1af14e8f225b inform_file_processed: made even more robust against bad file specs;
wenzelm
parents: 25442
diff changeset
   264
      Toplevel.init_empty (fn _ => file <> "") (vacuous_inform_file_processed file) o
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   265
      Toplevel.kill o
25442
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   266
      Toplevel.init_empty (fn _ => check_thy file) (proper_inform_file_processed file)));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   267
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   268
fun inform_file_retractedP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   269
  OuterSyntax.improper_command "ProofGeneral.inform_file_retracted" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   270
    (P.name >> (Toplevel.no_timing oo
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   271
      (fn file => Toplevel.imperative (fn () => inform_file_retracted file))));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   272
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   273
fun process_pgipP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   274
  OuterSyntax.improper_command "ProofGeneral.process_pgip" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   275
    (P.text >> (Toplevel.no_timing oo
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   276
      (fn txt => Toplevel.imperative (fn () => ProofGeneralPgip.process_pgip txt))));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   277
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   278
fun init_outer_syntax () = List.app (fn f => f ())
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   279
 [undoP, restartP, kill_proofP, inform_file_processedP, inform_file_retractedP, process_pgipP];
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   280
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   281
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   282
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   283
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   284
(* init *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   285
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   286
val initialized = ref false;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   287
22699
938c1011ac94 removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents: 22678
diff changeset
   288
fun init false = panic "No Proof General interface support for Isabelle/classic mode."
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   289
  | init true =
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   290
      (! initialized orelse
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   291
        (Output.no_warnings init_outer_syntax ();
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   292
          setup_xsymbols_output ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   293
          setup_messages ();
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   294
          ProofGeneralPgip.init_pgip_channel (! Output.priority_fn);
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   295
          setup_thy_loader ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   296
          setup_present_hook ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   297
          set initialized);
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   298
        sync_thy_loader ();
25749
wenzelm
parents: 25630
diff changeset
   299
       change print_mode (update (op =) proof_generalN);
26643
99f5407c05ef Isar.toplevel_loop: separate init/welcome flag;
wenzelm
parents: 26613
diff changeset
   300
       Isar.toplevel_loop {init = true, welcome = true, sync = true, secure = Secure.is_secure ()});
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   301
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   302
end;