[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs lisp - unable to write a function maker

From: Tim Landscheidt
Subject: Re: emacs lisp - unable to write a function maker
Date: Fri, 23 Sep 2011 15:31:21 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

"Drew Adams" <> wrote:

> [...]
> Well, not quite - the OP quoted the function symbol, indicating that s?he 
> would
> pass something that needs to be eval'd. If that's rally part of the 
> requirement,
> then:

> (defmacro makeAbrevFun (name val)
>  `(defun ,(eval name) () (insert ,val)))

> (makeAbrevFun 'aa "aaaaaaaaaaaaaa")

> In both cases: (symbol-function 'aa) gives:
> (lambda () (insert "aaaaaaaaaaaaaa"))

On a related note - how do I proceed if I do not want to
create a macro that creates a function, but create multiple
functions directly? For example, after some trial and error
my ~/.emacs ended up with (paraphrased):

| (dolist (i '(("once"   . 1)
|              ("twice"  . 2)
|              ("thrice" . 3)))
|   (fset (intern (concat "tl-say-" (downcase (car i))))
|         `(lambda (s)
|            ,(concat "Say S only " (car i) ".")
|            (interactive "sWhat to message: ")
|            (dotimes (j ,(cdr i))
|              (message "I say it only %s: %s." ,(car i) s)))))

I didn't manage to use defun as I got stuck in quoting and
non-quoting "magic".


reply via email to

[Prev in Thread] Current Thread [Next in Thread]