annotate lisp/winner.el @ 20892:18f3cb26243f before-miles-orphaned-changes gcc-2_8_1-980401 gcc-2_8_1-980407 gcc-2_8_1-980412 gcc-2_8_1-980413 gcc-2_8_1-RELEASE gcc_2_8_1-980315 libc-980214 libc-980215 libc-980216 libc-980217 libc-980218 libc-980219 libc-980220 libc-980221 libc-980222 libc-980223 libc-980224 libc-980225 libc-980226 libc-980227 libc-980228 libc-980301 libc-980302 libc-980303 libc-980304 libc-980306 libc-980307 libc-980308 libc-980309 libc-980310 libc-980311 libc-980312 libc-980313 libc-980314 libc-980315 libc-980316 libc-980317 libc-980318 libc-980319 libc-980320 libc-980321 libc-980322 libc-980323 libc-980324 libc-980325 libc-980326 libc-980327 libc-980328 libc-980329 libc-980330 libc-980331 libc-980401 libc-980402 libc-980403 libc-980404 libc-980405 libc-980406 libc-980407 libc-980408 libc-980409 libc-980410 libc-980411 libc-980412 libc-980413 libc-980414 libc-980428 libc-980429 libc-980430 libc-980501 libc-980502 libc-980503 libc-980504 libc-980505 libc-980506 libc-980507 libc-980508 libc-980509 libc-980510 libc-980512 libc-980513 libc-980514 libc-980515 libc-980516 libc-980517 libc-980518 libc-980519 libc-980520 libc-980521 libc-980522 libc-980523 libc-980524 libc-980525 libc-980526 libc-980527 libc-980528 libc-980529 libc-980530 libc-980531 libc-980601 libc-980602 libc-980603 libc-980604 libc-980605 libc-980606 libc-980607 libc-980608 libc-980609 libc-980610 libc-980611 libc-980612 libc-980613

Add PentiumII (i786). Add '7' to all i[3456] entries. Add AMD and Cyrix names for P5 and P6.
author Richard Kenner <kenner@gnu.org>
date Fri, 13 Feb 1998 12:16:46 +0000
parents 92b4edaf6482
children 7072722c5071
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
8 ;; Keywords: extensions, windows
17469
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:
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
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; Code:
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
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 (defvar winner-skip-buffers
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 '("*Messages*",
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 "*Compile-Log*",
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ".newsrc-dribble",
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 "*Completions*",
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
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 (defvar winner-skip-regexps '("^ ")
19502
95f1938d0296 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18959
diff changeset
66 "Winner excludes buffers with names matching any of these regexps.
95f1938d0296 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 18959
diff changeset
67 They are not included in any Winner mode list of buffers.
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 By default `winner-skip-regexps' is set to \(\"^ \"\),
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 which excludes \"invisible buffers\".")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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 ()
20047
735f0cdfc5b9 (winner-change-fun): Don't use pushnew.
Karl Heuer <kwzh@gnu.org>
parents: 19564
diff changeset
84 (or (memq (selected-frame) winner-modified-list)
735f0cdfc5b9 (winner-change-fun): Don't use pushnew.
Karl Heuer <kwzh@gnu.org>
parents: 19564
diff changeset
85 (push (selected-frame) winner-modified-list)))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
86
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
87 (defun winner-save-new-configurations ()
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
88 (while winner-modified-list
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
89 (ring-insert
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
90 (winner-ring (car winner-modified-list))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
91 (current-window-configuration (pop winner-modified-list)))))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
92
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
93 (defun winner-set (conf)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
94 (set-window-configuration conf)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
95 (if (eq (selected-window) (minibuffer-window))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
96 (other-window 1)))
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
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
99 ;;; Winner mode (a minor mode)
17469
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
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
107 (defvar winner-mode nil) ; mode variable
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (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
109
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (defun winner-mode (&optional arg)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 "Toggle Winner mode.
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 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
113 (interactive "P")
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (let ((on-p (if arg (> (prefix-numeric-value arg) 0)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (not winner-mode))))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (cond
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
117 ;; Turn mode on
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
118 (on-p
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
119 (setq winner-mode t)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
120 (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
121 (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
122 (setq winner-modified-list (frame-list))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
123 (winner-save-new-configurations)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
124 (run-hooks 'winner-mode-hook))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
125 ;; Turn mode off
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
126 (winner-mode
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
127 (setq winner-mode nil)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
128 (run-hooks 'winner-mode-leave-hook)))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (force-mode-line-update)))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
131 ;; Inspired by undo (simple.el)
20086
92b4edaf6482 (winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents: 20047
diff changeset
132
92b4edaf6482 (winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents: 20047
diff changeset
133 (defvar winner-pending-undo-ring nil)
92b4edaf6482 (winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents: 20047
diff changeset
134
92b4edaf6482 (winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents: 20047
diff changeset
135 (defvar winner-undo-counter nil)
92b4edaf6482 (winner-pending-undo-ring): Defvar before first use.
Karl Heuer <kwzh@gnu.org>
parents: 20047
diff changeset
136
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
137 (defun winner-undo (arg)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
138 "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
139 In other words, \"undo\" changes in window configuration."
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
140 (interactive "p")
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
141 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
142 ((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
143 ((eq (selected-window) (minibuffer-window))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
144 (error "No winner undo from minibuffer."))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
145 (t (setq this-command t)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
146 (if (eq last-command 'winner-undo)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
147 ;; This was no new window configuration after all.
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
148 (ring-remove winner-pending-undo-ring 0)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
149 (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
150 (setq winner-undo-counter 0))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
151 (winner-undo-more (or arg 1))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
152 (message "Winner undo (%d)!" winner-undo-counter)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
153 (setq this-command 'winner-undo))))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
155 (defun winner-undo-more (count)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
156 "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
157 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
158 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
159 (let ((len (ring-length winner-pending-undo-ring)))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
160 (incf winner-undo-counter count)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
161 (if (>= winner-undo-counter len)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
162 (error "No further window configuration undo information")
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
163 (winner-set
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
164 (ring-ref winner-pending-undo-ring
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
165 winner-undo-counter)))))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
167 (defun winner-redo ()
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
168 "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
169 (interactive)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
170 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
171 ((eq last-command 'winner-undo)
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 (winner-set
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 (or (eq (selected-window) (minibuffer-window))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
176 (message "Winner undid undo!")))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
177 (t (error "Previous command was not a winner-undo"))))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
179 ;;; Winner switch
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
180
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
181 (defun winner-switch-buffer-list ()
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (loop for buf in (buffer-list)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 for name = (buffer-name buf)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 unless (or (eq (current-buffer) buf)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (member name winner-skip-buffers)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (loop for regexp in winner-skip-regexps
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 if (string-match regexp name) return t
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 finally return nil))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 collect name))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
190
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
191 (defvar winner-switch-list nil)
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
193 (defun winner-switch (count)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
194 "Step through your buffers without disturbing `winner-mode'.
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
195 `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
196 `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
197 (interactive "p")
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
198 (decf count)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
199 (setq this-command t)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
200 (cond
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
201 ((eq last-command 'winner-switch)
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
202 (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
203 (bury-buffer (current-buffer))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
204 (mapcar 'bury-buffer winner-switch-list))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
205 (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
206 (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
207 (or winner-switch-list
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
208 (setq winner-switch-list (winner-switch-buffer-list))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
209 (error "No more buffers"))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
210 (switch-to-buffer (pop winner-switch-list))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
211 (message (concat "Winner: [%s] "
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
212 (mapconcat 'identity winner-switch-list " "))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
213 (buffer-name))
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
214 (setq this-command 'winner-switch))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 ;;;; To be evaluated when the package is loaded:
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (unless winner-mode-map
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (setq winner-mode-map (make-sparse-keymap))
19564
8d89cc0f2b42 Many changes by Ivar Rummelhoff.
Richard M. Stallman <rms@gnu.org>
parents: 19502
diff changeset
220 (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
221 (define-key winner-mode-map [?\C-x right] 'winner-redo))
17469
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (unless (or (assq 'winner-mode minor-mode-map-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 winner-dont-bind-my-keys)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (push (cons 'winner-mode winner-mode-map)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 minor-mode-map-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (unless (assq 'winner-mode minor-mode-alist)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (push '(winner-mode " Win") minor-mode-alist))
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (provide 'winner)
141077afaa74 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
17470
c4cd2317fe60 Clean up comments, etc.
Richard M. Stallman <rms@gnu.org>
parents: 17469
diff changeset
233 ;;; winner.el ends here