/[emacs]/emacs/lisp/calc/calc-undo.el
ViewVC logotype

Diff of /emacs/lisp/calc/calc-undo.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by walters, Wed Nov 14 09:07:36 2001 UTC revision 1.3 by walters, Mon Nov 19 07:41:59 2001 UTC
# Line 1  Line 1 
1  ;; Calculator for GNU Emacs, part II [calc-undo.el]  ;;; calc-undo.el --- undo functions for Calc
2    
3  ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.  ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
4  ;; Written by Dave Gillespie, daveg@synaptics.com.  
5    ;; Author: David Gillespie <daveg@synaptics.com>
6    ;; Maintainer: Colin Walters <walters@debian.org>
7    
8  ;; This file is part of GNU Emacs.  ;; This file is part of GNU Emacs.
9    
# Line 19  Line 22 
22  ;; file named COPYING.  Among other things, the copyright notice  ;; file named COPYING.  Among other things, the copyright notice
23  ;; and this notice must be preserved on all copies.  ;; and this notice must be preserved on all copies.
24    
25    ;;; Commentary:
26    
27    ;;; Code:
28    
29  ;; This file is autoloaded from calc-ext.el.  ;; This file is autoloaded from calc-ext.el.
30  (require 'calc-ext)  (require 'calc-ext)
# Line 33  Line 38 
38    
39  (defun calc-undo (n)  (defun calc-undo (n)
40    (interactive "p")    (interactive "p")
41    (and calc-executing-macro    (when calc-executing-macro
42         (error "Use C-x e, not X, to run a keyboard macro that uses Undo."))      (error "Use C-x e, not X, to run a keyboard macro that uses Undo"))
43    (if (<= n 0)    (if (<= n 0)
44        (if (< n 0)        (if (< n 0)
45            (calc-redo (- n))            (calc-redo (- n))
46          (calc-last-args 1))          (calc-last-args 1))
47      (calc-wrapper      (calc-wrapper
48       (if (null (nthcdr (1- n) calc-undo-list))       (when (null (nthcdr (1- n) calc-undo-list))
49           (error "No further undo information available"))         (error "No further undo information available"))
50       (setq calc-undo-list       (setq calc-undo-list
51             (prog1             (prog1
52                 (nthcdr n calc-undo-list)                 (nthcdr n calc-undo-list)
# Line 52  Line 57 
57       (message "Undo!"))))       (message "Undo!"))))
58    
59  (defun calc-handle-undos (cl n)  (defun calc-handle-undos (cl n)
60    (if (> n 0)    (when (> n 0)
61        (progn      (let ((old-redo calc-redo-list))
62          (let ((old-redo calc-redo-list))        (setq calc-undo-list nil)
63            (setq calc-undo-list nil)        (calc-handle-undo (car cl))
64            (calc-handle-undo (car cl))        (setq calc-redo-list (append calc-undo-list old-redo)))
65            (setq calc-redo-list (append calc-undo-list old-redo)))      (calc-handle-undos (cdr cl) (1- n))))
         (calc-handle-undos (cdr cl) (1- n)))))  
66    
67  (defun calc-handle-undo (list)  (defun calc-handle-undo (list)
68    (and list    (when list
69         (let ((action (car list)))         (let ((action (car list)))
70           (cond           (cond
71            ((eq (car action) 'push)            ((eq (car action) 'push)
# Line 90  Line 94 
94    
95  (defun calc-redo (n)  (defun calc-redo (n)
96    (interactive "p")    (interactive "p")
97    (and calc-executing-macro    (when calc-executing-macro
98         (error "Use C-x e, not X, to run a keyboard macro that uses Redo."))      (error "Use C-x e, not X, to run a keyboard macro that uses Redo"))
99    (if (<= n 0)    (if (<= n 0)
100        (calc-undo (- n))        (calc-undo (- n))
101      (calc-wrapper      (calc-wrapper
102       (if (null (nthcdr (1- n) calc-redo-list))       (when (null (nthcdr (1- n) calc-redo-list))
103           (error "Unable to redo"))         (error "Unable to redo"))
104       (setq calc-redo-list       (setq calc-redo-list
105             (prog1             (prog1
106                 (nthcdr n calc-redo-list)                 (nthcdr n calc-redo-list)
# Line 107  Line 111 
111       (message "Redo!"))))       (message "Redo!"))))
112    
113  (defun calc-handle-redos (cl n)  (defun calc-handle-redos (cl n)
114    (if (> n 0)    (when (> n 0)
115        (progn      (let ((old-undo calc-undo-list))
116          (let ((old-undo calc-undo-list))        (setq calc-undo-list nil)
117            (setq calc-undo-list nil)        (calc-handle-undo (car cl))
118            (calc-handle-undo (car cl))        (setq calc-undo-list (append calc-undo-list old-undo)))
119            (setq calc-undo-list (append calc-undo-list old-undo)))      (calc-handle-redos (cdr cl) (1- n))))
         (calc-handle-redos (cdr cl) (1- n)))))  
120    
121  (defun calc-last-args (n)  (defun calc-last-args (n)
122    (interactive "p")    (interactive "p")
123    (and calc-executing-macro    (when calc-executing-macro
124         (error "Use C-x e, not X, to run a keyboard macro that uses last-args."))      (error "Use C-x e, not X, to run a keyboard macro that uses last-args"))
125    (calc-wrapper    (calc-wrapper
126     (let ((urec (calc-find-last-x calc-undo-list n)))     (let ((urec (calc-find-last-x calc-undo-list n)))
127       (if urec       (if urec
# Line 126  Line 129 
129         (error "Not enough undo information available")))))         (error "Not enough undo information available")))))
130    
131  (defun calc-handle-last-x (list)  (defun calc-handle-last-x (list)
132    (and list    (when list
133         (let ((action (car list)))      (let ((action (car list)))
134           (if (eq (car action) 'pop)        (if (eq (car action) 'pop)
135               (calc-pop-push-record-list 0 "larg"            (calc-pop-push-record-list 0 "larg"
136                                          (delq 'top-of-stack (nth 2 action))))                                       (delq 'top-of-stack (nth 2 action))))
137           (calc-handle-last-x (cdr list)))))        (calc-handle-last-x (cdr list)))))
138    
139  (defun calc-find-last-x (ul n)  (defun calc-find-last-x (ul n)
140    (and ul    (when ul
141         (if (calc-undo-does-pushes (car ul))      (if (calc-undo-does-pushes (car ul))
142             (if (<= n 1)          (if (<= n 1)
143                 (car ul)              (car ul)
144               (calc-find-last-x (cdr ul) (1- n)))            (calc-find-last-x (cdr ul) (1- n)))
145           (calc-find-last-x (cdr ul) n))))        (calc-find-last-x (cdr ul) n))))
146    
147  (defun calc-undo-does-pushes (list)  (defun calc-undo-does-pushes (list)
148    (and list    (and list

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26