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?

brab
  • 925
  • 1
  • 7
  • 8
  • 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 Jun 07 '15 at 15:08

1 Answers1

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"))
  • 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 Jun 08 '15 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. – Gilles 'SO- stop being evil' Jun 08 '15 at 11:46