lunes, 21 de junio de 2010

Kill Buffers Illustrated (emacs)


A side effect of using emacs intensively is that you end with lots (I mean *LOTS*) of open buffers scattered on your emacs.

This is not necessarily a problem (provided you use ido/iswitchb/icicles modes), but it kind of gets on my nerves having 30+ buffers opened knowing that I don't need them anymore. Most of them are temporary buffers like dired-mode ones, or perldoc ones. Like most things in emacs world, someone has already thought of it and there is already a function to do what you want.

For example, scattered dired-mode buffers.

(defun kill-all-dired-buffers()
"Kill all dired buffers."
(interactive)
(save-excursion
(let((count 0))
(dolist(buffer (buffer-list))
(set-buffer buffer)
(when (equal major-mode 'dired-mode)
(setq count (1+ count))
(kill-buffer buffer)))
(message "Killed %i dired buffer(s)." count ))))
And you're done.

great, isn't it?

What if you want to purge some buffers, that have no name in common, nor mode? You can kill them one at a time with kill-buffer (c-x k) but if you want to do it faster, you can use Buffer List buffer.

c-x c-b will open a buffer with a list of all buffers. That's not a normal (Fundamental) buffer, but a 'Buffer Menu' buffer. If you press 'd', the buffer that has the point (cursor) will be marked for deletion. Once you have the list of buffers to kill, just press 'x', and buffers will be killed.

If you press 'x', 3 erc buffers will be killed. Mnd you, once a buffer has been killed, it cannot be unkilled. :)

That's all for now.

No hay comentarios: