Mercurial > emacs
annotate lisp/gnus/gnus-undo.el @ 86933:553d66dcf5fd
(math-compose-var): Fix declaration.
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Sun, 02 Dec 2007 03:45:14 +0000 |
parents | a3c27999decb |
children | 107ccd98fa12 880960b70474 |
rev | line source |
---|---|
17493 | 1 ;;; gnus-undo.el --- minor mode for undoing in Gnus |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
2 |
74547 | 3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
75347 | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
17493 | 5 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
17493 | 7 ;; Keywords: news |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
78224
24202b793a08
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
17493 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
17493 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;; This package allows arbitrary undoing in Gnus buffers. As all the | |
29 ;; Gnus buffers aren't very text-oriented (what is in the buffers is | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
30 ;; just some arbitrary representation of the actual data), normal Emacs |
17493 | 31 ;; undoing doesn't work at all for Gnus. |
32 ;; | |
33 ;; This package works by letting Gnus register functions for reversing | |
34 ;; actions, and then calling these functions when the user pushes the | |
35 ;; `undo' key. As with normal `undo', there it is possible to set | |
36 ;; undo boundaries and so on. | |
37 ;; | |
38 ;; Internally, the undo sequence is represented by the | |
39 ;; `gnus-undo-actions' list, where each element is a list of functions | |
40 ;; to be called, in sequence, to undo some action. (An "action" is a | |
41 ;; collection of functions.) | |
42 ;; | |
43 ;; For instance, a function for killing a group will call | |
44 ;; `gnus-undo-register' with a function that un-kills the group. This | |
45 ;; package will put that function into an action. | |
46 | |
47 ;;; Code: | |
48 | |
19531
f5b98be7c142
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
49 (eval-when-compile (require 'cl)) |
f5b98be7c142
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
50 |
17493 | 51 (require 'gnus-util) |
52 (require 'gnus) | |
53 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
54 (defgroup gnus-undo nil |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
55 "Undoing in Gnus buffers." |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
56 :group 'gnus) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
57 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
58 (defcustom gnus-undo-limit 2000 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
59 "The number of undoable actions recorded." |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
60 :type 'integer |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
61 :group 'gnus-undo) |
17493 | 62 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
63 (defcustom gnus-undo-mode nil |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
64 "Minor mode for undoing in Gnus buffers." |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
65 :type 'boolean |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
66 :group 'gnus-undo) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
67 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
68 (defcustom gnus-undo-mode-hook nil |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
69 "Hook called in all `gnus-undo-mode' buffers." |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
70 :type 'hook |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
71 :group 'gnus-undo) |
17493 | 72 |
73 ;;; Internal variables. | |
74 | |
75 (defvar gnus-undo-actions nil) | |
76 (defvar gnus-undo-boundary t) | |
77 (defvar gnus-undo-last nil) | |
78 (defvar gnus-undo-boundary-inhibit nil) | |
79 | |
80 ;;; Minor mode definition. | |
81 | |
82 (defvar gnus-undo-mode-map nil) | |
83 | |
84 (unless gnus-undo-mode-map | |
85 (setq gnus-undo-mode-map (make-sparse-keymap)) | |
86 | |
87 (gnus-define-keys gnus-undo-mode-map | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
88 "\M-\C-_" gnus-undo |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
89 "\C-_" gnus-undo |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
90 "\C-xu" gnus-undo |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
91 ;; many people are used to type `C-/' on X terminals and get `C-_'. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
92 [(control /)] gnus-undo)) |
17493 | 93 |
94 (defun gnus-undo-make-menu-bar () | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
95 ;; This is disabled for the time being. |
17493 | 96 (when nil |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
97 (define-key-after (current-local-map) [menu-bar file gnus-undo] |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
98 (cons "Undo" 'gnus-undo-actions) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
99 [menu-bar file whatever]))) |
17493 | 100 |
101 (defun gnus-undo-mode (&optional arg) | |
102 "Minor mode for providing `undo' in Gnus buffers. | |
103 | |
104 \\{gnus-undo-mode-map}" | |
105 (interactive "P") | |
106 (set (make-local-variable 'gnus-undo-mode) | |
107 (if (null arg) (not gnus-undo-mode) | |
108 (> (prefix-numeric-value arg) 0))) | |
109 (set (make-local-variable 'gnus-undo-actions) nil) | |
110 (set (make-local-variable 'gnus-undo-boundary) t) | |
111 (when gnus-undo-mode | |
112 ;; Set up the menu. | |
113 (when (gnus-visual-p 'undo-menu 'menu) | |
114 (gnus-undo-make-menu-bar)) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
115 (add-minor-mode 'gnus-undo-mode "" gnus-undo-mode-map) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
116 (gnus-make-local-hook 'post-command-hook) |
17493 | 117 (add-hook 'post-command-hook 'gnus-undo-boundary nil t) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
118 (gnus-run-hooks 'gnus-undo-mode-hook))) |
17493 | 119 |
120 ;;; Interface functions. | |
121 | |
122 (defun gnus-disable-undo (&optional buffer) | |
123 "Disable undoing in the current buffer." | |
124 (interactive) | |
125 (save-excursion | |
126 (when buffer | |
127 (set-buffer buffer)) | |
128 (gnus-undo-mode -1))) | |
129 | |
130 (defun gnus-undo-boundary () | |
131 "Set Gnus undo boundary." | |
132 (if gnus-undo-boundary-inhibit | |
133 (setq gnus-undo-boundary-inhibit nil) | |
134 (setq gnus-undo-boundary t))) | |
135 | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
136 (defun gnus-undo-force-boundary () |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
137 "Set Gnus undo boundary." |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
138 (setq gnus-undo-boundary-inhibit nil |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
139 gnus-undo-boundary t)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
140 |
17493 | 141 (defun gnus-undo-register (form) |
142 "Register FORMS as something to be performed to undo a change. | |
143 FORMS may use backtick quote syntax." | |
144 (when gnus-undo-mode | |
145 (gnus-undo-register-1 | |
146 `(lambda () | |
147 ,form)))) | |
148 | |
149 (put 'gnus-undo-register 'lisp-indent-function 0) | |
150 (put 'gnus-undo-register 'edebug-form-spec '(body)) | |
151 | |
152 (defun gnus-undo-register-1 (function) | |
153 "Register FUNCTION as something to be performed to undo a change." | |
154 (when gnus-undo-mode | |
155 (cond | |
156 ;; We are on a boundary, so we create a new action. | |
157 (gnus-undo-boundary | |
158 (push (list function) gnus-undo-actions) | |
159 (setq gnus-undo-boundary nil)) | |
160 ;; Prepend the function to an old action. | |
161 (gnus-undo-actions | |
162 (setcar gnus-undo-actions (cons function (car gnus-undo-actions)))) | |
163 ;; Initialize list. | |
164 (t | |
165 (setq gnus-undo-actions (list (list function))))) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
166 ;; Limit the length of the undo list. |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
167 (let ((next (nthcdr gnus-undo-limit gnus-undo-actions))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
168 (when next |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
169 (setcdr next nil))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
170 ;; We are not at a boundary... |
17493 | 171 (setq gnus-undo-boundary-inhibit t))) |
172 | |
173 (defun gnus-undo (n) | |
174 "Undo some previous changes in Gnus buffers. | |
175 Repeat this command to undo more changes. | |
176 A numeric argument serves as a repeat count." | |
177 (interactive "p") | |
178 (unless gnus-undo-mode | |
179 (error "Undoing is not enabled in this buffer")) | |
180 (message "%s" last-command) | |
181 (when (or (not (eq last-command 'gnus-undo)) | |
182 (not gnus-undo-last)) | |
183 (setq gnus-undo-last gnus-undo-actions)) | |
184 (let ((action (pop gnus-undo-last))) | |
185 (unless action | |
186 (error "Nothing further to undo")) | |
187 (setq gnus-undo-actions (delq action gnus-undo-actions)) | |
188 (setq gnus-undo-boundary t) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
189 (mapc 'funcall action))) |
17493 | 190 |
191 (provide 'gnus-undo) | |
192 | |
52401 | 193 ;;; arch-tag: 0d787bc7-787d-499a-837f-211d2cb07f2e |
17493 | 194 ;;; gnus-undo.el ends here |