Skip to content

Instantly share code, notes, and snippets.

@satyr
Created June 10, 2010 04:38
Show Gist options
  • Save satyr/432559 to your computer and use it in GitHub Desktop.
Save satyr/432559 to your computer and use it in GitHub Desktop.
(defun buffer-directory (&optional buf (selected-buffer))
(let ((name (get-buffer-file-name buf)))
(and name (directory-namestring name))))
(defun close-buffers-within (&optional (dir (buffer-directory)))
(interactive)
(when dir
(let ((re (concat "^" (regexp-quote dir)))
(closed '()))
(dolist (buf (buffer-list))
(when (string-match re (or (buffer-directory buf) ""))
(push (buffer-name buf) closed)
(delete-buffer buf)))
(message "~A: ~{~A ~}" (length closed) closed))))
(global-set-key '(#\C-c #\w) 'close-buffers-within)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment