1 ;;; calc-undo.el --- undo functions for Calc
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; Maintainer: Jay Belanger <belanger@truman.edu>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY. No author or distributor
13 ;; accepts responsibility to anyone for the consequences of using it
14 ;; or for whether it serves any particular purpose or works at all,
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public
16 ;; License for full details.
18 ;; Everyone is granted permission to copy, modify and redistribute
19 ;; GNU Emacs, but only under the conditions described in the
20 ;; GNU Emacs General Public License. A copy of this license is
21 ;; supposed to have been given to you along with GNU Emacs so you
22 ;; can know your rights and responsibilities. It should be in a
23 ;; file named COPYING. Among other things, the copyright notice
24 ;; and this notice must be preserved on all copies.
30 ;; This file is autoloaded from calc-ext.el.
39 (when calc-executing-macro
40 (error "Use C-x e, not X, to run a keyboard macro that uses Undo"))
46 (when (null (nthcdr (1- n
) calc-undo-list
))
47 (error "No further undo information available"))
50 (nthcdr n calc-undo-list
)
51 (let ((saved-stack-top calc-stack-top
))
52 (let ((calc-stack-top 0))
53 (calc-handle-undos calc-undo-list n
))
54 (setq calc-stack-top saved-stack-top
))))
57 (defun calc-handle-undos (cl n
)
59 (let ((old-redo calc-redo-list
))
60 (setq calc-undo-list nil
)
61 (calc-handle-undo (car cl
))
62 (setq calc-redo-list
(append calc-undo-list old-redo
)))
63 (calc-handle-undos (cdr cl
) (1- n
))))
65 (defun calc-handle-undo (list)
67 (let ((action (car list
)))
69 ((eq (car action
) 'push
)
70 (calc-pop-stack 1 (nth 1 action
) t
))
71 ((eq (car action
) 'pop
)
72 (calc-push-list (nth 2 action
) (nth 1 action
)))
73 ((eq (car action
) 'set
)
74 (calc-record-undo (list 'set
(nth 1 action
)
75 (symbol-value (nth 1 action
))))
76 (set (nth 1 action
) (nth 2 action
)))
77 ((eq (car action
) 'store
)
78 (let ((v (intern (nth 1 action
))))
79 (calc-record-undo (list 'store
(nth 1 action
)
80 (and (boundp v
) (symbol-value v
))))
81 (if (y-or-n-p (format "Un-store variable %s? "
82 (calc-var-name (nth 1 action
))))
85 (set v
(nth 2 action
))
87 (calc-refresh-evaltos v
)))))
88 ((eq (car action
) 'eval
)
89 (calc-record-undo (append (list 'eval
(nth 2 action
) (nth 1 action
))
90 (cdr (cdr (cdr action
)))))
91 (apply (nth 1 action
) (cdr (cdr (cdr action
))))))
92 (calc-handle-undo (cdr list
)))))
96 (when calc-executing-macro
97 (error "Use C-x e, not X, to run a keyboard macro that uses Redo"))
101 (when (null (nthcdr (1- n
) calc-redo-list
))
102 (error "Unable to redo"))
105 (nthcdr n calc-redo-list
)
106 (let ((saved-stack-top calc-stack-top
))
107 (let ((calc-stack-top 0))
108 (calc-handle-redos calc-redo-list n
))
109 (setq calc-stack-top saved-stack-top
))))
112 (defun calc-handle-redos (cl n
)
114 (let ((old-undo calc-undo-list
))
115 (setq calc-undo-list nil
)
116 (calc-handle-undo (car cl
))
117 (setq calc-undo-list
(append calc-undo-list old-undo
)))
118 (calc-handle-redos (cdr cl
) (1- n
))))
120 (defun calc-last-args (n)
122 (when calc-executing-macro
123 (error "Use C-x e, not X, to run a keyboard macro that uses last-args"))
125 (let ((urec (calc-find-last-x calc-undo-list n
)))
127 (calc-handle-last-x urec
)
128 (error "Not enough undo information available")))))
130 (defun calc-handle-last-x (list)
132 (let ((action (car list
)))
133 (if (eq (car action
) 'pop
)
134 (calc-pop-push-record-list 0 "larg"
135 (delq 'top-of-stack
(nth 2 action
))))
136 (calc-handle-last-x (cdr list
)))))
138 (defun calc-find-last-x (ul n
)
140 (if (calc-undo-does-pushes (car ul
))
143 (calc-find-last-x (cdr ul
) (1- n
)))
144 (calc-find-last-x (cdr ul
) n
))))
146 (defun calc-undo-does-pushes (list)
148 (or (eq (car (car list
)) 'pop
)
149 (calc-undo-does-pushes (cdr list
)))))
153 ;;; arch-tag: eeb485d2-fb3d-454a-9d79-450af1f50d6c
154 ;;; calc-undo.el ends here