Mercurial > emacs
annotate lisp/winner.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128
typos.
author | Jeff Law <law@redhat.com> |
---|---|
date | Wed, 10 Sep 1997 21:16:20 +0000 |
parents | 8d89cc0f2b42 |
children | 735f0cdfc5b9 |
rev | line source |
---|---|
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
1 ;;; winner.el --- Restore window configuration (or switch buffer) |
17469 | 2 |
17470
c4cd2317fe60
Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents:
17469
diff
changeset
|
3 ;; Copyright (C) 1997 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 | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
8 ;; Keywords: extensions, windows |
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 |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
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 | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Commentary: | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
28 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
29 ;; Winner mode is a global minor mode that when turned on records |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
30 ;; changes in window configuration. This way the changes can be |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
31 ;; "undone" using the function `winner-undo'. By default this one is |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
32 ;; bound to the key sequence ctrl-x left. If you change your mind |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
33 ;; (while undoing), you can press ctrl-x right (calling |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
34 ;; `winner-redo'). Unlike the normal undo, you may have to skip |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
35 ;; through several identical window configurations in order to find |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
36 ;; the one you want. This is a bug due to some techical limitations |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
37 ;; in Emacs and can maybe be fixed in the future. |
17469 | 38 ;; |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
39 ;; In addition to this I have added `winner-switch' which is a program |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
40 ;; that switches to other buffers without disturbing Winner mode. If |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
41 ;; you bind this command to a key sequence, you may step through all |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
42 ;; your buffers (except the ones mentioned in `winner-skip-buffers' or |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
43 ;; matched by `winner-skip-regexps'). With a numeric prefix argument |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
44 ;; skip several buffers at a time. |
17469 | 45 |
46 ;;; Code: | |
47 | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
48 (eval-when-compile (require 'cl)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
49 (require 'ring) |
17469 | 50 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
51 (defvar winner-dont-bind-my-keys nil |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
52 "If non-nil: Do not use `winner-mode-map' in Winner mode.") |
17469 | 53 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
54 (defvar winner-ring-size 100 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
55 "Maximum number of stored window configurations per frame.") |
17469 | 56 |
57 (defvar winner-skip-buffers | |
58 '("*Messages*", | |
59 "*Compile-Log*", | |
60 ".newsrc-dribble", | |
61 "*Completions*", | |
62 "*Buffer list*") | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
63 "Exclude these buffer names from any \(Winner switch\) list of buffers.") |
17469 | 64 |
65 (defvar winner-skip-regexps '("^ ") | |
19502 | 66 "Winner excludes buffers with names matching any of these regexps. |
67 They are not included in any Winner mode list of buffers. | |
17469 | 68 |
69 By default `winner-skip-regexps' is set to \(\"^ \"\), | |
70 which excludes \"invisible buffers\".") | |
71 | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
72 (defvar winner-ring-alist nil) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
73 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
74 (defsubst winner-ring (frame) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
75 (or (cdr (assq frame winner-ring-alist)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
76 (progn |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
77 (push (cons frame (make-ring winner-ring-size)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
78 winner-ring-alist) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
79 (cdar winner-ring-alist)))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
80 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
81 (defvar winner-modified-list nil) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
82 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
83 (defun winner-change-fun () |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
84 (pushnew (selected-frame) winner-modified-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
85 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
86 (defun winner-save-new-configurations () |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
87 (while winner-modified-list |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
88 (ring-insert |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
89 (winner-ring (car winner-modified-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
90 (current-window-configuration (pop winner-modified-list))))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
91 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
92 (defun winner-set (conf) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
93 (set-window-configuration conf) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
94 (if (eq (selected-window) (minibuffer-window)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
95 (other-window 1))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
96 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
97 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
98 ;;; Winner mode (a minor mode) |
17469 | 99 |
100 (defvar winner-mode-hook nil | |
101 "Functions to run whenever Winner mode is turned on.") | |
102 | |
103 (defvar winner-mode-leave-hook nil | |
104 "Functions to run whenever Winner mode is turned off.") | |
105 | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
106 (defvar winner-mode nil) ; mode variable |
17469 | 107 (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
|
108 |
17469 | 109 (defun winner-mode (&optional arg) |
110 "Toggle Winner mode. | |
111 With arg, turn Winner mode on if and only if arg is positive." | |
112 (interactive "P") | |
113 (let ((on-p (if arg (> (prefix-numeric-value arg) 0) | |
114 (not winner-mode)))) | |
115 (cond | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
116 ;; Turn mode on |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
117 (on-p |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
118 (setq winner-mode t) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
119 (add-hook 'window-configuration-change-hook 'winner-change-fun) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
120 (add-hook 'post-command-hook 'winner-save-new-configurations) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
121 (setq winner-modified-list (frame-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
122 (winner-save-new-configurations) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
123 (run-hooks 'winner-mode-hook)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
124 ;; Turn mode off |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
125 (winner-mode |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
126 (setq winner-mode nil) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
127 (run-hooks 'winner-mode-leave-hook))) |
17469 | 128 (force-mode-line-update))) |
129 | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
130 ;; Inspired by undo (simple.el) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
131 (defun winner-undo (arg) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
132 "Switch back to an earlier window configuration saved by Winner mode. |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
133 In other words, \"undo\" changes in window configuration." |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
134 (interactive "p") |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
135 (cond |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
136 ((not winner-mode) (error "Winner mode is turned off")) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
137 ((eq (selected-window) (minibuffer-window)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
138 (error "No winner undo from minibuffer.")) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
139 (t (setq this-command t) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
140 (if (eq last-command 'winner-undo) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
141 ;; This was no new window configuration after all. |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
142 (ring-remove winner-pending-undo-ring 0) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
143 (setq winner-pending-undo-ring (winner-ring (selected-frame))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
144 (setq winner-undo-counter 0)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
145 (winner-undo-more (or arg 1)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
146 (message "Winner undo (%d)!" winner-undo-counter) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
147 (setq this-command 'winner-undo)))) |
17469 | 148 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
149 (defvar winner-pending-undo-ring nil) |
17469 | 150 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
151 (defvar winner-undo-counter nil) |
17469 | 152 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
153 (defun winner-undo-more (count) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
154 "Undo N window configuration changes beyond what was already undone. |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
155 Call `winner-undo-start' to get ready to undo recent changes, |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
156 then call `winner-undo-more' one or more times to undo them." |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
157 (let ((len (ring-length winner-pending-undo-ring))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
158 (incf winner-undo-counter count) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
159 (if (>= winner-undo-counter len) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
160 (error "No further window configuration undo information") |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
161 (winner-set |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
162 (ring-ref winner-pending-undo-ring |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
163 winner-undo-counter))))) |
17469 | 164 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
165 (defun winner-redo () |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
166 "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
|
167 (interactive) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
168 (cond |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
169 ((eq last-command 'winner-undo) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
170 (ring-remove winner-pending-undo-ring 0) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
171 (winner-set |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
172 (ring-remove winner-pending-undo-ring 0)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
173 (or (eq (selected-window) (minibuffer-window)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
174 (message "Winner undid undo!"))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
175 (t (error "Previous command was not a winner-undo")))) |
17469 | 176 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
177 ;;; Winner switch |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
178 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
179 (defun winner-switch-buffer-list () |
17469 | 180 (loop for buf in (buffer-list) |
181 for name = (buffer-name buf) | |
182 unless (or (eq (current-buffer) buf) | |
183 (member name winner-skip-buffers) | |
184 (loop for regexp in winner-skip-regexps | |
185 if (string-match regexp name) return t | |
186 finally return nil)) | |
187 collect name)) | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
188 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
189 (defvar winner-switch-list nil) |
17469 | 190 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
191 (defun winner-switch (count) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
192 "Step through your buffers without disturbing `winner-mode'. |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
193 `winner-switch' does not consider buffers mentioned in the list |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
194 `winner-skip-buffers' or matched by `winner-skip-regexps'." |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
195 (interactive "p") |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
196 (decf count) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
197 (setq this-command t) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
198 (cond |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
199 ((eq last-command 'winner-switch) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
200 (if winner-mode (ring-remove (winner-ring (selected-frame)) 0)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
201 (bury-buffer (current-buffer)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
202 (mapcar 'bury-buffer winner-switch-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
203 (t (setq winner-switch-list (winner-switch-buffer-list)))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
204 (setq winner-switch-list (nthcdr count winner-switch-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
205 (or winner-switch-list |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
206 (setq winner-switch-list (winner-switch-buffer-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
207 (error "No more buffers")) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
208 (switch-to-buffer (pop winner-switch-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
209 (message (concat "Winner: [%s] " |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
210 (mapconcat 'identity winner-switch-list " ")) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
211 (buffer-name)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
212 (setq this-command 'winner-switch)) |
17469 | 213 |
214 ;;;; To be evaluated when the package is loaded: | |
215 | |
216 (unless winner-mode-map | |
217 (setq winner-mode-map (make-sparse-keymap)) | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
218 (define-key winner-mode-map [?\C-x left] 'winner-undo) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
219 (define-key winner-mode-map [?\C-x right] 'winner-redo)) |
17469 | 220 |
221 (unless (or (assq 'winner-mode minor-mode-map-alist) | |
222 winner-dont-bind-my-keys) | |
223 (push (cons 'winner-mode winner-mode-map) | |
224 minor-mode-map-alist)) | |
225 | |
226 (unless (assq 'winner-mode minor-mode-alist) | |
227 (push '(winner-mode " Win") minor-mode-alist)) | |
228 | |
229 (provide 'winner) | |
230 | |
17470
c4cd2317fe60
Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents:
17469
diff
changeset
|
231 ;;; winner.el ends here |