From ee03e838479a616adb77c996240972fcd6961c25 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 9 Apr 2024 12:42:00 -0400 Subject: [PATCH] fix: doom-run-hook-on: check context & chain hooks unconditionally Consult the doom-context to determine if a transient hook should fire, rather than after-init-time (less reliable; there may be times we want them to fire post-init). Also ensures that they're chained to find-file hooks whether or not this is a daemon session (since they could concievably be triggered before the daemon finishes initializing, but after Doom initializes). --- lisp/doom-lib.el | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index fd6f34967..8f87b885b 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -246,29 +246,29 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions." (fset fn (lambda (&rest _) ;; Only trigger this after Emacs has initialized. - (when (and after-init-time - (not running?) + (when (and (not running?) + (not (doom-context-p 'init)) (or (daemonp) ;; In some cases, hooks may be lexically unset to ;; inhibit them during expensive batch operations on ;; buffers (such as when processing buffers - ;; internally). In these cases we should assume this - ;; hook wasn't invoked interactively. + ;; internally). In that case assume this hook was + ;; invoked non-interactively. (and (boundp hook) (symbol-value hook)))) (setq running? t) ; prevent infinite recursion (doom-run-hooks hook-var) (set hook-var nil)))) - (cond ((daemonp) - ;; In a daemon session we don't need all these lazy loading - ;; shenanigans. Just load everything immediately. - (add-hook 'after-init-hook fn 'append)) - ((eq hook 'find-file-hook) - ;; Advise `after-find-file' instead of using `find-file-hook' - ;; because the latter is triggered too late (after the file has - ;; opened and modes are all set up). - (advice-add 'after-find-file :before fn '((depth . -101)))) - ((add-hook hook fn -101))) + (when (daemonp) + ;; In a daemon session we don't need all these lazy loading shenanigans. + ;; Just load everything immediately. + (add-hook 'server-after-make-frame-hook fn 'append)) + (if (eq hook 'find-file-hook) + ;; Advise `after-find-file' instead of using `find-file-hook' because + ;; the latter is triggered too late (after the file has opened and + ;; modes are all set up). + (advice-add 'after-find-file :before fn '((depth . -101))) + (add-hook hook fn -101)) fn))) (defun doom-compile-functions (&rest fns)