;;; winner.el --- Restore old window configurations
-;; Copyright (C) 1997-1998, 2001-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1997-1998, 2001-2016 Free Software Foundation, Inc.
;; Author: Ivar Rummelhoff <ivarru@math.uio.no>
;; Created: 27 Feb 1997
(if (featurep 'xemacs)
`(if ,store (zmacs-activate-region)
(zmacs-deactivate-region))
- `(setq mark-active ,store)))))
- (if (boundp 'mark-active)
- mark-active
- (region-active-p)))
+ `(if ,store (activate-mark) (deactivate-mark))))))
+ (region-active-p))
(defalias 'winner-edges
(if (featurep 'xemacs) 'window-pixel-edges 'window-edges))
;; Save current configuration.
;; (Called below by `winner-save-old-configurations').
(defun winner-remember ()
- (let ((entry (assq (selected-frame) winner-currents)))
- (if entry (setcdr entry (winner-conf))
- (push (cons (selected-frame) (winner-conf))
- winner-currents))))
+ (setf (alist-get (selected-frame) winner-currents) (winner-conf)))
;; Consult `winner-currents'.
(defun winner-configuration (&optional frame)
;; Called whenever the window configuration changes
;; (a `window-configuration-change-hook').
(defun winner-change-fun ()
+
+ ;; Cull dead frames.
+ (setq winner-modified-list
+ (cl-loop for frame in winner-modified-list
+ if (frame-live-p frame) collect frame))
+
(unless (or (memq (selected-frame) winner-modified-list)
(/= 0 (minibuffer-depth)))
(push (selected-frame) winner-modified-list)))
(set-window-configuration winconf))
(cond
((window-live-p chosen) (select-window chosen))
- ((window-minibuffer-p (selected-window))
- (other-window 1)))
+ ((window-minibuffer-p) (other-window 1)))
(when (/= minisize (window-height miniwin))
(with-selected-window miniwin
(setf (window-height) minisize)))))
map)
"Keymap for Winner mode.")
-;; Check if `window-configuration-change-hook' is working.
-(defun winner-hook-installed-p ()
- (save-window-excursion
- (let ((winner-var nil)
- (window-configuration-change-hook
- '((lambda () (setq winner-var t)))))
- (split-window)
- winner-var)))
-
\f
;;;###autoload
-(define-minor-mode winner-mode nil :global t ; let d-m-m make the doc
+(define-minor-mode winner-mode
+ "Toggle Winner mode on or off.
+With a prefix argument ARG, enable Winner mode if ARG is
+positive, and disable it otherwise. If called from Lisp, enable
+the mode if ARG is omitted or nil, and toggle it if ARG is ‘toggle’.
+
+Winner mode is a global minor mode that records the changes in
+the window configuration (i.e. how the frames are partitioned
+into windows) so that the changes can be \"undone\" using the
+command `winner-undo'. By default this one is bound to the key
+sequence `C-c <left>'. If you change your mind (while undoing),
+you can press `C-c <right>' (calling `winner-redo')."
+ :global t
(if winner-mode
(progn
- (if (winner-hook-installed-p)
- (progn
- (add-hook 'window-configuration-change-hook 'winner-change-fun)
- (add-hook 'post-command-hook 'winner-save-old-configurations))
- (add-hook 'post-command-hook 'winner-save-conditionally))
+ (add-hook 'window-configuration-change-hook 'winner-change-fun)
+ (add-hook 'post-command-hook 'winner-save-old-configurations)
(add-hook 'minibuffer-setup-hook 'winner-save-unconditionally)
(setq winner-modified-list (frame-list))
(winner-save-old-configurations))
(remove-hook 'window-configuration-change-hook 'winner-change-fun)
(remove-hook 'post-command-hook 'winner-save-old-configurations)
- (remove-hook 'post-command-hook 'winner-save-conditionally)
(remove-hook 'minibuffer-setup-hook 'winner-save-unconditionally)))
;; Inspired by undo (simple.el)
(setq winner-undone-data (list (winner-win-data))))
(cl-incf winner-undo-counter) ; starting at 1
(when (and (winner-undo-this)
- (not (window-minibuffer-p (selected-window))))
+ (not (window-minibuffer-p)))
(message "Winner undo (%d / %d)"
winner-undo-counter
(1- (ring-length winner-pending-undo-ring)))))))
(ring-ref winner-pending-undo-ring 0)))
(unless (eq (selected-window) (minibuffer-window))
(message "Winner undid undo")))
- (t (error "Previous command was not a `winner-undo'"))))
+ (t (user-error "Previous command was not a `winner-undo'"))))
(provide 'winner)
;;; winner.el ends here