unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How do i lookup a key but also respect key translations? (was: bug#66755: 30.0.50)
       [not found] ` <83msw5hmqn.fsf@gnu.org>
@ 2023-10-26 14:31   ` Stefan Monnier
  2023-10-28 15:12     ` StrawberryTea
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Monnier @ 2023-10-26 14:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: StrawberryTea, help-gnu-emacs

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

Sounds like pain.  Often the better solution is to step back and think
of some other way to get that result, e.g. temporarily disabling
corfu-mode beforehand.

>> (defun +corfu--get-passthrough-command ()
>>   (keymap-lookup
>>    (thread-last
>>      (current-active-maps t)
>>      (delq corfu-map)

I think you can get a similar result with

    (let ((corfu-mode nil))
      (current-active-maps t))

>> (keymap-lookup (current-active-maps t)
>>     (key-description (vector 'backspace)))
>>
>> returns nil whereas
>>
>> (keymap-lookup (current-active-maps t) (key-description (vector ?\C-?)))

Right, because you need to obey the various key-remapping keymaps, like
`function-key-map` and friends.

It's actually a fundamentally difficult problem.  Think of the case
where the "underlying binding" you're trying to find is actually
a keymap because the user decided to use his DEL key as a prefix key?
What should you do in that case?

If you can't know beforehand that you'll want to just "passthrough"
(hence you can't disable corfu ahead of time), a second best kind of
solution is to push the events back on `unread-command-events`.

Another approach that can be used sometime is to make the binding that
you sometimes want to fallthrough be dynamically enabled/disabled with
something like:

    (define-key map [THE-KEYS]
      `(menu-item THE-COMMAND
        :filter ,(lambda (cmd) (if (THE-CONDITION) cmd))))


-- Stefan




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How do i lookup a key but also respect key translations? (was: bug#66755: 30.0.50)
  2023-10-26 14:31   ` How do i lookup a key but also respect key translations? (was: bug#66755: 30.0.50) Stefan Monnier
@ 2023-10-28 15:12     ` StrawberryTea
  0 siblings, 0 replies; 2+ messages in thread
From: StrawberryTea @ 2023-10-28 15:12 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Eli Zaretskii, help-gnu-emacs

Hi Stefan. Using let-binding corfu-mode did not affect the output of
current-active-maps but the menu-item usage worked perfectly for all the
use-cases I was working on for a new Doom Emacs module. Thank you 😃.

I was hoping for a drop-in replacement for keymap-lookup/lookup-key/key-binding
that respects key translations to pick up some low-hanging fruit in Meow/God
Mode/Devil since those packages do not utilize the key-translation-map but it
seems that might be really complicated.

Love your MPC package by the way!

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> Hello. So I am trying to define a function which obtains the command
>>> that would be called if ’corfu-mode’ was not enabled:
>
> Sounds like pain.  Often the better solution is to step back and think
> of some other way to get that result, e.g. temporarily disabling
> corfu-mode beforehand.
>
>>> (defun +corfu–get-passthrough-command ()
>>>   (keymap-lookup
>>>    (thread-last
>>>      (current-active-maps t)
>>>      (delq corfu-map)
>
> I think you can get a similar result with
>
>     (let ((corfu-mode nil))
>       (current-active-maps t))
>
>>> (keymap-lookup (current-active-maps t)
>>>     (key-description (vector ’backspace)))
>>>
>>> returns nil whereas
>>>
>>> (keymap-lookup (current-active-maps t) (key-description (vector ?\C-?)))
>
> Right, because you need to obey the various key-remapping keymaps, like
> `function-key-map` and friends.
>
> It’s actually a fundamentally difficult problem.  Think of the case
> where the “underlying binding” you’re trying to find is actually
> a keymap because the user decided to use his DEL key as a prefix key?
> What should you do in that case?
>
> If you can’t know beforehand that you’ll want to just “passthrough”
> (hence you can’t disable corfu ahead of time), a second best kind of
> solution is to push the events back on `unread-command-events`.
>
> Another approach that can be used sometime is to make the binding that
> you sometimes want to fallthrough be dynamically enabled/disabled with
> something like:
>
>     (define-key map [THE-KEYS]
>       `(menu-item THE-COMMAND
>         :filter ,(lambda (cmd) (if (THE-CONDITION) cmd))))
>
> – Stefan


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-28 15:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87ttqeja59.fsf@strawberrytea.xyz>
     [not found] ` <83msw5hmqn.fsf@gnu.org>
2023-10-26 14:31   ` How do i lookup a key but also respect key translations? (was: bug#66755: 30.0.50) Stefan Monnier
2023-10-28 15:12     ` StrawberryTea

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).