aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-01-13 08:14:25 +0000
committerRichard M. Stallman1995-01-13 08:14:25 +0000
commit0b03ce3a17259c56ed922ae5fe9776ec75cbb38b (patch)
tree00da935f93647bc11fc2968e6c2d1132df4d7aba
parent5259c73786e38510a625beff715dcea233480cf7 (diff)
downloademacs-0b03ce3a17259c56ed922ae5fe9776ec75cbb38b.tar.gz
emacs-0b03ce3a17259c56ed922ae5fe9776ec75cbb38b.zip
(list-buffers): New function.
(ctl-x-map): Define C-x C-b to list-buffers.
-rw-r--r--lisp/buff-menu.el90
1 files changed, 90 insertions, 0 deletions
diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el
index 38926269b71..7924e6a6a4a 100644
--- a/lisp/buff-menu.el
+++ b/lisp/buff-menu.el
@@ -415,4 +415,94 @@ The current window remains selected."
415 (delete-char 1) 415 (delete-char 1)
416 (insert char)))))) 416 (insert char))))))
417 417
418
419
420(define-key ctl-x-map "\C-b" 'list-buffers)
421
422(defun list-buffers (&optional files-only)
423 "Display a list of names of existing buffers.
424The list is displayed in a buffer named `*Buffer List*'.
425Note that buffers with names starting with spaces are omitted.
426Non-null optional arg FILES-ONLY means mention only file buffers.
427
428The M column contains a * for buffers that are modified.
429The R column contains a % for buffers that are read-only."
430 (interactive "P")
431 (let ((old-buffer (current-buffer))
432 (blist-buffer (get-buffer-create "*Buffer List*"))
433 (desired-point nil))
434 (with-output-to-temp-buffer "*Buffer List*"
435 (set-buffer standard-output)
436 (princ "\
437 MR Buffer Size Mode File
438 -- ------ ---- ---- ----
439")
440 (let ((bl (buffer-list)))
441 (while bl
442 (let* ((buffer (car bl))
443 (name (buffer-name buffer))
444 (file (buffer-file-name buffer)))
445 (cond
446 ;; Don't mention internal buffers.
447 ((string= (substring name 0 1) " "))
448 ;; Maybe don't mention buffers without files.
449 ((and files-only (not file)))
450 ;; Otherwise output info.
451 (t
452 ;; Identify current buffer.
453 (if (eq buffer old-buffer)
454 (progn
455 (setq desired-point (point))
456 (princ "."))
457 (princ " "))
458 ;; Identify modified buffers.
459 (princ (if (buffer-modified-p buffer) "*" " "))
460 ;; Handle readonly status. The output buffer is special
461 ;; cased to be readonly; it is actually made so at a later
462 ;; date.
463 (princ (if (or (eq buffer standard-output) buffer-read-only)
464 "% "
465 " "))
466 (princ name)
467 (indent-to 17 2)
468 (let (size
469 mode
470 (excess (- (current-column) 17)))
471 (save-excursion
472 (set-buffer buffer)
473 (setq size (format "%8d" (buffer-size)))
474 ;; Ack -- if looking at the *Buffer List* buffer,
475 ;; always use "Buffer Menu" mode. Otherwise the
476 ;; first time the buffer is created, the mode will
477 ;; be wrong.
478 (setq mode (if (eq buffer standard-output)
479 "Buffer Menu"
480 mode-name))
481 (while (and (> excess 0) (= (aref size 0) ?\ ))
482 (setq size (substring size 1))
483 (setq excess (1- excess))))
484 (princ size)
485 (indent-to 27 1)
486 (princ mode))
487 (indent-to 40 1)
488 (if file
489 (princ file)
490 ;; No visited file. Check local value of
491 ;; list-buffers-directory.
492 (save-excursion
493 (set-buffer buffer)
494 (if (and (boundp list-buffers-directory)
495 list-buffers-directory)
496 (princ list-buffers-directory))))
497 (princ "\n"))))
498 (setq bl (cdr bl)))))
499 ;; DESIRED-POINT doesn't have to be set; it is not when the
500 ;; current buffer is not displayed for some reason.
501 (save-excursion
502 (set-buffer blist-buffer)
503 (Buffer-menu-mode)
504 (and desired-point
505 (goto-char desired-point))
506 (setq ZZZ (point)))))
507
418;;; buff-menu.el ends here 508;;; buff-menu.el ends here