Subject: bug#77345: 30.1; "C-h w" doesn't detect binding in the midst of an M-x invocation

From: Suhail Singh <[email-masked]>
Date: Sat, 29 Mar 2025 11:22:39 -0400

Eli Zaretskii <[email-masked]> writes:

> C-j in the minibuffer is not bound to eval-print-last-sexp ...
>
> If you try the same with eval-last-sexp, you will see the result you
> expect, because "C-x C-e" _is_ bound in the minibuffer.
>
> Why do you think there's a bug here?

Yes, it's clear that it's looking for bindings in the minibuffer.  This
was unexpected because I was expecting to be able to look up the binding
in the original buffer (lisp-interaction-mode in this case).  Thinking
some more about it, perhaps this isn't a bug as much as it is a feature
request.  I'll describe my use-case below.

Sometimes, I know (roughly) the name of the command, but not the
keybinding for it.  So I begin my journey by invoking M-x and rely on
TAB completion.  Having found the right command, I want to do two
things: one, invoke it; two, learn the keybinding if there is one
present.

To accomplish the latter, I have `marginalia' installed from ELPA, and
it adds annotations for keybindings in the completions buffer.  However,
if a completion is a sole completion then the completions buffer doesn't
show (see `minibuffer-completion-help').  The result is that for sole
completions, marginalia's keybinding annotations aren't accessible.

Running into this obstacle, I reached for the venerable `where-is'.
However, C-h w results in the lookup of bindings in the minibuffer
instead (as opposed to the original buffer where the M-x was invoked
from).

Of course completing the M-x invocation (or aborting it) and looking up
the binding of the command via C-h w in the original buffer works, but
it's a two-step process.

Some thoughts on possible ways this could be addressed:

- adding a user configuration which allows the completions buffer to be
  displayed even for sole completions
- adding an optional parameter for C-h w to be able to consult the
  binding in the original buffer (assuming the result reported by
  something like src_elisp{(window-buffer (minibuffer-selected-window))}
  is reliable for this purpose).

-- 
Suhail