5

Is there any easy way to determine the purpose of a prefix key shown in the output of (describe-key Chk?

I walked through my (kbd "C-x <key>") and (kbd "C-x C-<key>") combinations to find out what they are all bound to.

The method worked fine, except for prefix keys. Then, the Chk output in the minibuffer just showed the prefix keys typed so far, without saying something like "Prefix key for xxx mode", or "Prefix key for register actions (C-x r)."

I looked at the output of describe-prefix-bindings too, but for prefix keys, it just said things like this, without saying anything about the source or purpose of the prefix.

C-x RET         Prefix Command
C-x ESC         Prefix Command
C-x 8           Prefix Command
C-x r           Prefix Command
C-x n           Prefix Command
C-x             Prefix Command
C-h 4           Prefix Command

How can I find out the purpose of a Prefix Command listed in the output of describe-bindings?

4

In most cases, you can type the prefix and then C-h to get a list of all the bindings that begin with that prefix. This won't directly tell you what the prefix means and not all prefixes have a specific generic purpose. But, you may be able to tell from the set of functions what the commonality is.

The reason it's "in most cases" is that if the prefix defines something for C-h, that's what will be called (most don't define it, but some do). There's a generic handler for all prefixes that don't otherwise define C-h that does the listing. So, you may want to type it in some innocuous place, or try C-h c on it first.

  • What a clever trick, typing a second C-h. Thank you. That's a good enough answer for me. – Kevin Jun 26 '16 at 20:56
  • @Kevin: The other answer is more comprehensive, we were actually typing them at the same time. But, I really enjoyed seeing the addition of this trick when it came out and often find it useful. – MAP Jun 26 '16 at 21:27
  • n.b. As per duplicate stackoverflow.com/q/10330510 it is very slightly more reliable to use <f1> instead of C-h for this purpose. I still use C-h out of habit, though :) – phils Jun 26 '16 at 21:47
  • BTW: You say "when it came out", but Emacs has always had this feature. However, in vanilla Emacs there are still a few places where it doesn't work - C-s C-h, for instance (that works with Isearch+). – Drew Jun 26 '16 at 22:33
  • @Drew: Yes, "when it came out". I've been using emacs since the late 70's. I know this wasn't part of emacs when I first used it...although I do seem to recall it in the news somewhere around emacs 19. – MAP Jun 26 '16 at 23:58
2
  1. The first answer is that its purpose is to act as a prefix key to the keys that follow it; that is, to serve as a keymap for a certain number of key bindings. Those bindings are also shown in describe-key. Seriously; this is the purpose: to group those keys and their commands. Now what that grouping might be about is another question (see next).

  2. Beyond #1, yes. A prefix key is bound to a keymap, and that can have its own doc string. It is up to the creator of the keymap to provide a reasonable and useful doc string.

    To see the doc for a keymap, use C-h M-k (describe-keymap), from help-fns+.el.

    Here is what you see for bookmark-map, for example (manuals here is a link to the doc in the Emacs manuals):

    bookmark-map
    ------------
    
    For more information check the manuals.
    
    Keymap containing bindings to bookmark functions.
    It is not bound to any key by default: to bind it
    so that you have a bookmark prefix, just use `global-set-key' and bind a
    key of your choice to `bookmark-map'.  All interactive bookmark
    functions have a binding in this keymap.
    
    key             binding
    ---             -------
    
    d               bookmark-delete
    e               edit-bookmarks
    f               bookmark-insert-location
    g               bookmark-jump
    i               bookmark-insert
    j               bookmark-jump
    l               bookmark-load
    m               bookmark-set
    o               bookmark-jump-other-window
    r               bookmark-rename
    s               bookmark-save
    w               bookmark-write
    x               bookmark-set
    

    But some keymaps have a more rudimentary doc string. The keymap ctl-x-map, for instance, is general-purpose, so there is not much that can be said (beyond #1 above). This is what you get with C-h M-k ctl-x-map:

    ctl-x-map
    ---------
    
    For more information check the manuals.
    
    Default keymap for C-x commands.
    The normal global definition of the character C-x indirects to this keymap.
    
    key             binding
    ---             -------
    
    C-@             pop-global-mark
    C-b             list-buffers
    ...
    

    In this case, the doc string essentially just repeats #1 above: Default keymap for C-x commands.


Wrt your comment: Non-interactively, the argument to describe-keymap can be a keymap object instead of the name of a keymap variable. C-h f describe-keymap:

describe-keymap is an interactive Lisp function in `help-fns+.el'.

It is bound to C-h M-k, f1 M-k, help M-k, menu-bar help-menu describe
describe-keymap.

(describe-keymap KEYMAP &optional SEARCH-SYMBOLS-P)

For more information check the manuals.

Describe key bindings in KEYMAP.
Interactively, prompt for a variable that has a keymap value.
Completion is available for the variable name.

Non-interactively:
* KEYMAP can be such a keymap variable or a keymap.
* Non-nil optional arg SEARCH-SYMBOLS-P means that if KEYMAP is not a
  symbol then search all variables for one whose value is KEYMAP.
  • 1
    Wow, this is a really good answer too, showing just the doc that I was interested in seeing. It seems like I need to know the name of the keymap in order to search for the doc for it, but that was one of my stumbling blocks. Why doesn't describe-keybindings give the name of the bound keymap instead of (the almost useless) "Prefix Command"? How can I reliably get from the "Prefix Command" that I see to the name of the keymap? (I ended up doing a brute force manual search of the output of (describe-prefix-keybindings) to see which keys were bound, and then working backwards. – Kevin Jun 26 '16 at 21:57
  • The keymap needn't have a name. It can just be a keymap object (in which case displaying it would be ugly). You could certainly make a case that where there is a symbol, it could usefully be displayed as well. You could M-x report-emacs-bug if you can't find an existing one. – phils Jun 27 '16 at 3:34

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.