;;; winner.el --- Restore old window configurations
-;; Copyright (C) 1997, 1998, 2001, 2004 Free Software Foundation. Inc.
+;; Copyright (C) 1997, 1998, 2001, 2002, 2003, 2004,
+;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation. Inc.
;; Author: Ivar Rummelhoff <ivarru@math.uio.no>
;; Created: 27 Feb 1997
-;; Time-stamp: <2002-02-20 22:06:58 ivarru>
;; Keywords: convenience frames
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(defmacro winner-active-region ()
- (if (fboundp 'region-active-p)
- '(region-active-p)
- 'mark-active))
+ (if (boundp 'mark-active)
+ 'mark-active
+ '(region-active-p)))
(defsetf winner-active-region () (store)
- (if (fboundp 'zmacs-activate-region)
+ (if (featurep 'xemacs)
`(if ,store (zmacs-activate-region)
(zmacs-deactivate-region))
`(setq mark-active ,store)))
(require 'ring)
-(unless (fboundp 'defgroup)
- (defmacro defgroup (&rest rest)))
-
(defgroup winner nil
"Restoring window configurations."
:group 'windows)
-(unless (fboundp 'defcustom)
- (defmacro defcustom (symbol &optional initvalue docs &rest rest)
- (list 'defvar symbol initvalue docs)))
-
;;;###autoload
(defcustom winner-mode nil
- "Toggle winner-mode.
+ "Toggle Winner mode.
Setting this variable directly does not take effect;
use either \\[customize] or the function `winner-mode'."
:set #'(lambda (symbol value) (funcall symbol (or value 0)))
:group 'winner)
(defcustom winner-boring-buffers '("*Completions*")
- "`winner-undo' will not restore windows displaying any of these \
-buffers.
+ "`winner-undo' will not restore windows displaying any of these buffers.
You may want to include buffer names such as *Help*, *Apropos*,
*Buffer List*, *info* and *Compile-Log*."
:type '(repeat string)
-\f;;;; Saving old configurations (internal variables and subroutines)
+\f
+;;;; Saving old configurations (internal variables and subroutines)
;;; Current configuration
;; Find the right ring. If it does not exist, create one.
(defsubst winner-ring (frame)
(or (cdr (assq frame winner-ring-alist))
- (progn
- (let ((ring (make-ring winner-ring-size)))
- (ring-insert ring (winner-configuration frame))
- (push (cons frame ring) winner-ring-alist)
- ring))))
+ (let ((ring (make-ring winner-ring-size)))
+ (ring-insert ring (winner-configuration frame))
+ (push (cons frame ring) winner-ring-alist)
+ ring)))
-\f;; If the same command is called several times in a row,
+\f
+;; If the same command is called several times in a row,
;; we only save one window configuration.
(defvar winner-last-command nil)
(defvar winner-last-frames nil)
-(defun winner-equal (a b)
+(defsubst winner-equal (a b)
"Check whether two Winner configurations (as produced by
`winner-conf') are equal."
(equal (cdr a) (cdr b)))
-\f;;;; Restoring configurations
+\f
+;;;; Restoring configurations
;; Works almost as `set-window-configuration',
;; but does not change the contents or the size of the minibuffer,
(defun winner-get-point (buf win)
;; Consult (and possibly extend) `winner-point-alist'.
- ;; Returns nil iff buf no longer exists.
+ ;; Returns nil if buf no longer exists.
(when (buffer-name buf)
(let ((entry (assq buf winner-point-alist)))
(cond
winner-point-alist)
(point)))))))
-\f;; Make sure point does not end up in the minibuffer and delete
+\f
+;; Make sure point does not end up in the minibuffer and delete
;; windows displaying dead or boring buffers
-;; (c.f. `winner-boring-buffers'). Return nil iff all the windows
+;; (c.f. `winner-boring-buffers'). Return nil if all the windows
;; should be deleted. Preserve correct points and marks.
(defun winner-set (conf)
;; For the format of `conf', see `winner-conf'.
(setq winner-modified-list (frame-list))
(winner-save-old-configurations)
(run-hooks 'winner-mode-hook)
- (when (interactive-p) (message "Winner mode enabled")))
+ (when (called-interactively-p 'interactive)
+ (message "Winner mode enabled")))
;; Turn mode off
(winner-mode
(setq winner-mode nil)
(remove-hook 'post-command-hook 'winner-save-conditionally)
(remove-hook 'minibuffer-setup-hook 'winner-save-unconditionally)
(run-hooks 'winner-mode-leave-hook)
- (when (interactive-p) (message "Winner mode disabled"))))))
+ (when (called-interactively-p 'interactive)
+ (message "Winner mode disabled"))))))
;; Inspired by undo (simple.el)
(defvar winner-undo-frame nil)
(defvar winner-pending-undo-ring nil
- "The ring currently used by winner undo.")
+ "The ring currently used by `winner-undo'.")
(defvar winner-undo-counter nil)
(defvar winner-undone-data nil) ; There confs have been passed.
-\f(defun winner-undo-this () ; The heart of winner undo.
+\f
+(defun winner-undo-this () ; The heart of winner undo.
(loop
(cond
((>= winner-undo-counter (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 (error "Previous command was not a `winner-undo'"))))
;;; To be evaluated when the package is loaded: