emacselisp

Close all buffers besides the current one in Emacs


How do I close all but the current buffer in Emacs? Similar to "Close other tabs" feature in modern web browsers?


Solution

  • From EmacsWiki: Killing Buffers:

    (defun kill-other-buffers ()
        "Kill all other buffers."
        (interactive)
        (mapc 'kill-buffer 
              (delq (current-buffer) 
                    (remove-if-not 'buffer-file-name (buffer-list)))))
    

    Edit: updated with feedback from Gilles