Add & use add-transient-hook! macro
This commit is contained in:
parent
10b4d94627
commit
2d190fe0c5
3 changed files with 15 additions and 7 deletions
|
@ -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:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue