src/Pure/context_position.ML
author wenzelm
Thu, 18 Jul 2013 21:57:27 +0200
changeset 52700 d63f80f93025
parent 52699 abed4121c17e
child 55672 5e25cc741ab9
permissions -rw-r--r--
provide global operations as well;
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
52700
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    10
  val is_visible_global: theory -> bool
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    11
  val if_visible: Proof.context -> ('a -> unit) -> 'a -> unit
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    12
  val if_visible_global: theory -> ('a -> unit) -> 'a -> unit
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    13
  val set_visible: bool -> Proof.context -> Proof.context
52700
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    14
  val set_visible_global: bool -> theory -> theory
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    15
  val restore_visible: Proof.context -> Proof.context -> Proof.context
52700
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    16
  val restore_visible_global: theory -> theory -> theory
47005
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    17
  val report_generic: Context.generic -> Position.T -> Markup.T -> unit
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    18
  val reported_text: Proof.context -> Position.T -> Markup.T -> string -> string
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    19
  val report_text: Proof.context -> Position.T -> Markup.T -> string -> unit
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    20
  val report: Proof.context -> Position.T -> Markup.T -> unit
48767
7f0c469cc796 reports with body text, not just markup;
wenzelm
parents: 47813
diff changeset
    21
  val reports_text: Proof.context -> Position.report_text list -> unit
44736
c2a3f1c84179 bulk reports for improved message throughput;
wenzelm
parents: 41470
diff changeset
    22
  val reports: Proof.context -> Position.report list -> unit
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    23
end;
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    24
33383
12d79ece3f7e modernized structure Context_Position;
wenzelm
parents: 29606
diff changeset
    25
structure Context_Position: CONTEXT_POSITION =
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    26
struct
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    27
47813
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    28
structure Data = Generic_Data
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    29
(
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    30
  type T = bool option;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    31
  val empty: T = NONE;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    32
  val extend = I;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    33
  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
    34
);
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    35
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    36
val is_visible_generic = the_default true o Data.get;
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    37
val is_visible = is_visible_generic o Context.Proof;
52700
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    38
val is_visible_global = is_visible_generic o Context.Theory;
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    39
38831
4933a3dfd745 more careful treatment of context visibility flag wrt. spurious warnings;
wenzelm
parents: 38481
diff changeset
    40
fun if_visible ctxt f x = if is_visible ctxt then f x else ();
52700
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    41
fun if_visible_global thy f x = if is_visible_global thy then f x else ();
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    42
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    43
val set_visible = Context.proof_map o Data.put o SOME;
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    44
val set_visible_global = Context.theory_map o Data.put o SOME;
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    45
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    46
val restore_visible = set_visible o is_visible;
d63f80f93025 provide global operations as well;
wenzelm
parents: 52699
diff changeset
    47
val restore_visible_global = set_visible_global o is_visible_global;
38831
4933a3dfd745 more careful treatment of context visibility flag wrt. spurious warnings;
wenzelm
parents: 38481
diff changeset
    48
47005
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    49
fun report_generic context pos markup =
47813
18de60b8c906 made Context_Position independent from Config;
wenzelm
parents: 47005
diff changeset
    50
  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
    51
    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
    52
  else ();
421760a1efe7 maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents: 46874
diff changeset
    53
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    54
fun reported_text ctxt pos markup txt =
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    55
  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
    56
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    57
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
    58
fun report ctxt pos markup = report_text ctxt pos markup "";
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    59
48767
7f0c469cc796 reports with body text, not just markup;
wenzelm
parents: 47813
diff changeset
    60
fun reports_text ctxt reps = if is_visible ctxt then Position.reports_text reps else ();
44736
c2a3f1c84179 bulk reports for improved message throughput;
wenzelm
parents: 41470
diff changeset
    61
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
    62
28405
000dee6d5d80 Context position visibility.
wenzelm
parents:
diff changeset
    63
end;