| author | krauss | 
| Sat, 27 Dec 2008 17:49:15 +0100 | |
| changeset 29183 | f1648e009dc1 | 
| parent 28591 | 790d1863be28 | 
| child 29435 | a5f84ac14609 | 
| permissions | -rw-r--r-- | 
| 21637 | 1 | (* Title: Pure/ProofGeneral/preferences.ML | 
| 2 | ID: $Id$ | |
| 3 | Author: David Aspinall and Markus Wenzel | |
| 4 | ||
| 5 | User preferences for Isabelle which are maintained by the interface. | |
| 6 | *) | |
| 7 | ||
| 24329 | 8 | signature PREFERENCES = | 
| 21637 | 9 | sig | 
| 28587 | 10 | type preference = | 
| 11 |    {name: string,
 | |
| 12 | descr: string, | |
| 13 | default: string, | |
| 14 | pgiptype: PgipTypes.pgiptype, | |
| 15 | get: unit -> string, | |
| 16 | set: string -> unit} | |
| 17 |   val generic_pref: ('a -> string) -> (string -> 'a) -> PgipTypes.pgiptype ->
 | |
| 18 | 'a ref -> string -> string -> preference | |
| 19 | val string_pref: string ref -> string -> string -> preference | |
| 20 | val int_pref: int ref -> string -> string -> preference | |
| 21 | val nat_pref: int ref -> string -> string -> preference | |
| 22 | val bool_pref: bool ref -> string -> string -> preference | |
| 23 | type T = (string * preference list) list | |
| 24 | val pure_preferences: T | |
| 25 | val remove: string -> T -> T | |
| 26 | val add: string -> preference -> T -> T | |
| 27 | val set_default: string * string -> T -> T | |
| 21637 | 28 | end | 
| 29 | ||
| 28587 | 30 | structure Preferences: PREFERENCES = | 
| 21637 | 31 | struct | 
| 32 | ||
| 28587 | 33 | (* preferences and preference tables *) | 
| 21637 | 34 | |
| 28587 | 35 | type preference = | 
| 36 |  {name: string,
 | |
| 37 | descr: string, | |
| 38 | default: string, | |
| 39 | pgiptype: PgipTypes.pgiptype, | |
| 40 | get: unit -> string, | |
| 41 | set: string -> unit}; | |
| 42 | ||
| 43 | fun mkpref raw_get raw_set typ name descr : preference = | |
| 44 | let | |
| 45 | fun get () = CRITICAL raw_get; | |
| 46 | fun set x = CRITICAL (fn () => raw_set x); | |
| 47 |   in {name = name, descr = descr, pgiptype = typ, get = get, set = set, default = get ()} end;
 | |
