Subject: bug#12022: [PATCH] Unable to use anonymous functions for Key Translations,

From: Barry OReilly <[email-masked]>
Date: Sat, 11 Aug 2012 22:45:47 -0400

> Using an anonymous function to translate keys as described in the Elisp
manual at
http://www.gnu.org/software/emacs/manual/html_node/elisp/Translation-Keymaps.htmldoes
not work as expected.
>
> Using a named function to map C-e to C-c, the Key Translation is
successful:
>   (progn (fset 'foo (lambda (prompt) (kbd "C-c")))
>          (define-key key-translation-map (kbd "C-e") 'foo))
>
> Using an anonymous function for another keymap binds C-e to the
lambda-defined command.
>   (define-key global-map
>               (kbd "C-e")
>               (lambda () (interactive) (message "Inside C-e's lambda")))
>
> But using an anonymous function for key-translation-map does not change
behavior of inputting C-e:
>   (define-key key-translation-map
>               (kbd "C-e")
>               (lambda (prompt) (kbd "C-c")))
>
> I find no reason why the last Elisp shouldn't define a Key Translation.
The Elisp manual section on Anonymous Functions states "Anonymous functions
are valid wherever function names are."  (
http://www.gnu.org/software/emacs/manual/html_node/elisp/Anonymous-Functions.html)

Hi,
I found where the definition of a key translation is called, and made a
patch.  The quoted test case works correctly now.  Is the change ok?
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email-masked]
# target_branch: bzr://bzr.savannah.gnu.org/emacs/trunk/
# testament_sha1: 97ac7d396cfcbf692e8e88df42589ecba0fc8c70
# timestamp: 2012-08-11 22:24:03 -0400
# base_revision_id: [email-masked]
# 
# Begin patch
=== modified file 'src/keyboard.c'
--- src/keyboard.c	2012-08-08 15:53:52 +0000
+++ src/keyboard.c	2012-08-12 02:23:58 +0000
@@ -8837,7 +8837,8 @@
   /* If the keymap gives a function, not an
      array, then call the function with one arg and use
      its value instead.  */
-  if (SYMBOLP (next) && !NILP (Ffboundp (next)) && do_funcall)
+  if ((SYMBOLP (next) && !NILP (Ffboundp (next)) || FUNCTIONP(next))
+      && do_funcall)
     {
       Lisp_Object tem;
       tem = next;

# Begin bundle