From b4e6022c82efb51d80c3d39f8a9b17900a735c5a Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 6 Jun 2018 15:04:58 +0200 Subject: [PATCH] Fix buffer/window/frame hooks not being triggered In certain edge cases, the buffer/window/frame switch would not make the new buffer/window/frame current, which is what the after switch hooks should reasonably expect, causing some shenanigans. For example, persp wouldn't register magit buffers because `doom-after-switch-buffer-hook` was run in the context of the previous buffer. --- core/core-ui.el | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/core-ui.el b/core/core-ui.el index a052e7dbf..ebec467b4 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -364,7 +364,8 @@ from the default." (funcall orig-fn frame norecord) (run-hooks 'doom-before-switch-frame-hook) (prog1 (funcall orig-fn frame norecord) - (run-hooks 'doom-after-switch-frame-hook)))) + (with-selected-frame frame + (run-hooks 'doom-after-switch-frame-hook))))) (defun doom*switch-window-hooks (orig-fn window &optional norecord) (if (or doom-inhibit-switch-window-hooks (eq window (selected-window)) @@ -375,17 +376,20 @@ from the default." (prog1 (let ((doom-inhibit-switch-window-hooks t)) (funcall orig-fn window norecord)) - (run-hooks 'doom-after-switch-window-hook)))) + (with-selected-window window + (run-hooks 'doom-after-switch-window-hook))))) (defun doom*switch-buffer-hooks (orig-fn buffer-or-name &rest args) (if (or doom-inhibit-switch-buffer-hooks (eq (window-normalize-buffer-to-switch-to buffer-or-name) (current-buffer))) (apply orig-fn buffer-or-name args) - (run-hooks 'doom-before-switch-buffer-hook) - (prog1 - (let ((doom-inhibit-switch-buffer-hooks t)) - (apply orig-fn buffer-or-name args)) - (run-hooks 'doom-after-switch-buffer-hook)))) + (let ((dest (window-normalize-buffer-to-switch-to buffer-or-name))) + (run-hooks 'doom-before-switch-buffer-hook) + (prog1 + (let ((doom-inhibit-switch-buffer-hooks t)) + (apply orig-fn dest args)) + (with-current-buffer dest + (run-hooks 'doom-after-switch-buffer-hook)))))) (defun doom|init-custom-hooks () (advice-add #'select-frame :around #'doom*switch-frame-hooks)