| author | wenzelm | 
| Thu, 24 Apr 2025 21:39:40 +0200 | |
| changeset 82582 | bcee022fbe30 | 
| parent 80869 | 87395be1a299 | 
| permissions | -rw-r--r-- | 
| 23827 | 1  | 
(* Title: Pure/General/print_mode.ML  | 
2  | 
Author: Makarius  | 
|
3  | 
||
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
4  | 
Generic print mode as thread-local value derived from global template;  | 
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
5  | 
provides implicit configuration for various output mechanisms.  | 
| 39124 | 6  | 
|
7  | 
The special print mode "input" is never enabled for output.  | 
|
| 23827 | 8  | 
*)  | 
9  | 
||
| 23934 | 10  | 
signature BASIC_PRINT_MODE =  | 
| 23827 | 11  | 
sig  | 
| 32738 | 12  | 
val print_mode: string list Unsynchronized.ref (*global template*)  | 
13  | 
val print_mode_value: unit -> string list (*thread-local value*)  | 
|
14  | 
val print_mode_active: string -> bool (*thread-local value*)  | 
|
| 23827 | 15  | 
end;  | 
16  | 
||
| 23934 | 17  | 
signature PRINT_MODE =  | 
18  | 
sig  | 
|
19  | 
include BASIC_PRINT_MODE  | 
|
| 
25118
 
158149a6e95b
added input/internal, which are never active in print_mode_value;
 
wenzelm 
parents: 
24634 
diff
changeset
 | 
20  | 
val input: string  | 
| 
80861
 
9de19e3a7231
dismantle print_mode operations for Markup/Pretty: hardwired check of "print_mode_active Print_Mode.PIDE";
 
wenzelm 
parents: 
62889 
diff
changeset
 | 
21  | 
val internal: string  | 
| 
61957
 
301833d9013a
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 
wenzelm 
parents: 
39124 
diff
changeset
 | 
22  | 
val ASCII: string  | 
| 
80861
 
9de19e3a7231
dismantle print_mode operations for Markup/Pretty: hardwired check of "print_mode_active Print_Mode.PIDE";
 
wenzelm 
parents: 
62889 
diff
changeset
 | 
23  | 
val PIDE: string  | 
| 80862 | 24  | 
val latex: string  | 
| 24634 | 25  | 
  val setmp: string list -> ('a -> 'b) -> 'a -> 'b
 | 
| 23934 | 26  | 
  val with_modes: string list -> ('a -> 'b) -> 'a -> 'b
 | 
| 62542 | 27  | 
val add_modes: string list -> unit  | 
| 80867 | 28  | 
val PIDE_enabled: unit -> bool  | 
| 23934 | 29  | 
end;  | 
30  | 
||
| 
37146
 
f652333bbf8e
renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
 
wenzelm 
parents: 
33223 
diff
changeset
 | 
31  | 
structure Print_Mode: PRINT_MODE =  | 
| 23827 | 32  | 
struct  | 
33  | 
||
| 
25118
 
158149a6e95b
added input/internal, which are never active in print_mode_value;
 
wenzelm 
parents: 
24634 
diff
changeset
 | 
34  | 
val input = "input";  | 
| 
80861
 
9de19e3a7231
dismantle print_mode operations for Markup/Pretty: hardwired check of "print_mode_active Print_Mode.PIDE";
 
wenzelm 
parents: 
62889 
diff
changeset
 | 
35  | 
val internal = "internal";  | 
| 
61957
 
301833d9013a
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 
wenzelm 
parents: 
39124 
diff
changeset
 | 
36  | 
val ASCII = "ASCII";  | 
| 
80861
 
9de19e3a7231
dismantle print_mode operations for Markup/Pretty: hardwired check of "print_mode_active Print_Mode.PIDE";
 
wenzelm 
parents: 
62889 
diff
changeset
 | 
37  | 
val PIDE = "PIDE";  | 
| 80862 | 38  | 
val latex = "latex";  | 
| 24613 | 39  | 
|
| 32738 | 40  | 
val print_mode = Unsynchronized.ref ([]: string list);  | 
| 62889 | 41  | 
val print_mode_var = Thread_Data.var () : string list Thread_Data.var;  | 
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
42  | 
|
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
43  | 
fun print_mode_value () =  | 
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
44  | 
let val modes =  | 
| 62889 | 45  | 
(case Thread_Data.get print_mode_var of  | 
46  | 
SOME modes => modes  | 
|
47  | 
| NONE => ! print_mode)  | 
|
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
48  | 
in subtract (op =) [input, internal] modes end;  | 
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
49  | 
|
| 
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
50  | 
fun print_mode_active mode = member (op =) (print_mode_value ()) mode;  | 
| 
25118
 
158149a6e95b
added input/internal, which are never active in print_mode_value;
 
wenzelm 
parents: 
24634 
diff
changeset
 | 
51  | 
|
| 62889 | 52  | 
fun setmp modes f x = Thread_Data.setmp print_mode_var (SOME modes) f x;  | 
| 23827 | 53  | 
|
| 
25734
 
b00b903ae8ae
separated into global template vs. thread-local value;
 
wenzelm 
parents: 
25118 
diff
changeset
 | 
54  | 
fun with_modes modes f x = setmp (modes @ print_mode_value ()) f x;  | 
| 23934 | 55  | 
|
| 62542 | 56  | 
fun add_modes modes = Unsynchronized.change print_mode (append modes);  | 
57  | 
||
| 
80869
 
87395be1a299
clarified print_mode (again, amending 9de19e3a7231): support e.g. 'thm ("") symmetric' for formatting in ML and without markup;
 
wenzelm 
parents: 
80867 
diff
changeset
 | 
58  | 
fun PIDE_enabled () =  | 
| 
 
87395be1a299
clarified print_mode (again, amending 9de19e3a7231): support e.g. 'thm ("") symmetric' for formatting in ML and without markup;
 
wenzelm 
parents: 
80867 
diff
changeset
 | 
59  | 
find_first (fn mode => mode = PIDE orelse mode = "") (print_mode_value ()) = SOME PIDE;  | 
| 80867 | 60  | 
|
| 23827 | 61  | 
end;  | 
62  | 
||
| 
37146
 
f652333bbf8e
renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
 
wenzelm 
parents: 
33223 
diff
changeset
 | 
63  | 
structure Basic_Print_Mode: BASIC_PRINT_MODE = Print_Mode;  | 
| 
 
f652333bbf8e
renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
 
wenzelm 
parents: 
33223 
diff
changeset
 | 
64  | 
open Basic_Print_Mode;  |