annotate lisp/winner.el @ 19540:06552ba973ce libc-970827 libc-970828 libc-970829 libc-970830 libc-970831 libc-970901 libc-970902 libc-970903 libc-970904 libc-970905

(*:Linux:*:*): Recognize alpha-linux-gnulibc1.
author Richard Kenner <kenner@gnu.org>
date Tue, 26 Aug 1997 09:21:29 +0000
parents 95f1938d0296
children 8d89cc0f2b42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; winner.el --- Restore window configuration or change buffer
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Ivar Rummelhoff <ivarr@ifi.uio.no>
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Maintainer: Ivar Rummelhoff <ivarr@ifi.uio.no>
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: 27 Feb 1997
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: extensions,windows
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
29 ;; winner.el provides a minor mode (`winner-mode') that does
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; essentially two things:
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; 1) It keeps track of changing window configurations, so that
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; when you wish to go back to a previous view, all you have
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; to do is to press C-left a couple of times.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; 2) It lets you switch to other buffers by pressing C-right.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
38 ;; To use Winner mode, put this line in your .emacs file:
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; (add-hook 'after-init-hook (lambda () (winner-mode 1)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; Details:
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; 1. You may of course decide to use other bindings than those
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; mentioned above. Just set these variables in your .emacs:
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; `winner-prev-event'
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; `winner-next-event'
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; 2. When you have found the view of your choice
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; (using your favourite keys), you may press ctrl-space
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; (`winner-max-event') to `delete-other-windows'.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; 3. Winner now keeps one configuration stack for each frame.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; Yours sincerely, Ivar Rummelhoff
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;; Code:
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;;; Variables you may want to change
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (defvar winner-prev-event 'C-left
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 "Winner mode binds this event to the command `winner-previous'.")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (defvar winner-next-event 'C-right
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 "Winner mode binds this event to the command `winner-next'.")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (defvar winner-max-event 67108896 ; CTRL-space
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 "Event for deleting other windows
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 after having selected a view with Winner.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 The normal functions of this event will also be performed.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 In the default case (CTRL-SPACE) the mark will be set.")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (defvar winner-skip-buffers
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 '("*Messages*",
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 "*Compile-Log*",
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ".newsrc-dribble",
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 "*Completions*",
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 "*Buffer list*")
19502
95f1938d0296 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18959
diff changeset
87 "Exclude these buffer names from any \(Winner mode\) list of buffers.")
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (defvar winner-skip-regexps '("^ ")
19502
95f1938d0296 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18959
diff changeset
90 "Winner excludes buffers with names matching any of these regexps.
95f1938d0296 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18959
diff changeset
91 They are not included in any Winner mode list of buffers.
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 By default `winner-skip-regexps' is set to \(\"^ \"\),
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 which excludes \"invisible buffers\".")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (defvar winner-limit 50
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 "Winner will save no more than 2 * `winner-limit' window configurations.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 \(.. and no less than `winner-limit'.\)")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (defvar winner-mode-hook nil
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 "Functions to run whenever Winner mode is turned on.")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (defvar winner-mode-leave-hook nil
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 "Functions to run whenever Winner mode is turned off.")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (defvar winner-dont-bind-my-keys nil
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 "If non-nil: Do not use `winner-mode-map' in Winner mode.")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;;;; Winner mode
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (eval-when-compile (require 'cl))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (defvar winner-mode nil) ; For the modeline.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (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
119
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
120 ;;;###autoload
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (defun winner-mode (&optional arg)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 "Toggle Winner mode.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 With arg, turn Winner mode on if and only if arg is positive."
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (interactive "P")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (let ((on-p (if arg (> (prefix-numeric-value arg) 0)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (not winner-mode))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (cond
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (on-p (let ((winner-frames-changed (frame-list)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (winner-do-save)) ; Save current configurations
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (add-hook 'window-configuration-change-hook 'winner-save-configuration)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (setq winner-mode t)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (run-hooks 'winner-mode-hook))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (t (remove-hook 'window-configuration-change-hook 'winner-save-configuration)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (when winner-mode
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (setq winner-mode nil)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (run-hooks 'winner-mode-leave-hook))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (force-mode-line-update)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; List of frames which have changed
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (defvar winner-frames-changed nil)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 ;; Time to save the window configuration.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (defun winner-save-configuration ()
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (push (selected-frame) winner-frames-changed)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (add-hook 'post-command-hook 'winner-do-save))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (defun winner-do-save ()
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (let ((current (selected-frame)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (unwind-protect
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (do ((frames winner-frames-changed (cdr frames)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ((null frames))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (unless (memq (car frames) (cdr frames))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 ;; Process each frame once.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (select-frame (car frames))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (winner-push (current-window-configuration) (car frames))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (setq winner-frames-changed nil)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (select-frame current)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (remove-hook 'post-command-hook 'winner-do-save))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;;;; Configuration stacks (one for each frame)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (defvar winner-stacks nil) ; ------ " ------
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
18959
f6f245a3714b (custom-print-functions): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 17470
diff changeset
171 ;; This works around a bug in defstruct.
f6f245a3714b (custom-print-functions): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 17470
diff changeset
172 (defvar custom-print-functions nil)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; A stack of window configurations with some additional information.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (defstruct (winner-stack
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (:constructor winner-stack-new
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (config &aux
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (data (list config))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (place data))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 data place (count 1))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;; Return the stack of this frame
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (defun winner-stack (frame)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (let ((stack (cdr (assq frame winner-stacks))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (if stack (winner-stack-data stack)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 ;; Else make new stack
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (letf (((selected-frame) frame))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (let ((config (current-window-configuration)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (push (cons frame (winner-stack-new config))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 winner-stacks)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (list config))))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ;; Push this window configuration on the right stack,
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 ;; but make sure the stack doesn't get too large etc...
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (defun winner-push (config frame)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (let ((this (cdr (assq frame winner-stacks))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (if (not this) (push (cons frame (winner-stack-new config))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 winner-stacks)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (push config (winner-stack-data this))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (when (> (incf (winner-stack-count this)) winner-limit)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 ;; No more than 2*winner-limit configs
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (setcdr (winner-stack-place this) nil)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (setf (winner-stack-place this)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (winner-stack-data this))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (setf (winner-stack-count this) 1)))))
19502
95f1938d0296 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18959
diff changeset
207
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;;;; Selecting a window configuration
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; Return list of names of other buffers, excluding the current buffer
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; and buffers specified by the user.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (defun winner-other-buffers ()
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (loop for buf in (buffer-list)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 for name = (buffer-name buf)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 unless (or (eq (current-buffer) buf)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (member name winner-skip-buffers)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (loop for regexp in winner-skip-regexps
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 if (string-match regexp name) return t
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 finally return nil))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 collect name))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (defun winner-select (&optional arg)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 "Change to previous or new window configuration.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 With arg start at position 1 if arg is positive, and
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 at -1 if arg is negative; else start at position 0.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 \(For Winner to record changes in window configurations,
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 Winner mode must be turned on.\)"
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (interactive "P")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (setq arg
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (cond
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 ((not arg) nil)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 ((> (prefix-numeric-value arg) 0) winner-next-event)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 ((< (prefix-numeric-value arg) 0) winner-prev-event)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (t nil)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (if arg (push arg unread-command-events))
19502
95f1938d0296 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18959
diff changeset
237
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (let ((stack (winner-stack (selected-frame)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (store nil)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (buffers (winner-other-buffers))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (passed nil)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (config (current-window-configuration))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (pos 0) event)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 ;; `stack' and `store' are stacks of window configuration while
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 ;; `buffers' and `passed' are stacks of buffer names.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (condition-case nil
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (loop
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (setq event (read-event))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (cond
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 ((eq event winner-prev-event)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (cond (passed (push (pop passed) buffers)(decf pos))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 ((cdr stack)(push (pop stack) store) (decf pos))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (t (setq stack (append (nreverse store) stack))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (setq store nil)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (setq pos 0))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 ((eq event winner-next-event)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (cond (store (push (pop store) stack) (incf pos))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (buffers (push (pop buffers) passed) (incf pos))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (t (setq buffers (nreverse passed))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (setq passed nil)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (setq pos 0))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ((eq event winner-max-event)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 ;; Delete other windows and leave.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (delete-other-windows)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 ;; Let this change be saved.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (setq pos -1)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 ;; Perform other actions of this event.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (push event unread-command-events)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (return))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (t (push event unread-command-events) (return)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (cond
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 ;; Display
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (passed (set-window-buffer (selected-window) (car passed))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (message (concat "Winner\(%d\): [%s] "
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (mapconcat 'identity buffers " "))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 pos (car passed)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (t (set-window-configuration (car stack))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (if (window-minibuffer-p (selected-window))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (other-window 1))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (message "Winner\(%d\)" pos))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (quit (set-window-configuration config)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (setq pos 0)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (if (zerop pos)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 ;; Do not record these changes.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (remove-hook 'post-command-hook 'winner-do-save)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 ;; Else update the buffer list and make sure that the displayed
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 ;; buffer is the same as the current buffer.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (switch-to-buffer (window-buffer)))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (defun winner-previous ()
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 "Change to previous window configuration."
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (interactive)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (winner-select -1))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (defun winner-next ()
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 "Change to new window configuration."
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (interactive)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (winner-select 1))
19502
95f1938d0296 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18959
diff changeset
307
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 ;;;; To be evaluated when the package is loaded:
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (unless winner-mode-map
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (setq winner-mode-map (make-sparse-keymap))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (define-key winner-mode-map (vector winner-prev-event) 'winner-previous)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (define-key winner-mode-map (vector winner-next-event) 'winner-next))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (unless (or (assq 'winner-mode minor-mode-map-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 winner-dont-bind-my-keys)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (push (cons 'winner-mode winner-mode-map)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 minor-mode-map-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (unless (assq 'winner-mode minor-mode-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (push '(winner-mode " Win") minor-mode-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (provide 'winner)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
325 ;;; winner.el ends here