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).
This commit is contained in:
Henrik Lissner 2024-04-09 12:42:00 -04:00
parent 96e3255c33
commit ff4a0bc54a
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -246,29 +246,29 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions."
(fset (fset
fn (lambda (&rest _) fn (lambda (&rest _)
;; Only trigger this after Emacs has initialized. ;; Only trigger this after Emacs has initialized.
(when (and after-init-time (when (and (not running?)
(not running?) (not (doom-context-p 'init))
(or (daemonp) (or (daemonp)
;; In some cases, hooks may be lexically unset to ;; In some cases, hooks may be lexically unset to
;; inhibit them during expensive batch operations on ;; inhibit them during expensive batch operations on
;; buffers (such as when processing buffers ;; buffers (such as when processing buffers
;; internally). In these cases we should assume this ;; internally). In that case assume this hook was
;; hook wasn't invoked interactively. ;; invoked non-interactively.
(and (boundp hook) (and (boundp hook)
(symbol-value hook)))) (symbol-value hook))))
(setq running? t) ; prevent infinite recursion (setq running? t) ; prevent infinite recursion
(doom-run-hooks hook-var) (doom-run-hooks hook-var)
(set hook-var nil)))) (set hook-var nil))))
(cond ((daemonp) (when (daemonp)
;; In a daemon session we don't need all these lazy loading ;; In a daemon session we don't need all these lazy loading shenanigans.
;; shenanigans. Just load everything immediately. ;; Just load everything immediately.
(add-hook 'after-init-hook fn 'append)) (add-hook 'server-after-make-frame-hook fn 'append))
((eq hook 'find-file-hook) (if (eq hook 'find-file-hook)
;; Advise `after-find-file' instead of using `find-file-hook' ;; Advise `after-find-file' instead of using `find-file-hook' because
;; because the latter is triggered too late (after the file has ;; the latter is triggered too late (after the file has opened and
;; opened and modes are all set up). ;; modes are all set up).
(advice-add 'after-find-file :before fn '((depth . -101)))) (advice-add 'after-find-file :before fn '((depth . -101)))
((add-hook hook fn -101))) (add-hook hook fn -101))
fn))) fn)))
(defun doom-compile-functions (&rest fns) (defun doom-compile-functions (&rest fns)