From 40c757436da69d4e1babb1b618175a02ecc237ca Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 24 Feb 2024 23:00:04 +0800 Subject: basic: Move pdf cleanups to `kill-buffer-hook` * basic.el (durand-kill-current-buffer): This function used to perform some clean-ups of the timers set by `pdf-view-mode` that were not cleaned properly by the mode itself. Now this function does not perform these cleanups, as this is not the right place for that task. (kill-buffer-hook): This hook is designed to perform some clean-ups, so the pdf-timer-clean-ups are moved to this hook now. --- basic.el | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/basic.el b/basic.el index 31ed1c0..03a075e 100644 --- a/basic.el +++ b/basic.el @@ -257,11 +257,21 @@ If the optional ARG is non-nil, and if there are more than one window, then also delete the selected window." (interactive "P") (cond - ((window-minibuffer-p (selected-window)) ;; this is the same as calling `abort-recursive-edit'. - (throw 'exit t)) + ((window-minibuffer-p (selected-window)) (throw 'exit t)) + (t (kill-buffer (current-buffer)))) + (cond + ((and arg (not (one-window-p t))) + (delete-window (selected-window))))) + +(define-key global-map (vector ?\s-k) #'durand-kill-current-buffer) + +;;; Custom kill-buffer-hook + +(defun durand-kill-buffer-hook () + "Some cleanups that are run before killing buffers." + (cond ((derived-mode-p 'pdf-view-mode) - ;; We also want to kill the associated timer, if any. (mapc (lambda (timer) (cond @@ -279,14 +289,9 @@ window, then also delete the selected window." (listp (timer--args timer)) (memq (current-buffer) (timer--args timer))) (setq timer-list (delq timer timer-list))))) - timer-list) - (kill-buffer (current-buffer))) - (t (kill-buffer (current-buffer)))) - (cond - ((and arg (not (one-window-p t))) - (delete-window (selected-window))))) + timer-list)))) -(define-key global-map (vector ?\s-k) #'durand-kill-current-buffer) +(add-hook 'kill-buffer-hook #'durand-kill-buffer-hook) ;;; zap-up-to-char and zap-to-char are both useful. -- cgit v1.2.3-18-g5258