Mercurial > emacs
annotate lisp/calc/calc-undo.el @ 62131:ae455ff58429
Paren typo again.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 06 May 2005 21:24:32 +0000 |
parents | 5af1fe16a166 |
children | 842c8b2c2940 7e3f621f1dd4 |
rev | line source |
---|---|
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1 ;;; calc-undo.el --- undo functions for Calc |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
2 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
4 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
5 ;; Author: David Gillespie <daveg@synaptics.com> |
58676
a19f1d75f7d5
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
6 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
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. | |
16 | |
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. | |
24 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
25 ;;; Commentary: |
40785 | 26 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
27 ;;; Code: |
40785 | 28 |
29 ;; This file is autoloaded from calc-ext.el. | |
58676
a19f1d75f7d5
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
30 |
40785 | 31 (require 'calc-ext) |
32 (require 'calc-macs) | |
33 | |
34 ;;; Undo. | |
35 | |
36 (defun calc-undo (n) | |
37 (interactive "p") | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
38 (when calc-executing-macro |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
39 (error "Use C-x e, not X, to run a keyboard macro that uses Undo")) |
40785 | 40 (if (<= n 0) |
41 (if (< n 0) | |
42 (calc-redo (- n)) | |
43 (calc-last-args 1)) | |
44 (calc-wrapper | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
45 (when (null (nthcdr (1- n) calc-undo-list)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
46 (error "No further undo information available")) |
40785 | 47 (setq calc-undo-list |
48 (prog1 | |
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)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
54 (message "Undo!")))) |
40785 | 55 |
56 (defun calc-handle-undos (cl n) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
57 (when (> n 0) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
58 (let ((old-redo calc-redo-list)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
59 (setq calc-undo-list nil) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
60 (calc-handle-undo (car cl)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
61 (setq calc-redo-list (append calc-undo-list old-redo))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
62 (calc-handle-undos (cdr cl) (1- n)))) |
40785 | 63 |
64 (defun calc-handle-undo (list) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
65 (when list |
40785 | 66 (let ((action (car list))) |
67 (cond | |
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)))) | |
60081
5af1fe16a166
(calc-handle-undo): Remove prefix from variable in message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58676
diff
changeset
|
80 (if (y-or-n-p (format "Un-store variable %s? " |
5af1fe16a166
(calc-handle-undo): Remove prefix from variable in message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58676
diff
changeset
|
81 (calc-var-name (nth 1 action)))) |
40785 | 82 (progn |
83 (if (nth 2 action) | |
84 (set v (nth 2 action)) | |
85 (makunbound v)) | |
86 (calc-refresh-evaltos v))))) | |
87 ((eq (car action) 'eval) | |
88 (calc-record-undo (append (list 'eval (nth 2 action) (nth 1 action)) | |
89 (cdr (cdr (cdr action))))) | |
90 (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
|
91 (calc-handle-undo (cdr list))))) |
40785 | 92 |
93 (defun calc-redo (n) | |
94 (interactive "p") | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
95 (when calc-executing-macro |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
96 (error "Use C-x e, not X, to run a keyboard macro that uses Redo")) |
40785 | 97 (if (<= n 0) |
98 (calc-undo (- n)) | |
99 (calc-wrapper | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
100 (when (null (nthcdr (1- n) calc-redo-list)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
101 (error "Unable to redo")) |
40785 | 102 (setq calc-redo-list |
103 (prog1 | |
104 (nthcdr n calc-redo-list) | |
105 (let ((saved-stack-top calc-stack-top)) | |
106 (let ((calc-stack-top 0)) | |
107 (calc-handle-redos calc-redo-list n)) | |
108 (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
|
109 (message "Redo!")))) |
40785 | 110 |
111 (defun calc-handle-redos (cl n) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
112 (when (> n 0) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
113 (let ((old-undo calc-undo-list)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
114 (setq calc-undo-list nil) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
115 (calc-handle-undo (car cl)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
116 (setq calc-undo-list (append calc-undo-list old-undo))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
117 (calc-handle-redos (cdr cl) (1- n)))) |
40785 | 118 |
119 (defun calc-last-args (n) | |
120 (interactive "p") | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
121 (when calc-executing-macro |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
122 (error "Use C-x e, not X, to run a keyboard macro that uses last-args")) |
40785 | 123 (calc-wrapper |
124 (let ((urec (calc-find-last-x calc-undo-list n))) | |
125 (if urec | |
126 (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
|
127 (error "Not enough undo information available"))))) |
40785 | 128 |
129 (defun calc-handle-last-x (list) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
130 (when list |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
131 (let ((action (car list))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
132 (if (eq (car action) 'pop) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
133 (calc-pop-push-record-list 0 "larg" |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
134 (delq 'top-of-stack (nth 2 action)))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
135 (calc-handle-last-x (cdr list))))) |
40785 | 136 |
137 (defun calc-find-last-x (ul n) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
138 (when ul |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
139 (if (calc-undo-does-pushes (car ul)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
140 (if (<= n 1) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
141 (car ul) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
142 (calc-find-last-x (cdr ul) (1- n))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
143 (calc-find-last-x (cdr ul) n)))) |
40785 | 144 |
145 (defun calc-undo-does-pushes (list) | |
146 (and list | |
147 (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
|
148 (calc-undo-does-pushes (cdr list))))) |
40785 | 149 |
58676
a19f1d75f7d5
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
150 (provide 'calc-undo) |
a19f1d75f7d5
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
151 |
52401 | 152 ;;; arch-tag: eeb485d2-fb3d-454a-9d79-450af1f50d6c |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
153 ;;; calc-undo.el ends here |