Search code examples
emacselisp

How to show available key combinations and their descriptions, to learn about them


Searching for a better tool to learn key combination in Emacs

Though, I have used a package "guide-key" before, I like how "which-key" looks and feel. However, I encountered one problem. In contrast with "guide-key", it can also show the next key combination.

For example, type "C-x" then there is also "C-f" description.

Is there anyway we can configure "which-key" to do similar things?


Solution

  • You are searching for a better tool to show you what keys you can use to complete a key sequence that you have started (by using one or more prefix keys). You want to also have access to or immediately see additional info about those key completions, e.g., what the resulting key sequence does and what command it is bound to. You might also want to have the tool help you complete the key sequence, to invoke it.

    The key completion provided by library Icicles does all of this, and more.

    It is available all the time - just hit S-TAB to complete any key sequence. You can also hit S-TAB at the top level, to see all of the possible key sequences in the current context and complete any of them to invoke it.

    Each key-sequence completion candidate shows you the remainder of the key sequence, followed by =, followed by the command the sequence is bound to. You can type input to match either or both parts of this candidate, and matching can be as simple or fancy as you like (regexp etc.).

    As you type, the set of matching candidates is filtered to correspond. At any time you can also cycle among the current candidates. As you cycle, a description of the current candidate (which is highlighted) is shown in the mode line of the buffer (*Completions*) where they are listed.

    If you want more information about the current candidate that this one-liner, just hit C-M-RET to pop up buffer *Help* with the complete documentation of the key sequence and its command.

    Hit RET to choose the current candidate to invoke it. Or just hit C-g if you don't want to invoke any key now, but you just wanted info about the currently available keys.

    Prefix keys that are available in the current context are also listed as candidates. E.g., prefix key 4 is available as a candidate when you are completing prefix key C-x. You can navigate up, down, and around the entire hierarchy of all key sequences by choosing prefix-key candidates or by choosing the candidate .., which goes back up.

    Candidate key sequences are highlighted differently if they are local bindings (e.g. local to the current mode) or if they are prefix keys.

    You can sort the candidates in various ways: prefix keys first, local keys first, command-name alphabetical order, and so on.