Mercurial > emacs
annotate lisp/gnus/gnus-undo.el @ 19848:68c5c0b3ed0d
(input-method-verbose-flag):
Doc-string fied.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 09 Sep 1997 14:55:29 +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 |