helpful icon indicating copy to clipboard operation
helpful copied to clipboard

Add example of using `define-key` with `help-command`

Open skyvine opened this issue 4 years ago • 1 comments

Hello,

Would you consider adding this example to the README? I make heavy use of nested keymaps in my config, so the current example did not work well, and when I went to replace the default keys in help command's map it does not seem to follow the normal pattern I expect. Most of the time define-key calls look like:

(define-key Buffer-menu-mode-map " " saff-map)

But when replacing keys for help command, the first argument is supposed to be the symbol 'help-command instead of a keymap:

(define-key 'help-command "k" 'helpful-key)

This was confusing and frustrating at first and an example in the README would have made the integration process go a lot more smoothly.

Incidentally, it is not clear to me why passing in a symbol works here, when it needs to be a keymap value everywhere else. If you have any insight into this I would appreciate hearing why.

Thanks, Bryan

skyvine avatar Dec 30 '20 05:12 skyvine

It looks like the reason for this behavior is that the help-command variable stores the keymap in its function definition, and the keymap API will interpret the value properly no matter which slot it is stored in. This is the only place where I have seen a keymap used in this way. In addition to the Buffer-mode-map example above, magit-status-mode-map, project-prefix-map, and org-mode-map all store their keymap in the value slot. I think it's worth calling out the abnormal behavior here.

skyvine avatar Jan 02 '21 00:01 skyvine