annotate lisp/winner.el @ 37120:f863383a5c3e

Minor change.
author Richard M. Stallman <rms@gnu.org>
date Sun, 01 Apr 2001 03:20:52 +0000
parents 2420cf232647
children 63281ffd14fd
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
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
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
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
7 ;; Time-stamp: <1998-08-21 19:51:02 ivarr>
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
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
39 ;; Winner mode was improved august 1998.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
40
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
41 ;;; Code:
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
42
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
43 (eval-when-compile
28023
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
44 (require 'cl))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
28023
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
46 (eval-when-compile
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
47 (cond
25733
b2b3b42a23b3 Use aref instead of sref.
Richard M. Stallman <rms@gnu.org>
parents: 25639
diff changeset
48 ((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
49 (defmacro winner-active-region ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
50 '(region-active-p))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
51 (defsetf winner-active-region () (store)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
52 `(if ,store (zmacs-activate-region)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
53 (zmacs-deactivate-region))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
54 (t (defmacro winner-active-region ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
55 'mark-active)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
56 (defsetf winner-active-region () (store)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
57 `(setq mark-active ,store)))) )
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
58
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
59 (require 'ring)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
61 (when (fboundp 'defgroup)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
62 (defgroup winner nil
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
63 "Restoring window configurations."
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
64 :group 'windows))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
65
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
66 (unless (fboundp 'defcustom)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
67 (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
68 (list 'defvar symbol initvalue docs)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
69
28023
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
70
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
71 ;;;###autoload
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
72 (defcustom winner-mode nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
73 "Toggle winner-mode.
24637
331cca02c844 (winner-mode): Doc fix.
Dave Love <fx@gnu.org>
parents: 24590
diff changeset
74 Setting this variable directly does not take effect;
331cca02c844 (winner-mode): Doc fix.
Dave Love <fx@gnu.org>
parents: 24590
diff changeset
75 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
76 :set #'(lambda (symbol value)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
77 (winner-mode (or value 0)))
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
78 :initialize 'custom-initialize-default
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
79 :type 'boolean
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
80 :group 'winner
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
81 :require 'winner)
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
82
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
83 (defcustom winner-dont-bind-my-keys nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
84 "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
85 :type 'boolean
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
86 :group 'winner)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
87
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
88 (defcustom winner-ring-size 200
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
89 "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
90 :type 'integer
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
91 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
93
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
94
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
96 ;;;; Saving old configurations (internal variables and subroutines)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
97
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
98 ;; This variable is updated with the current window configuration
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
99 ;; after every command, so that when command make changes in the
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
100 ;; window configuration, the last configuration can be saved.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
101 (defvar winner-currents nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
102
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
103 ;; The current configuration (+ the buffers involved).
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
104 (defsubst winner-conf ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
105 (list (current-window-configuration)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
106 (loop for w being the windows
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
107 unless (window-minibuffer-p w)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
108 collect (window-buffer w)) ))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
109 ;; (if winner-testvar (incf winner-testvar) ; For debugging purposes
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
110 ;; (setq winner-testvar 0))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
111
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
112 ;; Save current configuration.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
113 ;; (Called by `winner-save-old-configurations' below).
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
114 (defun winner-remember ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
115 (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
116 (if entry (setcdr entry (winner-conf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
117 (push (cons (selected-frame) (winner-conf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
118 winner-currents))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
119
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
120 ;; Consult `winner-currents'.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
121 (defun winner-configuration (&optional frame)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
122 (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
123 (letf (((selected-frame) frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
124 (winner-conf))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
125
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
126
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
128 ;; This variable contains the window cofiguration rings.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
129 ;; 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
130 (defvar winner-ring-alist nil)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
131
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
132 ;; 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
133 (defsubst winner-ring (frame)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
134 (or (cdr (assq frame winner-ring-alist))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
135 (progn
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
136 (let ((ring (make-ring winner-ring-size)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
137 (ring-insert ring (winner-configuration frame))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
138 (push (cons frame ring) winner-ring-alist)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
139 ring))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
140
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
141 ;; 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
142 ;; we only save one window configuration.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
143 (defvar winner-last-command nil)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
144
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
145 ;; Frames affected by the previous command.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
146 (defvar winner-last-frames nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
147
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
148 ;; Save the current window configuration, if it has changed.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
149 ;; Then return frame, else return nil.
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
150 (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
151 (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
152 (eq this-command 'winner-redo))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
153 (let ((conf (winner-configuration frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
154 (ring (winner-ring frame)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
155 (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
156 (winner-equal conf (ring-ref ring 0)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
157 (ring-remove ring 0))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
158 (ring-insert ring conf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
159 (push frame winner-last-frames)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
160 frame)))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
161
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
162 ;; Frames affected by the current command.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
163 (defvar winner-modified-list nil)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
164
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
165 ;; Called whenever the window configuration changes
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
166 ;; (a `window-configuration-change-hook').
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
167 (defun winner-change-fun ()
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
168 (unless (memq (selected-frame) winner-modified-list)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
169 (push (selected-frame) winner-modified-list)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
170
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
171
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
172 ;; For Emacs20 (a `post-command-hook').
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
173 (defun winner-save-old-configurations ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
174 (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
175 (setq winner-last-frames nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
176 (setq winner-last-command this-command))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
177 (dolist (frame winner-modified-list)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
178 (winner-insert-if-new frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
179 (setq winner-modified-list nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
180 ;; (ir-trace ; For debugging purposes
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
181 ;; "%S"
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
182 ;; (loop with ring = (winner-ring (selected-frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
183 ;; for i from 0 to (1- (ring-length ring))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
184 ;; collect (caddr (ring-ref ring i))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
185 (winner-remember))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
186
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
187 ;; For compatibility with other emacsen
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
188 ;; and called by `winner-undo' before "undoing".
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
189 (defun winner-save-unconditionally ()
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
190 (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
191 (setq winner-last-frames nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
192 (setq winner-last-command this-command))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
193 (winner-insert-if-new (selected-frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
194 (winner-remember))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
195
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
196
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
197
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
198
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
199 ;;;; Restoring configurations
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
200
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
201 ;; Works almost as `set-window-configuration',
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
202 ;; but doesn't change the contents or the size of the minibuffer.
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
203 (defun winner-set-conf (winconf)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
204 (let ((miniwin (minibuffer-window))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
205 (minisel (window-minibuffer-p (selected-window))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
206 (let ((minibuf (window-buffer miniwin))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
207 (minipoint (window-point miniwin))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
208 (minisize (window-height miniwin)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
209 (set-window-configuration winconf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
210 (setf (window-buffer miniwin) minibuf
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
211 (window-point miniwin) minipoint)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
212 (when (/= minisize (window-height miniwin))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
213 (letf (((selected-window) miniwin) )
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
214 ;; Clumsy due to cl-macs-limitation
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
215 (setf (window-height) minisize)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
216 (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
217 (minisel (select-window miniwin))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
218 ((window-minibuffer-p (selected-window))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
219 (other-window 1))))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
220
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
221
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
222 (defvar winner-point-alist nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
223 ;; `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
224 ;; 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
225 ;; and marks before undoing window configurations.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
226 ;;
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
227 ;; 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
228
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
229 (defun winner-make-point-alist ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
230 (letf (((current-buffer)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
231 (loop with alist
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
232 with entry
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
233 for win being the windows
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
234 do (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
235 ((window-minibuffer-p win))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
236 ((setq entry (assq win alist))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
237 ;; Update existing entry
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
238 (push (cons win (window-point win))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
239 (cddr entry)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
240 (t;; Else create new entry
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
241 (push (list (set-buffer (window-buffer win))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
242 (cons (mark t) (winner-active-region))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
243 (cons win (window-point win)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
244 alist)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
245 finally return alist)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
246
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
247
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
248 (defun winner-get-point (buf win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
249 ;; Consult (and possibly extend) `winner-point-alist'.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
250 (when (buffer-name buf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
251 (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
252 (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
253 (entry
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
254 (or (cdr (assq win (cddr entry)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
255 (cdr (assq nil (cddr entry)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
256 (letf (((current-buffer) buf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
257 (push (cons nil (point)) (cddr entry))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
258 (point))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
259 (t (letf (((current-buffer) buf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
260 (push (list buf
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
261 (cons (mark t) (winner-active-region))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
262 (cons nil (point)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
263 winner-point-alist)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
264 (point)))))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
265
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
266 ;; Make sure point doesn't end up in the minibuffer and
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
267 ;; delete windows displaying dead buffers. Return nil
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
268 ;; if and only if all the windows should have been deleted.
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
269 ;; Do not move neither points nor marks.
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
270 (defun winner-set (conf)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
271 (let* ((buffers nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
272 (origpoints
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
273 (loop for buf in (cadr conf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
274 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
275 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
276 do (push buf buffers)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
277 collect pos)))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
278 (winner-set-conf (car conf))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
279 (let (xwins) ; These windows should be deleted
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
280 (loop for win being the windows
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
281 unless (window-minibuffer-p win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
282 do (if (pop origpoints)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
283 (setf (window-point win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
284 ;; Restore point
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
285 (winner-get-point
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
286 (window-buffer win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
287 win))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
288 (push win xwins))) ; delete this window
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
289 ;; Restore mark
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
290 (letf (((current-buffer)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
291 (loop for buf in buffers
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
292 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
293 do (progn (set-buffer buf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
294 (set-mark (car entry))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
295 (setf (winner-active-region) (cdr entry)))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
296 ;; Delete windows, whose buffers are dead.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
297 ;; 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
298 (or (null xwins)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
299 (progn (mapcar 'delete-window (cdr xwins))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
300 (if (one-window-p t)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
301 nil ; No windows left
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
302 (progn (delete-window (car xwins))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
303 t)))))))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
304
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
305
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
306
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
307 ;;;; Winner mode (a minor mode)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
309 (defcustom winner-mode-hook nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
310 "Functions to run whenever Winner mode is turned on."
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
311 :type 'hook
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
312 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
314 (defcustom winner-mode-leave-hook nil
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
315 "Functions to run whenever Winner mode is turned off."
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
316 :type 'hook
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
317 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (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
320
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
321 ;; Is `window-configuration-change-hook' working?
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
322 (defun winner-hook-installed-p ()
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
323 (save-window-excursion
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
324 (let ((winner-var nil)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
325 (window-configuration-change-hook
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
326 '((lambda () (setq winner-var t)))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
327 (split-window)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
328 winner-var)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
329
28023
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
330
3978c673322b Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents: 25733
diff changeset
331 ;;;###autoload
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (defun winner-mode (&optional arg)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 "Toggle Winner mode.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 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
335 (interactive "P")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (let ((on-p (if arg (> (prefix-numeric-value arg) 0)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (not winner-mode))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (cond
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
339 ;; Turn mode on
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
340 (on-p
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
341 (setq winner-mode t)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
342 (cond
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
343 ((winner-hook-installed-p)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
344 (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
345 (add-hook 'post-command-hook 'winner-save-old-configurations))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
346 (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
347 (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
348 (winner-save-old-configurations)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
349 (run-hooks 'winner-mode-hook))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
350 ;; Turn mode off
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
351 (winner-mode
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
352 (setq winner-mode nil)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
353 (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
354 (remove-hook 'post-command-hook 'winner-save-old-configurations)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
355 (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
356 (run-hooks 'winner-mode-leave-hook)))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (force-mode-line-update)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
359 ;; Inspired by undo (simple.el)
24590
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
360
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
361 (defvar winner-undo-frame nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
362
24590
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
363 (defvar winner-pending-undo-ring nil
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
364 "The ring currently used by winner undo.")
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
365 (defvar winner-undo-counter nil)
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
366 (defvar winner-undone-data nil) ; There confs have been passed.
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
367
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
368 (defun winner-undo ()
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
369 "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
370 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
371 (interactive)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
372 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
373 ((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
374 (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
375 (eq winner-undo-frame (selected-frame)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
376 (winner-save-unconditionally) ; current configuration->stack
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
377 (setq winner-undo-frame (selected-frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
378 (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
379 (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
380 (setq winner-undo-counter 0)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
381 (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
382 (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
383 (when (and (winner-undo-this)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
384 (not (window-minibuffer-p (selected-window))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
385 (message "Winner undo (%d / %d)"
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
386 winner-undo-counter
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
387 (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
388
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
389 (defun winner-win-data ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
390 ;; Essential properties of the windows in the selected frame.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
391 (loop for win being the windows
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
392 unless (window-minibuffer-p win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
393 collect (list (window-buffer win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
394 (window-width win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
395 (window-height win))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
396
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
397
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
398 (defun winner-undo-this () ; The heart of winner undo.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
399 (loop
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
400 (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
401 ((>= 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
402 (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
403 (return nil))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
404
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
405 ((and ; If possible configuration
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
406 (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
407 winner-undo-counter))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
408 ;; .. and new configuration
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
409 (let ((data (winner-win-data)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
410 (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
411 (push data winner-undone-data))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
412 (return t)) ; .. then everything is all right.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
413 (t ; Else; discharge it and try another one.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
414 (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
415
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
417 (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
418 "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
419 (interactive)
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 ((eq last-command 'winner-undo)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
422 (winner-set
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
423 (ring-remove winner-pending-undo-ring 0))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
424 (unless (eq (selected-window) (minibuffer-window))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
425 (message "Winner undid undo")))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
426 (t (error "Previous command was not a winner-undo"))))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
427
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
428 ;;; To be evaluated when the package is loaded:
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
430 (if (fboundp 'compare-window-configurations)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
431 (defalias 'winner-equal 'compare-window-configurations)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
432 (defalias 'winner-equal 'equal))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (unless winner-mode-map
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (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
436 (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
437 (define-key winner-mode-map [(control x) right] 'winner-redo))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (unless (or (assq 'winner-mode minor-mode-map-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 winner-dont-bind-my-keys)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (push (cons 'winner-mode winner-mode-map)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 minor-mode-map-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (unless (assq 'winner-mode minor-mode-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (push '(winner-mode " Win") minor-mode-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (provide 'winner)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
449 ;;; winner.el ends here