Fix switch-buffer hooks running from wrong buffer

The destination buffer should be current while the switch-buffer hooks
run.
This commit is contained in:
Henrik Lissner 2019-05-15 15:14:37 -04:00
parent 4dbf8f206b
commit 962f6a1032
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -97,23 +97,29 @@ behavior). Do not set this directly, this is let-bound in `doom|init-theme'.")
(run-hooks 'doom-switch-frame-hook)
(setq doom--last-frame (selected-frame)))))
(defun doom*run-switch-buffer-hooks (orig-fn &rest args)
(defun doom*run-switch-buffer-hooks (orig-fn buffer-or-name &rest args)
(if (or doom-inhibit-switch-buffer-hooks
(if (eq orig-fn 'switch-to-buffer)
(car args) ; norecord
(eq (car args) (current-buffer)))) ; buffer-or-name
(apply orig-fn args)
(eq (setq buffer-or-name (get-buffer buffer-or-name))
(current-buffer))
(and (eq orig-fn 'switch-to-buffer) (car args)))
(apply orig-fn buffer-or-name args)
(let ((doom-inhibit-switch-buffer-hooks t))
(prog1 (apply orig-fn args)
(run-hooks 'doom-switch-buffer-hook)))))
(when-let* ((buffer (apply orig-fn buffer-or-name args)))
(with-current-buffer
(if (windowp buffer)
(window-buffer buffer)
buffer)
(run-hooks 'doom-switch-buffer-hook))
buffer))))
(defun doom*run-switch-to-next-prev-buffer-hooks (orig-fn &rest args)
(if doom-inhibit-switch-buffer-hooks
(apply orig-fn args)
(let ((doom-inhibit-switch-buffer-hooks t))
(when-let* ((result (apply orig-fn args)))
(run-hooks 'doom-switch-buffer-hook)
result))))
(when-let* ((buffer (apply orig-fn args)))
(with-current-buffer buffer
(run-hooks 'doom-switch-buffer-hook))
buffer))))
(defun doom*run-load-theme-hooks (theme &optional _no-confirm no-enable)
"Set up `doom-load-theme-hook' to run after `load-theme' is called."