Skip to content

Instantly share code, notes, and snippets.

@sabof
Created March 21, 2013 20:18
Show Gist options
  • Save sabof/5216336 to your computer and use it in GitHub Desktop.
Save sabof/5216336 to your computer and use it in GitHub Desktop.
What I use to kill buffers
(require 'cl)
(defun es-kill-buffer-this-window ()
(interactive)
(let* (( was-dedicated (window-dedicated-p))
( buf (current-buffer))
( kill-result
(if (or (get-buffer-process buf) (buffer-modified-p buf))
(when (kill-buffer)
(when (and was-dedicated
(> (length (window-list)) 1))
(quit-window)) t)
(progn
(quit-window t)
t))))
kill-result))
(defun* es-delete-window-or-frame (window)
(unless (window-live-p window)
(return-from es-delete-window-or-frame))
(with-selected-window window
(if (= (list-length (window-list)) 1)
(delete-frame (window-frame window))
(delete-window))))
(defun es-full-window-list ()
(loop for frame in (remove terminal-frame (frame-list))
nconcing (with-selected-frame frame
(window-list))))
(defun* es-kill-buffer (&optional buffer)
(interactive)
(when (and (bufferp buffer)
(not (buffer-live-p buffer)))
(return-from es-kill-buffer))
(when buffer
(set-buffer buffer))
(setq kill-buffer-query-functions
(delete 'server-kill-buffer-query-function
kill-buffer-query-functions))
(let ((dead-major-mode major-mode)
(dead-name (buffer-name))
(kill-list (loop for window
in (remove (selected-window) (es-full-window-list))
when (eq (current-buffer) (window-buffer window))
collect window)))
(when (es-kill-buffer-this-window)
(mapc 'es-delete-window-or-frame kill-list)
(when (and (or (memq dead-major-mode
'(reb-mode ; re-builder
calc-mode
calc-trail-mode
calculator-mode))
(search "popup" dead-name))
(> (length (window-list)) 1))
(delete-window)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment