help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Trouble using a lambda in the key-translation-map


From: Barry Margolin
Subject: Re: Trouble using a lambda in the key-translation-map
Date: Wed, 18 Jul 2012 23:45:09 -0400
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <mailman.5119.1342663755.855.help-gnu-emacs@gnu.org>,
 Barry OReilly <gundaetiapo@gmail.com> wrote:

> As the Elisp manual describes, one can bind a key to a function in the
> key-translation-map, and use that function to programmatically
> determine what to translate the key to.
>   http://www.gnu.org/software/emacs/manual/html_node/elisp/Translation-Keymaps
>   .html
> 
> I got this to work for functions defined with defun, but can't get it
> to work with a lambda.  In an 'emacs -q' session, I put this in the
> scratch buffer:
>   (defun my-translate-key (prompt) (interactive) (kbd "C-c"))
>   (define-key key-translation-map (kbd "C-e") (lambda (prompt)
> (interactive) (kbd "C-c"))) ; Doesn't work
>   (define-key key-translation-map (kbd "C-e") 'my-translate-key) ; Works
> 
> I evaluate the first and second sexp, and find C-e still goes to the
> end of the line.  When I next execute the third sexp, C-e now
> translates to C-c.  Why doesn't the second sexp enable the translation
> from C-e to C-c?

Look at the description of define-key -- the third argument has to be a 
SYMBOL for it to be treated as a function.  Lambda doesn't return a 
function, it returns a list.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


reply via email to

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