What happened?
{{{Explain what went wrong.}}}
I was using add-transient-hook!
in a function, which I invoked multiple times, and in the end only 1 function was added to the hook.
What did you expect to happen?
I was expecting all the functions to be added to the hook variable.
Steps to reproduce
- Declare a function and a hook, i.e.
(defvar foo-hook nil "My hook.")
(defun foo()
(add-transient-hook! 'foo-mode (message "foo")))
- Invoke
foo
once. Now, the value offoo-hook
isdoom-transient-hook<number>
- Invoke
foo
again. Now, the value offoo-hook
is the same. The second function is not added.
When redefining the function (eval-last-sexp
) and invoking it, the same process is repeated – only 1 function is added (2 in total) and the rest are not.
I suspect (but not sure) it has something to do with the fact that add-transient-hook!
calculates the transient function’s name at macro expansion time. From the macro definition:
;; add-transient-hook!
;; ...
(let ((append? (if (eq (car forms) :after) (pop forms)))
(fn (gensym "doom-transient-hook")))
`(let ((sym ,hook-or-function))
(defun ,fn (&rest _)
;; ...
System information
Loading data dump...