Lowell Kirsh <lkirsh@cs.ubc.ca> writes:
This still doesn't seem to work. With the following defun and call:
(defmacro my-add-hooks (hooks &rest body)
`(dolist (hook ',hooks)
(my-add-hook hook ,@body)))
(my-add-hooks (inferior-lisp lisp emacs-lisp lisp-interaction)
(imenu-add-to-menubar "Symbols"))
I get the following macroexpansion, which looks correct to me, but
doesn't actually do anything:
(cl-block-wrapper
(catch (quote --cl-block-nil--)
(let ((--dolist-temp--20870 (quote (inferior-lisp lisp emacs-lisp
lisp-interaction)))
hook)
(while --dolist-temp--20870
(setq hook (car --dolist-temp--20870))
(my-add-hook hook
(imenu-add-to-menubar "Symbols"))
(setq --dolist-temp--20870 (cdr --dolist-temp--20870)))
nil)))
That's because my-add-hook is a macro, too, and so you just add stuff
to hook-mode-hook three times.
Apart from that, I consider this sort of thing a crock. What are
you hoping to achieve that you would not be better off doing by a
proper function instead of a macro?
In short, I still consider this sort of thing a crock, since you'd be
better off using a function instead of a macro. You are unable to
comprehend what your macros do, and it shows. Macros are just not
sensible for this sort of thing. Use functions instead. You'll need
to use some quotes at the outer level, but you'll understand what
happens.
To fix the above, you'd need to write something like
(defmacro my-add-hooks (hooks &rest body)
(dolist (hook hooks)
`(my-add-hook ,hook ,@body)))