src/Pure/context_position.ML
author wenzelm
Thu Jul 18 21:57:27 2013 +0200 (2013-07-18)
changeset 52700 d63f80f93025
parent 52699 abed4121c17e
child 55672 5e25cc741ab9
permissions -rw-r--r--
provide global operations as well;
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@28405
     9
  val is_visible: Proof.context -> bool
wenzelm@52700
    10
  val is_visible_global: theory -> bool
wenzelm@52700
    11
  val if_visible: Proof.context -> ('a -> unit) -> 'a -> unit
wenzelm@52700
    12
  val if_visible_global: theory -> ('a -> unit) -> 'a -> unit
wenzelm@28405
    13
  val set_visible: bool -> Proof.context -> Proof.context
wenzelm@52700
    14
  val set_visible_global: bool -> theory -> theory
wenzelm@28405
    15
  val restore_visible: Proof.context -> Proof.context -> Proof.context
wenzelm@52700
    16
  val restore_visible_global: theory -> theory -> theory
wenzelm@47005
    17
  val report_generic: Context.generic -> Position.T -> Markup.T -> unit
wenzelm@39507
    18
  val reported_text: Proof.context -> Position.T -> Markup.T -> string -> string
wenzelm@39507
    19
  val report_text: Proof.context -> Position.T -> Markup.T -> string -> unit
wenzelm@39507
    20
  val report: Proof.context -> Position.T -> Markup.T -> unit
wenzelm@48767
    21
  val reports_text: Proof.context -> Position.report_text list -> unit
wenzelm@44736
    22
  val reports: Proof.context -> Position.report list -> unit
wenzelm@28405
    23
end;
wenzelm@28405
    24
wenzelm@33383
    25
structure Context_Position: CONTEXT_POSITION =
wenzelm@28405
    26
struct
wenzelm@28405
    27
wenzelm@47813
    28
structure Data = Generic_Data
wenzelm@47813
    29
(
wenzelm@47813
    30
  type T = bool option;
wenzelm@47813
    31
  val empty: T = NONE;
wenzelm@47813
    32
  val extend = I;
wenzelm@47813
    33
  fun merge (x, y): T = if is_some x then x else y;
wenzelm@47813
    34
);
wenzelm@47813
    35
wenzelm@47813
    36
val is_visible_generic = the_default true o Data.get;
wenzelm@47813
    37
val is_visible = is_visible_generic o Context.Proof;
wenzelm@52700
    38
val is_visible_global = is_visible_generic o Context.Theory;
wenzelm@28405
    39
wenzelm@38831
    40
fun if_visible ctxt f x = if is_visible ctxt then f x else ();
wenzelm@52700
    41
fun if_visible_global thy f x = if is_visible_global thy then f x else ();
wenzelm@52700
    42
wenzelm@52700
    43
val set_visible = Context.proof_map o Data.put o SOME;
wenzelm@52700
    44
val set_visible_global = Context.theory_map o Data.put o SOME;
wenzelm@52700
    45
wenzelm@52700
    46
val restore_visible = set_visible o is_visible;
wenzelm@52700
    47
val restore_visible_global = set_visible_global o is_visible_global;
wenzelm@38831
    48
wenzelm@47005
    49
fun report_generic context pos markup =
wenzelm@47813
    50
  if is_visible_generic context then
wenzelm@47005
    51
    Output.report (Position.reported_text pos markup "")
wenzelm@47005
    52
  else ();
wenzelm@47005
    53
wenzelm@39507
    54
fun reported_text ctxt pos markup txt =
wenzelm@39507
    55
  if is_visible ctxt then Position.reported_text pos markup txt else "";
wenzelm@38481
    56
wenzelm@39507
    57
fun report_text ctxt pos markup txt = Output.report (reported_text ctxt pos markup txt);
wenzelm@39507
    58
fun report ctxt pos markup = report_text ctxt pos markup "";
wenzelm@28405
    59
wenzelm@48767
    60
fun reports_text ctxt reps = if is_visible ctxt then Position.reports_text reps else ();
wenzelm@44736
    61
fun reports ctxt reps = if is_visible ctxt then Position.reports reps else ();
wenzelm@44736
    62
wenzelm@28405
    63
end;