Question

In emacs, is there an M-x command or key combo to render all current open buffers into different windows? For clarity, let's suppose I have four open buffers, and I am only seeing one currently being displayed, and I would like in one step to show each buffer in one quadrant.

Was it helpful?

Solution

You will be able to start with the following code if there is not an already-known way to do it:

(defun buffer-in-window-list ()
  (let (buffers)
    (walk-windows (lambda (window) (push (window-buffer window) buffers)) t t)
    buffers))

(defun display-all-buffers ()
  (interactive)
  (let (buffers-in-window (buffer-in-window-list))
    (dolist (buffer (buffer-list))
      (when (and (not (string-match "\\`[[:space:]]*\\*" (buffer-name buffer)))
                 (not (memq buffer buffers-in-window)))
        (set-window-buffer (split-window (get-largest-window)) buffer)))
    (balance-windows)))

The display-all-buffers command opens a new window for each buffer that is not currently displayed anywhere (including other frames). For usability, it ignores buffers whose names start with * (optionally, prefixed with whitespace characters) because they are usually for internal use only.

Note that Emacs does not allow a user to make too small a window. So, when there are too many buffers to display, the command will display as many buffers as possible in order of most recent display or selection and signal an error.

OTHER TIPS

I recommend ibuffer. M-x ibuffer is probably what you want. Here's my ibuffer configuration:

;; *Messages* is so annoying. Also, I really like ibuffer
(require 'ibuf-ext)
(add-to-list 'ibuffer-never-show-predicates "^\\*Messages")
(add-to-list 'ibuffer-never-show-predicates "^\\*Completions")
(global-set-key (kbd "C-b") 'ibuffer)
(kill-buffer "*scratch*")
('ibuffer)
(switch-to-buffer "*Ibuffer*")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top