author | wenzelm |
Mon, 24 Jan 2022 21:29:37 +0100 | |
changeset 74995 | 68ffcf5cc94b |
parent 73559 | 22b5ecb53dd9 |
child 76403 | fb9c567a67cd |
permissions | -rw-r--r-- |
56864 | 1 |
(* Title: Pure/Tools/print_operation.ML |
2 |
Author: Makarius |
|
3 |
||
4 |
Print operations as asynchronous query. |
|
5 |
*) |
|
6 |
||
7 |
||
8 |
signature PRINT_OPERATION = |
|
9 |
sig |
|
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57415
diff
changeset
|
10 |
val register: string -> string -> (Toplevel.state -> Pretty.T list) -> unit |
56864 | 11 |
end; |
12 |
||
13 |
structure Print_Operation: PRINT_OPERATION = |
|
14 |
struct |
|
15 |
||
16 |
(* maintain print operations *) |
|
17 |
||
18 |
local |
|
19 |
||
20 |
val print_operations = |
|
21 |
Synchronized.var "print_operations" |
|
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57415
diff
changeset
|
22 |
([]: (string * (string * (Toplevel.state -> Pretty.T list))) list); |
56864 | 23 |
|
24 |
fun report () = |
|
25 |
Output.try_protocol_message Markup.print_operations |
|
73559 | 26 |
[Synchronized.value print_operations |
70991
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents:
64677
diff
changeset
|
27 |
|> map (fn (x, (y, _)) => (x, y)) |> rev |
73559 | 28 |
|> let open XML.Encode in list (pair string string) end]; |
56864 | 29 |
|
73225
3ab0cedaccad
clarified modules: allow early definition of protocol commands;
wenzelm
parents:
72156
diff
changeset
|
30 |
val _ = Protocol_Command.define "print_operations" (fn [] => report ()); |
56864 | 31 |
|
32 |
in |
|
33 |
||
34 |
fun register name description pr = |
|
35 |
(Synchronized.change print_operations (fn tab => |
|
56867 | 36 |
(if not (AList.defined (op =) tab name) then () |
56864 | 37 |
else warning ("Redefining print operation: " ^ quote name); |
56867 | 38 |
AList.update (op =) (name, (description, pr)) tab)); |
56864 | 39 |
report ()); |
40 |
||
41 |
val _ = |
|
60610
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
57605
diff
changeset
|
42 |
Query_Operation.register {name = "print_operation", pri = Task_Queue.urgent_pri} |
61223 | 43 |
(fn {state, args, writeln_result, ...} => |
60610
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
57605
diff
changeset
|
44 |
let |
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
57605
diff
changeset
|
45 |
val _ = Toplevel.context_of state handle Toplevel.UNDEF => error "Unknown context"; |
64677
8dc24130e8fe
more uniform treatment of "bad" like other messages (with serial number);
wenzelm
parents:
61223
diff
changeset
|
46 |
fun err s = Pretty.mark_str (Markup.bad (), s); |
60610
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
57605
diff
changeset
|
47 |
fun print name = |
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
57605
diff
changeset
|
48 |
(case AList.lookup (op =) (Synchronized.value print_operations) name of |
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
57605
diff
changeset
|
49 |
SOME (_, pr) => (pr state handle Toplevel.UNDEF => [err "Unknown context"]) |
f52b4b0c10c4
improved scheduling for urgent tasks, using farm of replacement threads (may lead to factor 2 overloading, but CPUs are usually hyperthreaded);
wenzelm
parents:
57605
diff
changeset
|
50 |
| NONE => [err ("Unknown print operation: " ^ quote name)]); |
61223 | 51 |
in writeln_result (Pretty.string_of (Pretty.chunks (maps print args))) end); |
56864 | 52 |
|
53 |
end; |
|
54 |
||
55 |
||
56 |
(* common print operations *) |
|
57 |
||
58 |
val _ = |
|
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57415
diff
changeset
|
59 |
register "context" "context of local theory target" Toplevel.pretty_context; |
56867 | 60 |
|
61 |
val _ = |
|
57605 | 62 |
register "cases" "cases of proof context" |
63 |
(Proof_Context.pretty_cases o Toplevel.context_of); |
|
56867 | 64 |
|
65 |
val _ = |
|
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56867
diff
changeset
|
66 |
register "terms" "term bindings of proof context" |
57604
30885e25c6de
support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents:
57415
diff
changeset
|
67 |
(Proof_Context.pretty_term_bindings o Toplevel.context_of); |
56867 | 68 |
|
69 |
val _ = |
|
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56867
diff
changeset
|
70 |
register "theorems" "theorems of local theory or proof context" |
57605 | 71 |
(Isar_Cmd.pretty_theorems false); |
56864 | 72 |
|
73 |
end; |