turned show_question_marks into proper configuration option;
authorwenzelm
Thu, 02 Sep 2010 00:48:07 +0200
changeset 38980 af73cf0dc31f
parent 38979 60dbf0b3f6c7
child 39040 e3799716b733
turned show_question_marks into proper configuration option; show_question_marks only affects regular type/term pretty printing, not raw Term.string_of_vname; tuned;
NEWS
doc-src/IsarRef/Thy/Inner_Syntax.thy
doc-src/IsarRef/Thy/document/Inner_Syntax.tex
doc-src/LaTeXsugar/Sugar/Sugar.thy
doc-src/LaTeXsugar/Sugar/document/Sugar.tex
src/Pure/Isar/attrib.ML
src/Pure/Isar/proof_context.ML
src/Pure/ProofGeneral/preferences.ML
src/Pure/Syntax/printer.ML
src/Pure/Thy/thy_output.ML
src/Pure/term.ML
src/Tools/WWW_Find/find_theorems.ML
--- a/NEWS	Wed Sep 01 23:43:45 2010 +0200
+++ b/NEWS	Thu Sep 02 00:48:07 2010 +0200
@@ -23,7 +23,7 @@
 at the cost of clarity of file dependencies.  Recall that Isabelle/ML
 files exclusively use the .ML extension.  Minor INCOMPATIBILTY.
 
-* Various options that affect document antiquotations are now properly
+* Various options that affect pretty printing etc. are now properly
 handled within the context via configuration options, instead of
 unsynchronized references.  There are both ML Config.T entities and
 Isar declaration attributes to access these.
@@ -36,15 +36,11 @@
   Thy_Output.source         thy_output_source
   Thy_Output.break          thy_output_break
 
+  show_question_marks       show_question_marks
+
 Note that the corresponding "..._default" references may be only
 changed globally at the ROOT session setup, but *not* within a theory.
 
-* ML structure Unsynchronized never opened, not even in Isar
-interaction mode as before.  Old Unsynchronized.set etc. have been
-discontinued -- use plain := instead.  This should be *rare* anyway,
-since modern tools always work via official context data, notably
-configuration options.
-
 
 *** Pure ***
 
@@ -217,6 +213,15 @@
 
 *** ML ***
 
+* Configuration option show_question_marks only affects regular pretty
+printing of types and terms, not raw Term.string_of_vname.
+
+* ML structure Unsynchronized never opened, not even in Isar
+interaction mode as before.  Old Unsynchronized.set etc. have been
+discontinued -- use plain := instead.  This should be *rare* anyway,
+since modern tools always work via official context data, notably
+configuration options.
+
 * ML antiquotations @{theory} and @{theory_ref} refer to named
 theories from the ancestry of the current context, not any accidental
 theory loader state as before.  Potential INCOMPATIBILITY, subtle
--- a/doc-src/IsarRef/Thy/Inner_Syntax.thy	Wed Sep 01 23:43:45 2010 +0200
+++ b/doc-src/IsarRef/Thy/Inner_Syntax.thy	Thu Sep 02 00:48:07 2010 +0200
@@ -108,7 +108,7 @@
     @{index_ML Proof.show_main_goal: "bool Unsynchronized.ref"} & default @{ML false} \\
     @{index_ML show_hyps: "bool Unsynchronized.ref"} & default @{ML false} \\
     @{index_ML show_tags: "bool Unsynchronized.ref"} & default @{ML false} \\
-    @{index_ML show_question_marks: "bool Unsynchronized.ref"} & default @{ML true} \\
+    @{index_ML show_question_marks: "bool Config.T"} & default @{ML true} \\
   \end{mldecls}
 
   These global ML variables control the detail of information that is
--- a/doc-src/IsarRef/Thy/document/Inner_Syntax.tex	Wed Sep 01 23:43:45 2010 +0200
+++ b/doc-src/IsarRef/Thy/document/Inner_Syntax.tex	Thu Sep 02 00:48:07 2010 +0200
@@ -130,7 +130,7 @@
     \indexdef{}{ML}{Proof.show\_main\_goal}\verb|Proof.show_main_goal: bool Unsynchronized.ref| & default \verb|false| \\
     \indexdef{}{ML}{show\_hyps}\verb|show_hyps: bool Unsynchronized.ref| & default \verb|false| \\
     \indexdef{}{ML}{show\_tags}\verb|show_tags: bool Unsynchronized.ref| & default \verb|false| \\
-    \indexdef{}{ML}{show\_question\_marks}\verb|show_question_marks: bool Unsynchronized.ref| & default \verb|true| \\
+    \indexdef{}{ML}{show\_question\_marks}\verb|show_question_marks: bool Config.T| & default \verb|true| \\
   \end{mldecls}
 
   These global ML variables control the detail of information that is
--- a/doc-src/LaTeXsugar/Sugar/Sugar.thy	Wed Sep 01 23:43:45 2010 +0200
+++ b/doc-src/LaTeXsugar/Sugar/Sugar.thy	Thu Sep 02 00:48:07 2010 +0200
@@ -132,19 +132,19 @@
 This \verb!no_vars! business can become a bit tedious.
 If you would rather never see question marks, simply put
 \begin{quote}
-@{ML "show_question_marks := false"}\verb!;!
+@{ML "show_question_marks_default := false"}\verb!;!
 \end{quote}
 at the beginning of your file \texttt{ROOT.ML}.
 The rest of this document is produced with this flag set to \texttt{false}.
 
-Hint: Setting \verb!show_question_marks! to \texttt{false} only
+Hint: Setting \verb!show_question_marks_default! to \texttt{false} only
 suppresses question marks; variables that end in digits,
 e.g. @{text"x1"}, are still printed with a trailing @{text".0"},
 e.g. @{text"x1.0"}, their internal index. This can be avoided by
 turning the last digit into a subscript: write \verb!x\<^isub>1! and
 obtain the much nicer @{text"x\<^isub>1"}. *}
 
-(*<*)ML "show_question_marks := false"(*>*)
+(*<*)declare [[show_question_marks = false]](*>*)
 
 subsection {*Qualified names*}
 
--- a/doc-src/LaTeXsugar/Sugar/document/Sugar.tex	Wed Sep 01 23:43:45 2010 +0200
+++ b/doc-src/LaTeXsugar/Sugar/document/Sugar.tex	Thu Sep 02 00:48:07 2010 +0200
@@ -164,7 +164,7 @@
 \begin{isamarkuptext}%
 If you print anything, especially theorems, containing
 schematic variables they are prefixed with a question mark:
