Skip to content

Instantly share code, notes, and snippets.

@ivan4th
Last active November 12, 2020 10:00
Show Gist options
  • Save ivan4th/ee8f5e4abac13d581d2a037403d3c00b to your computer and use it in GitHub Desktop.
Save ivan4th/ee8f5e4abac13d581d2a037403d3c00b to your computer and use it in GitHub Desktop.
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