helpful
helpful copied to clipboard
helpful-key with prefix key
I read your recent blog post about key bindings and ran through the "guru test" with my username (C-n C-i C-c C-k
, etc). Then I ran through it with M-
instead of C-
. I got to M-o
and realized I didn't know the answer, so I hit C-h k M-o
. The minibuffer said something about setting a face, but otherwise nothing happened. I hit C-g
and got M-o C-g is undefined
.
Using which-key
, I discovered that M-o
is the prefix key for facemenu
(which doesn't seem very useful to me, and I will probably rebind it). But how would you find that out with helpful-key
(or describe-key
, which has the same issue)? The general problem is that it's hard to use these key lookup functions if a key is prefix key and you don't already know that. I don't know what the solution is.
Unrelated to that, helpful-callable
and describe-function
give different results for facemenu-menu
. helpful-callable
prints Wrong type argument: sequencep, t
and opens a blank buffer named *helpful nil: facemenu-menu*
, while describe-function
gives
facemenu-menu is a sparse keymap in ‘facemenu.el’.
Prefix command (definition is a keymap associating keystrokes with commands).
[back]
The problem seems to stem from some strange facemenu
behavior: it runs (defvar facemenu-menu nil)
, then sets it as a keymap and defines bindings, then runs (defalias 'facemenu-menu facemenu-menu)
. What does that mean? Does that even make sense? I don't know what the appropriate behavior here is.
Interesting!
Regarding prefixes, we could probably try a little bit harder and progressively shorten the input. Something like "M-o C-g is undefined, but M-o is a prefix key" would be helpful.
Note that you can find all commands starting with a prefix by M-o C-h
. This is built-in functionality, not provided by helpful. Maybe we should offer an equivalent.
Regarding the defalias
issue, we should clearly be robust if the function slot is not a callable function. This has puzzled me in the past, but the Emacs stack exchange had the answer: https://emacs.stackexchange.com/questions/28576/when-does-emacs-treat-keymaps-as-functions
That said, we shouldn't crash if a user does something silly like (fset my-symbol 123)
, but tell the user what's going on. In most cases, it's a prefix key, so we could explain what's happening there.
I've opened justbur/emacs-which-key#235 regarding using which-key itself as a means of describe-key
/helpful-key
discovery, for what it's worth.