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