2

After several months of work, my Emacs easily accumulates 400 or 500 buffers. This makes restoring from desktop-mode irritatingly slow. I'd love to be able to delete buffers in bulk, ideally from the buffer list. For example, "mark for deletion every buffer associated with a file whose name matches regexp" or similar. But I can't find such a function, and looking at the way the buffer list is implemented, I can't figure out how to write one myself.

What functions or techniques exist for managing a large number of buffers?

5
  • 1
    You can also use midnight mode which will kill buffers that have not been looked at for a given time e.g. 3 days and that don't need to be saved. But emacs needs to be open for all the time not restarted from desktop-save – mmmmmm Jan 16 at 22:33
  • The question isn't a good fit for emacs.SE. It's too open-ended, not well defined, and encourages opinion-based answers. Questions that are specific how-to are good fits. – Drew Jan 17 at 0:52
  • See the similar question linked above. The example there is Ibuffer's % m which marks by mode, but there is also % f which marks by (displayed) buffer-file-name, as well as many other bells and whistles. – Basil Jan 17 at 12:55
  • @Basil if you'd care to write an answer involving ibuffer I'll mark it accepted. – Norman Ramsey Jan 17 at 16:31
  • @NormanRamsey I was in the middle of doing so, but then I realised I was mostly duplicating Phil's answer to the question that this one is marked as a duplicate of. – Basil Jan 17 at 16:41
2

I would activate electric-buffer-list and apply this small function :

(defun buffer-list-mark-for-deleting (rxp)
  "Mark all *Buffer Lines* lines matching the regexp RXP for deleting"
  (interactive  "sRegexp to delete : " )
  (with-current-buffer "*Buffer List*"
    (goto-char (point-min))
    (while (search-forward-regexp rxp nil t)
      (Buffer-menu-delete))))

For instance, the regexp "^ +* *[hH]elm" will mark all entry beginning with " * helm" or " * Helm" with the "D" letter. Selecting any non mark buffer will delete the marked ones.

You can build much more complex regexps using re-builder and write some specific functions for your needs.

Of course, you can bind this function to a key sequence according to your desire.

Not the answer you're looking for? Browse other questions tagged or ask your own question.