78 |
|
|
79 |
;;;###autoload |
;;;###autoload |
80 |
(defcustom winner-mode nil |
(defcustom winner-mode nil |
81 |
"Toggle winner-mode. |
"Toggle Winner mode. |
82 |
Setting this variable directly does not take effect; |
Setting this variable directly does not take effect; |
83 |
use either \\[customize] or the function `winner-mode'." |
use either \\[customize] or the function `winner-mode'." |
84 |
:set #'(lambda (symbol value) (funcall symbol (or value 0))) |
:set #'(lambda (symbol value) (funcall symbol (or value 0))) |
98 |
:group 'winner) |
:group 'winner) |
99 |
|
|
100 |
(defcustom winner-boring-buffers '("*Completions*") |
(defcustom winner-boring-buffers '("*Completions*") |
101 |
"`winner-undo' will not restore windows displaying any of these \ |
"`winner-undo' will not restore windows displaying any of these buffers. |
|
buffers. |
|
102 |
You may want to include buffer names such as *Help*, *Apropos*, |
You may want to include buffer names such as *Help*, *Apropos*, |
103 |
*Buffer List*, *info* and *Compile-Log*." |
*Buffer List*, *info* and *Compile-Log*." |
104 |
:type '(repeat string) |
:type '(repeat string) |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
;;;; Saving old configurations (internal variables and subroutines) |
|
111 |
|
;;;; Saving old configurations (internal variables and subroutines) |
112 |
|
|
113 |
|
|
114 |
;;; Current configuration |
;;; Current configuration |
162 |
;; Find the right ring. If it does not exist, create one. |
;; Find the right ring. If it does not exist, create one. |
163 |
(defsubst winner-ring (frame) |
(defsubst winner-ring (frame) |
164 |
(or (cdr (assq frame winner-ring-alist)) |
(or (cdr (assq frame winner-ring-alist)) |
165 |
(progn |
(let ((ring (make-ring winner-ring-size))) |
166 |
(let ((ring (make-ring winner-ring-size))) |
(ring-insert ring (winner-configuration frame)) |
167 |
(ring-insert ring (winner-configuration frame)) |
(push (cons frame ring) winner-ring-alist) |
168 |
(push (cons frame ring) winner-ring-alist) |
ring))) |
|
ring)))) |
|
169 |
|
|
170 |
;; If the same command is called several times in a row, |
|
171 |
|
;; If the same command is called several times in a row, |
172 |
;; we only save one window configuration. |
;; we only save one window configuration. |
173 |
(defvar winner-last-command nil) |
(defvar winner-last-command nil) |
174 |
|
|
176 |
(defvar winner-last-frames nil) |
(defvar winner-last-frames nil) |
177 |
|
|
178 |
|
|
179 |
(defun winner-equal (a b) |
(defsubst winner-equal (a b) |
180 |
"Check whether two Winner configurations (as produced by |
"Check whether two Winner configurations (as produced by |
181 |
`winner-conf') are equal." |
`winner-conf') are equal." |
182 |
(equal (cdr a) (cdr b))) |
(equal (cdr a) (cdr b))) |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
;;;; Restoring configurations |
|
244 |
|
;;;; Restoring configurations |
245 |
|
|
246 |
;; Works almost as `set-window-configuration', |
;; Works almost as `set-window-configuration', |
247 |
;; but does not change the contents or the size of the minibuffer, |
;; but does not change the contents or the size of the minibuffer, |
302 |
winner-point-alist) |
winner-point-alist) |
303 |
(point))))))) |
(point))))))) |
304 |
|
|
305 |
;; Make sure point does not end up in the minibuffer and delete |
|
306 |
|
;; Make sure point does not end up in the minibuffer and delete |
307 |
;; windows displaying dead or boring buffers |
;; windows displaying dead or boring buffers |
308 |
;; (c.f. `winner-boring-buffers'). Return nil iff all the windows |
;; (c.f. `winner-boring-buffers'). Return nil iff all the windows |
309 |
;; should be deleted. Preserve correct points and marks. |
;; should be deleted. Preserve correct points and marks. |
412 |
(defvar winner-undo-frame nil) |
(defvar winner-undo-frame nil) |
413 |
|
|
414 |
(defvar winner-pending-undo-ring nil |
(defvar winner-pending-undo-ring nil |
415 |
"The ring currently used by winner undo.") |
"The ring currently used by `winner-undo'.") |
416 |
(defvar winner-undo-counter nil) |
(defvar winner-undo-counter nil) |
417 |
(defvar winner-undone-data nil) ; There confs have been passed. |
(defvar winner-undone-data nil) ; There confs have been passed. |
418 |
|
|
439 |
|
|
440 |
|
|
441 |
|
|
442 |
(defun winner-undo-this () ; The heart of winner undo. |
|
443 |
|
(defun winner-undo-this () ; The heart of winner undo. |
444 |
(loop |
(loop |
445 |
(cond |
(cond |
446 |
((>= winner-undo-counter (ring-length winner-pending-undo-ring)) |
((>= winner-undo-counter (ring-length winner-pending-undo-ring)) |
470 |
(ring-ref winner-pending-undo-ring 0))) |
(ring-ref winner-pending-undo-ring 0))) |
471 |
(unless (eq (selected-window) (minibuffer-window)) |
(unless (eq (selected-window) (minibuffer-window)) |
472 |
(message "Winner undid undo"))) |
(message "Winner undid undo"))) |
473 |
(t (error "Previous command was not a winner-undo")))) |
(t (error "Previous command was not a `winner-undo'")))) |
474 |
|
|
475 |
;;; To be evaluated when the package is loaded: |
;;; To be evaluated when the package is loaded: |
476 |
|
|