I wanted a quick way to delete all the buffers that can accumulate in an Emacs session. A quick search threw up this post by Martin Owen.
It turned out all I needed was ibuffer mode. ibuffer has a toggle command which selects all unselected buffers.
But that’s not all. ibuffer will group your buffers by type, just like in the featured image for this post. It also comes with a range of commands for filtering buffers. Here are my five favourite commands:
- t to toggle files selected
- / . to filter by extensions
- / p to remove top level filter
- * h Mark all help buffers
- * s Mark all *special* buffers
and here’s my set up: I’ve basically just adapted Martin’s.
(global-set-key (kbd "C-x C-b") 'ibuffer) ; instead of buffer-list (setq ibuffer-expert t) ; stop yes no prompt on delete (setq ibuffer-saved-filter-groups (quote (("default" ("dired" (mode . dired-mode)) ("org" (mode . org-mode)) ("magit" (name . "^magit")) ("planner" (or (name . "^\\*Calendar\\*$") (name . "^\\*Org Agenda\\*"))) ("emacs" (or (name . "^\\*scratch\\*$") (name . "^\\*Messages\\*$"))))))) (add-hook 'ibuffer-mode-hook (lambda () (ibuffer-switch-to-saved-filter-groups "default")))
It took me about ten minutes to do all the above from start to finish. Ten minutes well spent, I say.