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