123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- (eval-when-compile (require 'cl))
- (eval-when-compile
- (when (featurep 'xemacs)
- (require 'easy-mmode)))
- (require 'gnus-util)
- (require 'gnus)
- (defgroup gnus-undo nil
- "Undoing in Gnus buffers."
- :group 'gnus)
- (defcustom gnus-undo-limit 2000
- "The number of undoable actions recorded."
- :type 'integer
- :group 'gnus-undo)
- (defcustom gnus-undo-mode nil
-
-
-
-
- "Minor mode for undoing in Gnus buffers."
- :type 'boolean
- :group 'gnus-undo)
- (defcustom gnus-undo-mode-hook nil
- "Hook called in all `gnus-undo-mode' buffers."
- :type 'hook
- :group 'gnus-undo)
- (defvar gnus-undo-actions nil)
- (defvar gnus-undo-boundary t)
- (defvar gnus-undo-last nil)
- (defvar gnus-undo-boundary-inhibit nil)
- (defvar gnus-undo-mode-map
- (let ((map (make-sparse-keymap)))
- (gnus-define-keys map
- "\M-\C-_" gnus-undo
- "\C-_" gnus-undo
- "\C-xu" gnus-undo
-
- [(control /)] gnus-undo)
- map))
- (defun gnus-undo-make-menu-bar ()
-
- (when nil
- (define-key-after (current-local-map) [menu-bar file gnus-undo]
- (cons "Undo" 'gnus-undo-actions)
- [menu-bar file whatever])))
- (define-minor-mode gnus-undo-mode
- "Minor mode for providing `undo' in Gnus buffers.
- \\{gnus-undo-mode-map}"
- :keymap gnus-undo-mode-map
- (set (make-local-variable 'gnus-undo-actions) nil)
- (set (make-local-variable 'gnus-undo-boundary) t)
- (when gnus-undo-mode
-
- (when (gnus-visual-p 'undo-menu 'menu)
- (gnus-undo-make-menu-bar))
- (gnus-make-local-hook 'post-command-hook)
- (add-hook 'post-command-hook 'gnus-undo-boundary nil t)))
- (defun gnus-disable-undo (&optional buffer)
- "Disable undoing in the current buffer."
- (interactive)
- (save-excursion
- (when buffer
- (set-buffer buffer))
- (gnus-undo-mode -1)))
- (defun gnus-undo-boundary ()
- "Set Gnus undo boundary."
- (if gnus-undo-boundary-inhibit
- (setq gnus-undo-boundary-inhibit nil)
- (setq gnus-undo-boundary t)))
- (defun gnus-undo-force-boundary ()
- "Set Gnus undo boundary."
- (setq gnus-undo-boundary-inhibit nil
- gnus-undo-boundary t))
- (defun gnus-undo-register (form)
- "Register FORMS as something to be performed to undo a change.
- FORMS may use backtick quote syntax."
- (when gnus-undo-mode
- (gnus-undo-register-1
- `(lambda ()
- ,form))))
- (put 'gnus-undo-register 'lisp-indent-function 0)
- (put 'gnus-undo-register 'edebug-form-spec '(body))
- (defun gnus-undo-register-1 (function)
- "Register FUNCTION as something to be performed to undo a change."
- (when gnus-undo-mode
- (cond
-
- (gnus-undo-boundary
- (push (list function) gnus-undo-actions)
- (setq gnus-undo-boundary nil))
-
- (gnus-undo-actions
- (setcar gnus-undo-actions (cons function (car gnus-undo-actions))))
-
- (t
- (setq gnus-undo-actions (list (list function)))))
-
- (let ((next (nthcdr gnus-undo-limit gnus-undo-actions)))
- (when next
- (setcdr next nil)))
-
- (setq gnus-undo-boundary-inhibit t)))
- (defun gnus-undo (n)
- "Undo some previous changes in Gnus buffers.
- Repeat this command to undo more changes.
- A numeric argument serves as a repeat count."
- (interactive "p")
- (unless gnus-undo-mode
- (error "Undoing is not enabled in this buffer"))
- (message "%s" last-command)
- (when (or (not (eq last-command 'gnus-undo))
- (not gnus-undo-last))
- (setq gnus-undo-last gnus-undo-actions))
- (let ((action (pop gnus-undo-last)))
- (unless action
- (error "Nothing further to undo"))
- (setq gnus-undo-actions (delq action gnus-undo-actions))
- (setq gnus-undo-boundary t)
- (mapc 'funcall action)))
- (provide 'gnus-undo)
|