-\verb!@!\verb!{thm conjI}! results in \isa{{\isasymlbrakk}P{\isacharsemicolon}\ Q{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ {\isasymand}\ Q}. Most of the time
+\verb!@!\verb!{thm conjI}! results in \isa{{\isasymlbrakk}{\isacharquery}P{\isacharsemicolon}\ {\isacharquery}Q{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharquery}P\ {\isasymand}\ {\isacharquery}Q}. Most of the time
 you would rather not see the question marks. There is an attribute
 \verb!no_vars! that you can attach to the theorem that turns its
 schematic into ordinary free variables: \verb!@!\verb!{thm conjI[no_vars]}!
@@ -173,12 +173,12 @@
 This \verb!no_vars! business can become a bit tedious.
 If you would rather never see question marks, simply put
 \begin{quote}
-\verb|show_question_marks := false|\verb!;!
+\verb|show_question_marks_default := false|\verb!;!
 \end{quote}
 at the beginning of your file \texttt{ROOT.ML}.
 The rest of this document is produced with this flag set to \texttt{false}.
 
-Hint: Setting \verb!show_question_marks! to \texttt{false} only
+Hint: Setting \verb!show_question_marks_default! to \texttt{false} only
 suppresses question marks; variables that end in digits,
 e.g. \isa{x{\isadigit{1}}}, are still printed with a trailing \isa{{\isachardot}{\isadigit{0}}},
 e.g. \isa{x{\isadigit{1}}{\isachardot}{\isadigit{0}}}, their internal index. This can be avoided by
@@ -187,19 +187,6 @@
 \end{isamarkuptext}%
 \isamarkuptrue%
 %
-\isadelimML
-%
-\endisadelimML
-%
-\isatagML
-%
-\endisatagML
-{\isafoldML}%
-%
-\isadelimML
-%
-\endisadelimML
-%
 \isamarkupsubsection{Qualified names%
 }
 \isamarkuptrue%
--- a/src/Pure/Isar/attrib.ML	Wed Sep 01 23:43:45 2010 +0200
+++ b/src/Pure/Isar/attrib.ML	Thu Sep 02 00:48:07 2010 +0200
@@ -392,7 +392,8 @@
 (* theory setup *)
 
 val _ = Context.>> (Context.map_theory
- (register_config Unify.trace_bound_value #>
+ (register_config show_question_marks_value #>
+  register_config Unify.trace_bound_value #>
   register_config Unify.search_bound_value #>
   register_config Unify.trace_simp_value #>
   register_config Unify.trace_types_value #>
--- a/src/Pure/Isar/proof_context.ML	Wed Sep 01 23:43:45 2010 +0200
+++ b/src/Pure/Isar/proof_context.ML	Thu Sep 02 00:48:07 2010 +0200
@@ -413,8 +413,7 @@
     SOME (x, i) =>
       (case try Name.dest_skolem x of
         NONE => Pretty.mark Markup.var (Pretty.str s)
-      | SOME x' => Pretty.mark Markup.skolem
-          (Pretty.str (setmp_CRITICAL show_question_marks true Term.string_of_vname (x', i))))
+      | SOME x' => Pretty.mark Markup.skolem (Pretty.str (Term.string_of_vname (x', i))))
   | NONE => Pretty.mark Markup.var (Pretty.str s));
 
 fun plain_markup m _ s = Pretty.mark m (Pretty.str s);
--- a/src/Pure/ProofGeneral/preferences.ML	Wed Sep 01 23:43:45 2010 +0200
+++ b/src/Pure/ProofGeneral/preferences.ML	Thu Sep 02 00:48:07 2010 +0200
@@ -141,7 +141,7 @@
     "prems-limit"
     "Setting for maximum number of premises printed",
   print_depth_pref,
-  bool_pref show_question_marks
+  bool_pref show_question_marks_default
     "show-question-marks"
     "Show leading question mark of variable name"];
 
--- a/src/Pure/Syntax/printer.ML	Wed Sep 01 23:43:45 2010 +0200
+++ b/src/Pure/Syntax/printer.ML	Thu Sep 02 00:48:07 2010 +0200
@@ -12,6 +12,9 @@
   val show_no_free_types: bool Unsynchronized.ref
   val show_all_types: bool Unsynchronized.ref
   val show_structs: bool Unsynchronized.ref
+  val show_question_marks_default: bool Unsynchronized.ref
+  val show_question_marks_value: Config.value Config.T
+  val show_question_marks: bool Config.T
   val pp_show_brackets: Pretty.pp -> Pretty.pp
 end;
 
@@ -52,6 +55,11 @@
 val show_all_types = Unsynchronized.ref false;
 val show_structs = Unsynchronized.ref false;
 
+val show_question_marks_default = Unsynchronized.ref true;
+val show_question_marks_value =
+  Config.declare false "show_question_marks" (fn _ => Config.Bool (! show_question_marks_default));
+val show_question_marks = Config.bool show_question_marks_value;
+
 fun pp_show_brackets pp = Pretty.pp (setmp_CRITICAL show_brackets true (Pretty.term pp),
   Pretty.typ pp, Pretty.sort pp, Pretty.classrel pp, Pretty.arity pp);
 
@@ -72,15 +80,18 @@
 
 (* simple_ast_of *)
 
-fun simple_ast_of (Const (c, _)) = Ast.Constant c
-  | simple_ast_of (Free (x, _)) = Ast.Variable x
-  | simple_ast_of (Var (xi, _)) = Ast.Variable (Term.string_of_vname xi)
-  | simple_ast_of (t as _ $ _) =
-      let val (f, args) = strip_comb t in
-        Ast.mk_appl (simple_ast_of f) (map simple_ast_of args)
-      end
-  | simple_ast_of (Bound i) = Ast.Variable ("B." ^ string_of_int i)
-  | simple_ast_of (Abs _) = raise Fail "simple_ast_of: Abs";
+fun simple_ast_of ctxt =
+  let
+    val tune_var = if Config.get ctxt show_question_marks then I else unprefix "?";
+    fun ast_of (Const (c, _)) = Ast.Constant c
+      | ast_of (Free (x, _)) = Ast.Variable x
+      | ast_of (Var (xi, _)) = Ast.Variable (tune_var (Term.string_of_vname xi))
+      | ast_of (t as _ $ _) =
+          let val (f, args) = strip_comb t
+          in Ast.mk_appl (ast_of f) (map ast_of args) end
+      | ast_of (Bound i) = Ast.Variable ("B." ^ string_of_int i)
+      | ast_of (Abs _) = raise Fail "simple_ast_of: Abs";
+  in ast_of end;
 
 
 
@@ -88,14 +99,14 @@
 
 fun ast_of_termT ctxt trf tm =
   let
-    fun ast_of (t as Const ("_tfree", _) $ Free _) = simple_ast_of t
-      | ast_of (t as Const ("_tvar", _) $ Var _) = simple_ast_of t
+    fun ast_of (t as Const ("_tfree", _) $ Free _) = simple_ast_of ctxt t
+      | ast_of (t as Const ("_tvar", _) $ Var _) = simple_ast_of ctxt t
       | ast_of (Const (a, _)) = trans a []
       | ast_of (t as _ $ _) =
           (case strip_comb t of
             (Const (a, _), args) => trans a args
           | (f, args) => Ast.Appl (map ast_of (f :: args)))
-      | ast_of t = simple_ast_of t
+      | ast_of t = simple_ast_of ctxt t
     and trans a args =
       ast_of (apply_trans ctxt (apply_typed false dummyT (trf a)) args)
         handle Match => Ast.mk_appl (Ast.Constant a) (map ast_of args);
@@ -168,7 +179,7 @@
           if show_all_types
           then Ast.mk_appl (constrain const T) (map ast_of ts)
           else trans c T ts
-      | (t, ts) => Ast.mk_appl (simple_ast_of t) (map ast_of ts))
+      | (t, ts) => Ast.mk_appl (simple_ast_of ctxt t) (map ast_of ts))
 
     and trans a T args =
       ast_of (apply_trans ctxt (apply_typed show_sorts T (trf a)) args)
