1 ;;; calc-undo.el --- undo functions for Calc
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <belanger@truman.edu>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY. No author or distributor
12 ;; accepts responsibility to anyone for the consequences of using it
13 ;; or for whether it serves any particular purpose or works at all,
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public
15 ;; License for full details.
17 ;; Everyone is granted permission to copy, modify and redistribute
18 ;; GNU Emacs, but only under the conditions described in the
19 ;; GNU Emacs General Public License. A copy of this license is
20 ;; supposed to have been given to you along with GNU Emacs so you
21 ;; can know your rights and responsibilities. It should be in a
22 ;; file named COPYING. Among other things, the copyright notice
23 ;; and this notice must be preserved on all copies.
29 ;; This file is autoloaded from calc-ext.el.
38 (when calc-executing-macro
39 (error "Use C-x e, not X, to run a keyboard macro that uses Undo"))
45 (when (null (nthcdr (1- n) calc-undo-list))
46 (error "No further undo information available"))
49 (nthcdr n calc-undo-list)
50 (let ((saved-stack-top calc-stack-top))
51 (let ((calc-stack-top 0))
52 (calc-handle-undos calc-undo-list n))
53 (setq calc-stack-top saved-stack-top))))
56 (defun calc-handle-undos (cl n)
58 (let ((old-redo calc-redo-list))
59 (setq calc-undo-list nil)
60 (calc-handle-undo (car cl))
61 (setq calc-redo-list (append calc-undo-list old-redo)))
62 (calc-handle-undos (cdr cl) (1- n))))
64 (defun calc-handle-undo (list)
66 (let ((action (car list)))
68 ((eq (car action) 'push)
69 (calc-pop-stack 1 (nth 1 action) t))
70 ((eq (car action) 'pop)
71 (calc-push-list (nth 2 action) (nth 1 action)))
72 ((eq (car action) 'set)
73 (calc-record-undo (list 'set (nth 1 action)
74 (symbol-value (nth 1 action))))
75 (set (nth 1 action) (nth 2 action)))
76 ((eq (car action) 'store)
77 (let ((v (intern (nth 1 action))))
78 (calc-record-undo (list 'store (nth 1 action)
79 (and (boundp v) (symbol-value v))))
80 (if (y-or-n-p (format "Un-store variable %s? " (nth 1 action)))
83 (set v (nth 2 action))
85 (calc-refresh-evaltos v)))))
86 ((eq (car action) 'eval)
87 (calc-record-undo (append (list 'eval (nth 2 action) (nth 1 action))
88 (cdr (cdr (cdr action)))))
89 (apply (nth 1 action) (cdr (cdr (cdr action))))))
90 (calc-handle-undo (cdr list)))))
94 (when calc-executing-macro
95 (error "Use C-x e, not X, to run a keyboard macro that uses Redo"))
99 (when (null (nthcdr (1- n) calc-redo-list))
100 (error "Unable to redo"))
103 (nthcdr n calc-redo-list)
104 (let ((saved-stack-top calc-stack-top))
105 (let ((calc-stack-top 0))
106 (calc-handle-redos calc-redo-list n))
107 (setq calc-stack-top saved-stack-top))))
110 (defun calc-handle-redos (cl n)
112 (let ((old-undo calc-undo-list))
113 (setq calc-undo-list nil)
114 (calc-handle-undo (car cl))
115 (setq calc-undo-list (append calc-undo-list old-undo)))
116 (calc-handle-redos (cdr cl) (1- n))))
118 (defun calc-last-args (n)
120 (when calc-executing-macro
121 (error "Use C-x e, not X, to run a keyboard macro that uses last-args"))
123 (let ((urec (calc-find-last-x calc-undo-list n)))
125 (calc-handle-last-x urec)
126 (error "Not enough undo information available")))))
128 (defun calc-handle-last-x (list)
130 (let ((action (car list)))
131 (if (eq (car action) 'pop)
132 (calc-pop-push-record-list 0 "larg"
133 (delq 'top-of-stack (nth 2 action))))
134 (calc-handle-last-x (cdr list)))))
136 (defun calc-find-last-x (ul n)
138 (if (calc-undo-does-pushes (car ul))
141 (calc-find-last-x (cdr ul) (1- n)))
142 (calc-find-last-x (cdr ul) n))))
144 (defun calc-undo-does-pushes (list)
146 (or (eq (car (car list)) 'pop)
147 (calc-undo-does-pushes (cdr list)))))
151 ;;; arch-tag: eeb485d2-fb3d-454a-9d79-450af1f50d6c
152 ;;; calc-undo.el ends here