| 21637 | 48 | |
| 49 | ||
| 28587 | 50 | (* generic preferences *) | 
| 21637 | 51 | |
| 28587 | 52 | fun generic_pref read write typ r = | 
| 53 | mkpref (fn () => read (! r)) (fn x => r := write x) typ; | |
| 54 | ||
| 55 | val string_pref = generic_pref I I PgipTypes.Pgipstring; | |
| 21637 | 56 | |
| 24329 | 57 | val int_pref = | 
| 28587 | 58 | generic_pref PgipTypes.int_to_pgstring (PgipTypes.read_pgipint (NONE, NONE)) | 
| 59 | (PgipTypes.Pgipint (NONE, NONE)); | |
| 60 | ||
| 21637 | 61 | val nat_pref = | 
| 28587 | 62 | generic_pref PgipTypes.int_to_pgstring PgipTypes.read_pgipnat PgipTypes.Pgipnat; | 
| 21637 | 63 | |
| 64 | val bool_pref = | |
| 28587 | 65 | generic_pref PgipTypes.bool_to_pgstring PgipTypes.read_pgipbool PgipTypes.Pgipbool; | 
| 66 | ||
| 67 | ||
| 68 | (* preferences of Pure *) | |
| 21637 | 69 | |
| 70 | val proof_pref = | |
| 28587 | 71 | let | 
| 72 | fun get () = PgipTypes.bool_to_pgstring (! Proofterm.proofs >= 2); | |
| 73 | fun set s = Proofterm.proofs := (if PgipTypes.read_pgipbool s then 2 else 1); | |
| 74 | in mkpref get set PgipTypes.Pgipbool "full-proofs" "Record full proof objects internally" end; | |
| 21637 | 75 | |
| 28587 | 76 | val thm_depsN = "thm_deps"; | 
| 24329 | 77 | val thm_deps_pref = | 
| 28587 | 78 | let | 
| 79 | fun get () = PgipTypes.bool_to_pgstring (print_mode_active thm_depsN); | |
| 80 | fun set s = | |
| 81 | if PgipTypes.read_pgipbool s then change print_mode (insert (op =) thm_depsN) | |
| 82 | else change print_mode (remove (op =) thm_depsN); | |
| 83 | in | |
| 84 | mkpref get set PgipTypes.Pgipbool "theorem-dependencies" | |
| 85 | "Track theorem dependencies within Proof General" | |
| 86 | end; | |
| 21637 | 87 | |
| 88 | val print_depth_pref = | |
| 28587 | 89 | let | 
| 90 | fun get () = PgipTypes.int_to_pgstring (get_print_depth ()); | |
| 91 | val set = print_depth o PgipTypes.read_pgipnat; | |
| 92 | in mkpref get set PgipTypes.Pgipnat "print-depth" "Setting for the ML print depth" end; | |
| 21637 | 93 | |
| 94 | ||
| 24329 | 95 | val display_preferences = | 
| 28587 | 96 | [bool_pref show_types | 
| 97 | "show-types" | |
| 98 | "Include types in display of Isabelle terms", | |
| 99 | bool_pref show_sorts | |
| 100 | "show-sorts" | |
| 101 | "Include sorts in display of Isabelle terms", | |
| 102 | bool_pref show_consts | |
| 103 | "show-consts" | |
| 104 | "Show types of consts in Isabelle goal display", | |
| 105 | bool_pref long_names | |
| 106 | "long-names" | |
| 107 | "Show fully qualified names in Isabelle terms", | |
| 108 | bool_pref show_brackets | |
| 109 | "show-brackets" | |
| 110 | "Show full bracketing in Isabelle terms", | |
| 111 | bool_pref Proof.show_main_goal | |
| 112 | "show-main-goal" | |
| 113 | "Show main goal in proof state display", | |
| 114 | bool_pref Syntax.eta_contract | |
| 115 | "eta-contract" | |
| 116 | "Print terms eta-contracted"]; | |
| 21637 | 117 | |
| 118 | val advanced_display_preferences = | |
| 28587 | 119 | [nat_pref goals_limit | 
| 120 | "goals-limit" | |
| 121 | "Setting for maximum number of goals printed", | |
| 122 | int_pref ProofContext.prems_limit | |
| 123 | "prems-limit" | |
| 124 | "Setting for maximum number of premises printed", | |
| 125 | print_depth_pref, | |
| 126 | bool_pref show_question_marks | |
| 127 | "show-question-marks" | |
| 128 | "Show leading question mark of variable name"]; | |
| 21637 | 129 | |
| 24329 | 130 | val tracing_preferences = | 
| 28587 | 131 | [bool_pref trace_simp | 
| 132 | "trace-simplifier" | |
| 133 | "Trace simplification rules.", | |
| 134 | nat_pref trace_simp_depth_limit | |
| 135 | "trace-simplifier-depth" | |
| 136 | "Trace simplifier depth limit.", | |
| 137 | bool_pref trace_rules | |
| 138 | "trace-rules" | |
| 139 | "Trace application of the standard rules", | |
| 140 | bool_pref Pattern.trace_unify_fail | |
| 141 | "trace-unification" | |
| 142 | "Output error diagnostics during unification", | |
| 143 | bool_pref Output.timing | |
| 144 | "global-timing" | |
| 145 | "Whether to enable timing in Isabelle.", | |
| 146 | bool_pref Toplevel.debug | |
| 147 | "debugging" | |
| 148 | "Whether to enable debugging.", | |
| 149 | bool_pref Quickcheck.auto | |
| 150 | "auto-quickcheck" | |
| 151 | "Whether to enable quickcheck automatically.", | |
| 152 | nat_pref Quickcheck.auto_time_limit | |
| 153 | "auto-quickcheck-time-limit" | |
| 154 | "Time limit for automatic quickcheck (in milliseconds).", | |
| 155 | thm_deps_pref]; | |
| 21637 | 156 | |
| 24329 | 157 | val proof_preferences = | 
| 28587 | 158 | [bool_pref quick_and_dirty | 
| 159 | "quick-and-dirty" | |
| 160 | "Take a few short cuts", | |
| 161 | bool_pref Toplevel.skip_proofs | |
| 162 | "skip-proofs" | |
| 163 | "Skip over proofs (interactive-only)", | |
| 164 | proof_pref, | |
| 165 | nat_pref Multithreading.max_threads | |
| 166 | "max-threads" | |
| 167 | "Maximum number of threads"]; | |
| 21637 | 168 | |
| 28587 | 169 | val pure_preferences = | 
| 170 |  [("Display", display_preferences),
 | |
| 171 |   ("Advanced Display", advanced_display_preferences),
 | |
| 172 |   ("Tracing", tracing_preferences),
 | |
| 173 |   ("Proof", proof_preferences)];
 | |
| 21637 | 174 | |
| 28587 | 175 | |
| 176 | (* table of categories and preferences; names must be unique *) | |
| 177 | ||
| 178 | type T = (string * preference list) list; | |
| 22214 
6e9ab159512f
Add operations on preference tables (remove, set_default).
 aspinall parents: 
22130diff
changeset | 179 | |
| 28587 | 180 | fun remove name (tab: T) = tab |> map | 
| 181 | (fn (cat, prefs) => (cat, filter_out (curry op = name o #name) prefs)); | |
| 22214 
6e9ab159512f
Add operations on preference tables (remove, set_default).
 aspinall parents: 
22130diff
changeset | 182 | |
| 28587 | 183 | fun set_default (setname, newdefault) (tab: T) = tab |> map | 
| 184 | (fn (cat, prefs) => | |
| 185 |     (cat, prefs |> map (fn (pref as {name, descr, default, pgiptype, get, set}) =>
 | |
| 186 | if name = setname then | |
| 187 | (set newdefault; | |
| 188 |           {name =name , descr = descr, default = newdefault,
 | |
| 189 | pgiptype = pgiptype, get = get, set = set}) | |
| 190 | else pref))); | |
| 22214 
6e9ab159512f
Add operations on preference tables (remove, set_default).
 aspinall parents: 
22130diff
changeset | 191 | |
| 28587 | 192 | fun add cname (pref: preference) (tab: T) = tab |> map | 
| 193 | (fn (cat, prefs) => | |
| 194 | if cat <> cname then (cat, prefs) | |
| 195 | else | |
| 196 |       if exists (fn {name, ...} => name = #name pref) prefs
 | |
| 28591 | 197 |       then (warning ("Preference already exists: " ^ quote (#name pref)); (cat, prefs))
 | 
| 28587 | 198 | else (cat, pref :: prefs)); | 
| 28066 
611e504c1191
extended interface to preferences to allow adding new ones
 nipkow parents: 
25440diff
changeset | 199 | |
| 28587 | 200 | end; |