annotate lisp/winner.el @ 22140:26e470569368

(uniquify-ignore-buffers-re): New variable. (uniquify-rationalize-file-buffer-names): Implement it.
author Richard M. Stallman <rms@gnu.org>
date Tue, 19 May 1998 05:07:48 +0000
parents d66c9c7b4927
children 976752e904ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
1 ;;; winner.el --- Restore old window configurations
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
3 ;; Copyright (C) 1997, 1998 Free Software Foundation. Inc.
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Ivar Rummelhoff <ivarr@ifi.uio.no>
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Maintainer: Ivar Rummelhoff <ivarr@ifi.uio.no>
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: 27 Feb 1997
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
8 ;; Time-stamp: <1998-03-05 19:01:37 ivarr>
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
9 ;; Keywords: windows
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
11 ;; This file is part of GNU Emacs.
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
12
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; any later version.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
29
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
30 ;; Winner mode is a global minor mode that records the changes in the
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
31 ;; window configuration (i.e. how the frames are partitioned into
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
32 ;; windows). This way the changes can be "undone" using the function
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
33 ;; `winner-undo'. By default this one is bound to the key sequence
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
34 ;; ctrl-x left. If you change your mind (while undoing), you can
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
35 ;; press ctrl-x right (calling `winner-redo'). Even though it uses
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
36 ;; some features of Emacs20.3, winner.el should also work with
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
37 ;; Emacs19.34 and XEmacs20, provided that the installed version of
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
38 ;; custom is not obsolete.
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
40 ;;; Code:
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
21016
f778c7136ff5 ((require 'cl)): Revert to compile-time require.
Dave Love <fx@gnu.org>
parents: 20980
diff changeset
42 (eval-when-compile (require 'cl))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
43 (require 'ring)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
45 (when (fboundp 'defgroup)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
46 (defgroup winner nil ; Customization by Dave Love
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
47 "Restoring window configurations."
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
48 :group 'windows))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
49
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
50 (unless (fboundp 'defcustom)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
51 (defmacro defcustom (symbol &optional initvalue docs &rest rest)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
52 (list 'defvar symbol initvalue docs)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
53
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
54
20980
85cc901f00ee (winner-mode): Autoload cookie for defcustom too.
Dave Love <fx@gnu.org>
parents: 20969
diff changeset
55 ;;;###autoload
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
56 (defcustom winner-mode nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
57 "Toggle winner-mode.
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
58 You must modify via \\[customize] for this variable to have an effect."
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
59 :set #'(lambda (symbol value)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
60 (winner-mode (or value 0)))
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
61 :initialize 'custom-initialize-default
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
62 :type 'boolean
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
63 :group 'winner
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
64 :require 'winner)
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
65
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
66 (defcustom winner-dont-bind-my-keys nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
67 "If non-nil: Do not use `winner-mode-map' in Winner mode."
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
68 :type 'boolean
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
69 :group 'winner)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
70
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
71 (defcustom winner-ring-size 200
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
72 "Maximum number of stored window configurations per frame."
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
73 :type 'integer
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
74 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
76
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
77
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
79 ;;;; Internal variables and subroutines
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
80
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
82 ;; This variable contains the window cofiguration rings.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
83 ;; The key in this alist is the frame.
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
84 (defvar winner-ring-alist nil)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
85
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
86 ;; Find the right ring. If it does not exist, create one.
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
87 (defsubst winner-ring (frame)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
88 (or (cdr (assq frame winner-ring-alist))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
89 (progn
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
90 (let ((ring (make-ring winner-ring-size)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
91 (ring-insert ring (winner-configuration frame))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
92 (push (cons frame ring) winner-ring-alist)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
93 ring))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
94
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
95 (defvar winner-last-saviour nil)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
96
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
97 ;; Save the current window configuration, if it has changed and return
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
98 ;; frame, else return nil. If the last change was due to the same
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
99 ;; command, save only the latest configuration.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
100 (defun winner-insert-if-new (frame)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
101 (let ((conf (winner-configuration))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
102 (ring (winner-ring frame)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
103 (cond
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
104 ((winner-equal conf (ring-ref ring 0)) nil)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
105 (t (when (and (eq this-command (car winner-last-saviour))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
106 (memq frame (cdr winner-last-saviour)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
107 (ring-remove ring 0))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
108 (ring-insert ring conf)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
109 frame))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
110
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
111 (defvar winner-modified-list nil) ; Which frames have changed?
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
112
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
113 ;; This function is called when the window configuration changes.
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
114 (defun winner-change-fun ()
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
115 (unless (memq (selected-frame) winner-modified-list)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
116 (push (selected-frame) winner-modified-list)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
117
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
118 ;; For Emacs20
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
119 (defun winner-save-new-configurations ()
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
120 (setq winner-last-saviour
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
121 (cons this-command
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
122 (mapcar 'winner-insert-if-new winner-modified-list)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
123 (setq winner-modified-list nil))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
124
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
125 ;; For compatibility with other emacsen.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
126 (defun winner-save-unconditionally ()
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
127 (setq winner-last-saviour
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
128 (cons this-command
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
129 (list (winner-insert-if-new (selected-frame))))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
130
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
131 ;; Arrgh. This is storing the same information twice.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
132 (defun winner-configuration (&optional frame)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
133 (if frame (letf (((selected-frame) frame)) (winner-configuration))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
134 (cons (current-window-configuration)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
135 (loop for w being the windows
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
136 collect (window-buffer w)))))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
137
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
138
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
139 ;; The same as `set-window-configuration',
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
140 ;; but doesn't touch the minibuffer.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
141 (defun winner-set-conf (winconf)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
142 (let ((min-sel (window-minibuffer-p (selected-window)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
143 (minibuf (window-buffer (minibuffer-window)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
144 (minipoint (letf ((selected-window) (minibuffer-window))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
145 (point)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
146 win)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
147 (set-window-configuration winconf)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
148 (setq win (selected-window))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
149 (select-window (minibuffer-window))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
150 (set-window-buffer (minibuffer-window) minibuf)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
151 (goto-char minipoint)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
152 (cond
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
153 (min-sel)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
154 ((window-minibuffer-p win)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
155 (other-window 1))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
156 (t (select-window win)))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
157
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
158 (defun winner-win-data () ; Information about the windows
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
159 (loop for win being the windows
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
160 unless (window-minibuffer-p win)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
161 collect (list (window-buffer win)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
162 (window-width win)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
163 (window-height win))))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
164
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
165 ;; Make sure point doesn't end up in the minibuffer and
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
166 ;; delete windows displaying dead buffers. Return nil
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
167 ;; if and only if all the windows should have been deleted.
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
168 (defun winner-set (conf)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
169 (let ((origpoints
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
170 (save-excursion
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
171 (loop for buf in (cdr conf)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
172 collect (if (buffer-name buf)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
173 (progn (set-buffer buf) (point))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
174 nil)))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
175 (winner-set-conf (car conf))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
176 (let* ((win (selected-window))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
177 (xwins (loop for window being the windows
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
178 for pos in origpoints
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
179 unless (window-minibuffer-p window)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
180 if pos do (progn (select-window window)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
181 (goto-char pos))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
182 else collect window)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
183 (select-window win)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
184 ;; Return t if possible configuration
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
185 (cond
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
186 ((null xwins) t)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
187 ((progn (mapcar 'delete-window (cdr xwins))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
188 (one-window-p t))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
189 nil) ; No existing buffers
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
190 (t (delete-window (car xwins)))))))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
191
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
192
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
193
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
194
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
195 ;;;; Winner mode (a minor mode)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
197 (defcustom winner-mode-hook nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
198 "Functions to run whenever Winner mode is turned on."
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
199 :type 'hook
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
200 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
202 (defcustom winner-mode-leave-hook nil
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
203 "Functions to run whenever Winner mode is turned off."
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
204 :type 'hook
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
205 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (defvar winner-mode-map nil "Keymap for Winner mode.")
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
208
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
209 ;; Is `window-configuration-change-hook' working?
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
210 (defun winner-hook-installed-p ()
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
211 (save-window-excursion
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
212 (let ((winner-var nil)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
213 (window-configuration-change-hook
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
214 '((lambda () (setq winner-var t)))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
215 (split-window)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
216 winner-var)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
217
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
218 ;;;###autoload
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (defun winner-mode (&optional arg)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 "Toggle Winner mode.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 With arg, turn Winner mode on if and only if arg is positive."
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (interactive "P")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (let ((on-p (if arg (> (prefix-numeric-value arg) 0)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (not winner-mode))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (cond
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
226 ;; Turn mode on
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
227 (on-p
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
228 (setq winner-mode t)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
229 (cond
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
230 ((winner-hook-installed-p)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
231 (add-hook 'window-configuration-change-hook 'winner-change-fun)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
232 (add-hook 'post-command-hook 'winner-save-new-configurations))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
233 (t (add-hook 'post-command-hook 'winner-save-unconditionally)))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
234 (setq winner-modified-list (frame-list))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
235 (winner-save-new-configurations)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
236 (run-hooks 'winner-mode-hook))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
237 ;; Turn mode off
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
238 (winner-mode
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
239 (setq winner-mode nil)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
240 (remove-hook 'window-configuration-change-hook 'winner-change-fun)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
241 (remove-hook 'post-command-hook 'winner-save-new-configurations)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
242 (remove-hook 'post-command-hook 'winner-save-unconditionally)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
243 (run-hooks 'winner-mode-leave-hook)))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (force-mode-line-update)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
246 ;; Inspired by undo (simple.el)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
247 (defun winner-undo (arg)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
248 "Switch back to an earlier window configuration saved by Winner mode.
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
249 In other words, \"undo\" changes in window configuration.
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
250 With prefix arg, undo that many levels."
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
251 (interactive "p")
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
252 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
253 ((not winner-mode) (error "Winner mode is turned off"))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
254 ;; ((eq (selected-window) (minibuffer-window))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
255 ;; (error "No winner undo from minibuffer."))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
256 (t (setq this-command t)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
257 (unless (eq last-command 'winner-undo)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
258 (setq winner-pending-undo-ring (winner-ring (selected-frame)))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
259 (setq winner-undo-counter 0)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
260 (setq winner-undone-data (list (winner-win-data))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
261 (incf winner-undo-counter arg)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
262 (winner-undo-this)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
263 (unless (window-minibuffer-p (selected-window))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
264 (message "Winner undo (%d)" winner-undo-counter))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
265 (setq this-command 'winner-undo))))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
267 (defvar winner-pending-undo-ring nil) ; The ring currently used by
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
268 ; undo.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
269 (defvar winner-undo-counter nil)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
270 (defvar winner-undone-data nil) ; There confs have been passed.
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
272 (defun winner-undo-this () ; The heart of winner undo.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
273 (if (>= winner-undo-counter (ring-length winner-pending-undo-ring))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
274 (error "No further window configuration undo information")
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
275 (unless (and
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
276 ;; Possible configuration
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
277 (winner-set
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
278 (ring-ref winner-pending-undo-ring
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
279 winner-undo-counter))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
280 ;; New configuration
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
281 (let ((data (winner-win-data)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
282 (if (member data winner-undone-data) nil
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
283 (push data winner-undone-data))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
284 (ring-remove winner-pending-undo-ring winner-undo-counter)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
285 (winner-undo-this))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
286
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
287 (defun winner-redo () ; If you change your mind.
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
288 "Restore a more recent window configuration saved by Winner mode."
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
289 (interactive)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
290 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
291 ((eq last-command 'winner-undo)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
292 (ring-remove winner-pending-undo-ring 0)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
293 (winner-set
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
294 (ring-remove winner-pending-undo-ring 0))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
295 (or (eq (selected-window) (minibuffer-window))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
296 (message "Winner undid undo")))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
297 (t (error "Previous command was not a winner-undo"))))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
299 ;;;; To be evaluated when the package is loaded:
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
301 (if (fboundp 'compare-window-configurations)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
302 (defalias 'winner-equal 'compare-window-configurations)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
303 (defalias 'winner-equal 'equal))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (unless winner-mode-map
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (setq winner-mode-map (make-sparse-keymap))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
307 (define-key winner-mode-map [(control x) left] 'winner-undo)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
308 (define-key winner-mode-map [(control x) right] 'winner-redo))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (unless (or (assq 'winner-mode minor-mode-map-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 winner-dont-bind-my-keys)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (push (cons 'winner-mode winner-mode-map)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 minor-mode-map-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (unless (assq 'winner-mode minor-mode-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (push '(winner-mode " Win") minor-mode-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (provide 'winner)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
320 ;;; winner.el ends here