Mercurial > emacs
annotate lisp/calc/calc-undo.el @ 69487:606d39d5dc60
(mac_init_fringe) [MAC_OS]: New function.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Wed, 15 Mar 2006 07:55:45 +0000 |
parents | 6bf177f8065b |
children | 7a3f13e2dd57 c5406394f567 |
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 |
64325
1db49616ce05
Update copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62442
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, |
68636
6bf177f8065b
Update copyright year.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
64325
diff
changeset
|
4 ;; 2005, 2006 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
|
5 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
6 ;; Author: David Gillespie <daveg@synaptics.com> |
58676
a19f1d75f7d5
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
7 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
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. | |
17 | |
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. | |
25 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
26 ;;; Commentary: |
40785 | 27 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
28 ;;; Code: |
40785 | 29 |
30 ;; 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
|
31 |
40785 | 32 (require 'calc-ext) |
33 (require 'calc-macs) | |
34 | |
35 ;;; Undo. | |
36 | |
37 (defun calc-undo (n) | |
38 (interactive "p") | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
39 (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
|
40 (error "Use C-x e, not X, to run a keyboard macro that uses Undo")) |
40785 | 41 (if (<= n 0) |
42 (if (< n 0) | |
43 (calc-redo (- n)) | |
44 (calc-last-args 1)) | |
45 (calc-wrapper | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
46 (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
|
47 (error "No further undo information available")) |
40785 | 48 (setq calc-undo-list |
49 (prog1 | |
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)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
55 (message "Undo!")))) |
40785 | 56 |
57 (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
|
58 (when (> n 0) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
59 (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
|
60 (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
|
61 (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
|
62 (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
|
63 (calc-handle-undos (cdr cl) (1- n)))) |
40785 | 64 |
65 (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
|
66 (when list |
40785 | 67 (let ((action (car list))) |
68 (cond | |
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)))) | |
60081
5af1fe16a166
(calc-handle-undo): Remove prefix from variable in message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58676
diff
changeset
|
81 (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
|
82 (calc-var-name (nth 1 action)))) |
40785 | 83 (progn |
84 (if (nth 2 action) | |
85 (set v (nth 2 action)) | |
86 (makunbound v)) | |
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)))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
92 (calc-handle-undo (cdr list))))) |
40785 | 93 |
94 (defun calc-redo (n) | |
95 (interactive "p") | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
96 (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
|
97 (error "Use C-x e, not X, to run a keyboard macro that uses Redo")) |
40785 | 98 (if (<= n 0) |
99 (calc-undo (- n)) | |
100 (calc-wrapper | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
101 (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
|
102 (error "Unable to redo")) |
40785 | 103 (setq calc-redo-list |
104 (prog1 | |
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)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
110 (message "Redo!")))) |
40785 | 111 |
112 (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
|
113 (when (> n 0) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
114 (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
|
115 (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
|
116 (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
|
117 (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
|
118 (calc-handle-redos (cdr cl) (1- n)))) |
40785 | 119 |
120 (defun calc-last-args (n) | |
121 (interactive "p") | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
122 (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
|
123 (error "Use C-x e, not X, to run a keyboard macro that uses last-args")) |
40785 | 124 (calc-wrapper |
125 (let ((urec (calc-find-last-x calc-undo-list n))) | |
126 (if urec | |
127 (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
|
128 (error "Not enough undo information available"))))) |
40785 | 129 |
130 (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
|
131 (when list |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
132 (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
|
133 (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
|
134 (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
|
135 (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
|
136 (calc-handle-last-x (cdr list))))) |
40785 | 137 |
138 (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
|
139 (when ul |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
140 (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
|
141 (if (<= n 1) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
142 (car ul) |
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) (1- n))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
144 (calc-find-last-x (cdr ul) n)))) |
40785 | 145 |
146 (defun calc-undo-does-pushes (list) | |
147 (and list | |
148 (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
|
149 (calc-undo-does-pushes (cdr list))))) |
40785 | 150 |
58676
a19f1d75f7d5
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
151 (provide 'calc-undo) |
a19f1d75f7d5
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
152 |
52401 | 153 ;;; 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
|
154 ;;; calc-undo.el ends here |