unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: StrawberryTea <look@strawberrytea.xyz>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 69306@debbugs.gnu.org
Subject: bug#69306: 30.0.50; defining menu-items with :enable enables them unconditionally
Date: Fri, 23 Feb 2024 09:23:45 +0200	[thread overview]
Message-ID: <86le7b1w5a.fsf@gnu.org> (raw)
In-Reply-To: <87edd4yyyn.fsf@strawberrytea.xyz> (message from StrawberryTea on Thu, 22 Feb 2024 15:19:26 -0600)

> From: StrawberryTea <look@strawberrytea.xyz>
> Cc: 69306@debbugs.gnu.org
> Date: Thu, 22 Feb 2024 15:19:26 -0600
> 
> Basically, I am trying to define a conditional keybinding. The real-world
> example I’m working with is:
> 
> (when-let ((cmds-del (and (modulep! :completion corfu +tng)
>                           ’(menu-item “Reset completion” corfu-reset
>                             :enable (and (> corfu–index -1)
>                                          (eq corfu-preview-current ’insert)))))
>            (cmds-ret ’(menu-item “Insert completion” corfu-insert
>                        :filter (lambda (cmd)
>                                  (if (eq corfu–index -1)
>                                      (corfu-quit)
>                                    cmd)))))
>   (map! :when (modulep! :completion corfu)
>         :after corfu
>         :map corfu-map
>         [backspace] cmds-del
>         “DEL” cmds-del
>         :ig [return] cmds-ret
>         :ig “RET” cmds-ret))
> 
> Here, the :filter and :enable properties are used to conditionally enable their
> respective keybindings. The :filter property works as expected, but the :enable
> property does not. The backspace keybinding is always enabled, even when the
> :enable property is evaluates to nil.

If you expect that the key binding will be disabled via :enable, then
I don't think this is supported except in menus (and tool bars and tab
bars): the value is evaluated by the menu-related code, when it
actually displays the menu, and in your case there's no menu.  The
:filter attribute is interpreted differently, so it just happens to
work.  But that's sheer luck, I'd say.

Adding Stefan in case he has comments.





  reply	other threads:[~2024-02-23  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 23:26 bug#69306: 30.0.50; defining menu-items with :enable enables them unconditionally StrawberryTea
2024-02-22  6:41 ` Eli Zaretskii
2024-02-22 21:19   ` StrawberryTea
2024-02-23  7:23     ` Eli Zaretskii [this message]
2024-02-23 12:23       ` 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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=86le7b1w5a.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=69306@debbugs.gnu.org \
    --cc=look@strawberrytea.xyz \
    --cc=monnier@iro.umontreal.ca \
    /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 public inbox

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

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