2021-08-16 Remapping commands

Several weeks ago I wrote about a nice feature of Emacs where you can bind some command to every key bound to another command in some (other) keymap. Since then, I found another feature solving the same (or at least a very similar) problem – command remapping. There’s not much to say about it – it does exactly what it says on the tin, i.e., you can define a special entry in a keymap that says “if the user presses a key invoking some-command, run another-command instead”:

(define-key keymap [remap some-command] 'another-command)

It is a bit primitive – for example, it only works on a single level (i.e., if you also remap another-command to yet-another-command, the key normally bound to some-command will still run another-command, not yet-another-command), but is a bit more “dynamic” than substitute-key-definition – even if some key is bound to some-command after the above invocation, it will still run another-command.

I am not entirely sure why both features exist in Emacs, but here they are.

CategoryEnglish, CategoryBlog, CategoryEmacs