src/Pure/context_position.ML
author wenzelm
Sun, 22 Jul 2012 12:26:41 +0200
changeset 48423 0ccf143a2a69
parent 47813 18de60b8c906
child 48767 7f0c469cc796
permissions -rw-r--r--
maintain set of source digests, including relevant parts of session entry;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/context_position.ML
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     3
28409
a1feb819b0a2 renamed report to report_visible;
wenzelm
parents: 28405
diff changeset
     4
Context position visibility flag.
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     5
*)
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     6
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     7
signature CONTEXT_POSITION =
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     8
sig
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
     9
  val is_visible: Proof.context -> bool
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    10
  val set_visible: bool -> Proof.context -> Proof.context
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    11
  val restore_visible: Proof.context -> Proof.context -> Proof.context
38831
4933a3dfd745 more careful treatment of context visibility flag wrt. spurious warnings;
wenzelm
parents: 38481
diff changeset
    12
  val if_visible: Proof.context -> ('a -> unit) -> 'a -> unit
46874
993c413746f4 tuned signature;
wenzelm
parents: 44736
diff changeset
    13
  val is_visible_proof: Context.generic -> bool
41470
890b25753bf7 added Context_Position.is_visible_proof, which treats a global theory as invisible (unlike the default);
wenzelm
parents: 39508
diff changeset
    14
  val if_visible_proof: Context.generic -> ('a -> unit) -> 'a -> unit
47005
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    15
  val report_generic: Context.generic -> Position.T -> Markup.T -> unit
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    16
  val reported_text: Proof.context -> Position.T -> Markup.T -> string -> string
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    17
  val report_text: Proof.context -> Position.T -> Markup.T -> string -> unit
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    18
  val report: Proof.context -> Position.T -> Markup.T -> unit
44736
c2a3f1c84179 bulk reports for improved message throughput;
wenzelm
parents: 41470
diff changeset
    19
  val reports: Proof.context -> Position.report list -> unit
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    20
end;
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    21
33383
12d79ece3f7e modernized structure Context_Position;
wenzelm
parents: 29606
diff changeset
    22
structure Context_Position: CONTEXT_POSITION =
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    23
struct
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    24
47813
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    25
structure Data = Generic_Data
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    26
(
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    27
  type T = bool option;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    28
  val empty: T = NONE;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    29
  val extend = I;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    30
  fun merge (x, y): T = if is_some x then x else y;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    31
);
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    32
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    33
val is_visible_generic = the_default true o Data.get;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    34
val is_visible = is_visible_generic o Context.Proof;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    35
val set_visible = Context.proof_map o Data.put o SOME;
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    36
val restore_visible = set_visible o is_visible;
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    37
38831
4933a3dfd745 more careful treatment of context visibility flag wrt. spurious warnings;
wenzelm
parents: 38481
diff changeset
    38
fun if_visible ctxt f x = if is_visible ctxt then f x else ();
4933a3dfd745 more careful treatment of context visibility flag wrt. spurious warnings;
wenzelm
parents: 38481
diff changeset
    39
46874
993c413746f4 tuned signature;
wenzelm
parents: 44736
diff changeset
    40
fun is_visible_proof (Context.Proof ctxt) = is_visible ctxt
993c413746f4 tuned signature;
wenzelm
parents: 44736
diff changeset
    41
  | is_visible_proof _ = false;
993c413746f4 tuned signature;
wenzelm
parents: 44736
diff changeset
    42
993c413746f4 tuned signature;
wenzelm
parents: 44736
diff changeset
    43
fun if_visible_proof context f x = if is_visible_proof context then f x else ();
41470
890b25753bf7 added Context_Position.is_visible_proof, which treats a global theory as invisible (unlike the default);
wenzelm
parents: 39508
diff changeset
    44
47005
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    45
fun report_generic context pos markup =
47813
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    46
  if is_visible_generic context then
47005
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    47
    Output.report (Position.reported_text pos markup "")
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    48
  else ();
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    49
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    50
fun reported_text ctxt pos markup txt =
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    51
  if is_visible ctxt then Position.reported_text pos markup txt else "";
38481
81ec258c4cd3 Output_Position.report_text -- markup with potential "arguments";
wenzelm
parents: 38237
diff changeset
    52
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    53
fun report_text ctxt pos markup txt = Output.report (reported_text ctxt pos markup txt);
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    54
fun report ctxt pos markup = report_text ctxt pos markup "";
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    55
44736
c2a3f1c84179 bulk reports for improved message throughput;
wenzelm
parents: 41470
diff changeset
    56
fun reports ctxt reps = if is_visible ctxt then Position.reports reps else ();
c2a3f1c84179 bulk reports for improved message throughput;
wenzelm
parents: 41470
diff changeset
    57
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    58
end;