src/Pure/context_position.ML
author wenzelm
Mon Mar 10 15:04:01 2014 +0100 (2014-03-10)
changeset 56026 893fe12639bc
parent 55923 4bdae9403baf
child 56294 85911b8a6868
permissions -rw-r--r--
tuned signature -- prefer Name_Space.get with its builtin error;
wenzelm@28405
     1
(*  Title:      Pure/context_position.ML
wenzelm@28405
     2
    Author:     Makarius
wenzelm@28405
     3
wenzelm@28409
     4
Context position visibility flag.
wenzelm@28405
     5
*)
wenzelm@28405
     6
wenzelm@28405
     7
signature CONTEXT_POSITION =
wenzelm@28405
     8
sig
wenzelm@55672
     9
  val is_visible_generic: Context.generic -> bool
wenzelm@28405
    10
  val is_visible: Proof.context -> bool
wenzelm@52700
    11
  val is_visible_global: theory -> bool
wenzelm@52700
    12
  val if_visible: Proof.context -> ('a -> unit) -> 'a -> unit
wenzelm@52700
    13
  val if_visible_global: theory -> ('a -> unit) -> 'a -> unit
wenzelm@28405
    14
  val set_visible: bool -> Proof.context -> Proof.context
wenzelm@52700
    15
  val set_visible_global: bool -> theory -> theory
wenzelm@28405
    16
  val restore_visible: Proof.context -> Proof.context -> Proof.context
wenzelm@52700
    17
  val restore_visible_global: theory -> theory -> theory
wenzelm@55923
    18
  val is_reported_generic: Context.generic -> Position.T -> bool
wenzelm@55923
    19
  val is_reported: Proof.context -> Position.T -> bool
wenzelm@47005
    20
  val report_generic: Context.generic -> Position.T -> Markup.T -> unit
wenzelm@39507
    21
  val reported_text: Proof.context -> Position.T -> Markup.T -> string -> string
wenzelm@39507
    22
  val report_text: Proof.context -> Position.T -> Markup.T -> string -> unit
wenzelm@39507
    23
  val report: Proof.context -> Position.T -> Markup.T -> unit
wenzelm@48767
    24
  val reports_text: Proof.context -> Position.report_text list -> unit
wenzelm@44736
    25
  val reports: Proof.context -> Position.report list -> unit
wenzelm@28405
    26
end;
wenzelm@28405
    27
wenzelm@33383
    28
structure Context_Position: CONTEXT_POSITION =
wenzelm@28405
    29
struct
wenzelm@28405
    30
wenzelm@47813
    31
structure Data = Generic_Data
wenzelm@47813
    32
(
wenzelm@47813
    33
  type T = bool option;
wenzelm@47813
    34
  val empty: T = NONE;
wenzelm@47813
    35
  val extend = I;
wenzelm@47813
    36
  fun merge (x, y): T = if is_some x then x else y;
wenzelm@47813
    37
);
wenzelm@47813
    38
wenzelm@47813
    39
val is_visible_generic = the_default true o Data.get;
wenzelm@47813
    40
val is_visible = is_visible_generic o Context.Proof;
wenzelm@52700
    41
val is_visible_global = is_visible_generic o Context.Theory;
wenzelm@28405
    42
wenzelm@38831
    43
fun if_visible ctxt f x = if is_visible ctxt then f x else ();
wenzelm@52700
    44
fun if_visible_global thy f x = if is_visible_global thy then f x else ();
wenzelm@52700
    45
wenzelm@52700
    46
val set_visible = Context.proof_map o Data.put o SOME;
wenzelm@52700
    47
val set_visible_global = Context.theory_map o Data.put o SOME;
wenzelm@52700
    48
wenzelm@52700
    49
val restore_visible = set_visible o is_visible;
wenzelm@52700
    50
val restore_visible_global = set_visible_global o is_visible_global;
wenzelm@38831
    51
wenzelm@55923
    52
fun is_reported_generic context pos = is_visible_generic context andalso Position.is_reported pos;
wenzelm@55923
    53
fun is_reported ctxt pos = is_visible ctxt andalso Position.is_reported pos;
wenzelm@55923
    54
wenzelm@47005
    55
fun report_generic context pos markup =
wenzelm@55923
    56
  if is_reported_generic context pos then
wenzelm@47005
    57
    Output.report (Position.reported_text pos markup "")
wenzelm@47005
    58
  else ();
wenzelm@47005
    59
wenzelm@39507
    60
fun reported_text ctxt pos markup txt =
wenzelm@55923
    61
  if is_reported ctxt pos then Position.reported_text pos markup txt else "";
wenzelm@38481
    62
wenzelm@39507
    63
fun report_text ctxt pos markup txt = Output.report (reported_text ctxt pos markup txt);
wenzelm@39507
    64
fun report ctxt pos markup = report_text ctxt pos markup "";
wenzelm@28405
    65
wenzelm@48767
    66
fun reports_text ctxt reps = if is_visible ctxt then Position.reports_text reps else ();
wenzelm@44736
    67
fun reports ctxt reps = if is_visible ctxt then Position.reports reps else ();
wenzelm@44736
    68
wenzelm@28405
    69
end;