1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(* $Id: edit.ml 10441 2008-01-15 16:37:46Z lmamane $ *)
15
mutable focus : 'a option;
16
mutable last_focused_stk : 'a list;
17
buf : ('a, 'b Bstack.t * 'c) Hashtbl.t }
21
last_focused_stk = [];
22
buf = Hashtbl.create 17 }
25
if not (Hashtbl.mem e.buf nd) then invalid_arg "Edit.focus";
26
begin match e.focus with
27
| Some foc when foc <> nd ->
28
e.last_focused_stk <- foc::(list_except foc e.last_focused_stk);
35
| None -> invalid_arg "Edit.unfocus"
38
e.last_focused_stk <- foc::(list_except foc e.last_focused_stk);
43
match e.last_focused_stk with
47
let restore_last_focus e =
48
match e.last_focused_stk with
61
let (bs,c) = Hashtbl.find e.buf d in
62
Some(d,Bstack.top bs,c)
66
| None -> invalid_arg "Edit.mutate"
68
let (bs,c) = Hashtbl.find e.buf d in
69
Bstack.app_push bs (f c)
73
| None -> invalid_arg "Edit.rev_mutate"
75
let (bs,c) = Hashtbl.find e.buf d in
76
Bstack.app_repl bs (f c)
80
| None -> invalid_arg "Edit.undo"
82
let (bs,_) = Hashtbl.find e.buf d in
83
if n >= Bstack.size bs then
84
errorlabstrm "Edit.undo" (str"Undo stack exhausted");
85
repeat n Bstack.pop bs
87
(* Return the depth of the focused proof of [e] stack, this is used to
88
put informations in coq prompt (in emacs mode). *)
91
| None -> invalid_arg "Edit.depth"
93
let (bs,_) = Hashtbl.find e.buf d in
96
(* Undo focused proof of [e] to reach depth [n] *)
97
let undo_todepth e n =
101
then errorlabstrm "Edit.undo_todepth" (str"No proof in progress")
102
else () (* if there is no proof in progress, then n must be zero *)
104
let (bs,_) = Hashtbl.find e.buf d in
105
let ucnt = Bstack.depth bs - n in
106
if ucnt >= Bstack.size bs then
107
errorlabstrm "Edit.undo_todepth" (str"Undo stack would be exhausted");
108
repeat ucnt Bstack.pop bs
110
let create e (d,b,c,usize) =
111
if Hashtbl.mem e.buf d then
112
errorlabstrm "Edit.create"
113
(str"Already editing something of that name");
114
let bs = Bstack.create usize b in
115
Hashtbl.add e.buf d (bs,c)
118
if not(Hashtbl.mem e.buf d) then
119
errorlabstrm "Edit.delete" (str"No such editor");
120
Hashtbl.remove e.buf d;
121
e.last_focused_stk <- (list_except d e.last_focused_stk);
123
| Some d' -> if d = d' then (e.focus <- None ; (restore_last_focus e))
128
Hashtbl.iter (fun x _ -> l := x :: !l) e.buf;
133
e.last_focused_stk <- [];