8

The key combination C-c is not convenient to type in the keyboard layout I use, and I'm trying to do change it globally. The goal is to replace every occurrence of C-c with another binding <apps> d, such that sending a message in Gnus would be <apps> d <apps> d, compiling in auxtex would be the same, and the user prefix key C-c would also always be <apps> d. The key <apps> is <f19> on my keyboard.

Reading the manual, it seems that I need to use key-translation map. It does work great with the translation of <f19> to <apps>

(define-key key-translation-map (kbd "<f19>") (kbd "<apps>"))
(global-set-key (kbd "<apps> s") 'save-buffer)

Unfortunately, it does not work when I want to do this for C-c.

(define-key key-translation-map (kbd "<apps> d") (kbd "C-c"))

When I try to use it, I get

<apps> d is undefined

and if I look it up (C-h k), I see

<apps> d (translated from <f19> d) is undefined

Is there a way to make this work?

1
  • A guess, a similar map (input-decode-map) has this in its documentation: "The events that come from bindings in `input-decode-map' are not themselves looked up in `input-decode-map'." Which makes sense, if you think about it: this would be a way to prevent infinite translations.
    – wvxvw
    Commented Jun 7, 2015 at 15:08

1 Answer 1

3

The problem in your attempt is that apps comes from a translation via key-translation-map, and this output is not searched in key-translation-map recursively. If you omit apps altogether and work with f19 directly, it works.

(global-set-key (kbd "<f19> s") 'save-buffer)
(define-key key-translation-map (kbd "<f19> d") (kbd "C-c"))

If you want to use the apps alias, you can make use of the fact that there are two similar translation maps: input-decode-map and key-translation-map. Use input-decode-map to declare virtual function keys corresponding to key sequences send by your keyboard, e.g. the translation from f19 to apps. Use key-translation-map to make an internal translation in Emacs, e.g. from apps d to C-c.

(define-key input-decode-map (kbd "<f19>") (kbd "<apps>"))
(global-set-key (kbd "<apps> s") 'save-buffer)
(define-key key-translation-map (kbd "<apps> d") (kbd "C-c"))
2
  • Thank you, this works great. I tried using local-function-key-map and it also works. Is there a reason for using one over the other?
    – brab
    Commented Jun 8, 2015 at 11:38
  • The difference with local-function-key-map is that local-function-key-map can be overridden with a global or local binding for apps d. Which come to think of it might be a feature rather than a bug. Commented Jun 8, 2015 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.