fix: run switch-buffer hooks on server-visit-hook

window-buffer-change-function does not trigger on the first buffer
displayed in a new client frame.

Fix: #6058
This commit is contained in:
Henrik Lissner 2022-01-29 19:40:20 +01:00
parent 9dbdb854b9
commit 4a6de2419c

View file

@ -590,22 +590,21 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
;;; Bootstrap ;;; Bootstrap
(defun doom-init-ui-h (&optional _) (defun doom-init-ui-h (&optional _)
"Initialize Doom's user interface by applying all its advice and hooks." "Initialize Doom's user interface by applying all its advice and hooks.
These should be done as late as possible, as to avoid/minimize prematurely
triggering hooks during startup."
(doom-run-hooks 'doom-init-ui-hook) (doom-run-hooks 'doom-init-ui-hook)
(add-hook 'kill-buffer-query-functions #'doom-protect-fallback-buffer-h) (add-hook 'kill-buffer-query-functions #'doom-protect-fallback-buffer-h)
(add-hook 'after-change-major-mode-hook #'doom-highlight-non-default-indentation-h 'append) (add-hook 'after-change-major-mode-hook #'doom-highlight-non-default-indentation-h 'append)
;; Initialize custom switch-{buffer,window,frame} hooks: ;; Initialize `doom-switch-window-hook' and `doom-switch-frame-hook'
;;
;; - `doom-switch-buffer-hook'
;; - `doom-switch-window-hook'
;; - `doom-switch-frame-hook'
;;
;; These should be done as late as possible, as not to prematurely trigger
;; hooks during startup.
(add-hook 'window-buffer-change-functions #'doom-run-switch-buffer-hooks-h)
(add-hook 'window-selection-change-functions #'doom-run-switch-window-or-frame-hooks-h) (add-hook 'window-selection-change-functions #'doom-run-switch-window-or-frame-hooks-h)
;; Initialize `doom-switch-buffer-hook'
(add-hook 'window-buffer-change-functions #'doom-run-switch-buffer-hooks-h)
;; `window-buffer-change-functions' doesn't trigger for files visited via the server.
(add-hook 'server-visit-hook #'doom-run-switch-buffer-hooks-h)
;; Only execute this function once. ;; Only execute this function once.
(remove-hook 'window-buffer-change-functions #'doom-init-ui-h)) (remove-hook 'window-buffer-change-functions #'doom-init-ui-h))