Open all marked buffers in Ibuffer

Posted: January 19, 2007 in Emacs

In emacs I use ibuffer to get a dired like list of all my open buffers. Because it’s often quite inconvenient to split emacs windows by hand and assign them the right buffers I came up with this idea: Why not mark some buffers in Ibuffer (with m) and then run a function which splits the windows itself and assigns the marked buffers to them.

So here’s the function:

(defun th-ibuffer-view-marked-buffers (horiz)
  "Open the marked buffers -- each in a separate window. By
default the windows will be created by splitting the current
window vertically, or horizontally if HORIZ is not nil."
  (interactive "P")
  (let ((buffers (ibuffer-marked-buffer-names)))
    (dotimes (var (1- (length buffers)))
      (if horiz
      (switch-to-buffer (nth var buffers))
      (other-window 1))
    (switch-to-buffer (car (last buffers)))

If you call it with a prefix arg it will split the windows horizontally, else it splits vertically.

ARGH!!! Now that I’ve written this fantastic function I found out that ibuffer-do-view and ibuffer-do-view-horizontally do exactly what my function does. Well, at least it was a nice quick elisp hack… :-)

The blog entry Conveniently save and restore frame configurations is related.

UPDATE: Hah, my version is better, because ibuffer-do-view and ibuffer-do-view-horizontally destroy the current window configuration. :-)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s