Trailing whitespace deleted.
[emacs.git] / lisp / buff-menu.el
blob696b7245d16ba169c363f41990db170e7906928e
1 ;;; buff-menu.el --- buffer menu main function and support functions
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 95, 2000, 2001, 2002, 2003
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: convenience
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
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 `list-buffers',
32 ;; normally bound to C-x C-b.
34 ;;; Change Log:
36 ;; Buffer-menu-view: New function
37 ;; Buffer-menu-view-other-window: New function
39 ;; Merged by esr with recent mods to Emacs 19 buff-menu, 23 Mar 1993
41 ;; Modified by Bob Weiner, Motorola, Inc., 4/14/89
43 ;; Added optional backup argument to 'Buffer-menu-unmark' to make it undelete
44 ;; current entry and then move to previous one.
46 ;; Based on FSF code dating back to 1985.
48 ;;; Code:
50 ;;;Trying to preserve the old window configuration works well in
51 ;;;simple scenarios, when you enter the buffer menu, use it, and exit it.
52 ;;;But it does strange things when you switch back to the buffer list buffer
53 ;;;with C-x b, later on, when the window configuration is different.
54 ;;;The choice seems to be, either restore the window configuration
55 ;;;in all cases, or in no cases.
56 ;;;I decided it was better not to restore the window config at all. -- rms.
58 ;;;But since then, I changed buffer-menu to use the selected window,
59 ;;;so q now once again goes back to the previous window configuration.
61 ;;;(defvar Buffer-menu-window-config nil
62 ;;; "Window configuration saved from entry to `buffer-menu'.")
64 ; Put buffer *Buffer List* into proper mode right away
65 ; so that from now on even list-buffers is enough to get a buffer menu.
67 (defgroup Buffer-menu nil
68 "Show a menu of all buffers in a buffer."
69 :group 'tools
70 :group 'convenience)
72 (defcustom Buffer-menu-use-header-line t
73 "*Non-nil means to use an immovable header-line."
74 :type 'boolean
75 :group 'Buffer-menu)
77 (defface Buffer-menu-buffer-face
78 '((t (:weight bold)))
79 "Face used to highlight buffer name."
80 :group 'font-lock-highlighting-faces)
82 (defcustom Buffer-menu-buffer+size-width 26
83 "*How wide to jointly make the buffer name and size columns."
84 :type 'number
85 :group 'Buffer-menu)
87 (defcustom Buffer-menu-mode-width 16
88 "*How wide to make the mode name column."
89 :type 'number
90 :group 'Buffer-menu)
92 ; This should get updated & resorted when you click on a column heading
93 (defvar Buffer-menu-sort-column nil
94 "*2 for sorting by buffer names. 5 for sorting by file names.
95 nil for default sorting by visited order.")
97 (defconst Buffer-menu-buffer-column 4)
99 (defvar Buffer-menu-mode-map nil "")
101 (if Buffer-menu-mode-map
103 (setq Buffer-menu-mode-map (make-keymap))
104 (suppress-keymap Buffer-menu-mode-map t)
105 (define-key Buffer-menu-mode-map "q" 'quit-window)
106 (define-key Buffer-menu-mode-map "v" 'Buffer-menu-select)
107 (define-key Buffer-menu-mode-map "2" 'Buffer-menu-2-window)
108 (define-key Buffer-menu-mode-map "1" 'Buffer-menu-1-window)
109 (define-key Buffer-menu-mode-map "f" 'Buffer-menu-this-window)
110 (define-key Buffer-menu-mode-map "e" 'Buffer-menu-this-window)
111 (define-key Buffer-menu-mode-map "\C-m" 'Buffer-menu-this-window)
112 (define-key Buffer-menu-mode-map "o" 'Buffer-menu-other-window)
113 (define-key Buffer-menu-mode-map "\C-o" 'Buffer-menu-switch-other-window)
114 (define-key Buffer-menu-mode-map "s" 'Buffer-menu-save)
115 (define-key Buffer-menu-mode-map "d" 'Buffer-menu-delete)
116 (define-key Buffer-menu-mode-map "k" 'Buffer-menu-delete)
117 (define-key Buffer-menu-mode-map "\C-d" 'Buffer-menu-delete-backwards)
118 (define-key Buffer-menu-mode-map "\C-k" 'Buffer-menu-delete)
119 (define-key Buffer-menu-mode-map "x" 'Buffer-menu-execute)
120 (define-key Buffer-menu-mode-map " " 'next-line)
121 (define-key Buffer-menu-mode-map "n" 'next-line)
122 (define-key Buffer-menu-mode-map "p" 'previous-line)
123 (define-key Buffer-menu-mode-map "\177" 'Buffer-menu-backup-unmark)
124 (define-key Buffer-menu-mode-map "~" 'Buffer-menu-not-modified)
125 (define-key Buffer-menu-mode-map "?" 'describe-mode)
126 (define-key Buffer-menu-mode-map "u" 'Buffer-menu-unmark)
127 (define-key Buffer-menu-mode-map "m" 'Buffer-menu-mark)
128 (define-key Buffer-menu-mode-map "t" 'Buffer-menu-visit-tags-table)
129 (define-key Buffer-menu-mode-map "%" 'Buffer-menu-toggle-read-only)
130 (define-key Buffer-menu-mode-map "b" 'Buffer-menu-bury)
131 (define-key Buffer-menu-mode-map "g" 'Buffer-menu-revert)
132 (define-key Buffer-menu-mode-map "V" 'Buffer-menu-view)
133 (define-key Buffer-menu-mode-map [mouse-2] 'Buffer-menu-mouse-select)
136 ;; Buffer Menu mode is suitable only for specially formatted data.
137 (put 'Buffer-menu-mode 'mode-class 'special)
139 (defun Buffer-menu-mode ()
140 "Major mode for editing a list of buffers.
141 Each line describes one of the buffers in Emacs.
142 Letters do not insert themselves; instead, they are commands.
143 \\<Buffer-menu-mode-map>
144 \\[Buffer-menu-mouse-select] -- select buffer you click on, in place of the buffer menu.
145 \\[Buffer-menu-this-window] -- select current line's buffer in place of the buffer menu.
146 \\[Buffer-menu-other-window] -- select that buffer in another window,
147 so the buffer menu buffer remains visible in its window.
148 \\[Buffer-menu-view] -- select current line's buffer, but in view-mode.
149 \\[Buffer-menu-view-other-window] -- select that buffer in
150 another window, in view-mode.
151 \\[Buffer-menu-switch-other-window] -- make another window display that buffer.
152 \\[Buffer-menu-mark] -- mark current line's buffer to be displayed.
153 \\[Buffer-menu-select] -- select current line's buffer.
154 Also show buffers marked with m, in other windows.
155 \\[Buffer-menu-1-window] -- select that buffer in full-frame window.
156 \\[Buffer-menu-2-window] -- select that buffer in one window,
157 together with buffer selected before this one in another window.
158 \\[Buffer-menu-visit-tags-table] -- visit-tags-table this buffer.
159 \\[Buffer-menu-not-modified] -- clear modified-flag on that buffer.
160 \\[Buffer-menu-save] -- mark that buffer to be saved, and move down.
161 \\[Buffer-menu-delete] -- mark that buffer to be deleted, and move down.
162 \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted, and move up.
163 \\[Buffer-menu-execute] -- delete or save marked buffers.
164 \\[Buffer-menu-unmark] -- remove all kinds of marks from current line.
165 With prefix argument, also move up one line.
166 \\[Buffer-menu-backup-unmark] -- back up a line and remove marks.
167 \\[Buffer-menu-toggle-read-only] -- toggle read-only status of buffer on this line.
168 \\[Buffer-menu-revert] -- update the list of buffers.
169 \\[Buffer-menu-bury] -- bury the buffer listed on this line."
170 (kill-all-local-variables)
171 (use-local-map Buffer-menu-mode-map)
172 (setq major-mode 'Buffer-menu-mode)
173 (setq mode-name "Buffer Menu")
174 (make-local-variable 'revert-buffer-function)
175 (setq revert-buffer-function 'Buffer-menu-revert-function)
176 (setq truncate-lines t)
177 (setq buffer-read-only t)
178 (run-hooks 'buffer-menu-mode-hook))
180 (defun Buffer-menu-revert ()
181 "Update the list of buffers."
182 (interactive)
183 (revert-buffer))
185 (defun Buffer-menu-revert-function (ignore1 ignore2)
186 (list-buffers))
188 (defun Buffer-menu-buffer (error-if-non-existent-p)
189 "Return buffer described by this line of buffer menu."
190 (let* ((where (save-excursion
191 (beginning-of-line)
192 (+ (point) Buffer-menu-buffer-column)))
193 (name (and (not (eobp)) (get-text-property where 'buffer-name)))
194 (buf (and (not (eobp)) (get-text-property where 'buffer))))
195 (if name
196 (or (get-buffer name)
197 (and buf (buffer-name buf) buf)
198 (if error-if-non-existent-p
199 (error "No buffer named `%s'" name)
200 nil))
201 (or (and buf (buffer-name buf) buf)
202 (if error-if-non-existent-p
203 (error "No buffer on this line")
204 nil)))))
206 (defun buffer-menu (&optional arg)
207 "Make a menu of buffers so you can save, delete or select them.
208 With argument, show only buffers that are visiting files.
209 Type ? after invocation to get help on commands available.
210 Type q to remove the buffer menu from the display.
212 The first column shows `>' for a buffer you have
213 marked to be displayed, `D' for one you have marked for
214 deletion, and `.' for the current buffer.
216 The C column has a `.' for the buffer from which you came.
217 The R column has a `%' if the buffer is read-only.
218 The M column has a `*' if it is modified,
219 or `S' if you have marked it for saving.
220 After this come the buffer name, its size in characters,
221 its major mode, and the visited file name (if any)."
222 (interactive "P")
223 ;;; (setq Buffer-menu-window-config (current-window-configuration))
224 (switch-to-buffer (list-buffers-noselect arg))
225 (message
226 "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help."))
228 (defun buffer-menu-other-window (&optional arg)
229 "Display a list of buffers in another window.
230 With the buffer list buffer, you can save, delete or select the buffers.
231 With argument, show only buffers that are visiting files.
232 Type ? after invocation to get help on commands available.
233 Type q to remove the buffer menu from the display.
234 For more information, see the function `buffer-menu'."
235 (interactive "P")
236 ;;; (setq Buffer-menu-window-config (current-window-configuration))
237 (switch-to-buffer-other-window (list-buffers-noselect arg))
238 (message
239 "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help."))
241 (defun Buffer-menu-no-header ()
242 (beginning-of-line)
243 (if (or Buffer-menu-use-header-line
244 (not (eq (char-after) ?C)))
246 (ding)
247 (forward-line 1)
248 nil))
250 (defun Buffer-menu-mark ()
251 "Mark buffer on this line for being displayed by \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command."
252 (interactive)
253 (when (Buffer-menu-no-header)
254 (let ((buffer-read-only nil))
255 (delete-char 1)
256 (insert ?>)
257 (forward-line 1))))
259 (defun Buffer-menu-unmark (&optional backup)
260 "Cancel all requested operations on buffer on this line and move down.
261 Optional ARG means move up."
262 (interactive "P")
263 (when (Buffer-menu-no-header)
264 (let* ((buf (Buffer-menu-buffer t))
265 (mod (buffer-modified-p buf))
266 (readonly (save-excursion (set-buffer buf) buffer-read-only))
267 (buffer-read-only nil))
268 (delete-char 3)
269 (insert (if readonly (if mod " %*" " % ") (if mod " *" " ")))))
270 (forward-line (if backup -1 1)))
272 (defun Buffer-menu-backup-unmark ()
273 "Move up and cancel all requested operations on buffer on line above."
274 (interactive)
275 (forward-line -1)
276 (Buffer-menu-unmark)
277 (forward-line -1))
279 (defun Buffer-menu-delete (&optional arg)
280 "Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command.
281 Prefix arg is how many buffers to delete.
282 Negative arg means delete backwards."
283 (interactive "p")
284 (when (Buffer-menu-no-header)
285 (let ((buffer-read-only nil))
286 (if (or (null arg) (= arg 0))
287 (setq arg 1))
288 (while (> arg 0)
289 (delete-char 1)
290 (insert ?D)
291 (forward-line 1)
292 (setq arg (1- arg)))
293 (while (and (< arg 0)
294 (Buffer-menu-no-header))
295 (delete-char 1)
296 (insert ?D)
297 (forward-line -1)
298 (setq arg (1+ arg))))))
300 (defun Buffer-menu-delete-backwards (&optional arg)
301 "Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command
302 and then move up one line. Prefix arg means move that many lines."
303 (interactive "p")
304 (Buffer-menu-delete (- (or arg 1))))
306 (defun Buffer-menu-save ()
307 "Mark buffer on this line to be saved by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command."
308 (interactive)
309 (when (Buffer-menu-no-header)
310 (let ((buffer-read-only nil))
311 (forward-char 2)
312 (delete-char 1)
313 (insert ?S)
314 (forward-line 1))))
316 (defun Buffer-menu-not-modified (&optional arg)
317 "Mark buffer on this line as unmodified (no changes to save)."
318 (interactive "P")
319 (save-excursion
320 (set-buffer (Buffer-menu-buffer t))
321 (set-buffer-modified-p arg))
322 (save-excursion
323 (beginning-of-line)
324 (forward-char 2)
325 (if (= (char-after) (if arg ? ?*))
326 (let ((buffer-read-only nil))
327 (delete-char 1)
328 (insert (if arg ?* ? ))))))
330 (defun Buffer-menu-execute ()
331 "Save and/or delete buffers marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-save] or \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
332 (interactive)
333 (save-excursion
334 (goto-char (point-min))
335 (unless Buffer-menu-use-header-line
336 (forward-line 1))
337 (while (re-search-forward "^..S" nil t)
338 (let ((modp nil))
339 (save-excursion
340 (set-buffer (Buffer-menu-buffer t))
341 (save-buffer)
342 (setq modp (buffer-modified-p)))
343 (let ((buffer-read-only nil))
344 (delete-char -1)
345 (insert (if modp ?* ? ))))))
346 (save-excursion
347 (goto-char (point-min))
348 (unless Buffer-menu-use-header-line
349 (forward-line 1))
350 (let ((buff-menu-buffer (current-buffer))
351 (buffer-read-only nil))
352 (while (re-search-forward "^D" nil t)
353 (forward-char -1)
354 (let ((buf (Buffer-menu-buffer nil)))
355 (or (eq buf nil)
356 (eq buf buff-menu-buffer)
357 (save-excursion (kill-buffer buf)))
358 (if (and buf (buffer-name buf))
359 (progn (delete-char 1)
360 (insert ? ))
361 (delete-region (point) (progn (forward-line 1) (point)))
362 (unless (bobp)
363 (forward-char -1))))))))
365 (defun Buffer-menu-select ()
366 "Select this line's buffer; also display buffers marked with `>'.
367 You can mark buffers with the \\<Buffer-menu-mode-map>\\[Buffer-menu-mark] command.
368 This command deletes and replaces all the previously existing windows
369 in the selected frame."
370 (interactive)
371 (let ((buff (Buffer-menu-buffer t))
372 (menu (current-buffer))
373 (others ())
374 tem)
375 (goto-char (point-min))
376 (unless Buffer-menu-use-header-line
377 (forward-line 1))
378 (while (re-search-forward "^>" nil t)
379 (setq tem (Buffer-menu-buffer t))
380 (let ((buffer-read-only nil))
381 (delete-char -1)
382 (insert ?\ ))
383 (or (eq tem buff) (memq tem others) (setq others (cons tem others))))
384 (setq others (nreverse others)
385 tem (/ (1- (frame-height)) (1+ (length others))))
386 (delete-other-windows)
387 (switch-to-buffer buff)
388 (or (eq menu buff)
389 (bury-buffer menu))
390 (if (equal (length others) 0)
391 (progn
392 ;;; ;; Restore previous window configuration before displaying
393 ;;; ;; selected buffers.
394 ;;; (if Buffer-menu-window-config
395 ;;; (progn
396 ;;; (set-window-configuration Buffer-menu-window-config)
397 ;;; (setq Buffer-menu-window-config nil)))
398 (switch-to-buffer buff))
399 (while others
400 (split-window nil tem)
401 (other-window 1)
402 (switch-to-buffer (car others))
403 (setq others (cdr others)))
404 (other-window 1) ;back to the beginning!
409 (defun Buffer-menu-visit-tags-table ()
410 "Visit the tags table in the buffer on this line. See `visit-tags-table'."
411 (interactive)
412 (let ((file (buffer-file-name (Buffer-menu-buffer t))))
413 (if file
414 (visit-tags-table file)
415 (error "Specified buffer has no file"))))
417 (defun Buffer-menu-1-window ()
418 "Select this line's buffer, alone, in full frame."
419 (interactive)
420 (switch-to-buffer (Buffer-menu-buffer t))
421 (bury-buffer (other-buffer))
422 (delete-other-windows))
424 (defun Buffer-menu-mouse-select (event)
425 "Select the buffer whose line you click on."
426 (interactive "e")
427 (let (buffer)
428 (save-excursion
429 (set-buffer (window-buffer (posn-window (event-end event))))
430 (save-excursion
431 (goto-char (posn-point (event-end event)))
432 (setq buffer (Buffer-menu-buffer t))))
433 (select-window (posn-window (event-end event)))
434 (if (and (window-dedicated-p (selected-window))
435 (eq (selected-window) (frame-root-window)))
436 (switch-to-buffer-other-frame buffer)
437 (switch-to-buffer buffer))))
439 (defun Buffer-menu-this-window ()
440 "Select this line's buffer in this window."
441 (interactive)
442 (switch-to-buffer (Buffer-menu-buffer t)))
444 (defun Buffer-menu-other-window ()
445 "Select this line's buffer in other window, leaving buffer menu visible."
446 (interactive)
447 (switch-to-buffer-other-window (Buffer-menu-buffer t)))
449 (defun Buffer-menu-switch-other-window ()
450 "Make the other window select this line's buffer.
451 The current window remains selected."
452 (interactive)
453 (display-buffer (Buffer-menu-buffer t)))
455 (defun Buffer-menu-2-window ()
456 "Select this line's buffer, with previous buffer in second window."
457 (interactive)
458 (let ((buff (Buffer-menu-buffer t))
459 (menu (current-buffer))
460 (pop-up-windows t))
461 (delete-other-windows)
462 (switch-to-buffer (other-buffer))
463 (pop-to-buffer buff)
464 (bury-buffer menu)))
466 (defun Buffer-menu-toggle-read-only ()
467 "Toggle read-only status of buffer on this line, perhaps via version control."
468 (interactive)
469 (let (char)
470 (save-excursion
471 (set-buffer (Buffer-menu-buffer t))
472 (vc-toggle-read-only)
473 (setq char (if buffer-read-only ?% ? )))
474 (save-excursion
475 (beginning-of-line)
476 (forward-char 1)
477 (if (/= (following-char) char)
478 (let (buffer-read-only)
479 (delete-char 1)
480 (insert char))))))
482 (defun Buffer-menu-bury ()
483 "Bury the buffer listed on this line."
484 (interactive)
485 (when (Buffer-menu-no-header)
486 (save-excursion
487 (beginning-of-line)
488 (bury-buffer (Buffer-menu-buffer t))
489 (let ((line (buffer-substring (point) (progn (forward-line 1) (point))))
490 (buffer-read-only nil))
491 (delete-region (point) (progn (forward-line -1) (point)))
492 (goto-char (point-max))
493 (insert line))
494 (message "Buried buffer moved to the end"))))
497 (defun Buffer-menu-view ()
498 "View this line's buffer in View mode."
499 (interactive)
500 (view-buffer (Buffer-menu-buffer t)))
503 (defun Buffer-menu-view-other-window ()
504 "View this line's buffer in View mode in another window."
505 (interactive)
506 (view-buffer-other-window (Buffer-menu-buffer t)))
509 (define-key ctl-x-map "\C-b" 'list-buffers)
511 (defun list-buffers (&optional files-only)
512 "Display a list of names of existing buffers.
513 The list is displayed in a buffer named `*Buffer List*'.
514 Note that buffers with names starting with spaces are omitted.
515 Non-null optional arg FILES-ONLY means mention only file buffers.
517 For more information, see the function `buffer-menu'."
518 (interactive "P")
519 (display-buffer (list-buffers-noselect files-only)))
521 (defun Buffer-menu-buffer+size (name size &optional name-props size-props)
522 (if (> (+ (length name) (length size) 2) Buffer-menu-buffer+size-width)
523 (setq name
524 (if (string-match "<[0-9]+>$" name)
525 (concat (substring name 0
526 (- Buffer-menu-buffer+size-width
527 (max (length size) 3)
528 (match-end 0)
529 (- (match-beginning 0))
531 ":" ; narrow ellipsis
532 (match-string 0 name))
533 (concat (substring name 0
534 (- Buffer-menu-buffer+size-width
535 (max (length size) 3)
537 ":"))) ; narrow ellipsis
538 ;; Don't put properties on (buffer-name).
539 (setq name (copy-sequence name)))
540 (add-text-properties 0 (length name) name-props name)
541 (add-text-properties 0 (length size) size-props size)
542 (concat name
543 (make-string (- Buffer-menu-buffer+size-width
544 (length name)
545 (length size))
547 size))
549 (defun list-buffers-noselect (&optional files-only)
550 "Create and return a buffer with a list of names of existing buffers.
551 The buffer is named `*Buffer List*'.
552 Note that buffers with names starting with spaces are omitted.
553 Non-null optional arg FILES-ONLY means mention only file buffers.
555 For more information, see the function `buffer-menu'."
556 (let* ((old-buffer (current-buffer))
557 (standard-output standard-output)
558 (mode-end (make-string (- Buffer-menu-mode-width 2) ? ))
559 ;; Fixme: This is wrong for left-hand scroll-bars.
560 (header (concat "CRM " (Buffer-menu-buffer+size "Buffer" "Size")
561 " Mode" mode-end "File\n"))
562 list desired-point name file mode)
563 (save-excursion
564 (set-buffer (get-buffer-create "*Buffer List*"))
565 (setq buffer-read-only nil)
566 (erase-buffer)
567 (setq standard-output (current-buffer))
568 (unless Buffer-menu-use-header-line
569 (insert header "--- ------")
570 (indent-to Buffer-menu-buffer+size-width)
571 (insert "---- ----" mode-end "----\n")
572 (put-text-property 1 (point) 'intangible t))
573 (setq list
574 (delq t
575 (mapcar
576 (lambda (buffer)
577 (with-current-buffer buffer
578 (setq name (buffer-name)
579 file (buffer-file-name))
580 (cond
581 ;; Don't mention internal buffers.
582 ((and (string= (substring name 0 1) " ") (null file)))
583 ;; Maybe don't mention buffers without files.
584 ((and files-only (not file)))
585 ((string= name "*Buffer List*"))
586 ;; Otherwise output info.
588 (unless file
589 ;; No visited file. Check local value of
590 ;; list-buffers-directory.
591 (when (and (boundp 'list-buffers-directory)
592 list-buffers-directory)
593 (setq file list-buffers-directory)))
594 (list buffer
595 (format "%c%c%c "
596 (if (eq buffer old-buffer) ?. ? )
597 ;; Handle readonly status. The output buffer is special
598 ;; cased to appear readonly; it is actually made so at a
599 ;; later date.
600 (if (or (eq buffer standard-output)
601 buffer-read-only)
602 ?% ? )
603 ;; Identify modified buffers.
604 (if (buffer-modified-p) ?* ? ))
605 name (buffer-size) mode-name file)))))
606 (buffer-list))))
607 (dolist (buffer
608 (if Buffer-menu-sort-column
609 (sort list
610 (if (eq Buffer-menu-sort-column 3)
611 (lambda (a b)
612 (< (nth Buffer-menu-sort-column a)
613 (nth Buffer-menu-sort-column b)))
614 (lambda (a b)
615 (string< (nth Buffer-menu-sort-column a)
616 (nth Buffer-menu-sort-column b)))))
617 list))
618 (if (eq (car buffer) old-buffer)
619 (setq desired-point (point)))
620 (insert (cadr buffer)
621 ;; Put the buffer name into a text property
622 ;; so we don't have to extract it from the text.
623 ;; This way we avoid problems with unusual buffer names.
624 (Buffer-menu-buffer+size (nth 2 buffer)
625 (int-to-string (nth 3 buffer))
626 `(buffer-name ,(nth 2 buffer)
627 buffer ,(car buffer)
628 face Buffer-menu-buffer-face
629 mouse-face highlight
630 help-echo "mouse-2: select this buffer"))
632 (if (> (length (nth 4 buffer)) Buffer-menu-mode-width)
633 (substring (nth 4 buffer) 0 Buffer-menu-mode-width)
634 (nth 4 buffer)))
635 (when (nth 5 buffer)
636 (indent-to (+ Buffer-menu-buffer-column Buffer-menu-buffer+size-width
637 Buffer-menu-mode-width 4) 1)
638 (princ (abbreviate-file-name (nth 5 buffer))))
639 (princ "\n"))
640 (Buffer-menu-mode)
641 (when Buffer-menu-use-header-line
642 (set (make-local-variable 'Buffer-menu-header-line)
643 (concat " " header))
644 (setq header-line-format 'Buffer-menu-header-line))
645 ;; DESIRED-POINT doesn't have to be set; it is not when the
646 ;; current buffer is not displayed for some reason.
647 (and desired-point
648 (goto-char desired-point))
649 (current-buffer))))
651 ;;; buff-menu.el ends here