Comments on 2021-08-16 Remapping commands

Last edit

Summary: Well, you're right – but still, they solve a very similar problem. At least I couldn't think about a real-life situation when only one of them would . . .

Added:

> ----
> Well, you're right – but still, they solve a very similar problem. At least I couldn't think about a real-life situation when only one of them would be suitable. Still, it's well possible such a situation may exist.
> -- mbork 2021-08-23 04:21 UTC


Probably they both exist because they do slightly different things. As far as I understand it,

(substitute-key-definition
‘do-something
‘cool-do-something
cool-mode-map
global-map)

will create bindings for any already-existing bindings at the time it’s called. But if you later bind a new key to do-something in global-map, that binding won’t get substituted by cool-do-something. Also, you need to create a new cool-mode-map keymap and ensure it is active and takes precedence over global-map for this to have any effect.

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

will cause any key bound to some-commend in keymap to instead invoke another-command, even if that key binding was created after the call the define-key. Also, the command remappings can be created in the same keymap as the original bindings, so they are always active whenever keymap is active. (Though you can also create them in a separate keymap.)

Toby Cubitt 2021-08-16 22:18 UTC


Well, you’re right – but still, they solve a very similar problem. At least I couldn’t think about a real-life situation when only one of them would be suitable. Still, it’s well possible such a situation may exist.

– mbork 2021-08-23 04:21 UTC