@@ -176,9 +187,9 @@
 
     and constrain t T =
       if show_types andalso T <> dummyT then
-        Ast.Appl [Ast.Constant Syn_Ext.constrainC, simple_ast_of t,
+        Ast.Appl [Ast.Constant Syn_Ext.constrainC, simple_ast_of ctxt t,
           ast_of_termT ctxt trf (Type_Ext.term_of_typ show_sorts T)]
-      else simple_ast_of t;
+      else simple_ast_of ctxt t;
   in
     tm
     |> Syn_Trans.prop_tr'
--- a/src/Pure/Thy/thy_output.ML	Wed Sep 01 23:43:45 2010 +0200
+++ b/src/Pure/Thy/thy_output.ML	Thu Sep 02 00:48:07 2010 +0200
@@ -447,7 +447,7 @@
 val _ = add_option "show_types" (add_wrapper o setmp_CRITICAL Syntax.show_types o boolean);
 val _ = add_option "show_sorts" (add_wrapper o setmp_CRITICAL Syntax.show_sorts o boolean);
 val _ = add_option "show_structs" (add_wrapper o setmp_CRITICAL show_structs o boolean);
-val _ = add_option "show_question_marks" (add_wrapper o setmp_CRITICAL show_question_marks o boolean);
+val _ = add_option "show_question_marks" (Config.put show_question_marks o boolean);
 val _ = add_option "long_names" (add_wrapper o setmp_CRITICAL Name_Space.long_names o boolean);
 val _ = add_option "short_names" (add_wrapper o setmp_CRITICAL Name_Space.short_names o boolean);
 val _ = add_option "unique_names" (add_wrapper o setmp_CRITICAL Name_Space.unique_names o boolean);
--- a/src/Pure/term.ML	Wed Sep 01 23:43:45 2010 +0200
+++ b/src/Pure/term.ML	Thu Sep 02 00:48:07 2010 +0200
@@ -114,7 +114,6 @@
   val exists_type: (typ -> bool) -> term -> bool
   val exists_subterm: (term -> bool) -> term -> bool
   val exists_Const: (string * typ -> bool) -> term -> bool
-  val show_question_marks: bool Unsynchronized.ref
 end;
 
 signature TERM =
@@ -983,11 +982,8 @@
 
 (* display variables *)
 
-val show_question_marks = Unsynchronized.ref true;
-
 fun string_of_vname (x, i) =
   let
-    val question_mark = if ! show_question_marks then "?" else "";
     val idx = string_of_int i;
     val dot =
       (case rev (Symbol.explode x) of
@@ -996,9 +992,9 @@
       | c :: _ => Symbol.is_digit c
       | _ => true);
   in
-    if dot then question_mark ^ x ^ "." ^ idx
-    else if i <> 0 then question_mark ^ x ^ idx
-    else question_mark ^ x
+    if dot then "?" ^ x ^ "." ^ idx
+    else if i <> 0 then "?" ^ x ^ idx
+    else "?" ^ x
   end;
 
 fun string_of_vname' (x, ~1) = x
--- a/src/Tools/WWW_Find/find_theorems.ML	Wed Sep 01 23:43:45 2010 +0200
+++ b/src/Tools/WWW_Find/find_theorems.ML	Thu Sep 02 00:48:07 2010 +0200
@@ -143,9 +143,9 @@
 
 fun html_thm ctxt (n, (thmref, thm)) =
   let
-    val string_of_thm =
+    val output_thm =
       Output.output o Pretty.string_of_margin 100 o
-        setmp_CRITICAL show_question_marks false (Display.pretty_thm ctxt);
+        Display.pretty_thm (Config.put show_question_marks false ctxt);
   in
     tag' "tr" (class ("row" ^ Int.toString (n mod 2)))
       [
@@ -153,7 +153,7 @@
           [span' (sorry_class thm)
              [raw_text (Facts.string_of_ref thmref)]
           ],
-        tag' "td" (class "thm") [pre noid (string_of_thm thm)]
+        tag' "td" (class "thm") [pre noid (output_thm thm)]
       ]
   end;
 
@@ -236,7 +236,7 @@
   end;
 in
 
-val () = show_question_marks := false;
+val () = show_question_marks_default := false;
 val () = ScgiServer.register (find_theorems_url, SOME Mime.html, find_theorems);
 
 end;