Mercurial > emacs
annotate lisp/winner.el @ 92171:c06259187010
*** empty log message ***
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Sun, 24 Feb 2008 23:21:56 +0000 |
parents | d77b6e5ee8af |
children | c70e45a7acfd ee5932bf781d |
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 | 2 |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64287
diff
changeset
|
3 ;; Copyright (C) 1997, 1998, 2001, 2002, 2003, 2004, |
79721 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation. Inc. |
17469 | 5 |
28071 | 6 ;; Author: Ivar Rummelhoff <ivarru@math.uio.no> |
17469 | 7 ;; Created: 27 Feb 1997 |
28023
3978c673322b
Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents:
25733
diff
changeset
|
8 ;; Keywords: convenience frames |
17469 | 9 |
17470
c4cd2317fe60
Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents:
17469
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
c4cd2317fe60
Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents:
17469
diff
changeset
|
11 |
c4cd2317fe60
Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents:
17469
diff
changeset
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
17469 | 13 ;; it under the terms of the GNU General Public License as published by |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
17469 | 15 ;; any later version. |
16 | |
17470
c4cd2317fe60
Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents:
17469
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful, |
17469 | 18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64091 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
17469 | 26 |
27 ;;; Commentary: | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
28 |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
29 ;; Winner mode is a global minor mode that records the changes in the |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
30 ;; window configuration (i.e. how the frames are partitioned into |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
31 ;; windows) so that the changes can be "undone" using the command |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
32 ;; `winner-undo'. By default this one is bound to the key sequence |
55349
96c2a9272e97
(winner-mode-map): Move winner-undo and winner-redo to C-c <left> and C-c
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
33 ;; ctrl-c left. If you change your mind (while undoing), you can |
96c2a9272e97
(winner-mode-map): Move winner-undo and winner-redo to C-c <left> and C-c
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
34 ;; press ctrl-c right (calling `winner-redo'). Even though it uses |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
35 ;; some features of Emacs20.3, winner.el should also work with |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
36 ;; Emacs19.34 and XEmacs20, provided that the installed version of |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
37 ;; custom is not obsolete. |
17469 | 38 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
39 ;; Winner mode was improved August 1998. |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
40 ;; Further improvements February 2002. |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
41 |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
42 ;;; Code: |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
43 |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
44 (eval-when-compile |
28023
3978c673322b
Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents:
25733
diff
changeset
|
45 (require 'cl)) |
17469 | 46 |
58213
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
47 |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
48 (defmacro winner-active-region () |
87402
733157417ec4
(winner-active-region): Use `mark-active' if it's defined.
Richard M. Stallman <rms@gnu.org>
parents:
87384
diff
changeset
|
49 (if (boundp 'mark-active) |
733157417ec4
(winner-active-region): Use `mark-active' if it's defined.
Richard M. Stallman <rms@gnu.org>
parents:
87384
diff
changeset
|
50 'mark-active |
733157417ec4
(winner-active-region): Use `mark-active' if it's defined.
Richard M. Stallman <rms@gnu.org>
parents:
87384
diff
changeset
|
51 '(region-active-p))) |
58213
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
52 |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
53 (defsetf winner-active-region () (store) |
87941
d77b6e5ee8af
* sieve.el (sieve-make-overlay, sieve-overlay-put, sieve-overlays-at):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
87649
diff
changeset
|
54 (if (featurep 'xemacs) |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
55 `(if ,store (zmacs-activate-region) |
58213
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
56 (zmacs-deactivate-region)) |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
57 `(setq mark-active ,store))) |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
58 |
58213
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
59 (defalias 'winner-edges |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
60 (if (featurep 'xemacs) 'window-pixel-edges 'window-edges)) |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
61 (defalias 'winner-window-list |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
62 (if (featurep 'xemacs) |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
63 (lambda () (delq (minibuffer-window) (window-list nil 0))) |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
64 (lambda () (window-list nil 0)))) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
65 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
66 (require 'ring) |
17469 | 67 |
48248
ee08f1e3d269
(defgroup winner): Handle Emacs 19 compatibility so that definition
Markus Rost <rost@math.uni-bielefeld.de>
parents:
43556
diff
changeset
|
68 (defgroup winner nil |
ee08f1e3d269
(defgroup winner): Handle Emacs 19 compatibility so that definition
Markus Rost <rost@math.uni-bielefeld.de>
parents:
43556
diff
changeset
|
69 "Restoring window configurations." |
ee08f1e3d269
(defgroup winner): Handle Emacs 19 compatibility so that definition
Markus Rost <rost@math.uni-bielefeld.de>
parents:
43556
diff
changeset
|
70 :group 'windows) |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
71 |
28023
3978c673322b
Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents:
25733
diff
changeset
|
72 ;;;###autoload |
20968 | 73 (defcustom winner-mode nil |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
74 "Toggle Winner mode. |
24637 | 75 Setting this variable directly does not take effect; |
76 use either \\[customize] or the function `winner-mode'." | |
58213
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
77 :set #'(lambda (symbol value) (funcall symbol (or value 0))) |
20968 | 78 :initialize 'custom-initialize-default |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
79 :type 'boolean |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
80 :group 'winner |
20968 | 81 :require 'winner) |
82 | |
83 (defcustom winner-dont-bind-my-keys nil | |
84 "If non-nil: Do not use `winner-mode-map' in Winner mode." | |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
85 :type 'boolean |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
86 :group 'winner) |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
87 |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
88 (defcustom winner-ring-size 200 |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
89 "Maximum number of stored window configurations per frame." |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
90 :type 'integer |
20968 | 91 :group 'winner) |
17469 | 92 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
93 (defcustom winner-boring-buffers '("*Completions*") |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
94 "`winner-undo' will not restore windows displaying any of these buffers. |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
95 You may want to include buffer names such as *Help*, *Apropos*, |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
96 *Buffer List*, *info* and *Compile-Log*." |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
97 :type '(repeat string) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
98 :group 'winner) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
99 |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
100 |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
101 |
17469 | 102 |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
103 |
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
104 ;;;; Saving old configurations (internal variables and subroutines) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
105 |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
106 |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
107 ;;; Current configuration |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
108 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
109 ;; List the windows according to their edges. |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
110 (defun winner-sorted-window-list () |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
111 (sort (winner-window-list) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
112 (lambda (x y) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
113 (loop for a in (winner-edges x) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
114 for b in (winner-edges y) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
115 while (= a b) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
116 finally return (< a b))))) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
117 |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
118 (defun winner-win-data () |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
119 ;; Essential properties of the windows in the selected frame. |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
120 (loop for win in (winner-sorted-window-list) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
121 collect (cons (winner-edges win) (window-buffer win)))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
122 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
123 ;; This variable is updated with the current window configuration |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
124 ;; every time it changes. |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
125 (defvar winner-currents nil) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
126 |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
127 ;; The current configuration (+ the buffers involved). |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
128 (defsubst winner-conf () |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
129 (cons (current-window-configuration) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
130 (winner-win-data))) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
131 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
132 |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
133 ;; Save current configuration. |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
134 ;; (Called below by `winner-save-old-configurations'). |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
135 (defun winner-remember () |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
136 (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
|
137 (if entry (setcdr entry (winner-conf)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
138 (push (cons (selected-frame) (winner-conf)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
139 winner-currents)))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
140 |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
141 ;; Consult `winner-currents'. |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
142 (defun winner-configuration (&optional frame) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
143 (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
|
144 (letf (((selected-frame) frame)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
145 (winner-conf)))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
146 |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
147 |
17469 | 148 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
149 ;;; Saved configurations |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
150 |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
151 ;; This variable contains the window cofiguration rings. |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
152 ;; 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
|
153 (defvar winner-ring-alist nil) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
154 |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
155 ;; 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
|
156 (defsubst winner-ring (frame) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
157 (or (cdr (assq frame winner-ring-alist)) |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
158 (let ((ring (make-ring winner-ring-size))) |
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
159 (ring-insert ring (winner-configuration frame)) |
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
160 (push (cons frame ring) winner-ring-alist) |
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
161 ring))) |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
162 |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
163 |
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
164 ;; If the same command is called several times in a row, |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
165 ;; we only save one window configuration. |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
166 (defvar winner-last-command nil) |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
167 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
168 ;; Frames affected by the previous command. |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
169 (defvar winner-last-frames nil) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
170 |
38334
63281ffd14fd
(winner-equal): Make it a defun. Don't compare Winner
Gerd Moellmann <gerd@gnu.org>
parents:
28071
diff
changeset
|
171 |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
172 (defsubst winner-equal (a b) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
173 "Check whether two Winner configurations (as produced by |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
174 `winner-conf') are equal." |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
175 (equal (cdr a) (cdr b))) |
38334
63281ffd14fd
(winner-equal): Make it a defun. Don't compare Winner
Gerd Moellmann <gerd@gnu.org>
parents:
28071
diff
changeset
|
176 |
63281ffd14fd
(winner-equal): Make it a defun. Don't compare Winner
Gerd Moellmann <gerd@gnu.org>
parents:
28071
diff
changeset
|
177 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
178 ;; Save the current window configuration, if it has changed. |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
179 ;; If so return frame, otherwise return nil. |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
180 (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
|
181 (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
|
182 (eq this-command 'winner-redo)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
183 (let ((conf (winner-configuration frame)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
184 (ring (winner-ring frame))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
185 (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
|
186 (winner-equal conf (ring-ref ring 0))) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
187 ;; When the previous configuration was very similar, |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
188 ;; keep only the latest. |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
189 (ring-remove ring 0)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
190 (ring-insert ring conf) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
191 (push frame winner-last-frames) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
192 frame))) |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
193 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
194 |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
195 |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
196 ;;; Hooks |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
197 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
198 ;; Frames affected by the current command. |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
199 (defvar winner-modified-list nil) |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
200 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
201 ;; Called whenever the window configuration changes |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
202 ;; (a `window-configuration-change-hook'). |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
203 (defun winner-change-fun () |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
204 (unless (or (memq (selected-frame) winner-modified-list) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
205 (/= 0 (minibuffer-depth))) |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
206 (push (selected-frame) winner-modified-list))) |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
207 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
208 ;; A `post-command-hook' for emacsen with |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
209 ;; `window-configuration-change-hook'. |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
210 (defun winner-save-old-configurations () |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
211 (when (zerop (minibuffer-depth)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
212 (unless (eq this-command winner-last-command) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
213 (setq winner-last-frames nil) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
214 (setq winner-last-command this-command)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
215 (dolist (frame winner-modified-list) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
216 (winner-insert-if-new frame)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
217 (setq winner-modified-list nil) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
218 (winner-remember))) |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
219 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
220 ;; A `minibuffer-setup-hook'. |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
221 (defun winner-save-unconditionally () |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
222 (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
|
223 (setq winner-last-frames nil) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
224 (setq winner-last-command this-command)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
225 (winner-insert-if-new (selected-frame)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
226 (winner-remember)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
227 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
228 ;; A `post-command-hook' for other emacsen. |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
229 ;; Also called by `winner-undo' before "undoing". |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
230 (defun winner-save-conditionally () |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
231 (when (zerop (minibuffer-depth)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
232 (winner-save-unconditionally))) |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
233 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
234 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
235 |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
236 |
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
237 ;;;; Restoring configurations |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
238 |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
239 ;; Works almost as `set-window-configuration', |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
240 ;; but does not change the contents or the size of the minibuffer, |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
241 ;; and tries to preserve the selected window. |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
242 (defun winner-set-conf (winconf) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
243 (let* ((miniwin (minibuffer-window)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
244 (chosen (selected-window)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
245 (minisize (window-height miniwin))) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
246 (letf (((window-buffer miniwin)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
247 ((window-point miniwin))) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
248 (set-window-configuration winconf)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
249 (cond |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
250 ((window-live-p chosen) (select-window chosen)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
251 ((window-minibuffer-p (selected-window)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
252 (other-window 1))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
253 (when (/= minisize (window-height miniwin)) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
254 (letf (((selected-window) miniwin) ) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
255 (setf (window-height) minisize))))) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
256 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
257 |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
258 |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
259 (defvar winner-point-alist nil) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
260 ;; `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
|
261 ;; 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
|
262 ;; and marks before undoing window configurations. |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
263 ;; |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
264 ;; 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
|
265 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
266 (defun winner-make-point-alist () |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
267 (letf (((current-buffer))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
268 (loop with alist |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
269 for win in (winner-window-list) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
270 for entry = |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
271 (or (assq (window-buffer win) alist) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
272 (car (push (list (set-buffer (window-buffer win)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
273 (cons (mark t) (winner-active-region))) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
274 alist))) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
275 do (push (cons win (window-point win)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
276 (cddr entry)) |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
277 finally return alist))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
278 |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
279 (defun winner-get-point (buf win) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
280 ;; Consult (and possibly extend) `winner-point-alist'. |
78491 | 281 ;; Returns nil if buf no longer exists. |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
282 (when (buffer-name buf) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
283 (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
|
284 (cond |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
285 (entry |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
286 (or (cdr (assq win (cddr entry))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
287 (cdr (assq nil (cddr entry))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
288 (letf (((current-buffer) buf)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
289 (push (cons nil (point)) (cddr entry)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
290 (point)))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
291 (t (letf (((current-buffer) buf)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
292 (push (list buf |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
293 (cons (mark t) (winner-active-region)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
294 (cons nil (point))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
295 winner-point-alist) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
296 (point))))))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
297 |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
298 |
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
299 ;; Make sure point does not end up in the minibuffer and delete |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
300 ;; windows displaying dead or boring buffers |
78491 | 301 ;; (c.f. `winner-boring-buffers'). Return nil if all the windows |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
302 ;; should be deleted. Preserve correct points and marks. |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
303 (defun winner-set (conf) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
304 ;; For the format of `conf', see `winner-conf'. |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
305 (let* ((buffers nil) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
306 (alive |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
307 ;; Possibly update `winner-point-alist' |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
308 (loop for buf in (mapcar 'cdr (cdr conf)) |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
309 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
|
310 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
|
311 do (push buf buffers) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
312 collect pos))) |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
313 (winner-set-conf (car conf)) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
314 (let (xwins) ; to be deleted |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
315 |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
316 ;; Restore points |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
317 (dolist (win (winner-sorted-window-list)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
318 (unless (and (pop alive) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
319 (setf (window-point win) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
320 (winner-get-point (window-buffer win) win)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
321 (not (member (buffer-name (window-buffer win)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
322 winner-boring-buffers))) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
323 (push win xwins))) ; delete this window |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
324 |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
325 ;; Restore marks |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
326 (letf (((current-buffer))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
327 (loop for buf in buffers |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
328 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
|
329 do (progn (set-buffer buf) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
330 (set-mark (car entry)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
331 (setf (winner-active-region) (cdr entry))))) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
332 ;; Delete windows, whose buffers are dead or boring. |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
333 ;; 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
|
334 (or (null xwins) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
335 (progn |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
336 (mapc 'delete-window (cdr xwins)) ; delete all but one |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
337 (unless (one-window-p t) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
338 (delete-window (car xwins)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
339 t)))))) |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
340 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
341 |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
342 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
343 ;;;; Winner mode (a minor mode) |
17469 | 344 |
20968 | 345 (defcustom winner-mode-hook nil |
346 "Functions to run whenever Winner mode is turned on." | |
347 :type 'hook | |
20969
6007dc30ec3b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20968
diff
changeset
|
348 :group 'winner) |
17469 | 349 |
20969
6007dc30ec3b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20968
diff
changeset
|
350 (defcustom winner-mode-leave-hook nil |
20968 | 351 "Functions to run whenever Winner mode is turned off." |
352 :type 'hook | |
20969
6007dc30ec3b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20968
diff
changeset
|
353 :group 'winner) |
17469 | 354 |
58213
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
355 (defvar winner-mode-map |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
356 (let ((map (make-sparse-keymap))) |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
357 (define-key map [(control c) left] 'winner-undo) |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
358 (define-key map [(control c) right] 'winner-redo) |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
359 map) |
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
360 "Keymap for Winner mode.") |
17470
c4cd2317fe60
Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents:
17469
diff
changeset
|
361 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
362 ;; Check if `window-configuration-change-hook' is working. |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
363 (defun winner-hook-installed-p () |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
364 (save-window-excursion |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
365 (let ((winner-var nil) |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
366 (window-configuration-change-hook |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
367 '((lambda () (setq winner-var t))))) |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
368 (split-window) |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
369 winner-var))) |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
370 |
28023
3978c673322b
Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents:
25733
diff
changeset
|
371 |
3978c673322b
Fix keywords, autoload cookies. Split
Dave Love <fx@gnu.org>
parents:
25733
diff
changeset
|
372 ;;;###autoload |
17469 | 373 (defun winner-mode (&optional arg) |
374 "Toggle Winner mode. | |
375 With arg, turn Winner mode on if and only if arg is positive." | |
376 (interactive "P") | |
377 (let ((on-p (if arg (> (prefix-numeric-value arg) 0) | |
378 (not winner-mode)))) | |
379 (cond | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
380 ;; Turn mode on |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
381 (on-p |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
382 (setq winner-mode t) |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
383 (cond |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
384 ((winner-hook-installed-p) |
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
385 (add-hook 'window-configuration-change-hook 'winner-change-fun) |
58213
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
386 (add-hook 'post-command-hook 'winner-save-old-configurations)) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
387 (t (add-hook 'post-command-hook 'winner-save-conditionally))) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
388 (add-hook 'minibuffer-setup-hook 'winner-save-unconditionally) |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
389 (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
|
390 (winner-save-old-configurations) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
391 (run-hooks 'winner-mode-hook) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
392 (when (interactive-p) (message "Winner mode enabled"))) |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
393 ;; Turn mode off |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
394 (winner-mode |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
395 (setq winner-mode nil) |
21125
d66c9c7b4927
Use list syntax for key definitions.
Richard M. Stallman <rms@gnu.org>
parents:
21016
diff
changeset
|
396 (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
|
397 (remove-hook 'post-command-hook 'winner-save-old-configurations) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
398 (remove-hook 'post-command-hook 'winner-save-conditionally) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
399 (remove-hook 'minibuffer-setup-hook 'winner-save-unconditionally) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
400 (run-hooks 'winner-mode-leave-hook) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
401 (when (interactive-p) (message "Winner mode disabled")))))) |
17469 | 402 |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
403 ;; Inspired by undo (simple.el) |
24590 | 404 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
405 (defvar winner-undo-frame nil) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
406 |
24590 | 407 (defvar winner-pending-undo-ring nil |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
408 "The ring currently used by `winner-undo'.") |
24590 | 409 (defvar winner-undo-counter nil) |
410 (defvar winner-undone-data nil) ; There confs have been passed. | |
411 | |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
412 (defun winner-undo () |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
413 "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
|
414 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
|
415 (interactive) |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
416 (cond |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
417 ((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
|
418 (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
|
419 (eq winner-undo-frame (selected-frame))) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
420 (winner-save-conditionally) ; current configuration->stack |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
421 (setq winner-undo-frame (selected-frame)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
422 (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
|
423 (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
|
424 (setq winner-undo-counter 0) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
425 (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
|
426 (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
|
427 (when (and (winner-undo-this) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
428 (not (window-minibuffer-p (selected-window)))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
429 (message "Winner undo (%d / %d)" |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
430 winner-undo-counter |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
431 (1- (ring-length winner-pending-undo-ring))))))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
432 |
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
433 |
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
434 |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
435 |
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
436 (defun winner-undo-this () ; The heart of winner undo. |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
437 (loop |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
438 (cond |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
439 ((>= 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
|
440 (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
|
441 (return nil)) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
442 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
443 ((and ; If possible configuration |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
444 (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
|
445 winner-undo-counter)) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
446 ; .. and new configuration |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
447 (let ((data (winner-win-data))) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
448 (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
|
449 (push data winner-undone-data)))) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
450 (return t)) ; .. then everything is fine. |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
451 (t ;; Otherwise, discharge it (and try the next one). |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
452 (ring-remove winner-pending-undo-ring winner-undo-counter))))) |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48248
diff
changeset
|
453 |
17469 | 454 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
455 (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
|
456 "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
|
457 (interactive) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
458 (cond |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
459 ((eq last-command 'winner-undo) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
460 (winner-set |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
461 (if (zerop (minibuffer-depth)) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
462 (ring-remove winner-pending-undo-ring 0) |
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
463 (ring-ref winner-pending-undo-ring 0))) |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
464 (unless (eq (selected-window) (minibuffer-window)) |
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
465 (message "Winner undid undo"))) |
64287
22103717b63b
(winner-mode, winner-boring-buffers, winner-pending-undo-ring): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64091
diff
changeset
|
466 (t (error "Previous command was not a `winner-undo'")))) |
43556
9e4a1be87f8c
(winner-boring-buffers, winner-set): A window which
Richard M. Stallman <rms@gnu.org>
parents:
38334
diff
changeset
|
467 |
25639
8d9a53e6b71c
Major changes. Avoid changing point and mark.
Richard M. Stallman <rms@gnu.org>
parents:
24637
diff
changeset
|
468 ;;; To be evaluated when the package is loaded: |
17469 | 469 |
470 (unless (or (assq 'winner-mode minor-mode-map-alist) | |
471 winner-dont-bind-my-keys) | |
472 (push (cons 'winner-mode winner-mode-map) | |
473 minor-mode-map-alist)) | |
474 | |
475 (provide 'winner) | |
58213
5201ea9b1985
(winner-active-region, winner-edges, winner-window-list): Define at toplevel.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55349
diff
changeset
|
476 ;; arch-tag: 686d1c1b-010e-42ca-a192-b5685112418f |
17470
c4cd2317fe60
Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents:
17469
diff
changeset
|
477 ;;; winner.el ends here |