all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Eli Zaretskii <eliz@gnu.org>
Cc: StrawberryTea <look@strawberrytea.xyz>,  help-gnu-emacs@gnu.org
Subject: How do i lookup a key but also respect key translations? (was: bug#66755: 30.0.50)
Date: Thu, 26 Oct 2023 10:31:07 -0400	[thread overview]
Message-ID: <jwvsf5xv534.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83msw5hmqn.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 26 Oct 2023 10:22:08 +0300")

>> 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




  reply	other threads:[~2023-10-26 14:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-26  3:57 bug#66755: 30.0.50; how do i lookup a key but also respect key translations? StrawberryTea
2023-10-26  7:22 ` Eli Zaretskii
2023-10-26 14:31   ` Stefan Monnier [this message]
2023-10-28 15:12     ` How do i lookup a key but also respect key translations? (was: bug#66755: 30.0.50) StrawberryTea
2024-01-10 18:00   ` bug#66755: 30.0.50; how do i lookup a key but also respect key translations? Stefan Kangas
2024-01-11  3:41 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvsf5xv534.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=look@strawberrytea.xyz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.