Remove doom-cleanup-hook & doom/cleanup-session

These weren't reliable, often times buggy or overzealous about killing
buffers and processes. Best to do it manually or come up with a better
solution.
This commit is contained in:
Henrik Lissner 2019-02-26 22:56:32 -05:00
parent 3e85981695
commit 9b7d95f43a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
5 changed files with 2 additions and 53 deletions

View file

@ -34,11 +34,6 @@ See `doom-real-buffer-p' for more information.")
"The name of the buffer to fall back to if no other buffers exist (will create "The name of the buffer to fall back to if no other buffers exist (will create
it if it doesn't exist).") it if it doesn't exist).")
;;;###autoload
(defvar doom-cleanup-hook ()
"A list of hooks run when `doom/cleanup-session' is run, meant to clean up
leftover buffers and processes.")
;; ;;
;; Functions ;; Functions
@ -264,10 +259,11 @@ If DONT-SAVE, don't prompt to save modified buffers (discarding their changes)."
If PROJECT-P (universal argument), don't close windows and only kill buffers If PROJECT-P (universal argument), don't close windows and only kill buffers
that belong to the current project." that belong to the current project."
(interactive "P") (interactive "P")
(save-some-buffers)
(unless project-p (unless project-p
(delete-other-windows)) (delete-other-windows))
(switch-to-buffer (doom-fallback-buffer)) (switch-to-buffer (doom-fallback-buffer))
(doom/cleanup-session nil (if project-p (doom-project-buffer-list)))) (mapc #'kill-buffer (if project-p (doom-project-buffer-list) (doom-buffer-list))))
;;;###autoload ;;;###autoload
(defun doom/kill-other-buffers (&optional project-p) (defun doom/kill-other-buffers (&optional project-p)
@ -297,40 +293,3 @@ project."
(n (doom-kill-matching-buffers pattern buffers))) (n (doom-kill-matching-buffers pattern buffers)))
(when (called-interactively-p 'interactive) (when (called-interactively-p 'interactive)
(message "Killed %s buffers" n)))) (message "Killed %s buffers" n))))
;;;###autoload
(defun doom/cleanup-session (arg &optional buffer-list)
"Clean up buried buries and orphaned processes in the current workspace. If
ALL-P (universal argument), clean them up globally."
(interactive "P")
(let ((buffers (doom-buried-buffers buffer-list))
(n 0))
(dolist (buf buffers)
(unless (buffer-modified-p buf)
(kill-buffer buf)
(cl-incf n)))
(when arg
(setq n (+ n (doom/cleanup-buffer-processes))))
(dolist (hook doom-cleanup-hook)
(let ((m (funcall hook)))
(when (integerp m)
(setq n (+ n m)))))
(message "Cleaned up %s buffers" n)
n))
;;;###autoload
(defun doom/cleanup-buffer-processes ()
"Kill all processes that have no visible associated buffers. Return number of
processes killed."
(interactive)
(let ((n 0))
(dolist (p (process-list))
(let ((process-buffer (process-buffer p)))
(when (and (process-live-p p)
(not (string= (process-name p) "server"))
(or (not process-buffer)
(and (bufferp process-buffer)
(not (buffer-live-p process-buffer)))))
(delete-process p)
(cl-incf n))))
n))

View file

@ -1,9 +1,5 @@
;;; feature/evil/+commands.el -*- lexical-binding: t; -*- ;;; feature/evil/+commands.el -*- lexical-binding: t; -*-
(evil-define-command +evil:cleanup-session (bang)
(interactive "<!>")
(doom/cleanup-session bang))
(evil-define-operator +evil:open-scratch-buffer (bang) (evil-define-operator +evil:open-scratch-buffer (bang)
(interactive "<!>") (interactive "<!>")
(doom/open-scratch-buffer bang)) (doom/open-scratch-buffer bang))
@ -94,7 +90,6 @@ This command understands vim file modifiers (like %:p:h). See
(evil-ex-define-cmd "grevert" #'git-gutter:revert-hunk) (evil-ex-define-cmd "grevert" #'git-gutter:revert-hunk)
;;; Dealing with buffers ;;; Dealing with buffers
(evil-ex-define-cmd "clean[up]" #'+evil:cleanup-session)
(evil-ex-define-cmd "k[ill]" #'doom/kill-this-buffer) (evil-ex-define-cmd "k[ill]" #'doom/kill-this-buffer)
(evil-ex-define-cmd "k[ill]all" #'+default:kill-all-buffers) (evil-ex-define-cmd "k[ill]all" #'+default:kill-all-buffers)
(evil-ex-define-cmd "k[ill]m" #'+default:kill-matching-buffers) (evil-ex-define-cmd "k[ill]m" #'+default:kill-matching-buffers)

View file

@ -102,8 +102,6 @@ Uses `+workspaces-main' to determine the name of the main workspace."
(advice-add #'persp-asave-on-exit :around #'+workspaces*autosave-real-buffers) (advice-add #'persp-asave-on-exit :around #'+workspaces*autosave-real-buffers)
(add-hook 'doom-cleanup-hook #'+workspaces|cleanup-unassociated-buffers)
;; Ensure buffers we've opened/switched to are auto-added to the current ;; Ensure buffers we've opened/switched to are auto-added to the current
;; perspective ;; perspective
(setq persp-add-buffer-on-find-file t (setq persp-add-buffer-on-find-file t

View file

@ -210,7 +210,6 @@ compilation database is present in the project.")
:definition #'rtags-find-symbol-at-point :definition #'rtags-find-symbol-at-point
:references #'rtags-find-references-at-point) :references #'rtags-find-references-at-point)
(add-hook 'doom-cleanup-hook #'+cc|cleanup-rtags)
(add-hook! 'kill-emacs-hook (ignore-errors (rtags-cancel-process))) (add-hook! 'kill-emacs-hook (ignore-errors (rtags-cancel-process)))
;; Use rtags-imenu instead of imenu/counsel-imenu ;; Use rtags-imenu instead of imenu/counsel-imenu

View file

@ -56,7 +56,6 @@ adjustment.")
:keymap +popup-mode-map :keymap +popup-mode-map
(cond (+popup-mode (cond (+popup-mode
(add-hook 'doom-escape-hook #'+popup|close-on-escape t) (add-hook 'doom-escape-hook #'+popup|close-on-escape t)
(add-hook 'doom-cleanup-hook #'+popup|cleanup-rules)
(setq +popup--old-display-buffer-alist display-buffer-alist (setq +popup--old-display-buffer-alist display-buffer-alist
display-buffer-alist +popup--display-buffer-alist display-buffer-alist +popup--display-buffer-alist
window--sides-inhibit-check t) window--sides-inhibit-check t)
@ -64,7 +63,6 @@ adjustment.")
(push (cons prop 'writable) window-persistent-parameters))) (push (cons prop 'writable) window-persistent-parameters)))
(t (t
(remove-hook 'doom-escape-hook #'+popup|close-on-escape) (remove-hook 'doom-escape-hook #'+popup|close-on-escape)
(remove-hook 'doom-cleanup-hook #'+popup|cleanup-rules)
(setq display-buffer-alist +popup--old-display-buffer-alist (setq display-buffer-alist +popup--old-display-buffer-alist
window--sides-inhibit-check nil) window--sides-inhibit-check nil)
(+popup|cleanup-rules) (+popup|cleanup-rules)