mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
Add & use add-transient-hook! macro
This commit is contained in:
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user