5

I have a tree of deeply nested keymaps, with many possible leaves (commands), too many for a human to remember. For simplicity, let's say each command is associated with a given file name.

I would like to display a help tool-tip as the user is walking down these keymaps, indicating which files/commands are bound to which keys.

So, I would like to associate with certain keymaps a short documentation, and display it whenever the user is "on" the keymap (perhaps using help-fns+.el or some other custom docstring).

What is the best way of doing this?

1
  • What do you mean by "as the user is walking down these keymaps"? What do you mean here by "walk down"? Likewise, what do you mean by a user being "on" a keymap? Can you describe what the user is doing in such a situation?
    – Drew
    Feb 28, 2016 at 15:58

3 Answers 3

6

This sounds like exactly what the which-key package does. When you type a prefix key, after a short pause, a list of keys in the keymap and the commands they are bound to is shown in a side window. It's great for things you don't quit do often enough to have memorized.

Install it with package-install which-key and activate it with (which-key-mode).

2
  • This almost does what I want except for a few problems: 1. since my functions are unnamed, I get an unhelpful "key ==> lambda" for all keys. 2. the minibuffer area is too small to display all bindings, I would need a temporary buffer, and 3. I would like 0 delay before showing map. But I can surely look at the source and fix these for my case. Thanks
    – erjoalgo
    Feb 28, 2016 at 18:13
  • You can change the delay by setting which-key-idle-delay to 0.0. You can change where the popup is shown. I use which-key-setup-side-window-right to make it a temp buffer on the right side.
    – erikstokes
    Feb 29, 2016 at 0:52
2

There is an underused built-in functionality with a similar aim.

You can see it in action by doing: M-x smerg-mode RET and then C-c ^ = which should immediately show you the possible options in that prefix keymap, along the lines of

Diff: = = mine-other, > = base-other, < = base-mine

Being underused it's also rather primitive (the confusion between the = key and the = sign is rather annoying in the above example). To get this, the main part of the code was (transliterated from the use of easy-mmode-defmap):

(define-key map [?=] (make-sparse-keymap "Diff")
(define-key map [?= ?<] '("base-mine" . smerge-diff-base-mine))
(define-key map [?= ?>] '("base-other" . smerge-diff-base-other))
(define-key map [?= ?=] '("mine-other" . smerge-diff-mine-other))
5
  • Your answer has nothing to do with original question.
    – avp
    Apr 28, 2016 at 14:49
  • @avp: maybe I misunderstood his question, but I think it's definitely an answer to the original question.
    – Stefan
    Apr 28, 2016 at 15:18
  • Ah crap, you are right. I had to reread both the question and your answer to find that you've meant not the smerg-mode itself, but the hint after the C-c^=. Sorry, I could not figure it out after not only reading the answer but actually trying it as well. And still, in org-mode I cannot use it.
    – avp
    Apr 28, 2016 at 21:27
  • If you want to use this facility and are having trouble with it, I can help you. The above answer is just showing how smerge uses it.
    – Stefan
    Apr 30, 2016 at 12:47
  • How can I apply C-c ^ = : is it C-c and shift-6 than = sign?
    – alper
    Mar 8, 2022 at 17:01
1
  1. Not sure I understand the question, but it sounds like Icicles key completion will help.

    When you have hit a prefix key (e.g. C-x or C-x 4), if you hit S-TAB (by default) all of the bindings on that prefix key are displayed in buffer *Completions* along with the commands they are bound to. You can explore them (showing complete descriptions on demand or short descriptions just by cycling among them) -- and hit C-g if you don't want to invoke any of them. Or you can complete any of them and invoke it.

    This works also for prefix keys that are on prefix keys, such as C-x 4, which is in C-x. If you hit C-x S-TAB then one of the candidates you see in *Completions* is 4 = .... The ... here means that 4 is itself a prefix key. If you choose that candidate then *Completions* is changed to show you the keys (and commands) bound on C-x 4.

    You can also navigate upward in the keymap hierarchy. The first candidate in *Completions* for a prefix keymap is ... Choosing that candidate moves you back up to the parent keymap.

  2. There is another library, guide-key, which some of what Icicles key completion does, if you are not interested in using Icicles in general.

  3. Without Icicles or guide-key, you can at least use C-h with vanilla Emacs to get a listing (in *Help*) of the keys bound on a prefix key. For example, C-x C-h shows you the keys bound on prefix key C-x.

1
  • Although havibg very promising documentation, the feature itself works very counter-intuitive. Therefore I vote for which-key.
    – avp
    Apr 28, 2016 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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