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