src/Pure/Tools/proof_general.ML
author wenzelm
Sat, 15 Mar 2014 11:22:25 +0100
changeset 56158 c2c6d560e7b2
parent 55387 51f0876f61df
child 56208 06cc31dff138
permissions -rw-r--r--
more explicit treatment of verbose mode, which includes concealed entries;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52009
3b18ef9df768 moved files;
wenzelm
parents: 52007
diff changeset
     1
(*  Title:      Pure/Tools/proof_general.ML
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
     2
    Author:     David Aspinall
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
     3
    Author:     Makarius
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
     4
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
     5
Isabelle/Isar configuration for Proof General / Emacs.
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
53403
c09f4005d6bd some explicit indication of Proof General legacy;
wenzelm
parents: 52852
diff changeset
     9
(*Proof General legacy*)
c09f4005d6bd some explicit indication of Proof General legacy;
wenzelm
parents: 52852
diff changeset
    10
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    11
signature PROOF_GENERAL =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    12
sig
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    13
  type category = string
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    14
  val category_display: category
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    15
  val category_advanced_display: category
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    16
  val category_tracing: category
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    17
  val category_proof: category
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    18
  type pgiptype = string
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    19
  val pgipbool: pgiptype
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    20
  val pgipint: pgiptype
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    21
  val pgipfloat: pgiptype
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    22
  val pgipstring: pgiptype
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    23
  val preference: category -> string option ->
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    24
    (unit -> string) -> (string -> unit) -> string -> string -> string -> unit
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    25
  val preference_bool: category -> string option ->
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    26
    bool Unsynchronized.ref -> string -> string -> unit
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    27
  val preference_int: category -> string option ->
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    28
    int Unsynchronized.ref -> string -> string -> unit
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    29
  val preference_real: category -> string option ->
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    30
    real Unsynchronized.ref -> string -> string -> unit
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    31
  val preference_string: category -> string option ->
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    32
    string Unsynchronized.ref -> string -> string -> unit
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    33
  val preference_option: category -> string option -> string -> string -> string -> unit
52437
c88354589b43 more formal ProofGeneral command setup within theory Pure;
wenzelm
parents: 52017
diff changeset
    34
  val process_pgip: string -> unit
c88354589b43 more formal ProofGeneral command setup within theory Pure;
wenzelm
parents: 52017
diff changeset
    35
  val tell_clear_goals: unit -> unit
c88354589b43 more formal ProofGeneral command setup within theory Pure;
wenzelm
parents: 52017
diff changeset
    36
  val tell_clear_response: unit -> unit
c88354589b43 more formal ProofGeneral command setup within theory Pure;
wenzelm
parents: 52017
diff changeset
    37
  val inform_file_processed: string -> unit
c88354589b43 more formal ProofGeneral command setup within theory Pure;
wenzelm
parents: 52017
diff changeset
    38
  val inform_file_retracted: string -> unit
54450
7815563f50dc tuned signature -- clarified Proof General legacy;
wenzelm
parents: 54387
diff changeset
    39
  val master_path: Path.T Unsynchronized.ref
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    40
  structure ThyLoad: sig val add_path: string -> unit end
52012
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
    41
  val thm_deps: bool Unsynchronized.ref
52013
ebb119a9f712 more basic print mode "ProofGeneral" (again);
wenzelm
parents: 52012
diff changeset
    42
  val proof_generalN: string
51938
cf9c8d8d8939 Proof General interaction always uses Isar loop;
wenzelm
parents: 51935
diff changeset
    43
  val init: unit -> unit
52437
c88354589b43 more formal ProofGeneral command setup within theory Pure;
wenzelm
parents: 52017
diff changeset
    44
  val restart: unit -> unit
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    45
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    46
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    47
structure ProofGeneral: PROOF_GENERAL =
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    48
struct
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
    49
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    50
(** preferences **)
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    51
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    52
(* type preference *)
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
    53
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    54
type category = string;
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    55
val category_display = "Display";
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    56
val category_advanced_display = "Advanced Display";
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    57
val category_tracing = "Tracing";
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    58
val category_proof = "Proof";
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
    59
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    60
type pgiptype = string;
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    61
val pgipbool = "pgipbool";
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    62
val pgipint = "pgipint";
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    63
val pgipfloat = "pgipint";  (*NB: PG 3.7.x and 4.0 lack pgipfloat, but accept floats as pgipint*)
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    64
val pgipstring = "pgipstring";
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
    65
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    66
type preference =
52014
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    67
 {category: string,
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    68
  override: string option,
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    69
  descr: string,
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    70
  pgiptype: pgiptype,
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    71
  get: unit -> string,
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    72
  set: string -> unit};
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
    73
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
    74
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    75
(* global preferences *)
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    76
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    77
local
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    78
  val preferences =
52014
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    79
    Synchronized.var "ProofGeneral.preferences" ([]: (string * preference) list);
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    80
in
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    81
52014
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    82
fun add_preference name pref =
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    83
  Synchronized.change preferences (fn prefs =>
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    84
   (if not (AList.defined (op =) prefs name) then ()
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    85
    else warning ("Redefining ProofGeneral preference: " ^ quote name);
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    86
    AList.update (op =) (name, pref) prefs));
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    87
52014
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    88
fun set_preference name value =
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    89
  (case AList.lookup (op =) (Synchronized.value preferences) name of
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    90
    SOME {set, ...} => set value
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    91
  | NONE => error ("Unknown ProofGeneral preference: " ^ quote name));
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    92
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    93
fun all_preferences () =
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    94
  rev (Synchronized.value preferences)
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    95
  |> map (fn (name, {category, descr, pgiptype, get, ...}) =>
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    96
    (category, {name = name, descr = descr, default = get (), pgiptype = pgiptype}))
52014
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
    97
  |> AList.group (op =);
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
    98
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
    99
fun init_preferences () =
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   100
  Synchronized.value preferences
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   101
  |> List.app (fn (_, {set, override = SOME value, ...}) => set value | _ => ());
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   102
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   103
end;
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   104
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   105
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   106
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   107
(* raw preferences *)
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   108
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   109
fun preference category override get set typ name descr =
52016
4b77f444afbb simplified ProofGeneral.preference operation -- no need for CRITICAL section for atomic access (and sequential execution of PG/TTY loop);
wenzelm
parents: 52015
diff changeset
   110
  add_preference name
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   111
    {category = category, override = override, descr = descr, pgiptype = typ, get = get, set = set};
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   112
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   113
fun preference_ref category override read write typ r =
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   114
  preference category override (fn () => read (! r)) (fn x => r := write x) typ;
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   115
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   116
fun preference_bool x y = preference_ref x y Markup.print_bool Markup.parse_bool pgipbool;
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   117
fun preference_int x y = preference_ref x y Markup.print_int Markup.parse_int pgipint;
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   118
fun preference_real x y = preference_ref x y Markup.print_real Markup.parse_real pgipfloat;
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   119
fun preference_string x y = preference_ref x y I I pgipstring;
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   120
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   121
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   122
(* system options *)
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   123
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   124
fun preference_option category override option_name pgip_name descr =
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   125
  let
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   126
    val typ = Options.default_typ option_name;
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   127
    val pgiptype =
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   128
      if typ = Options.boolT then pgipbool
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   129
      else if typ = Options.intT then pgipint
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   130
      else if typ = Options.realT then pgipfloat
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   131
      else pgipstring;
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   132
  in
52014
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
   133
    add_preference pgip_name
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
   134
     {category = category,
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   135
      override = override,
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   136
      descr = descr,
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   137
      pgiptype = pgiptype,
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   138
      get = fn () => Options.get_default option_name,
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   139
      set = Options.put_default option_name}
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   140
  end;
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   141
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   142
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   143
(* minimal PGIP support for <askprefs>, <haspref>, <setpref> *)
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   144
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   145
local
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   146
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   147
fun get_attr attrs name =
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   148
  (case Properties.get attrs name of
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   149
    SOME value => value
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   150
  | NONE => raise Fail ("Missing attribute: " ^ quote name));
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   151
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   152
fun attr x y = [(x, y)] : XML.attributes;
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   153
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   154
fun opt_attr _ NONE = []
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   155
  | opt_attr name (SOME value) = attr name value;
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   156
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   157
val pgip_id = "dummy";
52537
4b5941730bd8 more uniform Counter in ML and Scala;
wenzelm
parents: 52437
diff changeset
   158
val pgip_serial = Counter.make ();
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   159
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   160
fun output_pgip refid refseq content =
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   161
  XML.Elem (("pgip",
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   162
    attr "tag" "Isabelle/Isar" @
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   163
    attr "id" pgip_id @
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   164
    opt_attr "destid" refid @
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   165
    attr "class" "pg" @
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   166
    opt_attr "refid" refid @
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   167
    attr "refseq" refseq @
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   168
    attr "seq" (string_of_int (pgip_serial ()))), content)
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   169
  |> XML.string_of
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   170
  |> Output.urgent_message;
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   171
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   172
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   173
fun invalid_pgip () = raise Fail "Invalid PGIP packet";
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   174
52014
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
   175
fun haspref {name, descr, default, pgiptype} =
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   176
  XML.Elem (("haspref", [("name", name), ("descr", descr), ("default", default)]),
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   177
    [XML.Elem ((pgiptype, []), [])]);
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   178
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   179
fun process_element refid refseq (XML.Elem (("askprefs", _), _)) =
52014
45929e0e1d73 more standard Isabelle/ML structures for global preferences;
wenzelm
parents: 52013
diff changeset
   180
      all_preferences () |> List.app (fn (category, prefs) =>
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   181
        output_pgip refid refseq
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   182
          [XML.Elem (("hasprefs", [("prefcategory", category)]), map haspref prefs)])
52006
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   183
  | process_element _ _ (XML.Elem (("setpref", attrs), data)) =
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   184
      let
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   185
        val name =
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   186
          (case Properties.get attrs "name" of
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   187
            SOME name => name
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   188
          | NONE => invalid_pgip ());
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   189
        val value = XML.content_of data;
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   190
      in set_preference name value end
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   191
  | process_element _ _ _ = invalid_pgip ();
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   192
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   193
in
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   194
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   195
fun process_pgip str =
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   196
  (case XML.parse str of
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   197
    XML.Elem (("pgip", attrs), pgips) =>
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   198
      let
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   199
        val class = get_attr attrs "class";
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   200
        val dest = Properties.get attrs "destid";
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   201
        val refid = Properties.get attrs "id";
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   202
        val refseq = get_attr attrs "seq";
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   203
        val processit =
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   204
          (case dest of
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   205
            NONE => class = "pa"
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   206
          | SOME id => id = pgip_id);
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   207
       in if processit then List.app (process_element refid refseq) pgips else () end
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   208
  | _ => invalid_pgip ())
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   209
  handle Fail msg => raise Fail (msg ^ "\n" ^ str);
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   210
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   211
end;
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   212
9402221f77dd just one ProofGeneral module;
wenzelm
parents: 51970
diff changeset
   213
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   214
(** messages **)
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   215
51939
65548ab2fc55 removed obsolete test_markup;
wenzelm
parents: 51938
diff changeset
   216
(* render markup *)
26549
9838e45c6e6c moved test_markup here;
wenzelm
parents: 26542
diff changeset
   217
43777
22c87ff1b8a9 tuned signature -- less cryptic ASCII names;
wenzelm
parents: 43557
diff changeset
   218
fun special ch = chr 1 ^ ch;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   219
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   220
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   221
29326
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   222
fun render_trees ts = fold render_tree ts
49658
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   223
and render_tree t =
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   224
  (case XML.unwrap_elem t of
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   225
    SOME (_, ts) => render_trees ts
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   226
  | NONE =>
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   227
      (case t of
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   228
        XML.Text s => Buffer.add s
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   229
      | XML.Elem ((name, props), ts) =>
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   230
          let
51939
65548ab2fc55 removed obsolete test_markup;
wenzelm
parents: 51938
diff changeset
   231
            val (bg, en) =
49658
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   232
              if null ts then Markup.no_output
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   233
              else if name = Markup.stateN then (special "O" ^ "\n", "\n" ^ special "P")
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   234
              else if name = Markup.sendbackN then (special "W", special "X")
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   235
              else if name = Markup.intensifyN then (special "0", special "1")
52643
34c29356930e more explicit Markup.information for messages produced by "auto" tools;
wenzelm
parents: 52537
diff changeset
   236
              else if name = Markup.informationN then ("\n" ^ special "0", special "1")
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   237
              else if name = Markup.tfreeN then (special "C", special "A")
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   238
              else if name = Markup.tvarN then (special "D", special "A")
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   239
              else if name = Markup.freeN then (special "E", special "A")
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   240
              else if name = Markup.boundN then (special "F", special "A")
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   241
              else if name = Markup.varN then (special "G", special "A")
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   242
              else if name = Markup.skolemN then (special "H", special "A")
49658
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   243
              else
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   244
                (case Markup.get_entity_kind (name, props) of
49658
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   245
                  SOME kind =>
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   246
                    if kind = Markup.classN then (special "B", special "A")
49658
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   247
                    else Markup.no_output
ae8c8b745f82 ignore wrapped markup elements in Proof General;
wenzelm
parents: 49358
diff changeset
   248
                | NONE => Markup.no_output);
51939
65548ab2fc55 removed obsolete test_markup;
wenzelm
parents: 51938
diff changeset
   249
          in Buffer.add bg #> render_trees ts #> Buffer.add en end));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   250
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   251
in
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   252
29326
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   253
fun render text =
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   254
  Buffer.content (render_trees (YXML.parse_body text) Buffer.empty);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   255
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   256
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   257
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   258
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   259
(* hooks *)
29326
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   260
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   261
fun message bg en prfx text =
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   262
  (case render text of
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   263
    "" => ()
44389
a3b5fdfb04a3 tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents: 44270
diff changeset
   264
  | s => Output.physical_writeln (enclose bg en (prefix_lines prfx s)));
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   265
29326
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   266
fun setup_messages () =
55387
51f0876f61df seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents: 54450
diff changeset
   267
 (Output.writeln_fn := message "" "" "";
51f0876f61df seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents: 54450
diff changeset
   268
  Output.status_fn := (fn _ => ());
51f0876f61df seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents: 54450
diff changeset
   269
  Output.report_fn := (fn _ => ());
51f0876f61df seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents: 54450
diff changeset
   270
  Output.urgent_message_fn := message (special "I") (special "J") "";
51f0876f61df seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents: 54450
diff changeset
   271
  Output.tracing_fn := message (special "I" ^ special "V") (special "J") "";
51f0876f61df seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents: 54450
diff changeset
   272
  Output.warning_fn := message (special "K") (special "L") "### ";
51f0876f61df seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents: 54450
diff changeset
   273
  Output.error_message_fn := (fn (_, s) => message (special "M") (special "N") "*** " s);
51f0876f61df seal system channels at end of Pure bootstrap -- Isabelle/Scala provides official interfaces;
wenzelm
parents: 54450
diff changeset
   274
  Output.prompt_fn := (fn s => Output.physical_stdout (render s ^ special "S")));
29326
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   275
23641
d6f9d3acffaa toplevel prompt/print_state: proper markup, removed hooks;
wenzelm
parents: 23621
diff changeset
   276
29326
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   277
(* notification *)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   278
29326
da275b7809bd xsymbols: use plain Symbol.output;
wenzelm
parents: 29321
diff changeset
   279
val emacs_notify = message (special "I") (special "J") "";
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   280
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   281
fun tell_clear_goals () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   282
  emacs_notify "Proof General, please clear the goals buffer.";
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   283
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   284
fun tell_clear_response () =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   285
  emacs_notify "Proof General, please clear the response buffer.";
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   286
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   287
fun tell_file_loaded path =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   288
  emacs_notify ("Proof General, this file is loaded: " ^ quote (File.platform_path path));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   289
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   290
fun tell_file_retracted path =
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21858
diff changeset
   291
  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
   292
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   293
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   294
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   295
(** theory loader **)
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   296
54450
7815563f50dc tuned signature -- clarified Proof General legacy;
wenzelm
parents: 54387
diff changeset
   297
(* global master path *)
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   298
54450
7815563f50dc tuned signature -- clarified Proof General legacy;
wenzelm
parents: 54387
diff changeset
   299
val master_path = Unsynchronized.ref Path.current;
7815563f50dc tuned signature -- clarified Proof General legacy;
wenzelm
parents: 54387
diff changeset
   300
7815563f50dc tuned signature -- clarified Proof General legacy;
wenzelm
parents: 54387
diff changeset
   301
(*fake old ThyLoad -- with new semantics*)
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   302
structure ThyLoad =
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   303
struct
54450
7815563f50dc tuned signature -- clarified Proof General legacy;
wenzelm
parents: 54387
diff changeset
   304
  fun add_path path = master_path := Path.explode path;
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   305
end;
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   306
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   307
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   308
(* actions *)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   309
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   310
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   311
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   312
fun trace_action action name =
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36953
diff changeset
   313
  if action = Thy_Info.Update then
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36953
diff changeset
   314
    List.app tell_file_loaded (Thy_Info.loaded_files name)
37981
9a15982f41fe theory loader: removed obsolete touch/outdate operations (require_thy no longer changes the database implicitly);
wenzelm
parents: 37977
diff changeset
   315
  else if action = Thy_Info.Remove then
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36953
diff changeset
   316
    List.app tell_file_retracted (Thy_Info.loaded_files name)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   317
  else ();
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   318
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   319
in
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36953
diff changeset
   320
  fun setup_thy_loader () = Thy_Info.add_hook trace_action;
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36953
diff changeset
   321
  fun sync_thy_loader () = List.app (trace_action Thy_Info.Update) (Thy_Info.get_names ());
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   322
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   323
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   324
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   325
(* get informed about files *)
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   326
25442
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   327
(*liberal low-level version*)
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   328
val thy_name = perhaps (try (unsuffix ".thy")) o List.last o space_explode "/";
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   329
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37954
diff changeset
   330
val inform_file_retracted = Thy_Info.kill_thy o thy_name;
25442
0337e3df3187 removed unused inform_file_processed;
wenzelm
parents: 25436
diff changeset
   331
27577
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   332
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
   333
  let
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   334
    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
   335
    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
   336
    val _ =
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37954
diff changeset
   337
      Thy_Info.register_thy (Toplevel.end_theory Position.none (Isar.state ()))
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37954
diff changeset
   338
        handle ERROR msg =>
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37954
diff changeset
   339
          (warning (cat_lines ["Failed to register theory: " ^ quote name, msg]);
46737
09ab89658a5d clarified module Thy_Load;
wenzelm
parents: 45666
diff changeset
   340
            tell_file_retracted (Thy_Load.thy_path (Path.basic name)))
29349
b49d8501720a Isar.init;
wenzelm
parents: 29326
diff changeset
   341
    val _ = Isar.init ();
27577
7c7a9a343ca5 proper_inform_file_processed: new implementation based on global Isar state (cf. isar.ML);
wenzelm
parents: 27537
diff changeset
   342
  in () end;
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   343
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   344
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   345
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   346
(** theorem dependencies **)
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   347
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   348
(* thm_deps *)
51970
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   349
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   350
local
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   351
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   352
fun add_proof_body (PBody {thms, ...}) =
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   353
  thms |> fold (fn (_, (name, _, _)) => name <> "" ? Symtab.update (name, ()));
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   354
51970
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   355
fun add_thm th =
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   356
  (case Thm.proof_body_of th of
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   357
    PBody {proof = PThm (_, ((name, _, _), body)), ...} =>
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   358
      if Thm.has_name_hint th andalso Thm.get_name_hint th = name
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   359
      then add_proof_body (Future.join body)
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   360
      else I
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   361
  | body => add_proof_body body);
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   362
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   363
in
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   364
52011
56dfc90a5c75 more elementary ProofGeneral.thm_deps;
wenzelm
parents: 52009
diff changeset
   365
fun get_thm_deps ths =
51970
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   366
  let
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   367
    (* FIXME proper derivation names!? *)
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   368
    val names = map Thm.get_name_hint (filter Thm.has_name_hint ths);
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   369
    val deps = Symtab.keys (fold add_thm ths Symtab.empty);
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   370
  in (names, deps) end;
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   371
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   372
end;
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   373
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   374
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   375
(* report via hook *)
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   376
52011
56dfc90a5c75 more elementary ProofGeneral.thm_deps;
wenzelm
parents: 52009
diff changeset
   377
val thm_deps = Unsynchronized.ref false;
51939
65548ab2fc55 removed obsolete test_markup;
wenzelm
parents: 51938
diff changeset
   378
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   379
local
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   380
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   381
val spaces_quote = space_implode " " o map quote;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   382
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   383
fun thm_deps_message (thms, deps) =
21948
e34bc5e4e7bc removed obsolete init_pgip;
wenzelm
parents: 21945
diff changeset
   384
  emacs_notify ("Proof General, theorem dependencies of " ^ thms ^ " are " ^ deps);
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   385
28096
046418f64474 theorem dependency output: Toplevel.add_hook, ProofGeneralPgip.new_thms_deps;
wenzelm
parents: 28020
diff changeset
   386
in
046418f64474 theorem dependency output: Toplevel.add_hook, ProofGeneralPgip.new_thms_deps;
wenzelm
parents: 28020
diff changeset
   387
28103
b79e61861f0f simplified Toplevel.add_hook: cover successful transactions only;
wenzelm
parents: 28100
diff changeset
   388
fun setup_present_hook () = Toplevel.add_hook (fn _ => fn state => fn state' =>
52011
56dfc90a5c75 more elementary ProofGeneral.thm_deps;
wenzelm
parents: 52009
diff changeset
   389
  if ! thm_deps andalso can Toplevel.theory_of state andalso Toplevel.is_theory state'
28106
48b9c8756020 theorem dependency hook: check previous state;
wenzelm
parents: 28103
diff changeset
   390
  then
51970
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   391
    let
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   392
      val prev_facts = Global_Theory.facts_of (Toplevel.theory_of state);
f08366cb9fd1 tuned signature;
wenzelm
parents: 51963
diff changeset
   393
      val facts = Global_Theory.facts_of (Toplevel.theory_of state');
56158
c2c6d560e7b2 more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents: 55387
diff changeset
   394
      val (names, deps) = get_thm_deps (maps #2 (Facts.dest_static true [prev_facts] facts));
28100
7650d5e0f8fb refined theorem dependency output: previous state needs to contain a theory (not empty toplevel);
wenzelm
parents: 28096
diff changeset
   395
    in
21968
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   396
      if null names orelse null deps then ()
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   397
      else thm_deps_message (spaces_quote names, spaces_quote deps)
883cd697112e removed conditional combinator;
wenzelm
parents: 21959
diff changeset
   398
    end
28096
046418f64474 theorem dependency output: Toplevel.add_hook, ProofGeneralPgip.new_thms_deps;
wenzelm
parents: 28020
diff changeset
   399
  else ());
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   400
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   401
end;
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   402
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   403
52007
0b1183012a3c maintain ProofGeneral preferences within ProofGeneral module;
wenzelm
parents: 52006
diff changeset
   404
52012
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   405
(** startup **)
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   406
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   407
(* init *)
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   408
52013
ebb119a9f712 more basic print mode "ProofGeneral" (again);
wenzelm
parents: 52012
diff changeset
   409
val proof_generalN = "ProofGeneral";
52012
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   410
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   411
val initialized = Unsynchronized.ref false;
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   412
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   413
fun init () =
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   414
  (if ! initialized then ()
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   415
   else
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   416
    (Output.add_mode Symbol.xsymbolsN Symbol.output Output.default_escape;
52013
ebb119a9f712 more basic print mode "ProofGeneral" (again);
wenzelm
parents: 52012
diff changeset
   417
     Output.add_mode proof_generalN Output.default_output Output.default_escape;
ebb119a9f712 more basic print mode "ProofGeneral" (again);
wenzelm
parents: 52012
diff changeset
   418
     Markup.add_mode proof_generalN YXML.output_markup;
52012
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   419
     setup_messages ();
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   420
     setup_thy_loader ();
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   421
     setup_present_hook ();
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   422
     initialized := true);
52017
bc0238c1f73a clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents: 52016
diff changeset
   423
   init_preferences ();
52012
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   424
   sync_thy_loader ();
52013
ebb119a9f712 more basic print mode "ProofGeneral" (again);
wenzelm
parents: 52012
diff changeset
   425
   Unsynchronized.change print_mode (update (op =) proof_generalN);
52012
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   426
   Secure.PG_setup ();
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   427
   Isar.toplevel_loop TextIO.stdIn
52015
d021c180e7df back to hidden welcome -- revert change 9ebf2da69b29, which appears to disturb startup protocol of PG 4.1;
wenzelm
parents: 52014
diff changeset
   428
    {init = true, welcome = true, sync = true, secure = Secure.is_secure ()});
52012
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   429
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   430
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   431
(* restart *)
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   432
52015
d021c180e7df back to hidden welcome -- revert change 9ebf2da69b29, which appears to disturb startup protocol of PG 4.1;
wenzelm
parents: 52014
diff changeset
   433
val welcome = Output.urgent_message o Session.welcome;
d021c180e7df back to hidden welcome -- revert change 9ebf2da69b29, which appears to disturb startup protocol of PG 4.1;
wenzelm
parents: 52014
diff changeset
   434
52012
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   435
fun restart () =
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   436
 (sync_thy_loader ();
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   437
  tell_clear_goals ();
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   438
  tell_clear_response ();
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   439
  Isar.init ();
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   440
  welcome ());
9ebf2da69b29 uniform welcome -- actually visible on startup via Output.urgent_message;
wenzelm
parents: 52011
diff changeset
   441
21642
54b00ca67e0e Add separate PG Emacs configuration
aspinall
parents:
diff changeset
   442
end;
37977
3ceccd415145 simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents: 37954
diff changeset
   443