summaryrefslogtreecommitdiff
path: root/lisp/buff-menu.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1995-01-13 08:14:25 +0000
committerRichard M. Stallman <rms@gnu.org>1995-01-13 08:14:25 +0000
commit0b03ce3a17259c56ed922ae5fe9776ec75cbb38b (patch)
tree00da935f93647bc11fc2968e6c2d1132df4d7aba /lisp/buff-menu.el
parent5259c73786e38510a625beff715dcea233480cf7 (diff)
downloademacs-0b03ce3a17259c56ed922ae5fe9776ec75cbb38b.tar.gz
(list-buffers): New function.
(ctl-x-map): Define C-x C-b to list-buffers.
Diffstat (limited to 'lisp/buff-menu.el')
-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."
(delete-char 1)
(insert char))))))
+
+
+(define-key ctl-x-map "\C-b" 'list-buffers)
+
+(defun list-buffers (&optional files-only)
+ "Display a list of names of existing buffers.
+The list is displayed in a buffer named `*Buffer List*'.
+Note that buffers with names starting with spaces are omitted.
+Non-null optional arg FILES-ONLY means mention only file buffers.
+
+The M column contains a * for buffers that are modified.
+The R column contains a % for buffers that are read-only."
+ (interactive "P")
+ (let ((old-buffer (current-buffer))
+ (blist-buffer (get-buffer-create "*Buffer List*"))
+ (desired-point nil))
+ (with-output-to-temp-buffer "*Buffer List*"
+ (set-buffer standard-output)
+ (princ "\
+ MR Buffer Size Mode File
+ -- ------ ---- ---- ----
+")
+ (let ((bl (buffer-list)))
+ (while bl
+ (let* ((buffer (car bl))
+ (name (buffer-name buffer))
+ (file (buffer-file-name buffer)))
+ (cond
+ ;; Don't mention internal buffers.
+ ((string= (substring name 0 1) " "))
+ ;; Maybe don't mention buffers without files.
+ ((and files-only (not file)))
+ ;; Otherwise output info.
+ (t
+ ;; Identify current buffer.
+ (if (eq buffer old-buffer)
+ (progn
+ (setq desired-point (point))
+ (princ "."))
+ (princ " "))
+ ;; Identify modified buffers.
+ (princ (if (buffer-modified-p buffer) "*" " "))
+ ;; Handle readonly status. The output buffer is special
+ ;; cased to be readonly; it is actually made so at a later
+ ;; date.
+ (princ (if (or (eq buffer standard-output) buffer-read-only)
+ "% "
+ " "))
+ (princ name)
+ (indent-to 17 2)
+ (let (size
+ mode
+ (excess (- (current-column) 17)))
+ (save-excursion
+ (set-buffer buffer)
+ (setq size (format "%8d" (buffer-size)))
+ ;; Ack -- if looking at the *Buffer List* buffer,
+ ;; always use "Buffer Menu" mode. Otherwise the
+ ;; first time the buffer is created, the mode will
+ ;; be wrong.
+ (setq mode (if (eq buffer standard-output)
+ "Buffer Menu"
+ mode-name))
+ (while (and (> excess 0) (= (aref size 0) ?\ ))
+ (setq size (substring size 1))
+ (setq excess (1- excess))))
+ (princ size)
+ (indent-to 27 1)
+ (princ mode))
+ (indent-to 40 1)
+ (if file
+ (princ file)
+ ;; No visited file. Check local value of
+ ;; list-buffers-directory.
+ (save-excursion
+ (set-buffer buffer)
+ (if (and (boundp list-buffers-directory)
+ list-buffers-directory)
+ (princ list-buffers-directory))))
+ (princ "\n"))))
+ (setq bl (cdr bl)))))
+ ;; DESIRED-POINT doesn't have to be set; it is not when the
+ ;; current buffer is not displayed for some reason.
+ (save-excursion
+ (set-buffer blist-buffer)
+ (Buffer-menu-mode)
+ (and desired-point
+ (goto-char desired-point))
+ (setq ZZZ (point)))))
+
;;; buff-menu.el ends here