Mercurial > emacs
annotate lisp/gnus/gnus-undo.el @ 95507:62ef79a054ca
Fix typos.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 03 Jun 2008 07:40:29 +0000 |
parents | f42ef85caf91 |
children | a9dc0e7c3f2b |
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, |
79708 | 4 ;; 2005, 2006, 2007, 2008 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 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
17493 | 12 ;; it under the terms of the GNU General Public License as published by |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
17493 | 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 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17493 | 19 ;; GNU General Public License for more details. |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
17493 | 23 |
24 ;;; Commentary: | |
25 | |
26 ;; This package allows arbitrary undoing in Gnus buffers. As all the | |
27 ;; 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
|
28 ;; just some arbitrary representation of the actual data), normal Emacs |
17493 | 29 ;; undoing doesn't work at all for Gnus. |
30 ;; | |
31 ;; This package works by letting Gnus register functions for reversing | |
32 ;; actions, and then calling these functions when the user pushes the | |
33 ;; `undo' key. As with normal `undo', there it is possible to set | |
34 ;; undo boundaries and so on. | |
35 ;; | |
36 ;; Internally, the undo sequence is represented by the | |
37 ;; `gnus-undo-actions' list, where each element is a list of functions | |
38 ;; to be called, in sequence, to undo some action. (An "action" is a | |
39 ;; collection of functions.) | |
40 ;; | |
41 ;; For instance, a function for killing a group will call | |
42 ;; `gnus-undo-register' with a function that un-kills the group. This | |
43 ;; package will put that function into an action. | |
44 | |
45 ;;; Code: | |
46 | |
19531
f5b98be7c142
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
47 (eval-when-compile (require 'cl)) |
f5b98be7c142
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
48 |
17493 | 49 (require 'gnus-util) |
50 (require 'gnus) | |
51 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
52 (defgroup gnus-undo nil |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
53 "Undoing in Gnus buffers." |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
54 :group 'gnus) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
55 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
56 (defcustom gnus-undo-limit 2000 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
57 "The number of undoable actions recorded." |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
58 :type 'integer |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
59 :group 'gnus-undo) |
17493 | 60 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
61 (defcustom gnus-undo-mode nil |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
62 "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
|
63 :type 'boolean |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
64 :group 'gnus-undo) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
65 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
66 (defcustom gnus-undo-mode-hook nil |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
67 "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
|
68 :type 'hook |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
69 :group 'gnus-undo) |
17493 | 70 |
71 ;;; Internal variables. | |
72 | |
73 (defvar gnus-undo-actions nil) | |
74 (defvar gnus-undo-boundary t) | |
75 (defvar gnus-undo-last nil) | |
76 (defvar gnus-undo-boundary-inhibit nil) | |
77 | |
78 ;;; Minor mode definition. | |
79 | |
80 (defvar gnus-undo-mode-map nil) | |
81 | |
82 (unless gnus-undo-mode-map | |
83 (setq gnus-undo-mode-map (make-sparse-keymap)) | |
84 | |
85 (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
|
86 "\M-\C-_" gnus-undo |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
87 "\C-_" gnus-undo |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
88 "\C-xu" gnus-undo |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
89 ;; 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
|
90 [(control /)] gnus-undo)) |
17493 | 91 |
92 (defun gnus-undo-make-menu-bar () | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
93 ;; This is disabled for the time being. |
17493 | 94 (when nil |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
95 (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
|
96 (cons "Undo" 'gnus-undo-actions) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
97 [menu-bar file whatever]))) |
17493 | 98 |
99 (defun gnus-undo-mode (&optional arg) | |
100 "Minor mode for providing `undo' in Gnus buffers. | |
101 | |
102 \\{gnus-undo-mode-map}" | |
103 (interactive "P") | |
104 (set (make-local-variable 'gnus-undo-mode) | |
105 (if (null arg) (not gnus-undo-mode) | |
106 (> (prefix-numeric-value arg) 0))) | |
107 (set (make-local-variable 'gnus-undo-actions) nil) | |
108 (set (make-local-variable 'gnus-undo-boundary) t) | |
109 (when gnus-undo-mode | |
110 ;; Set up the menu. | |
111 (when (gnus-visual-p 'undo-menu 'menu) | |
112 (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
|
113 (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
|
114 (gnus-make-local-hook 'post-command-hook) |
17493 | 115 (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
|
116 (gnus-run-hooks 'gnus-undo-mode-hook))) |
17493 | 117 |
118 ;;; Interface functions. | |
119 | |
120 (defun gnus-disable-undo (&optional buffer) | |
121 "Disable undoing in the current buffer." | |
122 (interactive) | |
123 (save-excursion | |
124 (when buffer | |
125 (set-buffer buffer)) | |
126 (gnus-undo-mode -1))) | |
127 | |
128 (defun gnus-undo-boundary () | |
129 "Set Gnus undo boundary." | |
130 (if gnus-undo-boundary-inhibit | |
131 (setq gnus-undo-boundary-inhibit nil) | |
132 (setq gnus-undo-boundary t))) | |
133 | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
134 (defun gnus-undo-force-boundary () |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
135 "Set Gnus undo boundary." |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
136 (setq gnus-undo-boundary-inhibit nil |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
137 gnus-undo-boundary t)) |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19531
diff
changeset
|
138 |
17493 | 139 (defun gnus-undo-register (form) |
140 "Register FORMS as something to be performed to undo a change. | |
141 FORMS may use backtick quote syntax." | |
142 (when gnus-undo-mode | |
143 (gnus-undo-register-1 | |
144 `(lambda () | |
145 ,form)))) | |
146 | |
147 (put 'gnus-undo-register 'lisp-indent-function 0) | |
148 (put 'gnus-undo-register 'edebug-form-spec '(body)) | |
149 | |
150 (defun gnus-undo-register-1 (function) | |
151 "Register FUNCTION as something to be performed to undo a change." | |
152 (when gnus-undo-mode | |
153 (cond | |
154 ;; We are on a boundary, so we create a new action. | |
155 (gnus-undo-boundary | |
156 (push (list function) gnus-undo-actions) | |
157 (setq gnus-undo-boundary nil)) | |
158 ;; Prepend the function to an old action. | |
159 (gnus-undo-actions | |
160 (setcar gnus-undo-actions (cons function (car gnus-undo-actions)))) | |
161 ;; Initialize list. | |
162 (t | |
163 (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
|
164 ;; 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
|
165 (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
|
166 (when next |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
167 (setcdr next nil))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
168 ;; We are not at a boundary... |
17493 | 169 (setq gnus-undo-boundary-inhibit t))) |
170 | |
171 (defun gnus-undo (n) | |
172 "Undo some previous changes in Gnus buffers. | |
173 Repeat this command to undo more changes. | |
174 A numeric argument serves as a repeat count." | |
175 (interactive "p") | |
176 (unless gnus-undo-mode | |
177 (error "Undoing is not enabled in this buffer")) | |
178 (message "%s" last-command) | |
179 (when (or (not (eq last-command 'gnus-undo)) | |
180 (not gnus-undo-last)) | |
181 (setq gnus-undo-last gnus-undo-actions)) | |
182 (let ((action (pop gnus-undo-last))) | |
183 (unless action | |
184 (error "Nothing further to undo")) | |
185 (setq gnus-undo-actions (delq action gnus-undo-actions)) | |
186 (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
|
187 (mapc 'funcall action))) |
17493 | 188 |
189 (provide 'gnus-undo) | |
190 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
191 ;; arch-tag: 0d787bc7-787d-499a-837f-211d2cb07f2e |
17493 | 192 ;;; gnus-undo.el ends here |