Minor refactors & reformatting

This commit is contained in:
Henrik Lissner 2020-12-01 13:51:48 -05:00
parent c517be8e69
commit affd076d53
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
5 changed files with 40 additions and 47 deletions

View file

@ -125,6 +125,25 @@ unreadable. Returns the names of envvars that were changed."
(default-value 'shell-file-name)))
env)))
(defun doom-run-hook-on (hook-var triggers)
"Configure HOOK-VAR to be invoked exactly once after init whenever any of the
TRIGGERS are invoked. Once HOOK-VAR gets triggered, it resets to nil.
HOOK-VAR is a quoted hook.
TRIGGERS is a list of quoted hooks and/or sharp-quoted functions."
(let ((fn (intern (format "%s-h" hook-var))))
(fset
fn (lambda (&rest _)
(when after-init-time
(run-hook-wrapped hook-var #'doom-try-run-hook)
(set hook-var nil))))
(put hook-var 'permanent-local t)
(dolist (on triggers)
(if (functionp on)
(advice-add on :before fn)
(add-hook on fn)))))
;;
;;; Functional library
@ -487,25 +506,6 @@ advised)."
(put ',fn 'permanent-local-hook t)
(add-hook sym #',fn ,append))))))
(defmacro add-hook-trigger! (hook-var &rest targets)
"Configure HOOK-VAR to be invoked exactly once after init whenever any of the
TARGETS are invoked. Once HOOK-VAR gets triggered, it resets to nil.
HOOK-VAR is a quoted hook.
TARGETS is a list of quoted hooks and/or sharp-quoted functions."
`(let ((fn (intern (format "%s-h" ,hook-var))))
(fset
fn (lambda (&rest _)
(when after-init-time
(run-hook-wrapped ,hook-var #'doom-try-run-hook)
(set ,hook-var nil))))
(put ,hook-var 'permanent-local t)
(dolist (on (list ,@targets))
(if (functionp on)
(advice-add on :before fn)
(add-hook on fn)))))
(defmacro add-hook! (hooks &rest rest)
"A convenience macro for adding N functions to M hooks.