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

[-- Attachment #1: Type: text/plain, Size: 1929 bytes --]

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.

Eli Zaretskii <eliz@gnu.org> writes:

>> From: StrawberryTea <look@strawberrytea.xyz>
>> Date: Wed, 21 Feb 2024 17:26:02 -0600
>>
>> Hi. I am not sure if I open a vanilla Emacs session and evaluate:
>> (defvar hello nil)
>> (setq hello nil)
>> (define-key global-map (kbd “C-M-S-f”) ’(menu-item “” delete-backward-char :enable hello))
>>
>> and then press C-M-S-f, the delete-backward-char menu item will be
>> enabled, even though hello is nil.
>
> Enabled where?  After evaluating the above, I don’t see your menu item
> anywhere (since it is not added to any existing menu, I guess?), so
> I’m not sure what you are describing here.  Is some step missing from
> the recipe?  Can you show a full recipe starting from “emacs -Q”?

  reply	other threads:[~2024-02-22 21:19 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 [this message]
2024-02-23  7:23     ` Eli Zaretskii
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=87edd4yyyn.fsf@strawberrytea.xyz \
    --to=look@strawberrytea.xyz \
    --cc=69306@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /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).