70 |
|
|
71 |
(require 'ring) |
(require 'ring) |
72 |
|
|
73 |
(when (fboundp 'defgroup) |
(unless (fboundp 'defgroup) |
74 |
(defgroup winner nil |
(defmacro defgroup (&rest rest))) |
75 |
"Restoring window configurations." |
|
76 |
:group 'windows)) |
(defgroup winner nil |
77 |
|
"Restoring window configurations." |
78 |
|
:group 'windows) |
79 |
|
|
80 |
(unless (fboundp 'defcustom) |
(unless (fboundp 'defcustom) |
81 |
(defmacro defcustom (symbol &optional initvalue docs &rest rest) |
(defmacro defcustom (symbol &optional initvalue docs &rest rest) |
128 |
while (= a b) |
while (= a b) |
129 |
finally return (< a b))))) |
finally return (< a b))))) |
130 |
|
|
131 |
(defun winner-win-data () |
(defun winner-win-data () |
132 |
;; Essential properties of the windows in the selected frame. |
;; Essential properties of the windows in the selected frame. |
133 |
(loop for win in (winner-sorted-window-list) |
(loop for win in (winner-sorted-window-list) |
134 |
collect (cons (winner-edges win) (window-buffer win)))) |
collect (cons (winner-edges win) (window-buffer win)))) |
135 |
|
|
136 |
;; This variable is updated with the current window configuration |
;; This variable is updated with the current window configuration |
137 |
;; every time it changes. |
;; every time it changes. |
138 |
(defvar winner-currents nil) |
(defvar winner-currents nil) |
262 |
((window-live-p chosen) (select-window chosen)) |
((window-live-p chosen) (select-window chosen)) |
263 |
((window-minibuffer-p (selected-window)) |
((window-minibuffer-p (selected-window)) |
264 |
(other-window 1))) |
(other-window 1))) |
265 |
(when (/= minisize (window-height miniwin)) |
(when (/= minisize (window-height miniwin)) |
266 |
(letf (((selected-window) miniwin) ) |
(letf (((selected-window) miniwin) ) |
267 |
(setf (window-height) minisize))))) |
(setf (window-height) minisize))))) |
268 |
|
|
279 |
(letf (((current-buffer))) |
(letf (((current-buffer))) |
280 |
(loop with alist |
(loop with alist |
281 |
for win in (winner-window-list) |
for win in (winner-window-list) |
282 |
for entry = |
for entry = |
283 |
(or (assq (window-buffer win) alist) |
(or (assq (window-buffer win) alist) |
284 |
(car (push (list (set-buffer (window-buffer win)) |
(car (push (list (set-buffer (window-buffer win)) |
285 |
(cons (mark t) (winner-active-region))) |
(cons (mark t) (winner-active-region))) |
335 |
|
|
336 |
;; Restore marks |
;; Restore marks |
337 |
(letf (((current-buffer))) |
(letf (((current-buffer))) |
338 |
(loop for buf in buffers |
(loop for buf in buffers |
339 |
for entry = (cadr (assq buf winner-point-alist)) |
for entry = (cadr (assq buf winner-point-alist)) |
340 |
do (progn (set-buffer buf) |
do (progn (set-buffer buf) |
341 |
(set-mark (car entry)) |
(set-mark (car entry)) |
384 |
(not winner-mode)))) |
(not winner-mode)))) |
385 |
(cond |
(cond |
386 |
;; Turn mode on |
;; Turn mode on |
387 |
(on-p |
(on-p |
388 |
(setq winner-mode t) |
(setq winner-mode t) |
389 |
(cond |
(cond |
390 |
((winner-hook-installed-p) |
((winner-hook-installed-p) |
435 |
(message "Winner undo (%d / %d)" |
(message "Winner undo (%d / %d)" |
436 |
winner-undo-counter |
winner-undo-counter |
437 |
(1- (ring-length winner-pending-undo-ring))))))) |
(1- (ring-length winner-pending-undo-ring))))))) |
438 |
|
|
439 |
|
|
440 |
|
|
441 |
(defun winner-undo-this () ; The heart of winner undo. |
(defun winner-undo-this () ; The heart of winner undo. |
442 |
(loop |
(loop |
443 |
(cond |
(cond |
444 |
((>= winner-undo-counter (ring-length winner-pending-undo-ring)) |
((>= winner-undo-counter (ring-length winner-pending-undo-ring)) |
445 |
(message "No further window configuration undo information") |
(message "No further window configuration undo information") |
446 |
(return nil)) |
(return nil)) |
447 |
|
|
448 |
((and ; If possible configuration |
((and ; If possible configuration |
449 |
(winner-set (ring-ref winner-pending-undo-ring |
(winner-set (ring-ref winner-pending-undo-ring |
450 |
winner-undo-counter)) |
winner-undo-counter)) |
455 |
(return t)) ; .. then everything is fine. |
(return t)) ; .. then everything is fine. |
456 |
(t ;; Otherwise, discharge it (and try the next one). |
(t ;; Otherwise, discharge it (and try the next one). |
457 |
(ring-remove winner-pending-undo-ring winner-undo-counter))))) |
(ring-remove winner-pending-undo-ring winner-undo-counter))))) |
458 |
|
|
459 |
|
|
460 |
(defun winner-redo () ; If you change your mind. |
(defun winner-redo () ; If you change your mind. |
461 |
"Restore a more recent window configuration saved by Winner mode." |
"Restore a more recent window configuration saved by Winner mode." |