annotate lisp/winner.el @ 25863:4a31721836b5

#
author Dave Love <fx@gnu.org>
date Mon, 04 Oct 1999 15:35:04 +0000
parents b2b3b42a23b3
children 3978c673322b
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
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Ivar Rummelhoff <ivarr@ifi.uio.no>
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Maintainer: Ivar Rummelhoff <ivarr@ifi.uio.no>
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: 27 Feb 1997
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
8 ;; Time-stamp: <1998-08-21 19:51:02 ivarr>
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
9 ;; Keywords: windows
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
11 ;; This file is part of GNU Emacs.
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
12
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; any later version.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
29
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
30 ;; Winner mode is a global minor mode that records the changes in the
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
31 ;; window configuration (i.e. how the frames are partitioned into
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
32 ;; 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
33 ;; `winner-undo'. By default this one is bound to the key sequence
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
34 ;; ctrl-x left. If you change your mind (while undoing), you can
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
35 ;; press ctrl-x right (calling `winner-redo'). Even though it uses
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
36 ;; some features of Emacs20.3, winner.el should also work with
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
37 ;; Emacs19.34 and XEmacs20, provided that the installed version of
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
38 ;; custom is not obsolete.
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
40 ;; Winner mode was improved august 1998.
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
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
45 (require 'cl)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
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
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
70 ;;;###autoload
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
71 (defcustom winner-mode nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
72 "Toggle winner-mode.
24637
331cca02c844 (winner-mode): Doc fix.
Dave Love <fx@gnu.org>
parents: 24590
diff changeset
73 Setting this variable directly does not take effect;
331cca02c844 (winner-mode): Doc fix.
Dave Love <fx@gnu.org>
parents: 24590
diff changeset
74 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
75 :set #'(lambda (symbol value)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
76 (winner-mode (or value 0)))
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
77 :initialize 'custom-initialize-default
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
78 :type 'boolean
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
79 :group 'winner
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
80 :require 'winner)
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
81
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
82 (defcustom winner-dont-bind-my-keys nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
83 "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
84 :type 'boolean
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
85 :group 'winner)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
86
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
87 (defcustom winner-ring-size 200
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
88 "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
89 :type 'integer
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
90 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
92
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
93
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
95 ;;;; 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
96
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
97 ;; 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
98 ;; 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
99 ;; 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
100 (defvar winner-currents nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
101
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
102 ;; The current configuration (+ the buffers involved).
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
103 (defsubst winner-conf ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
104 (list (current-window-configuration)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
105 (loop for w being the windows
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
106 unless (window-minibuffer-p w)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
107 collect (window-buffer w)) ))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
108 ;; (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
109 ;; (setq winner-testvar 0))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
110
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
111 ;; Save current configuration.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
112 ;; (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
113 (defun winner-remember ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
114 (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
115 (if entry (setcdr entry (winner-conf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
116 (push (cons (selected-frame) (winner-conf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
117 winner-currents))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
118
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
119 ;; Consult `winner-currents'.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
120 (defun winner-configuration (&optional frame)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
121 (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
122 (letf (((selected-frame) frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
123 (winner-conf))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
124
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
125
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
127 ;; This variable contains the window cofiguration rings.
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
128 ;; 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
129 (defvar winner-ring-alist nil)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
130
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
131 ;; 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
132 (defsubst winner-ring (frame)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
133 (or (cdr (assq frame winner-ring-alist))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
134 (progn
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
135 (let ((ring (make-ring winner-ring-size)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
136 (ring-insert ring (winner-configuration frame))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
137 (push (cons frame ring) winner-ring-alist)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
138 ring))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
139
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
140 ;; 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
141 ;; we only save one window configuration.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
142 (defvar winner-last-command nil)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
143
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
144 ;; Frames affected by the previous command.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
145 (defvar winner-last-frames nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
146
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
147 ;; 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
148 ;; Then return frame, else return nil.
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
149 (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
150 (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
151 (eq this-command 'winner-redo))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
152 (let ((conf (winner-configuration frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
153 (ring (winner-ring frame)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
154 (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
155 (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
156 (ring-remove ring 0))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
157 (ring-insert ring conf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
158 (push frame winner-last-frames)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
159 frame)))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
160
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
161 ;; Frames affected by the current command.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
162 (defvar winner-modified-list nil)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
163
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
164 ;; Called whenever the window configuration changes
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
165 ;; (a `window-configuration-change-hook').
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
166 (defun winner-change-fun ()
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
167 (unless (memq (selected-frame) winner-modified-list)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
168 (push (selected-frame) winner-modified-list)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
169
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
170
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
171 ;; For Emacs20 (a `post-command-hook').
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
172 (defun winner-save-old-configurations ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
173 (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
174 (setq winner-last-frames nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
175 (setq winner-last-command this-command))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
176 (dolist (frame winner-modified-list)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
177 (winner-insert-if-new frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
178 (setq winner-modified-list nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
179 ;; (ir-trace ; For debugging purposes
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
180 ;; "%S"
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
181 ;; (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
182 ;; 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
183 ;; collect (caddr (ring-ref ring i))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
184 (winner-remember))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
185
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
186 ;; For compatibility with other emacsen
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
187 ;; 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
188 (defun winner-save-unconditionally ()
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
189 (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
190 (setq winner-last-frames nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
191 (setq winner-last-command this-command))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
192 (winner-insert-if-new (selected-frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
193 (winner-remember))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
194
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
195
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
196
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
197
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
198 ;;;; Restoring configurations
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
199
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
200 ;; Works almost as `set-window-configuration',
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
201 ;; 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
202 (defun winner-set-conf (winconf)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
203 (let ((miniwin (minibuffer-window))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
204 (minisel (window-minibuffer-p (selected-window))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
205 (let ((minibuf (window-buffer miniwin))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
206 (minipoint (window-point miniwin))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
207 (minisize (window-height miniwin)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
208 (set-window-configuration winconf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
209 (setf (window-buffer miniwin) minibuf
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
210 (window-point miniwin) minipoint)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
211 (when (/= minisize (window-height miniwin))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
212 (letf (((selected-window) miniwin) )
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
213 ;; Clumsy due to cl-macs-limitation
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
214 (setf (window-height) minisize)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
215 (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
216 (minisel (select-window miniwin))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
217 ((window-minibuffer-p (selected-window))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
218 (other-window 1))))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
219
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 (defvar winner-point-alist nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
222 ;; `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
223 ;; 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
224 ;; and marks before undoing window configurations.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
225 ;;
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
226 ;; 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
227
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
228 (defun winner-make-point-alist ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
229 (letf (((current-buffer)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
230 (loop with alist
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
231 with entry
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
232 for win being the windows
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
233 do (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
234 ((window-minibuffer-p win))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
235 ((setq entry (assq win alist))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
236 ;; Update existing entry
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
237 (push (cons win (window-point win))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
238 (cddr entry)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
239 (t;; Else create new entry
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
240 (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
241 (cons (mark t) (winner-active-region))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
242 (cons win (window-point win)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
243 alist)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
244 finally return alist)))
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 (defun winner-get-point (buf win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
248 ;; 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
249 (when (buffer-name buf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
250 (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
251 (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
252 (entry
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
253 (or (cdr (assq win (cddr entry)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
254 (cdr (assq nil (cddr entry)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
255 (letf (((current-buffer) buf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
256 (push (cons nil (point)) (cddr entry))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
257 (point))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
258 (t (letf (((current-buffer) buf))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
259 (push (list buf
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
260 (cons (mark t) (winner-active-region))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
261 (cons nil (point)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
262 winner-point-alist)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
263 (point)))))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
264
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
265 ;; 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
266 ;; delete windows displaying dead buffers. Return nil
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
267 ;; 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
268 ;; Do not move neither points nor marks.
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
269 (defun winner-set (conf)
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
270 (let* ((buffers nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
271 (origpoints
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
272 (loop for buf in (cadr conf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
273 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
274 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
275 do (push buf buffers)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
276 collect pos)))
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
277 (winner-set-conf (car conf))
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
278 (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
279 (loop for win being the windows
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
280 unless (window-minibuffer-p win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
281 do (if (pop origpoints)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
282 (setf (window-point win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
283 ;; Restore point
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
284 (winner-get-point
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
285 (window-buffer win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
286 win))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
287 (push win xwins))) ; delete this window
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
288 ;; Restore mark
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
289 (letf (((current-buffer)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
290 (loop for buf in buffers
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
291 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
292 do (progn (set-buffer buf)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
293 (set-mark (car entry))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
294 (setf (winner-active-region) (cdr entry)))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
295 ;; Delete windows, whose buffers are dead.
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
296 ;; 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
297 (or (null xwins)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
298 (progn (mapcar 'delete-window (cdr xwins))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
299 (if (one-window-p t)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
300 nil ; No windows left
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
301 (progn (delete-window (car xwins))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
302 t)))))))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
303
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
304
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
305
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
306 ;;;; Winner mode (a minor mode)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
308 (defcustom winner-mode-hook nil
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
309 "Functions to run whenever Winner mode is turned on."
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
310 :type 'hook
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
311 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
313 (defcustom winner-mode-leave-hook nil
20968
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
314 "Functions to run whenever Winner mode is turned off."
7072722c5071 (require 'cl) unconditionally.
Dave Love <fx@gnu.org>
parents: 20086
diff changeset
315 :type 'hook
20969
6007dc30ec3b *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20968
diff changeset
316 :group 'winner)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (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
319
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
320 ;; Is `window-configuration-change-hook' working?
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
321 (defun winner-hook-installed-p ()
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
322 (save-window-excursion
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
323 (let ((winner-var nil)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
324 (window-configuration-change-hook
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
325 '((lambda () (setq winner-var t)))))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
326 (split-window)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
327 winner-var)))
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
328
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
329 ;;;###autoload
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (defun winner-mode (&optional arg)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 "Toggle Winner mode.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 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
333 (interactive "P")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (let ((on-p (if arg (> (prefix-numeric-value arg) 0)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (not winner-mode))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (cond
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
337 ;; Turn mode on
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
338 (on-p
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
339 (setq winner-mode t)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
340 (cond
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
341 ((winner-hook-installed-p)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
342 (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
343 (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
344 (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
345 (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
346 (winner-save-old-configurations)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
347 (run-hooks 'winner-mode-hook))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
348 ;; Turn mode off
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
349 (winner-mode
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
350 (setq winner-mode nil)
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
351 (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
352 (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
353 (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
354 (run-hooks 'winner-mode-leave-hook)))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (force-mode-line-update)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
357 ;; Inspired by undo (simple.el)
24590
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
358
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
359 (defvar winner-undo-frame nil)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
360
24590
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
361 (defvar winner-pending-undo-ring nil
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
362 "The ring currently used by winner undo.")
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
363 (defvar winner-undo-counter nil)
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
364 (defvar winner-undone-data nil) ; There confs have been passed.
d607db83cf72 Reorder definitions.
Richard M. Stallman <rms@gnu.org>
parents: 24550
diff changeset
365
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
366 (defun winner-undo ()
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
367 "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
368 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
369 (interactive)
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
370 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
371 ((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
372 (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
373 (eq winner-undo-frame (selected-frame)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
374 (winner-save-unconditionally) ; current configuration->stack
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
375 (setq winner-undo-frame (selected-frame))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
376 (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
377 (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
378 (setq winner-undo-counter 0)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
379 (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
380 (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
381 (when (and (winner-undo-this)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
382 (not (window-minibuffer-p (selected-window))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
383 (message "Winner undo (%d / %d)"
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
384 winner-undo-counter
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
385 (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
386
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
387 (defun winner-win-data ()
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
388 ;; 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
389 (loop for win being the windows
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
390 unless (window-minibuffer-p win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
391 collect (list (window-buffer win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
392 (window-width win)
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
393 (window-height win))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
394
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
395
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
396 (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
397 (loop
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
398 (cond
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
399 ((>= 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
400 (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
401 (return nil))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
402
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
403 ((and ; If possible configuration
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
404 (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
405 winner-undo-counter))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
406 ;; .. and new configuration
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
407 (let ((data (winner-win-data)))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
408 (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
409 (push data winner-undone-data))))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
410 (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
411 (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
412 (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
413
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
25639
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
415 (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
416 "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
417 (interactive)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
418 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
419 ((eq last-command 'winner-undo)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
420 (winner-set
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
421 (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
422 (unless (eq (selected-window) (minibuffer-window))
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
423 (message "Winner undid undo")))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
424 (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
425
8d9a53e6b71c Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents: 24637
diff changeset
426 ;;; To be evaluated when the package is loaded:
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
21125
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
428 (if (fboundp 'compare-window-configurations)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
429 (defalias 'winner-equal 'compare-window-configurations)
d66c9c7b4927 Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents: 21016
diff changeset
430 (defalias 'winner-equal 'equal))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (unless winner-mode-map
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (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
434 (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
435 (define-key winner-mode-map [(control x) right] 'winner-redo))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (unless (or (assq 'winner-mode minor-mode-map-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 winner-dont-bind-my-keys)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (push (cons 'winner-mode winner-mode-map)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 minor-mode-map-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (unless (assq 'winner-mode minor-mode-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (push '(winner-mode " Win") minor-mode-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (provide 'winner)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
447 ;;; winner.el ends here