From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: Trouble using a lambda in the key-translation-map
Date: Wed, 18 Jul 2012 23:45:09 -0400 [thread overview]
Message-ID: <barmar-507C27.23450918072012@news.eternal-september.org> (raw)
In-Reply-To: mailman.5119.1342663755.855.help-gnu-emacs@gnu.org
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 ***
next parent reply other threads:[~2012-07-19 3:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.5119.1342663755.855.help-gnu-emacs@gnu.org>
2012-07-19 3:45 ` Barry Margolin [this message]
2012-07-19 19:26 Trouble using a lambda in the key-translation-map Barry OReilly
-- strict thread matches above, loose matches on Subject: below --
2012-07-18 22:45 Barry OReilly
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=barmar-507C27.23450918072012@news.eternal-september.org \
--to=barmar@alum.mit.edu \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.