Subject: bug#50804: Command substitutions for keys without keymaps

From: Stefan Kangas <[email-masked]>
Date: Sat, 25 Sep 2021 11:01:38 -0700

Severity: wishlist

We have "\\[foo]" command substitutions in `substitute-command-keys'.
This also puts the face help-key-binding on the replaced text, which
makes key bindings stand out more clearly.

We don't always have a keymap to refer to, because the keys are read
through `read-key' or similar.

For example, in ispell.el:

    (message (concat "C-h or ? for more options; SPC to leave "
                     "unchanged, Character to replace word")))

In other cases, we have the same situation in a docstring, for example
in `isearch-lax-whitespace'.

It would be nice if we could have some way of putting a face on such key
bindings, without having to fiddle with propertize.  For example:

    (message (substitute-command-keys
              (concat "\\[[C-h]] or \\[[?]] for more options;
\\[[SPC]] to leave "
                      "unchanged, Character to replace word"))))

I'm not sure about the notation.  Perhaps "\\[[...]]" is okay, or
perhaps we want some other delimiter.

And perhaps we would want support for this notation also in
`format-messages'?  I'm not sure, but I'm putting it out there.