2

The following works:

(define-prefix-command 'my-map)
(global-set-key (kbd "C-@") 'my-map) ;; MacOS
(global-set-key (kbd "C-SPC") 'my-map) ;; Windows 10

The following does not:

(global-set-key [remap set-mark-command] 'my-map)

It fails with the error that my-map is not a command (commandp returns nil).

The emacs manual states that "putting a remapping in a prefix keymap like ctl-x-map typically has no effect, as such keymaps are not themselves active;" however, I am remapping a command in the active global map to a prefix map. So why does this fail?

0

Unfortunately, the use of [remap COMMMAND] syntax in a key-binding definition seems to require COMMAND to be a symbol that is a command (commandp). It doesn't seem to allow a prefix-key keymap or a prefix-key variable whose value is a keymap.

I just sent a mail to emacs-devel@gnu.org about this. Maybe I'm missing something (probably). But it seems like (1) the doc string of define-key says that it should work, but (2) it doesn't.


If you want, you can do almost the same thing this way:

(substitute-key-definition 'set-mark-command 'my-map global-map)

That's almost the same thing as what you tried:

(global-set-key [remap set-mark-command] 'my-map)

It does, in effect, what you ended up doing manually by binding each key individually.

The difference from remapping is that, well the command set-mark-command is not remapped. Instead, you've just rebound each of its global keys to keymap (prefix command) my-map.

  • At least I'm not alone in being confused by this. I ended up settling for the less-than-elegant workaround of binding both C-SPC and C-@ to the map. – LumpyGrads Sep 28 '19 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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