Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 force to pass value of a?

like image 379
Anycorn Avatar asked Feb 13 '11 05:02

Anycorn


1 Answers

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.

like image 113
Trey Jackson Avatar answered Sep 28 '22 01:09

Trey Jackson