src/Pure/context_position.ML
author wenzelm
Sun Nov 11 20:31:46 2012 +0100 (2012-11-11)
changeset 50081 9b92ee8dec98
parent 48767 7f0c469cc796
child 52699 abed4121c17e
permissions -rw-r--r--
tuned;
     1 (*  Title:      Pure/context_position.ML
     2     Author:     Makarius
     3 
     4 Context position visibility flag.
     5 *)
     6 
     7 signature CONTEXT_POSITION =
     8 sig
     9   val is_visible: Proof.context -> bool
    10   val set_visible: bool -> Proof.context -> Proof.context
    11   val restore_visible: Proof.context -> Proof.context -> Proof.context
    12   val if_visible: Proof.context -> ('a -> unit) -> 'a -> unit
    13   val is_visible_proof: Context.generic -> bool
    14   val if_visible_proof: Context.generic -> ('a -> unit) -> 'a -> unit
    15   val report_generic: Context.generic -> Position.T -> Markup.T -> unit
    16   val reported_text: Proof.context -> Position.T -> Markup.T -> string -> string
    17   val report_text: Proof.context -> Position.T -> Markup.T -> string -> unit
    18   val report: Proof.context -> Position.T -> Markup.T -> unit
    19   val reports_text: Proof.context -> Position.report_text list -> unit
    20   val reports: Proof.context -> Position.report list -> unit
    21 end;
    22 
    23 structure Context_Position: CONTEXT_POSITION =
    24 struct
    25 
    26 structure Data = Generic_Data
    27 (
    28   type T = bool option;
    29   val empty: T = NONE;
    30   val extend = I;
    31   fun merge (x, y): T = if is_some x then x else y;
    32 );
    33 
    34 val is_visible_generic = the_default true o Data.get;
    35 val is_visible = is_visible_generic o Context.Proof;
    36 val set_visible = Context.proof_map o Data.put o SOME;
    37 val restore_visible = set_visible o is_visible;
    38 
    39 fun if_visible ctxt f x = if is_visible ctxt then f x else ();
    40 
    41 fun is_visible_proof (Context.Proof ctxt) = is_visible ctxt
    42   | is_visible_proof _ = false;
    43 
    44 fun if_visible_proof context f x = if is_visible_proof context then f x else ();
    45 
    46 fun report_generic context pos markup =
    47   if is_visible_generic context then
    48     Output.report (Position.reported_text pos markup "")
    49   else ();
    50 
    51 fun reported_text ctxt pos markup txt =
    52   if is_visible ctxt then Position.reported_text pos markup txt else "";
    53 
    54 fun report_text ctxt pos markup txt = Output.report (reported_text ctxt pos markup txt);
    55 fun report ctxt pos markup = report_text ctxt pos markup "";
    56 
    57 fun reports_text ctxt reps = if is_visible ctxt then Position.reports_text reps else ();
    58 fun reports ctxt reps = if is_visible ctxt then Position.reports reps else ();
    59 
    60 end;