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.
This commit is contained in:
Henrik Lissner 2018-06-06 15:04:58 +02:00
parent 85a0c9efc9
commit b4e6022c82
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -364,7 +364,8 @@ from the default."
(funcall orig-fn frame norecord) (funcall orig-fn frame norecord)
(run-hooks 'doom-before-switch-frame-hook) (run-hooks 'doom-before-switch-frame-hook)
(prog1 (funcall orig-fn frame norecord) (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) (defun doom*switch-window-hooks (orig-fn window &optional norecord)
(if (or doom-inhibit-switch-window-hooks (if (or doom-inhibit-switch-window-hooks
(eq window (selected-window)) (eq window (selected-window))
@ -375,17 +376,20 @@ from the default."
(prog1 (prog1
(let ((doom-inhibit-switch-window-hooks t)) (let ((doom-inhibit-switch-window-hooks t))
(funcall orig-fn window norecord)) (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) (defun doom*switch-buffer-hooks (orig-fn buffer-or-name &rest args)
(if (or doom-inhibit-switch-buffer-hooks (if (or doom-inhibit-switch-buffer-hooks
(eq (window-normalize-buffer-to-switch-to buffer-or-name) (eq (window-normalize-buffer-to-switch-to buffer-or-name)
(current-buffer))) (current-buffer)))
(apply orig-fn buffer-or-name args) (apply orig-fn buffer-or-name args)
(run-hooks 'doom-before-switch-buffer-hook) (let ((dest (window-normalize-buffer-to-switch-to buffer-or-name)))
(prog1 (run-hooks 'doom-before-switch-buffer-hook)
(let ((doom-inhibit-switch-buffer-hooks t)) (prog1
(apply orig-fn buffer-or-name args)) (let ((doom-inhibit-switch-buffer-hooks t))
(run-hooks 'doom-after-switch-buffer-hook)))) (apply orig-fn dest args))
(with-current-buffer dest
(run-hooks 'doom-after-switch-buffer-hook))))))
(defun doom|init-custom-hooks () (defun doom|init-custom-hooks ()
(advice-add #'select-frame :around #'doom*switch-frame-hooks) (advice-add #'select-frame :around #'doom*switch-frame-hooks)