The Emacs clean-buffer-list Command

Some time ago, I enabled save-desktop-mode in Emacs and I've been really happy with it. I generally never close Emacs but sometimes I need to restart it for one reason or another or an OS upgrade requires me to reboot. Since I have a number of buffers that are always open, restarting Emacs was a pain before I started saving the sessions. Now when I restart Emacs, everything is just like it was before the restart. A downside of save-desktop-mode is that the buffer list grows and grows. Every once in a while I run ibuffer to get a list of active buffers and cull the list.

Today, I discovered the clean-buffer-list command that automates the process. The idea is that buffers that haven't been displayed recently are closed. The meaning of “recently” is, of course, configurable along with other attributes of the process. This is the command that the so-called Midnight Mode uses. My machines are usually asleep at midnight so in order for me to use automatic cleaning I'd have to schedule it for when I'm on the machine and I don't want to do that.

Happily, I can just run clean-buffer-list when I notice that the number of buffers is getting over large and have the list culled automatically for me. Another win for Emacs.

This entry was posted in General and tagged . Bookmark the permalink.

3 Responses to The Emacs clean-buffer-list Command

  1. Ryan says:

    If you don't want it running while emacs use in use but you also don't want to run it manually, why not set it on an idle timer with a nice long timeout?

    • jcs jcs says:

      Actually, I don't mind running it manually but it's a nice idea to put it on an idle timer. Something to keep in mind--not just for clean-buffer-list but for any periodic task.

  2. Xah Lee says:

    in my usage pattern, i find that one problem of emacs default UI is that it makes it difficult to close a buffer.

    【Ctrl+x k】 then eyeball what the buffer name, then Enter, and if it's not saved, one has to type full yes or no. Too many keystrokes. Also, when it's scratch or buffer not associated with file, it doesn't ask for save.

    these makes people not want to close buffer. So, buffer accumulates. Instead of close files we don't need, people use bury-buffer and switch-buffer more often than necessary. Tens or hundreds of buffers became a problem, Then, iwitch, ido, clean-buffer-list is invented to solve this new problem.

    i always close buffers that i'm done working with. So, usually i have no more than 20 buffers open. Single key is assigned to close buffer, with just y/n if unsaved. This also makes switching to next/prev buffer much more useful.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>