Elisp mapcar + lambda + defmacro help

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 make it pass a value a?

+5
source share
2 answers

My elisp is a little rusty, but until someone comes up with an actual explanation: I could make your examples work a little more, as expected, replacing cmdwith (eval cmd)(possibly with name) the body of the macro definition.

Hope this helps.

+4
source

lisp , . , . macroexpand . , backquote .

+7

All Articles