0
|
1 ;;; buff-menu.el --- buffer menu main function and support functions.
|
|
2
|
|
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 95 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: FSF
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
22
|
|
23 ;;; Synched up with: FSF 19.30 except as noted.
|
|
24
|
|
25 ;;; Commentary:
|
|
26
|
|
27 ;; Edit, delete, or change attributes of all currently active Emacs
|
|
28 ;; buffers from a list summarizing their state. A good way to browse
|
|
29 ;; any special or scratch buffers you have loaded, since you can't find
|
|
30 ;; them by filename. The single entry point is `Buffer-menu-mode',
|
|
31 ;; normally bound to C-x C-b.
|
|
32
|
|
33 ;;; Change Log:
|
|
34
|
|
35 ;; Merged by esr with recent mods to Emacs 19 buff-menu, 23 Mar 1993
|
|
36 ;;
|
|
37 ;; Modified by Bob Weiner, Motorola, Inc., 4/14/89
|
|
38 ;;
|
|
39 ;; Added optional backup argument to 'Buffer-menu-unmark' to make it undelete
|
|
40 ;; current entry and then move to previous one.
|
|
41 ;;
|
|
42 ;; Based on FSF code dating back to 1985.
|
|
43
|
|
44 ;;; Code:
|
|
45
|
|
46 ;;;Trying to preserve the old window configuration works well in
|
|
47 ;;;simple scenarios, when you enter the buffer menu, use it, and exit it.
|
|
48 ;;;But it does strange things when you switch back to the buffer list buffer
|
|
49 ;;;with C-x b, later on, when the window configuration is different.
|
|
50 ;;;The choice seems to be, either restore the window configuration
|
|
51 ;;;in all cases, or in no cases.
|
|
52 ;;;I decided it was better not to restore the window config at all. -- rms.
|
|
53
|
|
54 ;;;But since then, I changed buffer-menu to use the selected window,
|
|
55 ;;;so q now once again goes back to the previous window configuration.
|
|
56
|
|
57 ;;;(defvar Buffer-menu-window-config nil
|
|
58 ;;; "Window configuration saved from entry to `buffer-menu'.")
|
|
59
|
|
60 ; Put buffer *Buffer List* into proper mode right away
|
|
61 ; so that from now on even list-buffers is enough to get a buffer menu.
|
|
62
|
|
63 (defvar Buffer-menu-buffer-column 4)
|
|
64
|
|
65 (defvar Buffer-menu-mode-map nil "")
|
|
66
|
|
67 (if Buffer-menu-mode-map
|
|
68 ()
|
|
69 (setq Buffer-menu-mode-map (make-keymap))
|
|
70 (suppress-keymap Buffer-menu-mode-map t)
|
|
71 (set-keymap-name Buffer-menu-mode-map 'Buffer-menu-mode-map)
|
|
72 (define-key Buffer-menu-mode-map "q" 'Buffer-menu-quit)
|
|
73 (define-key Buffer-menu-mode-map "v" 'Buffer-menu-select)
|
|
74 (define-key Buffer-menu-mode-map "2" 'Buffer-menu-2-window)
|
|
75 (define-key Buffer-menu-mode-map "1" 'Buffer-menu-1-window)
|
|
76 (define-key Buffer-menu-mode-map "f" 'Buffer-menu-this-window)
|
|
77 (define-key Buffer-menu-mode-map "\C-m" 'Buffer-menu-this-window)
|
|
78 (define-key Buffer-menu-mode-map "o" 'Buffer-menu-other-window)
|
|
79 (define-key Buffer-menu-mode-map "\C-o" 'Buffer-menu-switch-other-window)
|
|
80 (define-key Buffer-menu-mode-map "s" 'Buffer-menu-save)
|
|
81 (define-key Buffer-menu-mode-map "d" 'Buffer-menu-delete)
|
|
82 (define-key Buffer-menu-mode-map "k" 'Buffer-menu-delete)
|
|
83 (define-key Buffer-menu-mode-map "\C-d" 'Buffer-menu-delete-backwards)
|
|
84 (define-key Buffer-menu-mode-map "\C-k" 'Buffer-menu-delete)
|
|
85 (define-key Buffer-menu-mode-map "x" 'Buffer-menu-execute)
|
|
86 (define-key Buffer-menu-mode-map " " 'next-line)
|
|
87 (define-key Buffer-menu-mode-map "n" 'next-line)
|
|
88 (define-key Buffer-menu-mode-map "p" 'previous-line)
|
|
89 (define-key Buffer-menu-mode-map "\177" 'Buffer-menu-backup-unmark)
|
|
90 (define-key Buffer-menu-mode-map "~" 'Buffer-menu-not-modified)
|
|
91 (define-key Buffer-menu-mode-map "?" 'describe-mode)
|
|
92 (define-key Buffer-menu-mode-map "u" 'Buffer-menu-unmark)
|
|
93 (define-key Buffer-menu-mode-map "m" 'Buffer-menu-mark)
|
|
94 (define-key Buffer-menu-mode-map "t" 'Buffer-menu-visit-tags-table)
|
|
95 (define-key Buffer-menu-mode-map "%" 'Buffer-menu-toggle-read-only)
|
|
96 (define-key Buffer-menu-mode-map "g" 'revert-buffer)
|
|
97 (define-key Buffer-menu-mode-map 'button2 'Buffer-menu-mouse-select)
|
|
98 (define-key Buffer-menu-mode-map 'button3 'Buffer-menu-popup-menu)
|
|
99 )
|
|
100
|
|
101 ;; Buffer Menu mode is suitable only for specially formatted data.
|
|
102 (put 'Buffer-menu-mode 'mode-class 'special)
|
|
103
|
|
104 (defun Buffer-menu-mode ()
|
|
105 "Major mode for editing a list of buffers.
|
|
106 Each line describes one of the buffers in Emacs.
|
|
107 Letters do not insert themselves; instead, they are commands.
|
|
108 \\<Buffer-menu-mode-map>
|
|
109 \\[Buffer-menu-mouse-select] -- select buffer you click on, in place of the buffer menu.
|
|
110 \\[Buffer-menu-this-window] -- select current line's buffer in place of the buffer menu.
|
|
111 \\[Buffer-menu-other-window] -- select that buffer in another window,
|
|
112 so the buffer menu buffer remains visible in its window.
|
|
113 \\[Buffer-menu-switch-other-window] -- make another window display that buffer.
|
|
114 \\[Buffer-menu-mark] -- mark current line's buffer to be displayed.
|
|
115 \\[Buffer-menu-select] -- select current line's buffer.
|
|
116 Also show buffers marked with m, in other windows.
|
|
117 \\[Buffer-menu-1-window] -- select that buffer in full-frame window.
|
|
118 \\[Buffer-menu-2-window] -- select that buffer in one window,
|
|
119 together with buffer selected before this one in another window.
|
|
120 \\[Buffer-menu-visit-tags-table] -- visit-tags-table this buffer.
|
|
121 \\[Buffer-menu-not-modified] -- clear modified-flag on that buffer.
|
|
122 \\[Buffer-menu-save] -- mark that buffer to be saved, and move down.
|
|
123 \\[Buffer-menu-delete] -- mark that buffer to be deleted, and move down.
|
|
124 \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted, and move up.
|
|
125 \\[Buffer-menu-execute] -- delete or save marked buffers.
|
|
126 \\[Buffer-menu-unmark] -- remove all kinds of marks from current line.
|
|
127 With prefix argument, also move up one line.
|
|
128 \\[Buffer-menu-backup-unmark] -- back up a line and remove marks.
|
|
129 \\[Buffer-menu-toggle-read-only] -- toggle read-only status of buffer on this line."
|
|
130 (kill-all-local-variables)
|
|
131 (use-local-map Buffer-menu-mode-map)
|
|
132 (setq major-mode 'Buffer-menu-mode)
|
|
133 (setq mode-name "Buffer Menu")
|
|
134 (make-local-variable 'revert-buffer-function)
|
|
135 (setq revert-buffer-function 'Buffer-menu-revert-function)
|
|
136 (setq truncate-lines t)
|
|
137 (setq buffer-read-only t)
|
|
138 (make-local-variable 'mouse-track-click-hook)
|
|
139 (add-hook 'mouse-track-click-hook 'Buffer-menu-maybe-mouse-select)
|
|
140 (run-hooks 'buffer-menu-mode-hook))
|
|
141
|
|
142 (defun Buffer-menu-revert-function (ignore1 ignore2)
|
|
143 (list-buffers))
|
|
144
|
|
145 (defun Buffer-menu-buffer (error-if-non-existent-p)
|
|
146 "Return buffer described by this line of buffer menu."
|
|
147 (let* ((where (save-excursion
|
|
148 (beginning-of-line)
|
|
149 (+ (point) Buffer-menu-buffer-column)))
|
|
150 (name (and (not (eobp)) (get-text-property where 'buffer-name))))
|
|
151 (if name
|
|
152 (or (get-buffer name)
|
|
153 (if error-if-non-existent-p
|
|
154 (error "No buffer named `%s'" name)
|
|
155 nil))
|
|
156 (if error-if-non-existent-p
|
|
157 (error "No buffer on this line")
|
|
158 nil))))
|
|
159
|
|
160 (defun buffer-menu (&optional arg)
|
|
161 "Make a menu of buffers so you can save, delete or select them.
|
|
162 With argument, show only buffers that are visiting files.
|
|
163 Type ? after invocation to get help on commands available.
|
|
164 Type q immediately to make the buffer menu go away."
|
|
165 (interactive "P")
|
|
166 ;;; (setq Buffer-menu-window-config (current-window-configuration))
|
|
167 (switch-to-buffer (list-buffers-noselect arg))
|
|
168 (message
|
|
169 "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help."))
|
|
170
|
|
171 (defun buffer-menu-other-window (&optional arg)
|
|
172 "Display a list of buffers in another window.
|
|
173 With the buffer list buffer, you can save, delete or select the buffers.
|
|
174 With argument, show only buffers that are visiting files.
|
|
175 Type ? after invocation to get help on commands available.
|
|
176 Type q immediately to make the buffer menu go away."
|
|
177 (interactive "P")
|
|
178 ;;; (setq Buffer-menu-window-config (current-window-configuration))
|
|
179 (switch-to-buffer-other-window (list-buffers-noselect arg))
|
|
180 (message
|
|
181 "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help."))
|
|
182
|
|
183 (defun Buffer-menu-quit ()
|
|
184 "Quit the buffer menu."
|
|
185 (interactive)
|
|
186 (let ((buffer (current-buffer)))
|
|
187 ;; Switch away from the buffer menu and bury it.
|
|
188 (switch-to-buffer (other-buffer))
|
|
189 (bury-buffer buffer)))
|
|
190
|
|
191 (defun Buffer-menu-mark ()
|
|
192 "Mark buffer on this line for being displayed by \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command."
|
|
193 (interactive)
|
|
194 (beginning-of-line)
|
|
195 (if (looking-at " [-M]")
|
|
196 (ding)
|
|
197 (let ((buffer-read-only nil))
|
|
198 (delete-char 1)
|
|
199 (insert ?>)
|
|
200 (forward-line 1))))
|
|
201
|
|
202 (defun Buffer-menu-unmark (&optional backup)
|
|
203 "Cancel all requested operations on buffer on this line and move down.
|
|
204 Optional ARG means move up."
|
|
205 (interactive "P")
|
|
206 (beginning-of-line)
|
|
207 (if (looking-at " [-M]")
|
|
208 (ding)
|
|
209 (let* ((buf (Buffer-menu-buffer t))
|
|
210 (mod (buffer-modified-p buf))
|
|
211 (readonly (save-excursion (set-buffer buf) buffer-read-only))
|
|
212 (buffer-read-only nil))
|
|
213 (delete-char 3)
|
|
214 (insert (if readonly (if mod " *%" " %") (if mod " * " " ")))))
|
|
215 (forward-line (if backup -1 1)))
|
|
216
|
|
217 (defun Buffer-menu-backup-unmark ()
|
|
218 "Move up and cancel all requested operations on buffer on line above."
|
|
219 (interactive)
|
|
220 (forward-line -1)
|
|
221 (Buffer-menu-unmark)
|
|
222 (forward-line -1))
|
|
223
|
|
224 (defun Buffer-menu-delete (&optional arg)
|
|
225 "Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command.
|
|
226 Prefix arg is how many buffers to delete.
|
|
227 Negative arg means delete backwards."
|
|
228 (interactive "p")
|
|
229 (beginning-of-line)
|
|
230 (if (looking-at " [-M]") ;header lines
|
|
231 (ding)
|
|
232 (let ((buffer-read-only nil))
|
|
233 (if (or (null arg) (= arg 0))
|
|
234 (setq arg 1))
|
|
235 (while (> arg 0)
|
|
236 (delete-char 1)
|
|
237 (insert ?D)
|
|
238 (forward-line 1)
|
|
239 (setq arg (1- arg)))
|
|
240 (while (< arg 0)
|
|
241 (delete-char 1)
|
|
242 (insert ?D)
|
|
243 (forward-line -1)
|
|
244 (setq arg (1+ arg))))))
|
|
245
|
|
246 (defun Buffer-menu-delete-backwards (&optional arg)
|
|
247 "Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command
|
|
248 and then move up one line. Prefix arg means move that many lines."
|
|
249 (interactive "p")
|
|
250 (Buffer-menu-delete (- (or arg 1)))
|
|
251 (while (looking-at " [-M]")
|
|
252 (forward-line 1)))
|
|
253
|
|
254 (defun Buffer-menu-save ()
|
|
255 "Mark buffer on this line to be saved by \\[Buffer-menu-execute] command."
|
|
256 (interactive)
|
|
257 (beginning-of-line)
|
|
258 (if (looking-at " [-M]") ;header lines
|
|
259 (ding)
|
|
260 (let ((buffer-read-only nil))
|
|
261 (forward-char 1)
|
|
262 (delete-char 1)
|
|
263 (insert ?S)
|
|
264 (forward-line 1))))
|
|
265
|
|
266 (defun Buffer-menu-not-modified (&optional arg)
|
|
267 "Mark buffer on this line as unmodified (no changes to save)."
|
|
268 (interactive "P")
|
|
269 (save-excursion
|
|
270 (set-buffer (Buffer-menu-buffer t))
|
|
271 (set-buffer-modified-p arg))
|
|
272 (save-excursion
|
|
273 (beginning-of-line)
|
|
274 (forward-char 1)
|
|
275 (if (= (char-after (point)) (if arg ? ?*))
|
|
276 (let ((buffer-read-only nil))
|
|
277 (delete-char 1)
|
|
278 (insert (if arg ?* ? ))))))
|
|
279
|
|
280 (defun Buffer-menu-execute ()
|
|
281 "Save and/or delete buffers marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-save] or \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
|
|
282 (interactive)
|
|
283 (save-excursion
|
|
284 (goto-char (point-min))
|
|
285 (forward-line 1)
|
|
286 (while (re-search-forward "^.S" nil t)
|
|
287 (let ((modp nil))
|
|
288 (save-excursion
|
|
289 (set-buffer (Buffer-menu-buffer t))
|
|
290 (save-buffer)
|
|
291 (setq modp (buffer-modified-p)))
|
|
292 (let ((buffer-read-only nil))
|
|
293 (delete-char -1)
|
|
294 (insert (if modp ?* ? ))))))
|
|
295 (save-excursion
|
|
296 (goto-char (point-min))
|
|
297 (forward-line 1)
|
|
298 (let ((buff-menu-buffer (current-buffer))
|
|
299 (buffer-read-only nil))
|
|
300 (while (search-forward "\nD" nil t)
|
|
301 (forward-char -1)
|
|
302 (let ((buf (Buffer-menu-buffer nil)))
|
|
303 (or (eq buf nil)
|
|
304 (eq buf buff-menu-buffer)
|
|
305 (save-excursion (kill-buffer buf))))
|
|
306 (if (Buffer-menu-buffer nil)
|
|
307 (progn (delete-char 1)
|
|
308 (insert ? ))
|
|
309 (delete-region (point) (progn (forward-line 1) (point)))
|
|
310 (forward-char -1))))))
|
|
311
|
|
312 (defun Buffer-menu-select ()
|
|
313 "Select this line's buffer; also display buffers marked with `>'.
|
|
314 You can mark buffers with the \\<Buffer-menu-mode-map>\\[Buffer-menu-mark] command.
|
|
315 This command deletes and replaces all the previously existing windows
|
|
316 in the selected frame."
|
|
317 (interactive)
|
|
318 (let ((buff (Buffer-menu-buffer t))
|
|
319 (menu (current-buffer))
|
|
320 (others ())
|
|
321 tem)
|
|
322 (goto-char (point-min))
|
|
323 (while (search-forward "\n>" nil t)
|
|
324 (setq tem (Buffer-menu-buffer t))
|
|
325 (let ((buffer-read-only nil))
|
|
326 (delete-char -1)
|
|
327 (insert ?\ ))
|
|
328 (or (eq tem buff) (memq tem others) (setq others (cons tem others))))
|
|
329 (setq others (nreverse others)
|
|
330 tem (/ (1- (frame-height)) (1+ (length others))))
|
|
331 (delete-other-windows)
|
|
332 (switch-to-buffer buff)
|
|
333 (or (eq menu buff)
|
|
334 (bury-buffer menu))
|
|
335 (if (equal (length others) 0)
|
|
336 (progn
|
|
337 ;;; ;; Restore previous window configuration before displaying
|
|
338 ;;; ;; selected buffers.
|
|
339 ;;; (if Buffer-menu-window-config
|
|
340 ;;; (progn
|
|
341 ;;; (set-window-configuration Buffer-menu-window-config)
|
|
342 ;;; (setq Buffer-menu-window-config nil)))
|
|
343 (switch-to-buffer buff))
|
|
344 (while others
|
|
345 (split-window nil tem)
|
|
346 (other-window 1)
|
|
347 (switch-to-buffer (car others))
|
|
348 (setq others (cdr others)))
|
|
349 (other-window 1) ;back to the beginning!
|
|
350 )))
|
|
351
|
|
352
|
|
353
|
|
354 (defun Buffer-menu-visit-tags-table ()
|
|
355 "Visit the tags table in the buffer on this line. See `visit-tags-table'."
|
|
356 (interactive)
|
|
357 (let ((file (buffer-file-name (Buffer-menu-buffer t))))
|
|
358 (if file
|
|
359 (visit-tags-table file)
|
|
360 (error "Specified buffer has no file"))))
|
|
361
|
|
362 (defun Buffer-menu-1-window ()
|
|
363 "Select this line's buffer, alone, in full frame."
|
|
364 (interactive)
|
|
365 (switch-to-buffer (Buffer-menu-buffer t))
|
|
366 (bury-buffer (other-buffer))
|
|
367 (delete-other-windows)
|
|
368 ;; This is to get w->force_start set to nil. Don't ask me, I only work here.
|
|
369 (set-window-buffer (selected-window) (current-buffer)))
|
|
370
|
|
371 (defun Buffer-menu-mouse-select (event)
|
|
372 "Select the buffer whose line you click on."
|
|
373 (interactive "e")
|
|
374 (let (buffer)
|
|
375 (save-excursion
|
|
376 (set-buffer (event-buffer event))
|
|
377 (save-excursion
|
|
378 (goto-char (event-point event))
|
|
379 (setq buffer (Buffer-menu-buffer t))))
|
|
380 (select-window (event-window event))
|
|
381 (if (and (window-dedicated-p (selected-window))
|
|
382 (eq (selected-window) (frame-root-window)))
|
|
383 (switch-to-buffer-other-frame buffer)
|
|
384 (switch-to-buffer buffer))))
|
|
385
|
|
386 (defun Buffer-menu-maybe-mouse-select (event &optional click-count)
|
|
387 (interactive "e")
|
|
388 (and (>= click-count 2)
|
|
389 (let ((buffer (current-buffer))
|
|
390 (point (point))
|
|
391 (config (current-window-configuration)))
|
|
392 (condition-case nil
|
|
393 (progn
|
|
394 (Buffer-menu-mouse-select event)
|
|
395 t)
|
|
396 (error
|
|
397 (set-window-configuration config)
|
|
398 (set-buffer buffer)
|
|
399 (goto-char point)
|
|
400 nil)))))
|
|
401
|
|
402 (defun Buffer-menu-this-window ()
|
|
403 "Select this line's buffer in this window."
|
|
404 (interactive)
|
|
405 (switch-to-buffer (Buffer-menu-buffer t)))
|
|
406
|
|
407 (defun Buffer-menu-other-window ()
|
|
408 "Select this line's buffer in other window, leaving buffer menu visible."
|
|
409 (interactive)
|
|
410 (switch-to-buffer-other-window (Buffer-menu-buffer t)))
|
|
411
|
|
412 (defun Buffer-menu-switch-other-window ()
|
|
413 "Make the other window select this line's buffer.
|
|
414 The current window remains selected."
|
|
415 (interactive)
|
|
416 (display-buffer (Buffer-menu-buffer t)))
|
|
417
|
|
418 (defun Buffer-menu-2-window ()
|
|
419 "Select this line's buffer, with previous buffer in second window."
|
|
420 (interactive)
|
|
421 (let ((buff (Buffer-menu-buffer t))
|
|
422 (menu (current-buffer))
|
|
423 (pop-up-windows t))
|
|
424 (delete-other-windows)
|
|
425 (switch-to-buffer (other-buffer))
|
|
426 (pop-to-buffer buff)
|
|
427 (bury-buffer menu)))
|
|
428
|
|
429 (defun Buffer-menu-toggle-read-only ()
|
|
430 "Toggle read-only status of buffer on this line, perhaps via version control."
|
|
431 (interactive)
|
|
432 (let (char)
|
|
433 (save-excursion
|
|
434 (set-buffer (Buffer-menu-buffer t))
|
|
435 (vc-toggle-read-only)
|
|
436 (setq char (if buffer-read-only ?% ? )))
|
|
437 (save-excursion
|
|
438 (beginning-of-line)
|
|
439 (forward-char 2)
|
|
440 (if (/= (following-char) char)
|
|
441 (let (buffer-read-only)
|
|
442 (delete-char 1)
|
|
443 (insert char))))))
|
|
444
|
|
445 (defvar Buffer-menu-popup-menu
|
|
446 '("Buffer Commands"
|
|
447 ["Select Buffer" Buffer-menu-select t]
|
|
448 ["Select buffer Other Window" Buffer-menu-other-window t]
|
|
449 ["Clear Buffer Modification Flag" Buffer-menu-not-modified t]
|
|
450 "----"
|
|
451 ["Mark Buffer for Selection" Buffer-menu-mark t]
|
|
452 ["Mark Buffer for Save" Buffer-menu-save t]
|
|
453 ["Mark Buffer for Deletion" Buffer-menu-delete t]
|
|
454 ["Unmark Buffer" Buffer-menu-unmark t]
|
|
455 "----"
|
|
456 ["Delete/Save Marked Buffers" Buffer-menu-execute t]
|
|
457 ))
|
|
458
|
|
459 (defun Buffer-menu-popup-menu (event)
|
|
460 (interactive "e")
|
|
461 (mouse-set-point event)
|
|
462 (beginning-of-line)
|
|
463 (let ((buffer (Buffer-menu-buffer nil)))
|
|
464 (if buffer
|
|
465 (popup-menu
|
|
466 (nconc (list (car Buffer-menu-popup-menu)
|
|
467 (concat
|
|
468 "Commands on buffer \"" (buffer-name buffer) "\":")
|
|
469 "----")
|
|
470 (cdr Buffer-menu-popup-menu)))
|
|
471 (error "no buffer on this line"))))
|
|
472
|
|
473
|
|
474 (defvar list-buffers-header-line
|
|
475 (purecopy (concat " MR Buffer Size Mode File\n"
|
|
476 " -- ------ ---- ---- ----\n")))
|
|
477
|
|
478 (defvar list-buffers-identification 'default-list-buffers-identification
|
|
479 "String used to identify this buffer, or a function of one argument
|
|
480 to generate such a string. This variable is always buffer-local.")
|
|
481 (make-variable-buffer-local 'list-buffers-identification)
|
|
482
|
|
483 (defvar list-buffers-directory)
|
|
484 (make-variable-buffer-local 'list-buffers-directory)
|
|
485
|
|
486 ;; #### not synched
|
|
487 (defun default-list-buffers-identification (output)
|
|
488 (save-excursion
|
|
489 (let ((file (or (buffer-file-name (current-buffer))
|
|
490 (and (boundp 'list-buffers-directory)
|
|
491 list-buffers-directory)))
|
|
492 (size (buffer-size))
|
|
493 (mode mode-name)
|
|
494 eob p s col)
|
|
495 (set-buffer output)
|
|
496 (end-of-line)
|
|
497 (setq eob (point))
|
|
498 (prin1 size output)
|
|
499 (setq p (point))
|
|
500 ;; right-justify the size
|
|
501 (move-to-column 19 t)
|
|
502 (setq col (point))
|
|
503 (if (> eob col)
|
|
504 (goto-char eob))
|
|
505 (setq s (- 6 (- p col)))
|
|
506 (while (> s 0) ; speed/consing tradeoff...
|
|
507 (insert ? )
|
|
508 (setq s (1- s)))
|
|
509 (end-of-line)
|
|
510 (indent-to 27 1)
|
|
511 (insert mode)
|
|
512 (if (not file)
|
|
513 nil
|
|
514 ;; if the mode-name is really long, clip it for the filename
|
|
515 (if (> 0 (setq s (- 39 (current-column))))
|
|
516 (delete-char (max s (- eob (point)))))
|
|
517 (indent-to 40 1)
|
|
518 (insert file)))))
|
|
519
|
|
520 ;; #### not synched
|
|
521 (defun list-buffers-internal (output &optional predicate)
|
|
522 (let ((current (current-buffer))
|
|
523 (buffers (buffer-list)))
|
|
524 (save-excursion
|
|
525 (set-buffer output)
|
|
526 (setq buffer-read-only nil)
|
|
527 (erase-buffer)
|
|
528 (buffer-disable-undo output)
|
|
529 (insert list-buffers-header-line)
|
|
530
|
|
531 (while buffers
|
|
532 (let* ((col1 19)
|
|
533 (buffer (car buffers))
|
|
534 (name (buffer-name buffer))
|
|
535 this-buffer-line-start)
|
|
536 (setq buffers (cdr buffers))
|
|
537 (cond ((null name)) ;deleted buffer
|
|
538 ((and predicate
|
|
539 (not (if (stringp predicate)
|
|
540 (string-match predicate name)
|
|
541 (funcall predicate buffer))))
|
|
542 nil)
|
|
543 (t
|
|
544 (set-buffer buffer)
|
|
545 (let ((ro buffer-read-only)
|
|
546 (id list-buffers-identification))
|
|
547 (set-buffer output)
|
|
548 (setq this-buffer-line-start (point))
|
|
549 (insert (if (eq buffer current)
|
|
550 (progn (setq current (point)) ?\.)
|
|
551 ?\ ))
|
|
552 (insert (if (buffer-modified-p buffer)
|
|
553 ?\*
|
|
554 ?\ ))
|
|
555 (insert (if ro
|
|
556 ?\%
|
|
557 ?\ ))
|
|
558 (if (string-match "[\n\"\\ \t]" name)
|
|
559 (let ((print-escape-newlines t))
|
|
560 (prin1 name output))
|
|
561 (insert ?\ name))
|
|
562 (indent-to col1 1)
|
|
563 (cond ((stringp id)
|
|
564 (insert id))
|
|
565 (id
|
|
566 (set-buffer buffer)
|
|
567 (condition-case e
|
|
568 (funcall id output)
|
|
569 (error
|
|
570 (princ "***" output) (prin1 e output)))
|
|
571 (set-buffer output)
|
|
572 (goto-char (point-max)))))
|
|
573 (put-nonduplicable-text-property this-buffer-line-start
|
|
574 (point)
|
|
575 'buffer-name name)
|
|
576 (put-nonduplicable-text-property this-buffer-line-start
|
|
577 (point)
|
|
578 'highlight t)
|
|
579 (insert ?\n)))))
|
|
580
|
|
581 (Buffer-menu-mode)
|
|
582 (if (not (bufferp current))
|
|
583 (goto-char current)))))
|
|
584
|
|
585 (defun list-buffers (&optional files-only)
|
|
586 "Display a list of names of existing buffers.
|
|
587 The list is displayed in a buffer named `*Buffer List*'.
|
|
588 Note that buffers with names starting with spaces are omitted.
|
|
589 Non-null optional arg FILES-ONLY means mention only file buffers.
|
|
590
|
|
591 The M column contains a * for buffers that are modified.
|
|
592 The R column contains a % for buffers that are read-only."
|
|
593 (interactive (list (if current-prefix-arg t nil)))
|
|
594 (display-buffer (list-buffers-noselect files-only)))
|
|
595
|
|
596 ;; #### not synched
|
|
597 (defun list-buffers-noselect (&optional files-only)
|
|
598 "Create and return a buffer with a list of names of existing buffers.
|
|
599 The buffer is named `*Buffer List*'.
|
|
600 Note that buffers with names starting with spaces are omitted.
|
|
601 Non-null optional arg FILES-ONLY means mention only file buffers.
|
|
602
|
|
603 The M column contains a * for buffers that are modified.
|
|
604 The R column contains a % for buffers that are read-only."
|
|
605 (let ((buffer (get-buffer-create "*Buffer List*")))
|
|
606 (list-buffers-internal buffer
|
|
607 (if (memq files-only '(t nil))
|
|
608 #'(lambda (b)
|
|
609 (let ((n (buffer-name b)))
|
|
610 (cond ((and (/= 0 (length n))
|
|
611 (= (aref n 0) ?\ ))
|
|
612 ;;don't mention if starts with " "
|
|
613 nil)
|
|
614 (files-only
|
|
615 (buffer-file-name b))
|
|
616 (t
|
|
617 t))))
|
|
618 files-only))
|
|
619 buffer))
|
|
620
|
|
621 (provide 'buff-menu)
|
|
622
|
|
623 ;;; buff-menu.el ends here
|