core-lib: add-transient-hook! add support for appending hooks/advice

This commit is contained in:
Henrik Lissner 2017-05-12 11:48:37 +02:00
parent 3ee1108c4a
commit eb064887a5

View file

@ -99,14 +99,15 @@ compilation."
advised instead). These forms will be evaluated only once when that advised instead). These forms will be evaluated only once when that
function/hook is first invoked, then it detaches itself." function/hook is first invoked, then it detaches itself."
(declare (indent 1)) (declare (indent 1))
(let ((fn (intern (format "doom--transient-hook-%s" hook)))) (let ((fn (intern (format "doom--transient-hook-%s" hook)))
(append (eq (car forms) :after)))
`(progn `(progn
(defun ,fn (&rest _) (defun ,fn (&rest _)
,@forms ,@forms
,(cond ((functionp hook) `(advice-remove #',hook #',fn)) ,(cond ((functionp hook) `(advice-remove #',hook #',fn))
((symbolp hook) `(remove-hook ',hook #',fn)))) ((symbolp hook) `(remove-hook ',hook #',fn))))
,(cond ((functionp hook) `(advice-add #',hook :before #',fn)) ,(cond ((functionp hook) `(advice-add #',hook ,(if append :after :before) #',fn))
((symbolp hook) `(add-hook ',hook #',fn)))))) ((symbolp hook) `(add-hook ',hook #',fn ,append))))))
(defmacro add-hook! (&rest args) (defmacro add-hook! (&rest args)
"A convenience macro for `add-hook'. Takes, in order: "A convenience macro for `add-hook'. Takes, in order: