Mercurial > emacs
annotate lisp/gnus/gnus-undo.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128
typos.
author | Jeff Law <law@redhat.com> |
---|---|
date | Wed, 10 Sep 1997 21:16:20 +0000 |
parents | f5b98be7c142 |
children | 5f1ab3dd344d |
rev | line source |
---|---|
17493 | 1 ;;; gnus-undo.el --- minor mode for undoing in Gnus |
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 ;; Keywords: news | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
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 | |
28 ;; just some random representation of the actual data), normal Emacs | |
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 | |
52 (defvar gnus-undo-mode nil | |
53 "Minor mode for undoing in Gnus buffers.") | |
54 | |
55 (defvar gnus-undo-mode-hook nil | |
56 "Hook called in all `gnus-undo-mode' buffers.") | |
57 | |
58 ;;; Internal variables. | |
59 | |
60 (defvar gnus-undo-actions nil) | |
61 (defvar gnus-undo-boundary t) | |
62 (defvar gnus-undo-last nil) | |
63 (defvar gnus-undo-boundary-inhibit nil) | |
64 | |
65 ;;; Minor mode definition. | |
66 | |
67 (defvar gnus-undo-mode-map nil) | |
68 | |
69 (unless gnus-undo-mode-map | |
70 (setq gnus-undo-mode-map (make-sparse-keymap)) | |
71 | |
72 (gnus-define-keys gnus-undo-mode-map | |
73 "\M-\C-_" gnus-undo | |
74 "\C-_" gnus-undo | |
75 "\C-xu" gnus-undo | |
76 [(control /)] gnus-undo ; many people are used to type `C-/' on | |
77 ; X terminals and get `C-_'. | |
78 )) | |
79 | |
80 (defun gnus-undo-make-menu-bar () | |
81 (when nil | |
82 (define-key-after (current-local-map) [menu-bar file gnus-undo] | |
83 (cons "Undo" 'gnus-undo-actions) | |
84 [menu-bar file whatever]))) | |
85 | |
86 (defun gnus-undo-mode (&optional arg) | |
87 "Minor mode for providing `undo' in Gnus buffers. | |
88 | |
89 \\{gnus-undo-mode-map}" | |
90 (interactive "P") | |
91 (set (make-local-variable 'gnus-undo-mode) | |
92 (if (null arg) (not gnus-undo-mode) | |
93 (> (prefix-numeric-value arg) 0))) | |
94 (set (make-local-variable 'gnus-undo-actions) nil) | |
95 (set (make-local-variable 'gnus-undo-boundary) t) | |
96 (when gnus-undo-mode | |
97 ;; Set up the menu. | |
98 (when (gnus-visual-p 'undo-menu 'menu) | |
99 (gnus-undo-make-menu-bar)) | |
100 ;; Don't display anything in the mode line -- too annoying. | |
101 ;;(unless (assq 'gnus-undo-mode minor-mode-alist) | |
102 ;; (push '(gnus-undo-mode " Undo") minor-mode-alist)) | |
103 (unless (assq 'gnus-undo-mode minor-mode-map-alist) | |
104 (push (cons 'gnus-undo-mode gnus-undo-mode-map) | |
105 minor-mode-map-alist)) | |
106 (make-local-hook 'post-command-hook) | |
107 (add-hook 'post-command-hook 'gnus-undo-boundary nil t) | |
108 (add-hook 'gnus-summary-exit-hook 'gnus-undo-boundary) | |
109 (run-hooks 'gnus-undo-mode-hook))) | |
110 | |
111 ;;; Interface functions. | |
112 | |
113 (defun gnus-disable-undo (&optional buffer) | |
114 "Disable undoing in the current buffer." | |
115 (interactive) | |
116 (save-excursion | |
117 (when buffer | |
118 (set-buffer buffer)) | |
119 (gnus-undo-mode -1))) | |
120 | |
121 (defun gnus-undo-boundary () | |
122 "Set Gnus undo boundary." | |
123 (if gnus-undo-boundary-inhibit | |
124 (setq gnus-undo-boundary-inhibit nil) | |
125 (setq gnus-undo-boundary t))) | |
126 | |
127 (defun gnus-undo-register (form) | |
128 "Register FORMS as something to be performed to undo a change. | |
129 FORMS may use backtick quote syntax." | |
130 (when gnus-undo-mode | |
131 (gnus-undo-register-1 | |
132 `(lambda () | |
133 ,form)))) | |
134 | |
135 (put 'gnus-undo-register 'lisp-indent-function 0) | |
136 (put 'gnus-undo-register 'edebug-form-spec '(body)) | |
137 | |
138 (defun gnus-undo-register-1 (function) | |
139 "Register FUNCTION as something to be performed to undo a change." | |
140 (when gnus-undo-mode | |
141 (cond | |
142 ;; We are on a boundary, so we create a new action. | |
143 (gnus-undo-boundary | |
144 (push (list function) gnus-undo-actions) | |
145 (setq gnus-undo-boundary nil)) | |
146 ;; Prepend the function to an old action. | |
147 (gnus-undo-actions | |
148 (setcar gnus-undo-actions (cons function (car gnus-undo-actions)))) | |
149 ;; Initialize list. | |
150 (t | |
151 (setq gnus-undo-actions (list (list function))))) | |
152 (setq gnus-undo-boundary-inhibit t))) | |
153 | |
154 (defun gnus-undo (n) | |
155 "Undo some previous changes in Gnus buffers. | |
156 Repeat this command to undo more changes. | |
157 A numeric argument serves as a repeat count." | |
158 (interactive "p") | |
159 (unless gnus-undo-mode | |
160 (error "Undoing is not enabled in this buffer")) | |
161 (message "%s" last-command) | |
162 (when (or (not (eq last-command 'gnus-undo)) | |
163 (not gnus-undo-last)) | |
164 (setq gnus-undo-last gnus-undo-actions)) | |
165 (let ((action (pop gnus-undo-last))) | |
166 (unless action | |
167 (error "Nothing further to undo")) | |
168 (setq gnus-undo-actions (delq action gnus-undo-actions)) | |
169 (setq gnus-undo-boundary t) | |
170 (while action | |
171 (funcall (pop action))))) | |
172 | |
173 (provide 'gnus-undo) | |
174 | |
175 ;;; gnus-undo.el ends here |