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