src/Pure/ProofGeneral/proof_general_emacs.ML
author wenzelm
Fri, 02 Jan 2009 19:59:26 +0100
changeset 29321 6b9ecb3a70ab
parent 28426 5bad734625ef
child 29326 da275b7809bd
permissions -rw-r--r--
removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
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
    Author:     David Aspinall and Markus Wenzel
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     3
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     4
Isabelle/Isar configuration for Emacs Proof General.
26549
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
     5
See also http://proofgeneral.inf.ed.ac.uk
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     6
*)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     7
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     8
signature PROOF_GENERAL =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     9
sig
26549
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
    10
  val test_markupN: string
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    11
  val init: bool -> unit
24874
e4400a70eeaa export init_outer_syntax;
wenzelm
parents: 24873
diff changeset
    12
  val init_outer_syntax: unit -> unit
24289
bfd59eb6e24e added sendback;
wenzelm
parents: 24244
diff changeset
    13
  val sendback: string -> Pretty.T list -> unit
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    14
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    15
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    16
structure ProofGeneral: PROOF_GENERAL =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    17
struct
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    18
21945
wenzelm
parents: 21940
diff changeset
    19
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    20
(* print modes *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    21
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    22
val proof_generalN = "ProofGeneralEmacs";  (*token markup (colouring vars, etc.)*)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    23
val thm_depsN = "thm_deps";                (*meta-information about theorem deps*)
26549
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
    24
val test_markupN = "test_markup";          (*XML markup for everything*)
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
    25
27592
6d81c734f7af print_mode "test_markup": do not change prompt, otherwise Proof General will not work;
wenzelm
parents: 27591
diff changeset
    26
val _ = Markup.add_mode test_markupN (fn (name, props) =>
6d81c734f7af print_mode "test_markup": do not change prompt, otherwise Proof General will not work;
wenzelm
parents: 27591
diff changeset
    27
  if name = Markup.promptN then ("", "") else XML.output_markup (name, props));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    28
29321
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    29
fun special ch = Symbol.SOH ^ ch;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    30
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    31
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    32
(* text output: print modes for xsymbol *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    33
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    34
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    35
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    36
fun xsym_output "\\" = "\\\\"
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    37
  | 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
    38
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    39
fun xsymbols_output s =
28375
c879d88d038a eliminated polymorphic equality;
wenzelm
parents: 28106
diff changeset
    40
  if print_mode_active Symbol.xsymbolsN andalso exists_string (fn c => c = "\\") s then
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    41
    let val syms = Symbol.explode s
23621
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22699
diff changeset
    42
    in (implode (map xsym_output syms), Symbol.length syms) end
e070a6ab1891 simplified pretty token metric: type int;
wenzelm
parents: 22699
diff changeset
    43
  else Output.default_output s;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    44
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    45
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    46
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    47
fun setup_xsymbols_output () =
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
    48
  Output.add_mode Symbol.xsymbolsN xsymbols_output Symbol.encode_raw;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    49
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    50
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    51
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    52
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
    53
(* common markup *)
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
    54
26706
4ea64590d28b replaced token translations by common markup;
wenzelm
parents: 26643
diff changeset
    55
val _ = Markup.add_mode proof_generalN (fn (name, props) =>
25630
wenzelm
parents: 25553
diff changeset
    56
  let
wenzelm
parents: 25553
diff changeset
    57
    val (bg1, en1) =
29321
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    58
      if name = Markup.stateN then (special "O" ^ "\n", "\n" ^ special "P")
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    59
      else if name = Markup.sendbackN then (special "W", special "X")
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    60
      else if name = Markup.hiliteN then (special "0", special "1")
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    61
      else if name = Markup.tclassN then (special "B", special "A")
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    62
      else if name = Markup.tfreeN then (special "C", special "A")
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    63
      else if name = Markup.tvarN then (special "D", special "A")
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    64
      else if name = Markup.freeN then (special "E", special "A")
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    65
      else if name = Markup.boundN then (special "F", special "A")
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    66
      else if name = Markup.varN then (special "G", special "A")
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    67
      else if name = Markup.skolemN then (special "H", special "A")
25630
wenzelm
parents: 25553
diff changeset
    68
      else ("", "");
wenzelm
parents: 25553
diff changeset
    69
    val (bg2, en2) =
27592
6d81c734f7af print_mode "test_markup": do not change prompt, otherwise Proof General will not work;
wenzelm
parents: 27591
diff changeset
    70
      if name <> Markup.promptN andalso print_mode_active test_markupN
26542
ffc1f97ab5fc XML.output_markup;
wenzelm
parents: 26526
diff changeset
    71
      then XML.output_markup (name, props)
25630
wenzelm
parents: 25553
diff changeset
    72
      else ("", "");
26706
4ea64590d28b replaced token translations by common markup;
wenzelm
parents: 26643
diff changeset
    73
  in (bg1 ^ bg2, en2 ^ en1) end);
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
    74
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
    75
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    76
(* messages and notification *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    77
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    78
fun decorate bg en prfx =
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
    79
  Output.writeln_default o enclose bg en o prefix_lines prfx;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    80
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    81
fun setup_messages () =
23662
91d06b04951f simplified writeln_fn;
wenzelm
parents: 23641
diff changeset
    82
 (Output.writeln_fn := Output.writeln_default;
27607
a21271f74bc7 refined Output.status_fn: priority (only visible for non-empty output, e.g. via test_markup print mode);
wenzelm
parents: 27604
diff changeset
    83
  Output.status_fn := (fn "" => () | s => ! Output.priority_fn s);
29321
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    84
  Output.priority_fn := (fn s => decorate (special "I") (special "J") "" s);
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    85
  Output.tracing_fn := (fn s => decorate (special "I" ^ special "V") (special "J") "" s);
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    86
  Output.debug_fn := (fn s => decorate (special "K") (special "L") "+++ " s);
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    87
  Output.warning_fn := (fn s => decorate (special "K") (special "L") "### " s);
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    88
  Output.error_fn := (fn s => decorate (special "M") (special "N") "*** " s);
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    89
  Output.prompt_fn := (fn s => Output.std_output (s ^ special "S")));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    90
22699
938c1011ac94 removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents: 22678
diff changeset
    91
fun panic s =
29321
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    92
  (decorate (special "M") (special "N") "!!! " ("## SYSTEM EXIT ##\n" ^ s); exit 1);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    93
29321
6b9ecb3a70ab removed print mode "PGASCII" -- 7-bit ASCII communication now always enabled;
wenzelm
parents: 28426
diff changeset
    94
fun emacs_notify s = decorate (special "I") (special "J") "" s;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    95
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    96
fun tell_clear_goals () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
    97
  emacs_notify "Proof General, please clear the goals buffer.";
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    98
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    99
fun tell_clear_response () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   100
  emacs_notify "Proof General, please clear the response buffer.";
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   101
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   102
fun tell_file_loaded path =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   103
  emacs_notify ("Proof General, this file is loaded: " ^ quote (File.platform_path path));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   104
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   105
fun tell_file_retracted path =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   106
  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
   107
24289
bfd59eb6e24e added sendback;
wenzelm
parents: 24244
diff changeset
   108
fun sendback heading prts =
bfd59eb6e24e added sendback;
wenzelm
parents: 24244
diff changeset
   109
  Pretty.writeln (Pretty.big_list heading [Pretty.markup Markup.sendback prts]);
bfd59eb6e24e added sendback;
wenzelm
parents: 24244
diff changeset
   110
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   111
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   112
(* theory loader actions *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   113
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   114
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   115
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   116
fun trace_action action name =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   117
  if action = ThyInfo.Update then
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   118
    List.app tell_file_loaded (ThyInfo.loaded_files name)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   119
  else if action = ThyInfo.Outdate orelse action = ThyInfo.Remove then
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   120
    List.app tell_file_retracted (ThyInfo.loaded_files name)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   121
  else ();
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   122
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   123
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   124
  fun setup_thy_loader () = ThyInfo.add_hook trace_action;
26613
725a3d9011d1 ThyInfo.get_names;
wenzelm
parents: 26607
diff changeset
   125
  fun sync_thy_loader () = List.app (trace_action ThyInfo.Update) (ThyInfo.get_names ());
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   126
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   127
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   128
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   129
(* get informed about files *)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   130
25442
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   131
(*liberal low-level version*)
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   132
val thy_name = perhaps (try (unsuffix ".thy")) o List.last o space_explode "/";
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   133
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   134
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
   135
27577
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   136
fun inform_file_processed file =
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   137
  let
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   138
    val name = thy_name file;
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   139
    val _ = name = "" andalso error ("Bad file name: " ^ quote file);
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   140
    val _ =
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   141
      if ThyInfo.check_known_thy name then
28426
5bad734625ef Toplevel.commit_exit: position;
wenzelm
parents: 28375
diff changeset
   142
        (Isar.>> (Toplevel.commit_exit Position.none);
5bad734625ef Toplevel.commit_exit: position;
wenzelm
parents: 28375
diff changeset
   143
            ThyInfo.touch_child_thys name; ThyInfo.register_thy name)
27585
2234ace5b538 inform_file_processed: try harder not to fail, ensure
wenzelm
parents: 27577
diff changeset
   144
          handle ERROR msg =>
27591
5e499b223a1e tuned message;
wenzelm
parents: 27589
diff changeset
   145
            (warning (cat_lines ["Failed to register theory: " ^ quote name, msg]);
27585
2234ace5b538 inform_file_processed: try harder not to fail, ensure
wenzelm
parents: 27577
diff changeset
   146
              tell_file_retracted (ThyLoad.thy_path name))
27577
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   147
      else ();
27589
68f98953c784 inform_file_processed: Isar.init_point last!
wenzelm
parents: 27585
diff changeset
   148
    val _ = Isar.init_point ();
27577
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   149
  in () end;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   150
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   151
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   152
(* restart top-level loop (keeps most state information) *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   153
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   154
val welcome = priority o Session.welcome;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   155
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   156
fun restart () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   157
 (sync_thy_loader ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   158
  tell_clear_goals ();
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   159
  tell_clear_response ();
27537
17838612217b restart: Isar.init_point;
wenzelm
parents: 27536
diff changeset
   160
  Isar.init_point ();
27577
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   161
  welcome ());
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   162
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   163
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   164
(* theorem dependency output *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   165
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   166
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   167
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   168
val spaces_quote = space_implode " " o map quote;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   169
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   170
fun thm_deps_message (thms, deps) =
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   171
  emacs_notify ("Proof General, theorem dependencies of " ^ thms ^ " are " ^ deps);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   172
28096
046418f64474 theorem dependency output: Toplevel.add_hook, ProofGeneralPgip.new_thms_deps;
wenzelm
parents: 28020
diff changeset
   173
in
046418f64474 theorem dependency output: Toplevel.add_hook, ProofGeneralPgip.new_thms_deps;
wenzelm
parents: 28020
diff changeset
   174
28103
b79e61861f0f simplified Toplevel.add_hook: cover successful transactions only;
wenzelm
parents: 28100
diff changeset
   175
fun setup_present_hook () = Toplevel.add_hook (fn _ => fn state => fn state' =>
28106
48b9c8756020 theorem dependency hook: check previous state;
wenzelm
parents: 28103
diff changeset
   176
  if print_mode_active thm_depsN andalso
48b9c8756020 theorem dependency hook: check previous state;
wenzelm
parents: 28103
diff changeset
   177
    can Toplevel.theory_of state andalso Toplevel.is_theory state'
48b9c8756020 theorem dependency hook: check previous state;
wenzelm
parents: 28103
diff changeset
   178
  then
28100
7650d5e0f8fb refined theorem dependency output: previous state needs to contain a theory (not empty toplevel);
wenzelm
parents: 28096
diff changeset
   179
    let val (names, deps) =
7650d5e0f8fb refined theorem dependency output: previous state needs to contain a theory (not empty toplevel);
wenzelm
parents: 28096
diff changeset
   180
      ProofGeneralPgip.new_thms_deps (Toplevel.theory_of state) (Toplevel.theory_of state')
7650d5e0f8fb refined theorem dependency output: previous state needs to contain a theory (not empty toplevel);
wenzelm
parents: 28096
diff changeset
   181
    in
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   182
      if null names orelse null deps then ()
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   183
      else thm_deps_message (spaces_quote names, spaces_quote deps)
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   184
    end
28096
046418f64474 theorem dependency output: Toplevel.add_hook, ProofGeneralPgip.new_thms_deps;
wenzelm
parents: 28020
diff changeset
   185
  else ());
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   186
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   187
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   188
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   189
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   190
(* additional outer syntax for Isar *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   191
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   192
local structure P = OuterParse and K = OuterKeyword in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   193
25192
b568f8c5d5ca made command 'undo' silent ('ProofGeneral.undo' becomes a historical relic);
wenzelm
parents: 24882
diff changeset
   194
fun undoP () = (*undo without output -- historical*)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   195
  OuterSyntax.improper_command "ProofGeneral.undo" "(internal)" K.control
27535
518380d43585 activated new versions of undo, kill_proof;
wenzelm
parents: 27532
diff changeset
   196
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative (fn () => Isar.undo 1)));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   197
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   198
fun restartP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   199
  OuterSyntax.improper_command "ProofGeneral.restart" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   200
    (P.opt_unit >> (Toplevel.no_timing oo K (Toplevel.imperative restart)));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   201
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   202
fun kill_proofP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   203
  OuterSyntax.improper_command "ProofGeneral.kill_proof" "(internal)" K.control
27532
f3d92b5dcd45 added ProofGeneral.isar_kill_proof;
wenzelm
parents: 26706
diff changeset
   204
    (Scan.succeed (Toplevel.no_timing o
f3d92b5dcd45 added ProofGeneral.isar_kill_proof;
wenzelm
parents: 26706
diff changeset
   205
      Toplevel.imperative (fn () => (Isar.kill_proof (); tell_clear_goals ()))));
f3d92b5dcd45 added ProofGeneral.isar_kill_proof;
wenzelm
parents: 26706
diff changeset
   206
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   207
fun inform_file_processedP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   208
  OuterSyntax.improper_command "ProofGeneral.inform_file_processed" "(internal)" K.control
27577
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   209
    (P.name >> (fn file =>
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   210
      Toplevel.no_timing o Toplevel.imperative (fn () => inform_file_processed file)));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   211
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   212
fun inform_file_retractedP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   213
  OuterSyntax.improper_command "ProofGeneral.inform_file_retracted" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   214
    (P.name >> (Toplevel.no_timing oo
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   215
      (fn file => Toplevel.imperative (fn () => inform_file_retracted file))));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   216
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   217
fun process_pgipP () =
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   218
  OuterSyntax.improper_command "ProofGeneral.process_pgip" "(internal)" K.control
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   219
    (P.text >> (Toplevel.no_timing oo
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   220
      (fn txt => Toplevel.imperative (fn () => ProofGeneralPgip.process_pgip txt))));
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   221
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   222
fun init_outer_syntax () = List.app (fn f => f ())
27535
518380d43585 activated new versions of undo, kill_proof;
wenzelm
parents: 27532
diff changeset
   223
  [undoP, restartP, kill_proofP, inform_file_processedP, inform_file_retractedP, process_pgipP];
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   224
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   225
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   226
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   227
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   228
(* init *)
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   229
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   230
val initialized = ref false;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   231
22699
938c1011ac94 removed unused Output.panic hook -- internal to PG wrapper;
wenzelm
parents: 22678
diff changeset
   232
fun init false = panic "No Proof General interface support for Isabelle/classic mode."
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   233
  | init true =
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   234
      (! initialized orelse
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   235
        (Output.no_warnings init_outer_syntax ();
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   236
          setup_xsymbols_output ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   237
          setup_messages ();
22590
ac84debdd7d3 removed unused info channel;
wenzelm
parents: 22228
diff changeset
   238
          ProofGeneralPgip.init_pgip_channel (! Output.priority_fn);
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   239
          setup_thy_loader ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   240
          setup_present_hook ();
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   241
          set initialized);
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   242
        sync_thy_loader ();
25749
wenzelm
parents: 25630
diff changeset
   243
       change print_mode (update (op =) proof_generalN);
26643
99f5407c05ef Isar.toplevel_loop: separate init/welcome flag;
wenzelm
parents: 26613
diff changeset
   244
       Isar.toplevel_loop {init = true, welcome = true, sync = true, secure = Secure.is_secure ()});
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   245
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   246
end;