Here is what I would like to do. I would like to customize key bindings that point to a different command depending on the file type on which the user is operating.
For instance, if one presses f5 in a Python file .py, I would like f5 to call the equivalent of C-c C-c:
(define-key key-translation-map [f5] (kbd "C-c C-c"))
But if one presses f5 in a R file .R, I would like f5 to call the equivalent of C-c C-b:
(define-key key-translation-map [f5] (kbd "C-c C-b"))
In the user-config function defined in .spacemacs, I tried doing the following:
(with-eval-after-load 'python
(define-key key-translation-map [f5] (kbd "C-c C-c"))
)
(with-eval-after-load 'ess
(define-key key-translation-map [f5] (kbd "C-c C-b"))
)
But it does not work properly. The last binding is the one that sticks, then f5becomes bounded to C-c C-b despite the file type.
I also tried putting each key binding above in the individual config.el files that exist in the .emacs.d/layers/+lang/python and .emacs.d/layers/+lang/ess folders. In this case, the opposite happens: only the binding associated to the first file type of the first file loaded is the one that sticks. The keybinding does not change according to in which file the user is.
So, what would be the appropriate way to implement what I want?