annotate lisp/gnus/gnus-undo.el @ 110:fe104dbd9147 r20-1b7

Import from CVS: tag r20-1b7
author cvs
date Mon, 13 Aug 2007 09:19:45 +0200
parents 0d2f883870bc
children 7d55a9ba150c
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
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
71 "\M-\C-_" gnus-undo))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
72
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
73 (defun gnus-undo-make-menu-bar ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
74 (when nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
75 (define-key-after (current-local-map) [menu-bar file gnus-undo]
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
76 (cons "Undo" 'gnus-undo-actions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
77 [menu-bar file whatever])))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
78
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
79 (defun gnus-undo-mode (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
80 "Minor mode for providing `undo' in Gnus buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
81
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
82 \\{gnus-undo-mode-map}"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
83 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
84 (set (make-local-variable 'gnus-undo-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
85 (if (null arg) (not gnus-undo-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
86 (> (prefix-numeric-value arg) 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
87 (set (make-local-variable 'gnus-undo-actions) nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
88 (set (make-local-variable 'gnus-undo-boundary) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
89 (when gnus-undo-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
90 ;; Set up the menu.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
91 (when (gnus-visual-p 'undo-menu 'menu)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
92 (gnus-undo-make-menu-bar))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
93 ;; Don't display anything in the mode line -- too annoying.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
94 ;;(unless (assq 'gnus-undo-mode minor-mode-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
95 ;; (push '(gnus-undo-mode " Undo") minor-mode-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
96 (unless (assq 'gnus-undo-mode minor-mode-map-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
97 (push (cons 'gnus-undo-mode gnus-undo-mode-map)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
98 minor-mode-map-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
99 (make-local-hook 'post-command-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
100 (gnus-add-hook 'post-command-hook 'gnus-undo-boundary nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
101 (add-hook 'gnus-summary-exit-hook 'gnus-undo-boundary)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
102 (run-hooks 'gnus-undo-mode-hook)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
103
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
104 ;;; Interface functions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
105
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
106 (defun gnus-disable-undo (&optional buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
107 "Disable undoing in the current buffer."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
108 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
109 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
110 (when buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
111 (set-buffer buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
112 (gnus-undo-mode -1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
113
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
114 (defun gnus-undo-boundary ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
115 "Set Gnus undo boundary."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
116 (if gnus-undo-boundary-inhibit
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
117 (setq gnus-undo-boundary-inhibit nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
118 (setq gnus-undo-boundary t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
119
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
120 (defun gnus-undo-register (form)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
121 "Register FORMS as something to be performed to undo a change.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
122 FORMS may use backtick quote syntax."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
123 (when gnus-undo-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
124 (gnus-undo-register-1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
125 `(lambda ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
126 ,form))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
127
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
128 (put 'gnus-undo-register 'lisp-indent-function 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
129 (put 'gnus-undo-register 'edebug-form-spec '(body))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
130
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
131 (defun gnus-undo-register-1 (function)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
132 "Register FUNCTION as something to be performed to undo a change."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
133 (when gnus-undo-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
134 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
135 ;; We are on a boundary, so we create a new action.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
136 (gnus-undo-boundary
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
137 (push (list function) gnus-undo-actions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
138 (setq gnus-undo-boundary nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
139 ;; Prepend the function to an old action.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
140 (gnus-undo-actions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
141 (setcar gnus-undo-actions (cons function (car gnus-undo-actions))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
142 ;; Initialize list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
143 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
144 (setq gnus-undo-actions (list (list function)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
145 (setq gnus-undo-boundary-inhibit t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
146
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
147 (defun gnus-undo (n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
148 "Undo some previous changes in Gnus buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
149 Repeat this command to undo more changes.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
150 A numeric argument serves as a repeat count."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
151 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
152 (unless gnus-undo-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
153 (error "Undoing is not enabled in this buffer"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
154 (message "%s" last-command)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
155 (when (or (not (eq last-command 'gnus-undo))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
156 (not gnus-undo-last))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
157 (setq gnus-undo-last gnus-undo-actions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
158 (let ((action (pop gnus-undo-last)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
159 (unless action
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
160 (error "Nothing further to undo"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
161 (setq gnus-undo-actions (delq action gnus-undo-actions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
162 (setq gnus-undo-boundary t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
163 (while action
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
164 (funcall (pop action)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
165
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
166 (provide 'gnus-undo)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
167
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
168 ;;; gnus-undo.el ends here