Created
September 14, 2016 00:58
-
-
Save angus-g/738c64eb4c8060d5b5dbfceb7e53cd00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(evil-define-command evil-delete-buffer (buffer &optional bang) | |
"Deletes a buffer. | |
All windows currently showing this buffer will be closed except | |
for the last window in each frame." | |
(interactive "<b><!>") | |
(with-current-buffer (or buffer (current-buffer)) | |
(when bang | |
(set-buffer-modified-p nil) | |
(dolist (process (process-list)) | |
(when (eq (process-buffer process) (current-buffer)) | |
(set-process-query-on-exit-flag process nil)))) | |
;; get all windows that show this buffer | |
(let ((wins (get-buffer-window-list (current-buffer) nil t))) | |
;; if the buffer which was initiated by emacsclient, | |
;; call `server-edit' from server.el to avoid | |
;; "Buffer still has clients" message | |
(if (and (fboundp 'server-edit) | |
(boundp 'server-buffer-clients) | |
server-buffer-clients) | |
(server-edit) | |
(kill-buffer nil)) | |
;; close all windows that showed this buffer | |
(mapc #'(lambda (w) | |
(condition-case nil | |
(delete-window w) | |
(error nil))) | |
wins)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment