Mercurial > emacs
annotate lisp/ebuff-menu.el @ 46123:90cae21cf871
*** empty log message ***
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Mon, 01 Jul 2002 22:01:13 +0000 |
parents | 7cbfb84f7362 |
children | 37645a051842 |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
475
diff
changeset
|
1 ;;; ebuff-menu.el --- electric-buffer-list mode |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
475
diff
changeset
|
2 |
7300 | 3 ;; Copyright (C) 1985, 1986, 1994 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
5 ;; Author: Richard Mlynarik <mly@ai.mit.edu> |
21045 | 6 ;; Maintainer: FSF |
31559 | 7 ;; Keywords: convenience |
475 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
475 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
475 | 25 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
26 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
27 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2026
diff
changeset
|
28 ;; Who says one can't have typeout windows in GNU Emacs? The entry |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2026
diff
changeset
|
29 ;; point, `electric-buffer-list' works like ^r select buffer from the |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2026
diff
changeset
|
30 ;; ITS Emacs lunar or tmacs libraries. |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
31 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
32 ;;; Code: |
475 | 33 |
34 (require 'electric) | |
35 | |
36 ;; this depends on the format of list-buffers (from src/buffer.c) and | |
37 ;; on stuff in lisp/buff-menu.el | |
38 | |
39 (defvar electric-buffer-menu-mode-map nil) | |
40 | |
41 ;;;###autoload | |
42 (defun electric-buffer-list (arg) | |
43 "Pops up a buffer describing the set of Emacs buffers. | |
44 Vaguely like ITS lunar select buffer; combining typeoutoid buffer | |
45 listing with menuoid buffer selection. | |
46 | |
47 If the very next character typed is a space then the buffer list | |
48 window disappears. Otherwise, one may move around in the buffer list | |
49 window, marking buffers to be selected, saved or deleted. | |
50 | |
51 To exit and select a new buffer, type a space when the cursor is on | |
52 the appropriate line of the buffer-list window. Other commands are | |
53 much like those of buffer-menu-mode. | |
54 | |
55 Calls value of `electric-buffer-menu-mode-hook' on entry if non-nil. | |
56 | |
57 \\{electric-buffer-menu-mode-map}" | |
58 (interactive "P") | |
59 (let (select buffer) | |
60 (save-window-excursion | |
38928
86b624b00b77
(electric-buffer-list): Use list-buffers-noselect.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31559
diff
changeset
|
61 (setq buffer (list-buffers-noselect arg)) |
86b624b00b77
(electric-buffer-list): Use list-buffers-noselect.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31559
diff
changeset
|
62 (Electric-pop-up-window buffer) |
475 | 63 (unwind-protect |
64 (progn | |
65 (set-buffer buffer) | |
66 (Electric-buffer-menu-mode) | |
41016
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
67 (electric-buffer-update-highlight) |
475 | 68 (setq select |
69 (catch 'electric-buffer-menu-select | |
8122
2fae14e8ae5d
(electric-buffer-list): Change prompt message.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
70 (message "<<< Press Return to bury the buffer list >>>") |
2026
3514a9bf50c5
(electric-buffer-list): Handle any kind of event.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
71 (if (eq (setq unread-command-events (list (read-event))) |
3514a9bf50c5
(electric-buffer-list): Handle any kind of event.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
72 ?\ ) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1607
diff
changeset
|
73 (progn (setq unread-command-events nil) |
475 | 74 (throw 'electric-buffer-menu-select nil))) |
12568
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
75 (let ((start-point (point)) |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
76 (first (progn (goto-char (point-min)) |
475 | 77 (forward-line 2) |
78 (point))) | |
79 (last (progn (goto-char (point-max)) | |
80 (forward-line -1) | |
81 (point))) | |
82 (goal-column 0)) | |
12568
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
83 ;; Use start-point if it is meaningful. |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
84 (goto-char (if (or (< start-point first) |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
85 (> start-point last)) |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
86 first |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
87 start-point)) |
475 | 88 (Electric-command-loop 'electric-buffer-menu-select |
89 nil | |
90 t | |
91 'electric-buffer-menu-looper | |
92 (cons first last)))))) | |
93 (set-buffer buffer) | |
94 (Buffer-menu-mode) | |
95 (bury-buffer buffer) | |
96 (message ""))) | |
97 (if select | |
98 (progn (set-buffer buffer) | |
99 (let ((opoint (point-marker))) | |
100 (Buffer-menu-execute) | |
101 (goto-char (point-min)) | |
102 (if (prog1 (search-forward "\n>" nil t) | |
103 (goto-char opoint) (set-marker opoint nil)) | |
104 (Buffer-menu-select) | |
105 (switch-to-buffer (Buffer-menu-buffer t)))))))) | |
106 | |
107 (defun electric-buffer-menu-looper (state condition) | |
108 (cond ((and condition | |
109 (not (memq (car condition) '(buffer-read-only | |
110 end-of-buffer | |
111 beginning-of-buffer)))) | |
112 (signal (car condition) (cdr condition))) | |
113 ((< (point) (car state)) | |
114 (goto-char (point-min)) | |
115 (forward-line 2)) | |
116 ((> (point) (cdr state)) | |
117 (goto-char (point-max)) | |
118 (forward-line -1) | |
119 (if (pos-visible-in-window-p (point-max)) | |
41016
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
120 (recenter -1)))) |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
121 (electric-buffer-update-highlight)) |
475 | 122 |
123 (put 'Electric-buffer-menu-mode 'mode-class 'special) | |
124 (defun Electric-buffer-menu-mode () | |
125 "Major mode for editing a list of buffers. | |
126 Each line describes one of the buffers in Emacs. | |
127 Letters do not insert themselves; instead, they are commands. | |
128 \\<electric-buffer-menu-mode-map> | |
129 \\[keyboard-quit] or \\[Electric-buffer-menu-quit] -- exit buffer menu, returning to previous window and buffer | |
130 configuration. If the very first character typed is a space, it | |
131 also has this effect. | |
132 \\[Electric-buffer-menu-select] -- select buffer of line point is on. | |
133 Also show buffers marked with m in other windows, | |
134 deletes buffers marked with \"D\", and saves those marked with \"S\". | |
135 \\[Buffer-menu-mark] -- mark buffer to be displayed. | |
136 \\[Buffer-menu-not-modified] -- clear modified-flag on that buffer. | |
137 \\[Buffer-menu-save] -- mark that buffer to be saved. | |
138 \\[Buffer-menu-delete] or \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted. | |
139 \\[Buffer-menu-unmark] -- remove all kinds of marks from current line. | |
140 \\[Electric-buffer-menu-mode-view-buffer] -- view buffer, returning when done. | |
141 \\[Buffer-menu-backup-unmark] -- back up a line and remove marks. | |
142 | |
143 \\{electric-buffer-menu-mode-map} | |
144 | |
145 Entry to this mode via command electric-buffer-list calls the value of | |
146 electric-buffer-menu-mode-hook if it is non-nil." | |
147 (kill-all-local-variables) | |
148 (use-local-map electric-buffer-menu-mode-map) | |
149 (setq mode-name "Electric Buffer Menu") | |
150 (setq mode-line-buffer-identification "Electric Buffer List") | |
151 (make-local-variable 'Helper-return-blurb) | |
152 (setq Helper-return-blurb "return to buffer editing") | |
153 (setq truncate-lines t) | |
154 (setq buffer-read-only t) | |
155 (setq major-mode 'Electric-buffer-menu-mode) | |
156 (goto-char (point-min)) | |
157 (if (search-forward "\n." nil t) (forward-char -1)) | |
158 (run-hooks 'electric-buffer-menu-mode-hook)) | |
159 | |
160 ;; generally the same as Buffer-menu-mode-map | |
161 ;; (except we don't indirect to global-map) | |
162 (put 'Electric-buffer-menu-undefined 'suppress-keymap t) | |
163 (if electric-buffer-menu-mode-map | |
164 nil | |
23007
62da6fd2d526
(electric-buffer-menu-mode-map): Don't wipe out all Meta keys.
Richard M. Stallman <rms@gnu.org>
parents:
21045
diff
changeset
|
165 (let ((map (make-keymap))) |
2397
2b34a2ef4d63
(electric-buffer-menu-mode-map): fillarray isn't a valid operation on maps
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
166 (fillarray (car (cdr map)) 'Electric-buffer-menu-undefined) |
23007
62da6fd2d526
(electric-buffer-menu-mode-map): Don't wipe out all Meta keys.
Richard M. Stallman <rms@gnu.org>
parents:
21045
diff
changeset
|
167 (define-key map "\e" nil) |
475 | 168 (define-key map "\C-z" 'suspend-emacs) |
169 (define-key map "v" 'Electric-buffer-menu-mode-view-buffer) | |
918
94b50bbd43c3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
917
diff
changeset
|
170 (define-key map (char-to-string help-char) 'Helper-help) |
475 | 171 (define-key map "?" 'Helper-describe-bindings) |
172 (define-key map "\C-c" nil) | |
173 (define-key map "\C-c\C-c" 'Electric-buffer-menu-quit) | |
174 (define-key map "\C-]" 'Electric-buffer-menu-quit) | |
175 (define-key map "q" 'Electric-buffer-menu-quit) | |
176 (define-key map " " 'Electric-buffer-menu-select) | |
8122
2fae14e8ae5d
(electric-buffer-list): Change prompt message.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
177 (define-key map "\C-m" 'Electric-buffer-menu-select) |
475 | 178 (define-key map "\C-l" 'recenter) |
179 (define-key map "s" 'Buffer-menu-save) | |
180 (define-key map "d" 'Buffer-menu-delete) | |
181 (define-key map "k" 'Buffer-menu-delete) | |
182 (define-key map "\C-d" 'Buffer-menu-delete-backwards) | |
183 ;(define-key map "\C-k" 'Buffer-menu-delete) | |
184 (define-key map "\177" 'Buffer-menu-backup-unmark) | |
185 (define-key map "~" 'Buffer-menu-not-modified) | |
186 (define-key map "u" 'Buffer-menu-unmark) | |
187 (let ((i ?0)) | |
188 (while (<= i ?9) | |
189 (define-key map (char-to-string i) 'digit-argument) | |
190 (define-key map (concat "\e" (char-to-string i)) 'digit-argument) | |
191 (setq i (1+ i)))) | |
192 (define-key map "-" 'negative-argument) | |
193 (define-key map "\e-" 'negative-argument) | |
194 (define-key map "m" 'Buffer-menu-mark) | |
195 (define-key map "\C-u" 'universal-argument) | |
196 (define-key map "\C-p" 'previous-line) | |
197 (define-key map "\C-n" 'next-line) | |
198 (define-key map "p" 'previous-line) | |
199 (define-key map "n" 'next-line) | |
200 (define-key map "\C-v" 'scroll-up) | |
201 (define-key map "\ev" 'scroll-down) | |
202 (define-key map ">" 'scroll-right) | |
203 (define-key map "<" 'scroll-left) | |
204 (define-key map "\e\C-v" 'scroll-other-window) | |
205 (define-key map "\e>" 'end-of-buffer) | |
206 (define-key map "\e<" 'beginning-of-buffer) | |
11275
53f0ebe096f5
(electric-buffer-menu-mode-map): Undefine ESC ESC
Richard M. Stallman <rms@gnu.org>
parents:
10115
diff
changeset
|
207 (define-key map "\e\e" nil) |
10115
e55ee438bd10
(electric-buffer-menu-mode-map):
Richard M. Stallman <rms@gnu.org>
parents:
8122
diff
changeset
|
208 (define-key map "\e\e\e" 'Electric-buffer-menu-quit) |
e55ee438bd10
(electric-buffer-menu-mode-map):
Richard M. Stallman <rms@gnu.org>
parents:
8122
diff
changeset
|
209 (define-key map [escape escape escape] 'Electric-buffer-menu-quit) |
7006
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
210 (define-key map [mouse-2] 'Electric-buffer-menu-mouse-select) |
475 | 211 (setq electric-buffer-menu-mode-map map))) |
212 | |
213 (defun Electric-buffer-menu-exit () | |
214 (interactive) | |
2026
3514a9bf50c5
(electric-buffer-list): Handle any kind of event.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
215 (setq unread-command-events (listify-key-sequence (this-command-keys))) |
475 | 216 ;; for robustness |
217 (condition-case () | |
218 (throw 'electric-buffer-menu-select nil) | |
219 (error (Buffer-menu-mode) | |
220 (other-buffer)))) | |
221 | |
222 (defun Electric-buffer-menu-select () | |
223 "Leave Electric Buffer Menu, selecting buffers and executing changes. | |
224 Saves buffers marked \"S\". Deletes buffers marked \"K\". | |
225 Selects buffer at point and displays buffers marked \">\" in other windows." | |
226 (interactive) | |
227 (throw 'electric-buffer-menu-select (point))) | |
228 | |
7006
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
229 (defun Electric-buffer-menu-mouse-select (event) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
230 (interactive "e") |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
231 (select-window (posn-window (event-end event))) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
232 (set-buffer (window-buffer (selected-window))) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
233 (goto-char (posn-point (event-end event))) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
234 (throw 'electric-buffer-menu-select (point))) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
235 |
475 | 236 (defun Electric-buffer-menu-quit () |
237 "Leave Electric Buffer Menu, restoring previous window configuration. | |
238 Does not execute select, save, or delete commands." | |
239 (interactive) | |
240 (throw 'electric-buffer-menu-select nil)) | |
241 | |
242 (defun Electric-buffer-menu-undefined () | |
243 (interactive) | |
244 (ding) | |
14310
49af6e2bfaa8
(Electric-buffer-menu-undefined): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
245 (message "%s" |
49af6e2bfaa8
(Electric-buffer-menu-undefined): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
246 (if (and (eq (key-binding "\C-c\C-c") 'Electric-buffer-menu-quit) |
475 | 247 (eq (key-binding " ") 'Electric-buffer-menu-select) |
919 | 248 (eq (key-binding (char-to-string help-char)) 'Helper-help) |
475 | 249 (eq (key-binding "?") 'Helper-describe-bindings)) |
916
938f166a0874
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
915
diff
changeset
|
250 (substitute-command-keys "Type C-c C-c to exit, Space to select, \\[Helper-help] for help, ? for commands") |
475 | 251 (substitute-command-keys "\ |
252 Type \\[Electric-buffer-menu-quit] to exit, \ | |
253 \\[Electric-buffer-menu-select] to select, \ | |
254 \\[Helper-help] for help, \\[Helper-describe-bindings] for commands."))) | |
255 (sit-for 4)) | |
256 | |
257 (defun Electric-buffer-menu-mode-view-buffer () | |
258 "View buffer on current line in Electric Buffer Menu. | |
259 Returns to Electric Buffer Menu when done." | |
260 (interactive) | |
261 (let ((bufnam (Buffer-menu-buffer nil))) | |
262 (if bufnam | |
263 (view-buffer bufnam) | |
264 (ding) | |
265 (message "Buffer %s does not exist!" bufnam) | |
266 (sit-for 4)))) | |
267 | |
41016
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
268 (defvar electric-buffer-overlay nil) |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
269 (defun electric-buffer-update-highlight () |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
270 ;; Make sure we have an overlay to use. |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
271 (or electric-buffer-overlay |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
272 (progn |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
273 (make-local-variable 'electric-buffer-overlay) |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
274 (setq electric-buffer-overlay (make-overlay (point) (point))))) |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
275 (move-overlay electric-buffer-overlay |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
276 (save-excursion (beginning-of-line) (point)) |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
277 (save-excursion (end-of-line) (point))) |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
278 (overlay-put electric-buffer-overlay 'face 'highlight)) |
7cbfb84f7362
(electric-buffer-update-highlight): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38928
diff
changeset
|
279 |
18383 | 280 (provide 'ebuff-menu) |
281 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
475
diff
changeset
|
282 ;;; ebuff-menu.el ends here |