Kill other buffers

Many text editors and IDEs offer the ability to close all open files with the exception of the one you’re currently in. Emacs does not. At least it doesn’t until you add a snippet such as this one to your Emacs setup:

(defun er-kill-other-buffers ()
  "Kill all buffers but the current one.
Don't mess with special buffers."
  (dolist (buffer (buffer-list))
    (unless (or (eql buffer (current-buffer)) (not (buffer-file-name buffer)))
      (kill-buffer buffer))))

Note that the command takes care not to kill special buffers (buffers that do not correspond to files).

I’d suggest binding kill-other-buffers to C-c k.

(global-set-key (kbd "C-c k") #'er-kill-other-buffers)

The command can be implemented in a more elegant manner if one chooses to leverage either the built-in cl.el library or the newer dash.el. Here’s the version of the same command from Prelude, using dash.el:

(require 'dash)

(defun prelude-kill-other-buffers ()
  "Kill all buffers but the current one.
Doesn't mess with special buffers."
   (->> (buffer-list)
     (-filter #'buffer-file-name)
     (--remove (eql (current-buffer) it)))

According to your personal preference on functional programming the second version might seem either much more elegant, ghastly or just the same as the original.