Eagerly trigger doom-first-* hooks early in daemon sessions

No need to lazy load as much in daemon sessions.
This commit is contained in:
Henrik Lissner 2021-05-06 15:38:58 -04:00
parent b12a0c02b3
commit 280bae0331

View file

@ -542,21 +542,26 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions."
(fset (fset
fn (lambda (&rest _) fn (lambda (&rest _)
(when (and after-init-time (when (and after-init-time
;; In some cases, hooks may be lexically unset to inhibit (or (daemonp)
;; them during expensive batch operations on buffers ;; In some cases, hooks may be lexically unset to
;; (such as when processing buffers internally). In these ;; inhibit them during expensive batch operations on
;; cases we should assume this hook wasn't invoked ;; buffers (such as when processing buffers
;; interactively. ;; internally). In these cases we should assume this
(boundp hook) ;; hook wasn't invoked interactively.
(symbol-value hook)) (and (boundp hook)
(symbol-value hook))))
(doom-run-hooks hook-var) (doom-run-hooks hook-var)
(set hook-var nil)))) (set hook-var nil))))
;; DEPRECATED This target switcheroo won't be necessary when 26 support is (cond ((daemonp)
;; dropped; `add-hook''s DEPTH argument was added in 27.1. ;; In a daemon session we don't need all these lazy loading
(let ((target (if (eq hook 'find-file-hook) 'after-find-file hook))) ;; shenanigans. Just load everything immediately.
(if (functionp target) (add-hook 'after-init-hook fn 'append))
(advice-add target :before fn '((depth . -101))) ((eq hook 'find-file-hook)
(add-hook target fn (if EMACS27+ -101))))))) ;; Advise `after-find-file' instead of use `find-file-hook' because
;; the latter isn't triggered late enough.
(advice-add 'after-find-file :before fn '((depth . -101))))
((add-hook hook fn (if EMACS27+ -101))))
fn)))
;; ;;