annotate lisp/winner.el @ 43556:9e4a1be87f8c

(winner-boring-buffers, winner-set): A window which displays a buffer whose name is in the list `winner-boring-buffers' will no longer be restored by `winner-undo'. (winner-sorted-window-list): Used to improve comparison between window configurations. (winner-win-data): Simplified and moved. (winner-conf): Simplified (now uses `winner-win-data'). (winner-change-fun, winner-save-old-configurations) (winner-save-(un)conditionally, winner-redo): Changes made while in the minibuffer will be ignored. (Such changes are undone upon exit for the minibuffer, anyway.) (winner-set-conf): Preserve selected window whenever possible. (winner-make-point-alist): Simplified. (winner-mode, winner-save-unconditionally): Save current window configuration on entering minibuffer. (minor-mode-alist): Don't add winner-mode to `minor-mode-alist', since it does not change the overall behavior of Emacs.
author Richard M. Stallman <rms@gnu.org>
date Tue, 26 Feb 2002 16:08:29 +0000
parents 63281ffd14fd
children ee08f1e3d269
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
1 ;;; winner.el --- Restore old window configurations
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
38334
63281ffd14fd (winner-equal): Make it a defun. Don't compare Winner
Gerd Moellmann <gerd@gnu.org>
parents: 28071
diff changeset
3 ;; Copyright (C) 1997, 1998, 2001 Free Software Foundation. Inc.
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
28071
2420cf232647 Update maintainer address.
Dave Love <fx@gnu.org>
parents: 28023
diff changeset
5 ;; Author: Ivar Rummelhoff <ivarru@math.uio.no>
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Created: 27 Feb 1997
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
7 ;; Time-stamp: <2002-02-20 22:06:58 ivarru>
28023
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
8 ;; Keywords: convenience frames
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
10 ;; This file is part of GNU Emacs.
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
11
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
12 ;; 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
13 ;; 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
14 ;; the Free Software Foundation; either version 2, or (at your option)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
17 ;; 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
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; 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
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
28
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
29 ;; 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
30 ;; window configuration (i.e. how the frames are partitioned into
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
31 ;; windows) so that the changes can be "undone" using the command
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
32 ;; `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
33 ;; 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
34 ;; 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
35 ;; 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
36 ;; 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
37 ;; custom is not obsolete.
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
39 ;; Winner mode was improved August 1998.
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
40 ;; Further improvements February 2002.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
41
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
42 ;;; Code:
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
43
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
44 (eval-when-compile
28023
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
45 (require 'cl))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
28023
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
47 (eval-when-compile
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
48 (cond
25733
b2b3b42a23b3 Use aref instead of sref.
Richard M. Stallman <rms@gnu.org>
parents: 25639
diff changeset
49 ((eq (aref (emacs-version) 0) ?X)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
50 (defmacro winner-active-region ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
51 '(region-active-p))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
52 (defsetf winner-active-region () (store)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
53 `(if ,store (zmacs-activate-region)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
54 (zmacs-deactivate-region))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
55 (t (defmacro winner-active-region ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
56 'mark-active)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
57 (defsetf winner-active-region () (store)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
58 `(setq mark-active ,store)))) )
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
59
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
60 (eval-and-compile
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
61 (cond
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
62 ((eq (aref (emacs-version) 0) ?X)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
63 (defalias 'winner-edges 'window-pixel-edges)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
64 (defsubst winner-window-list ()
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
65 (remq (minibuffer-window)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
66 (window-list nil 0))))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
67 (t (defalias 'winner-edges 'window-edges)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
68 (defsubst winner-window-list ()
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
69 (window-list nil 0)))) )
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
70
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
71 (require 'ring)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
73 (when (fboundp 'defgroup)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
74 (defgroup winner nil
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
75 "Restoring window configurations."
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
76 :group 'windows))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
77
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
78 (unless (fboundp 'defcustom)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
79 (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
80 (list 'defvar symbol initvalue docs)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
81
28023
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
82 ;;;###autoload
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
83 (defcustom winner-mode nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
84 "Toggle winner-mode.
24637
331cca02c844 (winner-mode): Doc fix.
Dave Love <fx@gnu.org>
parents: 24590
diff changeset
85 Setting this variable directly does not take effect;
331cca02c844 (winner-mode): Doc fix.
Dave Love <fx@gnu.org>
parents: 24590
diff changeset
86 use either \\[customize] or the function `winner-mode'."
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
87 :set #'(lambda (symbol value)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
88 (winner-mode (or value 0)))
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
89 :initialize 'custom-initialize-default
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
90 :type 'boolean
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
91 :group 'winner
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
92 :require 'winner)
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
93
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
94 (defcustom winner-dont-bind-my-keys nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
95 "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
96 :type 'boolean
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
97 :group 'winner)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
98
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
99 (defcustom winner-ring-size 200
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
100 "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
101 :type 'integer
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
102 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
104 (defcustom winner-boring-buffers '("*Completions*")
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
105 "`winner-undo' will not restore windows displaying any of these \
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
106 buffers.
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
107 You may want to include buffer names such as *Help*, *Apropos*,
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
108 *Buffer List*, *info* and *Compile-Log*."
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
109 :type '(repeat string)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
110 :group 'winner)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
111
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
112
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
113
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
115 ;;;; Saving old configurations (internal variables and subroutines)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
116
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
117
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
118 ;;; Current configuration
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
119
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
120 ;; List the windows according to their edges.
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
121 (defun winner-sorted-window-list ()
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
122 (sort (winner-window-list)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
123 (lambda (x y)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
124 (loop for a in (winner-edges x)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
125 for b in (winner-edges y)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
126 while (= a b)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
127 finally return (< a b)))))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
128
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
129 (defun winner-win-data ()
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
130 ;; Essential properties of the windows in the selected frame.
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
131 (loop for win in (winner-sorted-window-list)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
132 collect (cons (winner-edges win) (window-buffer win))))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
133
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
134 ;; This variable is updated with the current window configuration
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
135 ;; every time it changes.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
136 (defvar winner-currents nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
137
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
138 ;; The current configuration (+ the buffers involved).
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
139 (defsubst winner-conf ()
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
140 (cons (current-window-configuration)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
141 (winner-win-data)))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
142
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
143
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
144 ;; Save current configuration.
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
145 ;; (Called below by `winner-save-old-configurations').
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
146 (defun winner-remember ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
147 (let ((entry (assq (selected-frame) winner-currents)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
148 (if entry (setcdr entry (winner-conf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
149 (push (cons (selected-frame) (winner-conf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
150 winner-currents))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
151
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
152 ;; Consult `winner-currents'.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
153 (defun winner-configuration (&optional frame)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
154 (or (cdr (assq (or frame (selected-frame)) winner-currents))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
155 (letf (((selected-frame) frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
156 (winner-conf))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
157
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
158
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
160 ;;; Saved configurations
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
161
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
162 ;; This variable contains the window cofiguration rings.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
163 ;; 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
164 (defvar winner-ring-alist nil)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
165
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
166 ;; 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
167 (defsubst winner-ring (frame)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
168 (or (cdr (assq frame winner-ring-alist))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
169 (progn
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
170 (let ((ring (make-ring winner-ring-size)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
171 (ring-insert ring (winner-configuration frame))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
172 (push (cons frame ring) winner-ring-alist)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
173 ring))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
174
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
175 ;; If the same command is called several times in a row,
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
176 ;; we only save one window configuration.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
177 (defvar winner-last-command nil)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
178
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
179 ;; Frames affected by the previous command.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
180 (defvar winner-last-frames nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
181
38334
63281ffd14fd (winner-equal): Make it a defun. Don't compare Winner
Gerd Moellmann <gerd@gnu.org>
parents: 28071
diff changeset
182
63281ffd14fd (winner-equal): Make it a defun. Don't compare Winner
Gerd Moellmann <gerd@gnu.org>
parents: 28071
diff changeset
183 (defun winner-equal (a b)
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
184 "Check whether two Winner configurations (as produced by
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
185 `winner-conf') are equal."
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
186 (equal (cdr a) (cdr b)))
38334
63281ffd14fd (winner-equal): Make it a defun. Don't compare Winner
Gerd Moellmann <gerd@gnu.org>
parents: 28071
diff changeset
187
63281ffd14fd (winner-equal): Make it a defun. Don't compare Winner
Gerd Moellmann <gerd@gnu.org>
parents: 28071
diff changeset
188
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
189 ;; Save the current window configuration, if it has changed.
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
190 ;; If so return frame, otherwise return nil.
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
191 (defun winner-insert-if-new (frame)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
192 (unless (or (memq frame winner-last-frames)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
193 (eq this-command 'winner-redo))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
194 (let ((conf (winner-configuration frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
195 (ring (winner-ring frame)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
196 (when (and (not (ring-empty-p ring))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
197 (winner-equal conf (ring-ref ring 0)))
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
198 ;; When the previous configuration was very similar,
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
199 ;; keep only the latest.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
200 (ring-remove ring 0))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
201 (ring-insert ring conf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
202 (push frame winner-last-frames)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
203 frame)))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
204
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
205
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
206
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
207 ;;; Hooks
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
208
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
209 ;; Frames affected by the current command.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
210 (defvar winner-modified-list nil)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
211
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
212 ;; Called whenever the window configuration changes
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
213 ;; (a `window-configuration-change-hook').
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
214 (defun winner-change-fun ()
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
215 (unless (or (memq (selected-frame) winner-modified-list)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
216 (/= 0 (minibuffer-depth)))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
217 (push (selected-frame) winner-modified-list)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
218
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
219 ;; A `post-command-hook' for emacsen with
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
220 ;; `window-configuration-change-hook'.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
221 (defun winner-save-old-configurations ()
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
222 (when (zerop (minibuffer-depth))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
223 (unless (eq this-command winner-last-command)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
224 (setq winner-last-frames nil)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
225 (setq winner-last-command this-command))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
226 (dolist (frame winner-modified-list)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
227 (winner-insert-if-new frame))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
228 (setq winner-modified-list nil)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
229 (winner-remember)))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
230
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
231 ;; A `minibuffer-setup-hook'.
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
232 (defun winner-save-unconditionally ()
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
233 (unless (eq this-command winner-last-command)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
234 (setq winner-last-frames nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
235 (setq winner-last-command this-command))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
236 (winner-insert-if-new (selected-frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
237 (winner-remember))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
238
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
239 ;; A `post-command-hook' for other emacsen.
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
240 ;; Also called by `winner-undo' before "undoing".
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
241 (defun winner-save-conditionally ()
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
242 (when (zerop (minibuffer-depth))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
243 (winner-save-unconditionally)))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
244
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
245
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
246
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
247 ;;;; Restoring configurations
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
248
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
249 ;; Works almost as `set-window-configuration',
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
250 ;; but does not change the contents or the size of the minibuffer,
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
251 ;; and tries to preserve the selected window.
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
252 (defun winner-set-conf (winconf)
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
253 (let* ((miniwin (minibuffer-window))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
254 (chosen (selected-window))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
255 (minisize (window-height miniwin)))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
256 (letf (((window-buffer miniwin))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
257 ((window-point miniwin)))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
258 (set-window-configuration winconf))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
259 (cond
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
260 ((window-live-p chosen) (select-window chosen))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
261 ((window-minibuffer-p (selected-window))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
262 (other-window 1)))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
263 (when (/= minisize (window-height miniwin))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
264 (letf (((selected-window) miniwin) )
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
265 (setf (window-height) minisize)))))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
266
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
267
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
268
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
269 (defvar winner-point-alist nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
270 ;; `set-window-configuration' restores old points and marks. This is
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
271 ;; not what we want, so we make a list of the "real" (i.e. new) points
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
272 ;; and marks before undoing window configurations.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
273 ;;
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
274 ;; Format of entries: (buffer (mark . mark-active) (window . point) ..)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
275
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
276 (defun winner-make-point-alist ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
277 (letf (((current-buffer)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
278 (loop with alist
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
279 for win in (winner-window-list)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
280 for entry =
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
281 (or (assq (window-buffer win) alist)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
282 (car (push (list (set-buffer (window-buffer win))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
283 (cons (mark t) (winner-active-region)))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
284 alist)))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
285 do (push (cons win (window-point win))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
286 (cddr entry))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
287 finally return alist)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
288
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
289 (defun winner-get-point (buf win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
290 ;; Consult (and possibly extend) `winner-point-alist'.
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
291 ;; Returns nil iff buf no longer exists.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
292 (when (buffer-name buf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
293 (let ((entry (assq buf winner-point-alist)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
294 (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
295 (entry
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
296 (or (cdr (assq win (cddr entry)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
297 (cdr (assq nil (cddr entry)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
298 (letf (((current-buffer) buf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
299 (push (cons nil (point)) (cddr entry))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
300 (point))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
301 (t (letf (((current-buffer) buf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
302 (push (list buf
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
303 (cons (mark t) (winner-active-region))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
304 (cons nil (point)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
305 winner-point-alist)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
306 (point)))))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
307
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
308 ;; Make sure point does not end up in the minibuffer and delete
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
309 ;; windows displaying dead or boring buffers
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
310 ;; (c.f. `winner-boring-buffers'). Return nil iff all the windows
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
311 ;; should be deleted. Preserve correct points and marks.
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
312 (defun winner-set (conf)
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
313 ;; For the format of `conf', see `winner-conf'.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
314 (let* ((buffers nil)
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
315 (alive
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
316 ;; Possibly update `winner-point-alist'
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
317 (loop for buf in (mapcar 'cdr (cdr conf))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
318 for pos = (winner-get-point buf nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
319 if (and pos (not (memq buf buffers)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
320 do (push buf buffers)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
321 collect pos)))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
322 (winner-set-conf (car conf))
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
323 (let (xwins) ; to be deleted
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
324
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
325 ;; Restore points
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
326 (dolist (win (winner-sorted-window-list))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
327 (unless (and (pop alive)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
328 (setf (window-point win)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
329 (winner-get-point (window-buffer win) win))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
330 (not (member (buffer-name (window-buffer win))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
331 winner-boring-buffers)))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
332 (push win xwins))) ; delete this window
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
333
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
334 ;; Restore marks
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
335 (letf (((current-buffer)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
336 (loop for buf in buffers
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
337 for entry = (cadr (assq buf winner-point-alist))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
338 do (progn (set-buffer buf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
339 (set-mark (car entry))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
340 (setf (winner-active-region) (cdr entry)))))
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
341 ;; Delete windows, whose buffers are dead or boring.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
342 ;; Return t if this is still a possible configuration.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
343 (or (null xwins)
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
344 (progn
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
345 (mapc 'delete-window (cdr xwins)) ; delete all but one
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
346 (unless (one-window-p t)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
347 (delete-window (car xwins))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
348 t))))))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
349
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
350
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
351
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
352 ;;;; Winner mode (a minor mode)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
354 (defcustom winner-mode-hook nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
355 "Functions to run whenever Winner mode is turned on."
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
356 :type 'hook
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
357 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
359 (defcustom winner-mode-leave-hook nil
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
360 "Functions to run whenever Winner mode is turned off."
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
361 :type 'hook
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
362 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (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
365
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
366 ;; Check if `window-configuration-change-hook' is working.
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
367 (defun winner-hook-installed-p ()
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
368 (save-window-excursion
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
369 (let ((winner-var nil)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
370 (window-configuration-change-hook
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
371 '((lambda () (setq winner-var t)))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
372 (split-window)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
373 winner-var)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
374
28023
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
375
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
376 ;;;###autoload
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (defun winner-mode (&optional arg)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 "Toggle Winner mode.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 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
380 (interactive "P")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (let ((on-p (if arg (> (prefix-numeric-value arg) 0)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (not winner-mode))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (cond
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
384 ;; Turn mode on
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
385 (on-p
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
386 (setq winner-mode t)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
387 (cond
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
388 ((winner-hook-installed-p)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
389 (add-hook 'window-configuration-change-hook 'winner-change-fun)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
390 (add-hook 'post-command-hook 'winner-save-old-configurations))
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
391 (t (add-hook 'post-command-hook 'winner-save-conditionally)))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
392 (add-hook 'minibuffer-setup-hook 'winner-save-unconditionally)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
393 (setq winner-modified-list (frame-list))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
394 (winner-save-old-configurations)
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
395 (run-hooks 'winner-mode-hook)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
396 (when (interactive-p) (message "Winner mode enabled")))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
397 ;; Turn mode off
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
398 (winner-mode
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
399 (setq winner-mode nil)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
400 (remove-hook 'window-configuration-change-hook 'winner-change-fun)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
401 (remove-hook 'post-command-hook 'winner-save-old-configurations)
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
402 (remove-hook 'post-command-hook 'winner-save-conditionally)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
403 (remove-hook 'minibuffer-setup-hook 'winner-save-unconditionally)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
404 (run-hooks 'winner-mode-leave-hook)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
405 (when (interactive-p) (message "Winner mode disabled"))))))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
407 ;; Inspired by undo (simple.el)
24590
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
408
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
409 (defvar winner-undo-frame nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
410
24590
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
411 (defvar winner-pending-undo-ring nil
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
412 "The ring currently used by winner undo.")
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
413 (defvar winner-undo-counter nil)
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
414 (defvar winner-undone-data nil) ; There confs have been passed.
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
415
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
416 (defun winner-undo ()
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
417 "Switch back to an earlier window configuration saved by Winner mode.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
418 In other words, \"undo\" changes in window configuration."
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
419 (interactive)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
420 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
421 ((not winner-mode) (error "Winner mode is turned off"))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
422 (t (unless (and (eq last-command 'winner-undo)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
423 (eq winner-undo-frame (selected-frame)))
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
424 (winner-save-conditionally) ; current configuration->stack
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
425 (setq winner-undo-frame (selected-frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
426 (setq winner-point-alist (winner-make-point-alist))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
427 (setq winner-pending-undo-ring (winner-ring (selected-frame)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
428 (setq winner-undo-counter 0)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
429 (setq winner-undone-data (list (winner-win-data))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
430 (incf winner-undo-counter) ; starting at 1
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
431 (when (and (winner-undo-this)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
432 (not (window-minibuffer-p (selected-window))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
433 (message "Winner undo (%d / %d)"
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
434 winner-undo-counter
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
435 (1- (ring-length winner-pending-undo-ring)))))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
436
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
437
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
438
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
439 (defun winner-undo-this () ; The heart of winner undo.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
440 (loop
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
441 (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
442 ((>= winner-undo-counter (ring-length winner-pending-undo-ring))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
443 (message "No further window configuration undo information")
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
444 (return nil))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
445
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
446 ((and ; If possible configuration
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
447 (winner-set (ring-ref winner-pending-undo-ring
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
448 winner-undo-counter))
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
449 ; .. and new configuration
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
450 (let ((data (winner-win-data)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
451 (and (not (member data winner-undone-data))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
452 (push data winner-undone-data))))
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
453 (return t)) ; .. then everything is fine.
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
454 (t ;; Otherwise, discharge it (and try the next one).
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
455 (ring-remove winner-pending-undo-ring winner-undo-counter)))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
456
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
458 (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
459 "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
460 (interactive)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
461 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
462 ((eq last-command 'winner-undo)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
463 (winner-set
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
464 (if (zerop (minibuffer-depth))
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
465 (ring-remove winner-pending-undo-ring 0)
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
466 (ring-ref winner-pending-undo-ring 0)))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
467 (unless (eq (selected-window) (minibuffer-window))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
468 (message "Winner undid undo")))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
469 (t (error "Previous command was not a winner-undo"))))
43556
9e4a1be87f8c (winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents: 38334
diff changeset
470
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
471 ;;; To be evaluated when the package is loaded:
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (unless winner-mode-map
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (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
475 (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
476 (define-key winner-mode-map [(control x) right] 'winner-redo))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (unless (or (assq 'winner-mode minor-mode-map-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 winner-dont-bind-my-keys)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (push (cons 'winner-mode winner-mode-map)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 minor-mode-map-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (provide 'winner)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
485 ;;; winner.el ends here