Mercurial > emacs
annotate lisp/winner.el @ 21121:dd5c2baa6674
(latex-mode): Set fill-nobreak-predicate.
(slitex-mode): Set fill-nobreak-predicate, tex-face-alist,
and imenu-create-index-function.
(latex-fill-nobreak-predicate): New function.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 09 Mar 1998 06:36:25 +0000 |
parents | f778c7136ff5 |
children | d66c9c7b4927 |
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 |
20968 | 3 ;; Copyright (C) 1997, 1998 Free Software Foundation. Inc. |
17469 | 4 |
5 ;; Author: Ivar Rummelhoff <ivarr@ifi.uio.no> | |
6 ;; Maintainer: Ivar Rummelhoff <ivarr@ifi.uio.no> | |
7 ;; Created: 27 Feb 1997 | |
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 | |
21016
f778c7136ff5
((require 'cl)): Revert to compile-time require.
Dave Love <fx@gnu.org>
parents:
20980
diff
changeset
|
48 (eval-when-compile (require 'cl)) |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
49 (require 'ring) |
17469 | 50 |
20968 | 51 (defgroup winner nil |
52 "Restoring window configurations." | |
53 :group 'windows) | |
54 | |
20980
85cc901f00ee
(winner-mode): Autoload cookie for defcustom too.
Dave Love <fx@gnu.org>
parents:
20969
diff
changeset
|
55 ;;;###autoload |
20968 | 56 (defcustom winner-mode nil |
57 "Toggle winner-mode. | |
58 You must modify via \\[customize] for this variable to have an effect." | |
59 :set (lambda (symbol value) | |
60 (winner-mode (or value 0))) | |
61 :initialize 'custom-initialize-default | |
62 :type 'boolean | |
63 :group 'winner | |
64 :require 'winner) | |
65 | |
66 (defcustom winner-dont-bind-my-keys nil | |
67 "If non-nil: Do not use `winner-mode-map' in Winner mode." | |
68 :type 'boolean | |
69 :group 'winner) | |
17469 | 70 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
71 (defvar winner-ring-size 100 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
72 "Maximum number of stored window configurations per frame.") |
17469 | 73 |
20968 | 74 (defcustom winner-skip-buffers |
17469 | 75 '("*Messages*", |
76 "*Compile-Log*", | |
77 ".newsrc-dribble", | |
78 "*Completions*", | |
79 "*Buffer list*") | |
20968 | 80 "Exclude these buffer names from any \(Winner switch\) list of buffers." |
81 :type '(repeat string) | |
82 :group 'winner) | |
17469 | 83 |
20968 | 84 (defcustom winner-skip-regexps '("^ ") |
19502 | 85 "Winner excludes buffers with names matching any of these regexps. |
86 They are not included in any Winner mode list of buffers. | |
17469 | 87 |
88 By default `winner-skip-regexps' is set to \(\"^ \"\), | |
20968 | 89 which excludes \"invisible buffers\"." |
90 :type '(repeat regexp) | |
91 :group 'winner) | |
17469 | 92 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
93 (defvar winner-ring-alist nil) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
94 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
95 (defsubst winner-ring (frame) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
96 (or (cdr (assq frame winner-ring-alist)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
97 (progn |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
98 (push (cons frame (make-ring winner-ring-size)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
99 winner-ring-alist) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
100 (cdar winner-ring-alist)))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
101 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
102 (defvar winner-modified-list nil) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
103 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
104 (defun winner-change-fun () |
20047
735f0cdfc5b9
(winner-change-fun): Don't use pushnew.
Karl Heuer <kwzh@gnu.org>
parents:
19564
diff
changeset
|
105 (or (memq (selected-frame) winner-modified-list) |
735f0cdfc5b9
(winner-change-fun): Don't use pushnew.
Karl Heuer <kwzh@gnu.org>
parents:
19564
diff
changeset
|
106 (push (selected-frame) winner-modified-list))) |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
107 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
108 (defun winner-save-new-configurations () |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
109 (while winner-modified-list |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
110 (ring-insert |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
111 (winner-ring (car winner-modified-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
112 (current-window-configuration (pop winner-modified-list))))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
113 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
114 (defun winner-set (conf) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
115 (set-window-configuration conf) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
116 (if (eq (selected-window) (minibuffer-window)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
117 (other-window 1))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
118 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
119 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
120 ;;; Winner mode (a minor mode) |
17469 | 121 |
20968 | 122 (defcustom winner-mode-hook nil |
123 "Functions to run whenever Winner mode is turned on." | |
124 :type 'hook | |
20969
6007dc30ec3b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20968
diff
changeset
|
125 :group 'winner) |
17469 | 126 |
20969
6007dc30ec3b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20968
diff
changeset
|
127 (defcustom winner-mode-leave-hook nil |
20968 | 128 "Functions to run whenever Winner mode is turned off." |
129 :type 'hook | |
20969
6007dc30ec3b
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20968
diff
changeset
|
130 :group 'winner) |
17469 | 131 |
132 (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
|
133 |
20968 | 134 ;;;###autoload |
17469 | 135 (defun winner-mode (&optional arg) |
136 "Toggle Winner mode. | |
137 With arg, turn Winner mode on if and only if arg is positive." | |
138 (interactive "P") | |
139 (let ((on-p (if arg (> (prefix-numeric-value arg) 0) | |
140 (not winner-mode)))) | |
141 (cond | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
142 ;; Turn mode on |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
143 (on-p |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
144 (setq winner-mode t) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
145 (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
|
146 (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
|
147 (setq winner-modified-list (frame-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
148 (winner-save-new-configurations) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
149 (run-hooks 'winner-mode-hook)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
150 ;; Turn mode off |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
151 (winner-mode |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
152 (setq winner-mode nil) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
153 (run-hooks 'winner-mode-leave-hook))) |
17469 | 154 (force-mode-line-update))) |
155 | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
156 ;; Inspired by undo (simple.el) |
20086
92b4edaf6482
(winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents:
20047
diff
changeset
|
157 |
92b4edaf6482
(winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents:
20047
diff
changeset
|
158 (defvar winner-pending-undo-ring nil) |
92b4edaf6482
(winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents:
20047
diff
changeset
|
159 |
92b4edaf6482
(winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents:
20047
diff
changeset
|
160 (defvar winner-undo-counter nil) |
92b4edaf6482
(winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents:
20047
diff
changeset
|
161 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
162 (defun winner-undo (arg) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
163 "Switch back to an earlier window configuration saved by Winner mode. |
20968 | 164 In other words, \"undo\" changes in window configuration. |
165 With prefix arg, undo that many levels." | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
166 (interactive "p") |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
167 (cond |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
168 ((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
|
169 ((eq (selected-window) (minibuffer-window)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
170 (error "No winner undo from minibuffer.")) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
171 (t (setq this-command t) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
172 (if (eq last-command 'winner-undo) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
173 ;; This was no new window configuration after all. |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
174 (ring-remove winner-pending-undo-ring 0) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
175 (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
|
176 (setq winner-undo-counter 0)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
177 (winner-undo-more (or arg 1)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
178 (message "Winner undo (%d)!" winner-undo-counter) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
179 (setq this-command 'winner-undo)))) |
17469 | 180 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
181 (defun winner-undo-more (count) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
182 "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
|
183 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
|
184 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
|
185 (let ((len (ring-length winner-pending-undo-ring))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
186 (incf winner-undo-counter count) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
187 (if (>= winner-undo-counter len) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
188 (error "No further window configuration undo information") |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
189 (winner-set |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
190 (ring-ref winner-pending-undo-ring |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
191 winner-undo-counter))))) |
17469 | 192 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
193 (defun winner-redo () |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
194 "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
|
195 (interactive) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
196 (cond |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
197 ((eq last-command 'winner-undo) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
198 (ring-remove winner-pending-undo-ring 0) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
199 (winner-set |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
200 (ring-remove winner-pending-undo-ring 0)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
201 (or (eq (selected-window) (minibuffer-window)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
202 (message "Winner undid undo!"))) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
203 (t (error "Previous command was not a winner-undo")))) |
17469 | 204 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
205 ;;; Winner switch |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
206 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
207 (defun winner-switch-buffer-list () |
17469 | 208 (loop for buf in (buffer-list) |
209 for name = (buffer-name buf) | |
210 unless (or (eq (current-buffer) buf) | |
211 (member name winner-skip-buffers) | |
212 (loop for regexp in winner-skip-regexps | |
213 if (string-match regexp name) return t | |
214 finally return nil)) | |
215 collect name)) | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
216 |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
217 (defvar winner-switch-list nil) |
17469 | 218 |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
219 (defun winner-switch (count) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
220 "Step through your buffers without disturbing `winner-mode'. |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
221 `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
|
222 `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
|
223 (interactive "p") |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
224 (decf count) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
225 (setq this-command t) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
226 (cond |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
227 ((eq last-command 'winner-switch) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
228 (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
|
229 (bury-buffer (current-buffer)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
230 (mapcar 'bury-buffer winner-switch-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
231 (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
|
232 (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
|
233 (or winner-switch-list |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
234 (setq winner-switch-list (winner-switch-buffer-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
235 (error "No more buffers")) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
236 (switch-to-buffer (pop winner-switch-list)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
237 (message (concat "Winner: [%s] " |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
238 (mapconcat 'identity winner-switch-list " ")) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
239 (buffer-name)) |
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
240 (setq this-command 'winner-switch)) |
17469 | 241 |
242 ;;;; To be evaluated when the package is loaded: | |
243 | |
244 (unless winner-mode-map | |
245 (setq winner-mode-map (make-sparse-keymap)) | |
19564
8d89cc0f2b42
Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents:
19502
diff
changeset
|
246 (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
|
247 (define-key winner-mode-map [?\C-x right] 'winner-redo)) |
17469 | 248 |
249 (unless (or (assq 'winner-mode minor-mode-map-alist) | |
250 winner-dont-bind-my-keys) | |
251 (push (cons 'winner-mode winner-mode-map) | |
252 minor-mode-map-alist)) | |
253 | |
254 (unless (assq 'winner-mode minor-mode-alist) | |
255 (push '(winner-mode " Win") minor-mode-alist)) | |
256 | |
257 (provide 'winner) | |
258 | |
17470
c4cd2317fe60
Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents:
17469
diff
changeset
|
259 ;;; winner.el ends here |