Add & use add-transient-hook! macro

This commit is contained in:
Henrik Lissner 2017-03-02 01:43:00 -05:00
parent 10b4d94627
commit 2d190fe0c5
3 changed files with 15 additions and 7 deletions

View file

@ -65,6 +65,19 @@ compilation."
(save-silently t))
,@forms)))
(defmacro add-transient-hook! (hook &rest forms)
"Attaches transient forms to a hook (can also be a function, which will be
advised instead). These forms will be evaluated only once when that
function/hook is first invoked, then it detaches itself."
(let ((fn (intern (format "doom--transient-hook-%s" hook))))
`(progn
(defun ,fn (&rest _)
,@forms
,(cond ((functionp hook) `(advice-remove ',hook ',fn))
((symbolp hook) `(remove-hook ',hook ',fn))))
,(cond ((functionp hook) `(advice-add ',hook :before ',fn))
((symbolp hook) `(add-hook ',hook ',fn))))))
(defmacro add-hook! (&rest args)
"A convenience macro for `add-hook'. Takes, in order: