dealing with many buffers: ibuffer



If you are like me, you'll open a lot of buffers in emacs. There may be a couple of buffers with source code, a few for e-mail. org-mode will open buffers for all your agenda files. Then, maybe an info page, a few ERC-channels, a couple of special emacs buffers such as **Messages** and **scratch**. So, in a moderately busy emacs session there may 30-40 buffers open, and after a day or so there can be many more.



With so many buffers, it can be hard to quickly find the one you are looking for - and clearly a one-tab-per-buffer (like Firefox uses) would not work very well either.



So, what can we do instead? Here, on emacs-fu, we discussed this a couple of

times already:



  • using ido-mode, you can quickly switch to buffers by typing a subset of

    their name


  • using elscreen to step through buffer configurations (this comes close to a

    workable tab-like solution)




These are really useful tools. What's still missing though, is a way to get an overview of all buffers. For that, emacs provide buffer-menu, normally bound to C-x C-b. It lists all your buffers, and you can interact with them in a way similar to dired, e.g. you can switch to a buffer by moving the point (cursor) to the buffer and pressing Return. Or you mark buffers for deletion by pressing d when point is on the buffer, and then press x to kill them all.



Very useful. But if you really have a lot of buffers, just having a long list of them may still be a bit hard to deal with. For that, there is ibuffer, which allows you to put your buffers in different categories -- which can even overlap. Emacs ships ibuffer since version 22, so you'll probably already have it.



Using a setup like the following, you can put your buffers in categories; each buffer is shown only once (apparently, the first match), and you can match on mode (the Emacs-mode of the buffer), name (the buffer name), filename (the full path to the file being visited, if any), and a couple of others (see EmacsWiki).



(require 'ibuffer) 
(setq ibuffer-saved-filter-groups
(quote (("default"
("Org" ;; all org-related buffers
(mode . org-mode))
("Mail"
(or ;; mail-related buffers
(mode . message-mode)
(mode . mail-mode)
;; etc.; all your mail related modes
))
("MyProject1"
(filename . "src/myproject1/"))
("MyProject2"
(filename . "src/myproject2/"))
("Programming" ;; prog stuff not already in MyProjectX
(or
(mode . c-mode)
(mode . perl-mode)
(mode . python-mode)
(mode . emacs-lisp-mode)
;; etc
))
("ERC" (mode . erc-mode))))))

(add-hook 'ibuffer-mode-hook
(lambda ()
(ibuffer-switch-to-saved-filter-groups "default")))
If you like ibuffer, you can even override the buffer-menu key binding for

it:

(global-set-key (kbd "C-x C-b") 'ibuffer)
As with buffer-menu, you can do various funky things with those buffers, and also filter them further; see the documentation. I am mostly using it for its buffer-navigational qualities, and it's good at that.

No comments:

Post a Comment

Followers

Popular Posts