GNU bug report logs - #69306
30.0.50; defining menu-items with :enable enables them unconditionally

Previous Next

Package: emacs;

Reported by: StrawberryTea <look <at> strawberrytea.xyz>

Date: Wed, 21 Feb 2024 23:31:01 UTC

Severity: normal

Found in version 30.0.50

Full log


View this message in rfc822 format

From: StrawberryTea <look <at> strawberrytea.xyz>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 69306 <at> 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
[Message part 1 (text/plain, inline)]
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 <at> gnu.org> writes:

>> From: StrawberryTea <look <at> 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”?

This bug report was last modified 1 year and 114 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.