Mercurial > emacs
annotate lisp/calc/calc-undo.el @ 41220:0a6ed29cea73
Comment change.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 17 Nov 2001 22:41:26 +0000 |
parents | 73f364fd8aaa |
children | fcd507927105 |
rev | line source |
---|---|
40785 | 1 ;; Calculator for GNU Emacs, part II [calc-undo.el] |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
40785 | 3 ;; Written by Dave Gillespie, daveg@synaptics.com. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is distributed in the hope that it will be useful, | |
8 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
9 ;; accepts responsibility to anyone for the consequences of using it | |
10 ;; or for whether it serves any particular purpose or works at all, | |
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
12 ;; License for full details. | |
13 | |
14 ;; Everyone is granted permission to copy, modify and redistribute | |
15 ;; GNU Emacs, but only under the conditions described in the | |
16 ;; GNU Emacs General Public License. A copy of this license is | |
17 ;; supposed to have been given to you along with GNU Emacs so you | |
18 ;; can know your rights and responsibilities. It should be in a | |
19 ;; file named COPYING. Among other things, the copyright notice | |
20 ;; and this notice must be preserved on all copies. | |
21 | |
22 | |
23 | |
24 ;; This file is autoloaded from calc-ext.el. | |
25 (require 'calc-ext) | |
26 | |
27 (require 'calc-macs) | |
28 | |
29 (defun calc-Need-calc-undo () nil) | |
30 | |
31 | |
32 ;;; Undo. | |
33 | |
34 (defun calc-undo (n) | |
35 (interactive "p") | |
36 (and calc-executing-macro | |
37 (error "Use C-x e, not X, to run a keyboard macro that uses Undo.")) | |
38 (if (<= n 0) | |
39 (if (< n 0) | |
40 (calc-redo (- n)) | |
41 (calc-last-args 1)) | |
42 (calc-wrapper | |
43 (if (null (nthcdr (1- n) calc-undo-list)) | |
44 (error "No further undo information available")) | |
45 (setq calc-undo-list | |
46 (prog1 | |
47 (nthcdr n calc-undo-list) | |
48 (let ((saved-stack-top calc-stack-top)) | |
49 (let ((calc-stack-top 0)) | |
50 (calc-handle-undos calc-undo-list n)) | |
51 (setq calc-stack-top saved-stack-top)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
52 (message "Undo!")))) |
40785 | 53 |
54 (defun calc-handle-undos (cl n) | |
55 (if (> n 0) | |
56 (progn | |
57 (let ((old-redo calc-redo-list)) | |
58 (setq calc-undo-list nil) | |
59 (calc-handle-undo (car cl)) | |
60 (setq calc-redo-list (append calc-undo-list old-redo))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
61 (calc-handle-undos (cdr cl) (1- n))))) |
40785 | 62 |
63 (defun calc-handle-undo (list) | |
64 (and list | |
65 (let ((action (car list))) | |
66 (cond | |
67 ((eq (car action) 'push) | |
68 (calc-pop-stack 1 (nth 1 action) t)) | |
69 ((eq (car action) 'pop) | |
70 (calc-push-list (nth 2 action) (nth 1 action))) | |
71 ((eq (car action) 'set) | |
72 (calc-record-undo (list 'set (nth 1 action) | |
73 (symbol-value (nth 1 action)))) | |
74 (set (nth 1 action) (nth 2 action))) | |
75 ((eq (car action) 'store) | |
76 (let ((v (intern (nth 1 action)))) | |
77 (calc-record-undo (list 'store (nth 1 action) | |
78 (and (boundp v) (symbol-value v)))) | |
79 (if (y-or-n-p (format "Un-store variable %s? " (nth 1 action))) | |
80 (progn | |
81 (if (nth 2 action) | |
82 (set v (nth 2 action)) | |
83 (makunbound v)) | |
84 (calc-refresh-evaltos v))))) | |
85 ((eq (car action) 'eval) | |
86 (calc-record-undo (append (list 'eval (nth 2 action) (nth 1 action)) | |
87 (cdr (cdr (cdr action))))) | |
88 (apply (nth 1 action) (cdr (cdr (cdr action)))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
89 (calc-handle-undo (cdr list))))) |
40785 | 90 |
91 (defun calc-redo (n) | |
92 (interactive "p") | |
93 (and calc-executing-macro | |
94 (error "Use C-x e, not X, to run a keyboard macro that uses Redo.")) | |
95 (if (<= n 0) | |
96 (calc-undo (- n)) | |
97 (calc-wrapper | |
98 (if (null (nthcdr (1- n) calc-redo-list)) | |
99 (error "Unable to redo")) | |
100 (setq calc-redo-list | |
101 (prog1 | |
102 (nthcdr n calc-redo-list) | |
103 (let ((saved-stack-top calc-stack-top)) | |
104 (let ((calc-stack-top 0)) | |
105 (calc-handle-redos calc-redo-list n)) | |
106 (setq calc-stack-top saved-stack-top)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
107 (message "Redo!")))) |
40785 | 108 |
109 (defun calc-handle-redos (cl n) | |
110 (if (> n 0) | |
111 (progn | |
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))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
116 (calc-handle-redos (cdr cl) (1- n))))) |
40785 | 117 |
118 (defun calc-last-args (n) | |
119 (interactive "p") | |
120 (and calc-executing-macro | |
121 (error "Use C-x e, not X, to run a keyboard macro that uses last-args.")) | |
122 (calc-wrapper | |
123 (let ((urec (calc-find-last-x calc-undo-list n))) | |
124 (if urec | |
125 (calc-handle-last-x urec) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
126 (error "Not enough undo information available"))))) |
40785 | 127 |
128 (defun calc-handle-last-x (list) | |
129 (and 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)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
134 (calc-handle-last-x (cdr list))))) |
40785 | 135 |
136 (defun calc-find-last-x (ul n) | |
137 (and ul | |
138 (if (calc-undo-does-pushes (car ul)) | |
139 (if (<= n 1) | |
140 (car ul) | |
141 (calc-find-last-x (cdr ul) (1- n))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
142 (calc-find-last-x (cdr ul) n)))) |
40785 | 143 |
144 (defun calc-undo-does-pushes (list) | |
145 (and list | |
146 (or (eq (car (car list)) 'pop) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
147 (calc-undo-does-pushes (cdr list))))) |
40785 | 148 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
149 ;;; calc-undo.el ends here |