From 2395228ff8f9c0198a58eee30ebed3fc668d0876 Mon Sep 17 00:00:00 2001 From: Tim Ruffing Date: Wed, 3 Sep 2025 12:12:40 +0200 Subject: [PATCH] fix: Run hooks only after switch-to-buffer for server When a file is visited via `emacsclient`, server.el does the following in this order: - create a buffer `b` visiting the file - run `(set-buffer b)` - trigger `server-visit-hook` - run `(switch-buffer b)` - trigger `server-switch-hook` Thus, the right hook for `doom-run-switch-buffer-hooks-h` is `server-switch-hook` because the "switch buffer" hooks may assume that the buffer has already been switched to. This fixes an org error that occurs when running emacsclient --create-file --no-wait foo.txt while there's a frame containing an org-roam file. Without this commit, the server will create a new frame and set the current buffer to foo.txt. But the new frame will still display the (duplicated) window for the org-roam file. Then `server-visit-hook` will be triggered and eventually run `+org-roam-manage-backlinks-buffer-h`, which will try to enable the org-roam backlinks buffer. But this will error because the current buffer is not an org(-roam) buffer. Amend: 4a6de2419c81 --- lisp/doom-ui.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/doom-ui.el b/lisp/doom-ui.el index dbdb5306a..d2138bbbd 100644 --- a/lisp/doom-ui.el +++ b/lisp/doom-ui.el @@ -737,7 +737,7 @@ triggering hooks during startup." (add-hook 'window-selection-change-functions #'doom-run-switch-window-hooks-h) (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)) + (add-hook 'server-switch-hook #'doom-run-switch-buffer-hooks-h)) ;; Apply fonts and theme (let ((hook (if (daemonp)