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:
parent
4dbf8f206b
commit
962f6a1032
1 changed files with 16 additions and 10 deletions
|
@ -97,23 +97,29 @@ behavior). Do not set this directly, this is let-bound in `doom|init-theme'.")
|
||||||
(run-hooks 'doom-switch-frame-hook)
|
(run-hooks 'doom-switch-frame-hook)
|
||||||
(setq doom--last-frame (selected-frame)))))
|
(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 (or doom-inhibit-switch-buffer-hooks
|
||||||
(if (eq orig-fn 'switch-to-buffer)
|
(eq (setq buffer-or-name (get-buffer buffer-or-name))
|
||||||
(car args) ; norecord
|
(current-buffer))
|
||||||
(eq (car args) (current-buffer)))) ; buffer-or-name
|
(and (eq orig-fn 'switch-to-buffer) (car args)))
|
||||||
(apply orig-fn args)
|
(apply orig-fn buffer-or-name args)
|
||||||
(let ((doom-inhibit-switch-buffer-hooks t))
|
(let ((doom-inhibit-switch-buffer-hooks t))
|
||||||
(prog1 (apply orig-fn args)
|
(when-let* ((buffer (apply orig-fn buffer-or-name args)))
|
||||||
(run-hooks 'doom-switch-buffer-hook)))))
|
(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)
|
(defun doom*run-switch-to-next-prev-buffer-hooks (orig-fn &rest args)
|
||||||
(if doom-inhibit-switch-buffer-hooks
|
(if doom-inhibit-switch-buffer-hooks
|
||||||
(apply orig-fn args)
|
(apply orig-fn args)
|
||||||
(let ((doom-inhibit-switch-buffer-hooks t))
|
(let ((doom-inhibit-switch-buffer-hooks t))
|
||||||
(when-let* ((result (apply orig-fn args)))
|
(when-let* ((buffer (apply orig-fn args)))
|
||||||
(run-hooks 'doom-switch-buffer-hook)
|
(with-current-buffer buffer
|
||||||
result))))
|
(run-hooks 'doom-switch-buffer-hook))
|
||||||
|
buffer))))
|
||||||
|
|
||||||
(defun doom*run-load-theme-hooks (theme &optional _no-confirm no-enable)
|
(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."
|
"Set up `doom-load-theme-hook' to run after `load-theme' is called."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue