Reputation: 51465
I am trying to generate functions using a macro:
(defmacro make-my-emacs-command-region (cmd name)
(list 'defun (intern (format "my-emacs-command-%s-%s" cmd name))
'(&optional arg)
(list 'interactive "p")
(list (intern (format "mark-%s" name)) 'arg)
(list (intern (format "my-emacs-command-%s-region" cmd))
'(region-beginning) '(region-end))))
generator:
(mapcar (lambda (a) (make-my-emacs-command-region a buffer))
'(foo bar))
But I get:
my-emacs-command-a-buffer
What am I doing wrong? How can I force to pass value of a
?
Upvotes: 5
Views: 876
Reputation: 74430
A major point of lisp macros is that the arguments are not evaluated. Read up on the macro pages in the manual, specifically the expansion of macros. The macroexpand
function would be of use in debugging the problem. Also, backquote might help you write the body of the macro a little more succinctly.
Upvotes: 7
Reputation: 42094
My elisp is a bit rusty, but until someone comes up with the actual explanation: I could get your examples to work a bit more as expected my replacing cmd
with (eval cmd)
(possibly same with name
) in the macro definition body.
Hope this helps.
Upvotes: 4