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