src/Pure/context_position.ML
author wenzelm
Thu Aug 02 12:36:54 2012 +0200 (2012-08-02)
changeset 48646 91281e9472d8
parent 47813 18de60b8c906
child 48767 7f0c469cc796
permissions -rw-r--r--
more official command specifications, including source position;
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@28405
    10
  val set_visible: bool -> Proof.context -> Proof.context
wenzelm@28405
    11
  val restore_visible: Proof.context -> Proof.context -> Proof.context
wenzelm@38831
    12
  val if_visible: Proof.context -> ('a -> unit) -> 'a -> unit
wenzelm@46874
    13
  val is_visible_proof: Context.generic -> bool
wenzelm@41470
    14
  val if_visible_proof: Context.generic -> ('a -> unit) -> 'a -> unit
wenzelm@47005
    15
  val report_generic: Context.generic -> Position.T -> Markup.T -> unit
wenzelm@39507
    16
  val reported_text: Proof.context -> Position.T -> Markup.T -> string -> string
wenzelm@39507
    17
  val report_text: Proof.context -> Position.T -> Markup.T -> string -> unit
wenzelm@39507
    18
  val report: Proof.context -> Position.T -> Markup.T -> unit
wenzelm@44736
    19
  val reports: Proof.context -> Position.report list -> unit
wenzelm@28405
    20
end;
wenzelm@28405
    21
wenzelm@33383
    22
structure Context_Position: CONTEXT_POSITION =
wenzelm@28405
    23
struct
wenzelm@28405
    24
wenzelm@47813
    25
structure Data = Generic_Data
wenzelm@47813
    26
(
wenzelm@47813
    27
  type T = bool option;
wenzelm@47813
    28
  val empty: T = NONE;
wenzelm@47813
    29
  val extend = I;
wenzelm@47813
    30
  fun merge (x, y): T = if is_some x then x else y;
wenzelm@47813
    31
);
wenzelm@47813
    32
wenzelm@47813
    33
val is_visible_generic = the_default true o Data.get;
wenzelm@47813
    34
val is_visible = is_visible_generic o Context.Proof;
wenzelm@47813
    35
val set_visible = Context.proof_map o Data.put o SOME;
wenzelm@28405
    36
val restore_visible = set_visible o is_visible;
wenzelm@28405
    37
wenzelm@38831
    38
fun if_visible ctxt f x = if is_visible ctxt then f x else ();
wenzelm@38831
    39
wenzelm@46874
    40
fun is_visible_proof (Context.Proof ctxt) = is_visible ctxt
wenzelm@46874
    41
  | is_visible_proof _ = false;
wenzelm@46874
    42
wenzelm@46874
    43
fun if_visible_proof context f x = if is_visible_proof context then f x else ();
wenzelm@41470
    44
wenzelm@47005
    45
fun report_generic context pos markup =
wenzelm@47813
    46
  if is_visible_generic context then
wenzelm@47005
    47
    Output.report (Position.reported_text pos markup "")
wenzelm@47005
    48
  else ();
wenzelm@47005
    49
wenzelm@39507
    50
fun reported_text ctxt pos markup txt =
wenzelm@39507
    51
  if is_visible ctxt then Position.reported_text pos markup txt else "";
wenzelm@38481
    52
wenzelm@39507
    53
fun report_text ctxt pos markup txt = Output.report (reported_text ctxt pos markup txt);
wenzelm@39507
    54
fun report ctxt pos markup = report_text ctxt pos markup "";
wenzelm@28405
    55
wenzelm@44736
    56
fun reports ctxt reps = if is_visible ctxt then Position.reports reps else ();
wenzelm@44736
    57
wenzelm@28405
    58
end;