annotate lisp/gnus/gnus-undo.el @ 147:e186c2b7192d xemacs-20-2

Added tag r20-2p1 for changeset 2af401a6ecca
author cvs
date Mon, 13 Aug 2007 09:34:48 +0200
parents 585fb297b004
children 8eaf7971accc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1 ;;; gnus-undo.el --- minor mode for undoing in Gnus
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5 ;; Keywords: news
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
8
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
12 ;; any later version.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
13
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
18
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
23
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
24 ;;; Commentary:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
25
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
26 ;; This package allows arbitrary undoing in Gnus buffers. As all the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
27 ;; Gnus buffers aren't very text-oriented (what is in the buffers is
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
28 ;; just some random representation of the actual data), normal Emacs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
29 ;; undoing doesn't work at all for Gnus.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
30 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
31 ;; This package works by letting Gnus register functions for reversing
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
32 ;; actions, and then calling these functions when the user pushes the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
33 ;; `undo' key. As with normal `undo', there it is possible to set
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
34 ;; undo boundaries and so on.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
35 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
36 ;; Internally, the undo sequence is represented by the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
37 ;; `gnus-undo-actions' list, where each element is a list of functions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
38 ;; to be called, in sequence, to undo some action. (An "action" is a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
39 ;; collection of functions.)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
40 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
41 ;; For instance, a function for killing a group will call
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
42 ;; `gnus-undo-register' with a function that un-kills the group. This
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
43 ;; package will put that function into an action.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
44
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
45 ;;; Code:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
46
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
47 (require 'gnus-util)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
48 (require 'gnus)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
49
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
50 (defvar gnus-undo-mode nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
51 "Minor mode for undoing in Gnus buffers.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
52
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
53 (defvar gnus-undo-mode-hook nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
54 "Hook called in all `gnus-undo-mode' buffers.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
55
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
56 ;;; Internal variables.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
57
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
58 (defvar gnus-undo-actions nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
59 (defvar gnus-undo-boundary t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
60 (defvar gnus-undo-last nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
61 (defvar gnus-undo-boundary-inhibit nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
62
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
63 ;;; Minor mode definition.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
64
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
65 (defvar gnus-undo-mode-map nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
66
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
67 (unless gnus-undo-mode-map
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
68 (setq gnus-undo-mode-map (make-sparse-keymap))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
69
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
70 (gnus-define-keys gnus-undo-mode-map
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 98
diff changeset
71 "\M-\C-_" gnus-undo
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 98
diff changeset
72 "\C-_" gnus-undo
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 98
diff changeset
73 "\C-xu" gnus-undo
140
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
74 ;; many people are used to type `C-/' on X terminals and get `C-_'.
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
75 [(control /)] gnus-undo))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
76
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
77 (defun gnus-undo-make-menu-bar ()
140
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
78 ;; This is disabled for the time being.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
79 (when nil
140
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
80 (define-key-after (current-local-map) [menu-bar file gnus-undo]
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
81 (cons "Undo" 'gnus-undo-actions)
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
82 [menu-bar file whatever])))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
83
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
84 (defun gnus-undo-mode (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
85 "Minor mode for providing `undo' in Gnus buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
86
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
87 \\{gnus-undo-mode-map}"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
88 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
89 (set (make-local-variable 'gnus-undo-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
90 (if (null arg) (not gnus-undo-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
91 (> (prefix-numeric-value arg) 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
92 (set (make-local-variable 'gnus-undo-actions) nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
93 (set (make-local-variable 'gnus-undo-boundary) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
94 (when gnus-undo-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
95 ;; Set up the menu.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
96 (when (gnus-visual-p 'undo-menu 'menu)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
97 (gnus-undo-make-menu-bar))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
98 ;; Don't display anything in the mode line -- too annoying.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
99 ;;(unless (assq 'gnus-undo-mode minor-mode-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
100 ;; (push '(gnus-undo-mode " Undo") minor-mode-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
101 (unless (assq 'gnus-undo-mode minor-mode-map-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
102 (push (cons 'gnus-undo-mode gnus-undo-mode-map)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
103 minor-mode-map-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
104 (make-local-hook 'post-command-hook)
122
d2f30a177268 Import from CVS: tag r20-1b14
cvs
parents: 118
diff changeset
105 (add-hook 'post-command-hook 'gnus-undo-boundary nil t)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
106 (run-hooks 'gnus-undo-mode-hook)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
107
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
108 ;;; Interface functions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
109
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
110 (defun gnus-disable-undo (&optional buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
111 "Disable undoing in the current buffer."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
112 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
113 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
114 (when buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
115 (set-buffer buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
116 (gnus-undo-mode -1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
117
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
118 (defun gnus-undo-boundary ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
119 "Set Gnus undo boundary."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
120 (if gnus-undo-boundary-inhibit
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
121 (setq gnus-undo-boundary-inhibit nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
122 (setq gnus-undo-boundary t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
123
140
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
124 (defun gnus-undo-force-boundary ()
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
125 "Set Gnus undo boundary."
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
126 (setq gnus-undo-boundary-inhibit nil
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
127 gnus-undo-boundary t))
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 122
diff changeset
128
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
129 (defun gnus-undo-register (form)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
130 "Register FORMS as something to be performed to undo a change.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
131 FORMS may use backtick quote syntax."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
132 (when gnus-undo-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
133 (gnus-undo-register-1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
134 `(lambda ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
135 ,form))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
136
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
137 (put 'gnus-undo-register 'lisp-indent-function 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
138 (put 'gnus-undo-register 'edebug-form-spec '(body))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
139
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
140 (defun gnus-undo-register-1 (function)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
141 "Register FUNCTION as something to be performed to undo a change."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
142 (when gnus-undo-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
143 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
144 ;; We are on a boundary, so we create a new action.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
145 (gnus-undo-boundary
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
146 (push (list function) gnus-undo-actions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
147 (setq gnus-undo-boundary nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
148 ;; Prepend the function to an old action.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
149 (gnus-undo-actions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
150 (setcar gnus-undo-actions (cons function (car gnus-undo-actions))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
151 ;; Initialize list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
152 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
153 (setq gnus-undo-actions (list (list function)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
154 (setq gnus-undo-boundary-inhibit t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
155
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
156 (defun gnus-undo (n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
157 "Undo some previous changes in Gnus buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
158 Repeat this command to undo more changes.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
159 A numeric argument serves as a repeat count."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
160 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
161 (unless gnus-undo-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
162 (error "Undoing is not enabled in this buffer"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
163 (message "%s" last-command)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
164 (when (or (not (eq last-command 'gnus-undo))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
165 (not gnus-undo-last))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
166 (setq gnus-undo-last gnus-undo-actions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
167 (let ((action (pop gnus-undo-last)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
168 (unless action
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
169 (error "Nothing further to undo"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
170 (setq gnus-undo-actions (delq action gnus-undo-actions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
171 (setq gnus-undo-boundary t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
172 (while action
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
173 (funcall (pop action)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
174
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
175 (provide 'gnus-undo)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
176
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
177 ;;; gnus-undo.el ends here