Skip to content

Instantly share code, notes, and snippets.

@ivan4th
Last active November 12, 2020 10:00
Kill Emacs buffers by path
;; based on https://stackoverflow.com/a/32823597
(defun killemall (regexp)
(interactive "sKill buffers with paths matching this regexp: ")
(dolist (buffer (buffer-list))
(let ((name (or (buffer-file-name buffer)
(with-current-buffer buffer
(when (boundp 'dired-directory)
(if (consp dired-directory)
(car dired-directory)
dired-directory))))))
(when (and name (not (string-equal name ""))
(string-match regexp name))
(kill-buffer buffer)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment