Subject: bug#39035: Show key bindings on M-x completion

From: Stefan Monnier <[email-masked]>
Date: Tue, 28 Jan 2020 22:02:55 -0500

> Indeed, not hard at all:

Looks about right, thanks.

> +       (if (and suggest-key-bindings (eq action 'metadata))
> +	   '(metadata
> +	     (annotation-function . read-extended-command--annotation)
> +	     (category . suggest-key-bindings))

The `category` should describe the things that are being completed,
i.e. `command` rather than `suggest-key-bindings`.

> +(defun read-extended-command--annotation (command-name)
> +  (let* ((function (and (stringp command-name) (intern-soft command-name)))
> +         (binding (where-is-internal function overriding-local-map t)))
> +    (when binding
> +      (format " (%s)" (if (stringp binding)
> +                          (concat "M-x " binding " RET")
> +                        (key-description binding))))))

Since we're in the middle of a `M-x`, I think a `M-x foo RET` annotation
would not be useful at all: better not put anything when a command has
no corresponding key binding (one could argue that it could be useful to
put the `M-x <shortenedname> RET` like `M-x re-u RET` for
`rename-uniquely`, but it would be too costly to compute and still
wouldn't be terribly useful).

        Stefan