Subject: Re: bug#66755: 30.0.50; how do i lookup a key but also respect key translations?

From: Stefan Monnier <[email-masked]>
Date: Wed, 10 Jan 2024 22:41:15 -0500

> Hello. So I am trying to define a function which obtains the command
> that would be called if 'corfu-mode' was not enabled:

I recommend you try and avoid needing to do that.

> (defun +corfu--get-passthrough-command ()
>   (keymap-lookup
>    (thread-last
>      (current-active-maps t)
>      (delq corfu-map)
>      (delq (and (featurep 'evil)
>                 (evil-get-auxiliary-keymap corfu-map evil-state))))
>    (key-description (this-command-keys-vector))))

[ Eww... `keymap-lookup` forcing you to use `key-description` here is
  pretty hideous.  ]

> but I don't know how to look up that translation from Elisp. I looked at
> the code for 'help.el' and found the above description comes from
> 'read-key-sequence' returning 'C-?' and 'this-single-command-raw-keys'
> returning '[backspace]' but 'read-key-sequence' is defined in C and I
> don't know how trigger it's translation logic programmatically from
> Elisp.

Are you saying that `this-command-keys-vector` returns the same
`[backspace]` as `this-single-command-raw-keys` here?  That's odd, I'd
have expected to return `[?\C-?]`.
In any case it still won't always be the answer you're looking for.

There is simply no reliable way to do what you want, because even
deciding when the sequence of keys ends (to run your (presumably Corfu)
command) can be affected by the existence of a binding to that command.

I think the "closest" you can get is to take
`this-single-command-raw-keys` and push it back on `unread-command-events`.

Or else, arrange for your command's binding to be disabled when you
don't actually want to run it, rather than make it delegate manually to
the "next" binding.

        Stefan