diff options
| author | aspiwack | 2011-05-13 17:57:27 +0000 |
|---|---|---|
| committer | aspiwack | 2011-05-13 17:57:27 +0000 |
| commit | 1b906116b43f5975fef7bb6f4dfb9589cfe3d6ee (patch) | |
| tree | b208a30b47adeff36f83b248498f19e06038c0e8 /proofs | |
| parent | 7cde682014e0dd179ae3bed029a07c8bf0c71157 (diff) | |
New option [Set Bullet Behavior] allows to select the behaviour of bullets.
- Two predefined behaviours : "None" where bullet have no effect and
"Strict Subproofs" (default) which acts as previously.
- More behaviours can be registered by plugins via
[Proof_global.Bullet.register_behavior].
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@14118 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'proofs')
| -rw-r--r-- | proofs/proof_global.ml | 105 | ||||
| -rw-r--r-- | proofs/proof_global.mli | 42 |
2 files changed, 141 insertions, 6 deletions
diff --git a/proofs/proof_global.ml b/proofs/proof_global.ml index bcd9d6e0d3..f930486673 100644 --- a/proofs/proof_global.ml +++ b/proofs/proof_global.ml @@ -8,9 +8,9 @@ (***********************************************************************) (* *) -(* This module defines the global proof environment *) -(* In particular it keeps tracks of whether or not there is *) -(* a proof which is currently being edited. *) +(* This module defines proof facilities relevant to the *) +(* toplevel. In particular it defines the global proof *) +(* environment. *) (* *) (***********************************************************************) @@ -296,6 +296,105 @@ let maximal_unfocus k p = () end + +(**********************************************************) +(* *) +(* Bullets *) +(* *) +(**********************************************************) + +module Bullet = struct + + open Store.Field + + + type t = + | Dash + | Star + | Plus + + type behavior = { + name : string; + put : Proof.proof -> t -> unit + } + + let behaviors = Hashtbl.create 4 + let register_behavior b = Hashtbl.add behaviors b.name b + + (*** initial modes ***) + let none = { + name = "None"; + put = fun _ _ -> () + } + let _ = register_behavior none + + module Strict = struct + (* spiwack: we need only one focus kind as we keep a stack of (distinct!) bullets *) + let bullet_kind = Proof.new_focus_kind () + let bullet_cond = Proof.done_cond bullet_kind + let (get_bullets,set_bullets) = + let bullets = Store.field () in + begin fun pr -> Option.default [] (bullets.get (Proof.get_proof_info pr)) end , + begin fun bs pr -> Proof.set_proof_info (bullets.set bs (Proof.get_proof_info pr)) pr end + + let has_bullet bul pr = + let rec has_bullet = function + | b'::_ when bul=b' -> true + | _::l -> has_bullet l + | [] -> false + in + has_bullet (get_bullets pr) + + (* precondition: the stack is not empty *) + let pop pr = + match get_bullets pr with + | b::stk -> + Proof.unfocus bullet_kind pr ; + set_bullets stk pr ; + b + | [] -> Util.anomaly "Tried to pop bullet from an empty stack" + + let push b pr = + Proof.focus bullet_cond () 1 pr ; + set_bullets (b::get_bullets pr) pr + + let put p bul = + if has_bullet bul p then + begin + while bul <> pop p do () done; + push bul p + end + else + push bul p + + let strict = { + name = "Strict Subproofs"; + put = put + } + let _ = register_behavior strict + end + + (* Current bullet behavior, controled by the option *) + let current_behavior = ref Strict.strict + + let _ = + Goptions.declare_string_option {Goptions. + optsync = true; + optname = "bullet behavior"; + optkey = ["Bullet";"Behavior"]; + optread = begin fun () -> + (!current_behavior).name + end; + optwrite = begin fun n -> + current_behavior := Hashtbl.find behaviors n + end + } + + let put p b = + (!current_behavior).put p b +end + + module V82 = struct let get_current_initial_conclusions () = let p = give_me_the_proof () in diff --git a/proofs/proof_global.mli b/proofs/proof_global.mli index e32ec85ad9..f9dbe3438a 100644 --- a/proofs/proof_global.mli +++ b/proofs/proof_global.mli @@ -6,9 +6,9 @@ (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) -(** This module defines the global proof environment - - Especially it keeps tracks of whether or not there is a proof which is currently being edited. *) +(** This module defines proof facilities relevant to the + toplevel. In particular it defines the global proof + environment. *) (** Type of proof modes : - A name @@ -95,6 +95,42 @@ val with_end_tac : unit Proofview.tactic -> unit Proofview.tactic focused goal or that the last focus isn't of kind [k]. *) val maximal_unfocus : 'a Proof.focus_kind -> Proof.proof -> unit +(**********************************************************) +(* *) +(* Bullets *) +(* *) +(**********************************************************) + +module Bullet : sig + type t = + | Dash + | Star + | Plus + + (** A [behavior] is the data of a put function which + is called when a bullet prefixes a tactic, together + with a name to identify it. *) + type behavior = { + name : string; + put : Proof.proof -> t -> unit + } + + (** A registered behavior can then be accessed in Coq + through the command [Set Bullet Behavior "name"]. + + Two modes are registered originally: + * "Strict Subproofs": + - If this bullet follows another one of its kind, defocuses then focuses + (which fails if the focused subproof is not complete). + - If it is the first bullet of its kind, then focuses a new subproof. + * "None": bullets don't do anything *) + val register_behavior : behavior -> unit + + (** Handles focusing/defocusing with bullets: + *) + val put : Proof.proof -> t -> unit +end + module V82 : sig val get_current_initial_conclusions : unit -> Names.identifier *(Term.types list * Decl_kinds.goal_kind * Tacexpr.declaration_hook) end |
