GNU bug report logs - #50228
[PATCH] 'command-completion-using-modes-p' doesn't work with multiple modes

Previous Next

Package: emacs;

Reported by: Johannes Maier <johannes.maier <at> mailbox.org>

Date: Fri, 27 Aug 2021 15:18:02 UTC

Severity: normal

Tags: patch

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 50228 in the body.
You can then email your comments to 50228 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#50228; Package emacs. (Fri, 27 Aug 2021 15:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Johannes Maier <johannes.maier <at> mailbox.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 27 Aug 2021 15:18:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Johannes Maier <johannes.maier <at> mailbox.org>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] 'command-completion-using-modes-p' doesn't work with
 multiple modes
Date: Fri, 27 Aug 2021 12:38:38 +0200
[Message part 1 (text/plain, inline)]
Hello everyone,

I'm using an up-to-date build of Emacs on NixOS and on Ubuntu (M-x
emacs-version yields "GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu,
GTK+ Version 3.24.30, cairo version 1.16.0").

I tried writing a command that would only show up in M-x TAB in certain
modes, using the new MODES argument to 'interactive', like so:

(setq read-extended-command-predicate
      #'command-completion-default-include-p)

(defun my-foo ()
  (interactive nil haskell-mode emacs-lisp-mode)
  (message "foo"))

I would have expected the command 'my-foo' to be shown in an Elisp
buffer, but hidden in fundamental-mode.  But 'my-foo' never shows up (it
works in the case where the 'interactive' call only specifies one mode,
though).

I checked the code that is called and found that
'command-completion-using-modes-p' seems to be missing an 'or' around
the predicates in the alternative case.  Digging a little deeper I found
the predicate function 'command-completion-with-modes-p' that already
seems to do what's needed for the other predicate, but with slightly
different arguments.  In particular the single-mode case seems to be
handled correctly by the code in 'command-completion-with-modes-p' as
well.

I've attached a patch that removes the duplicated checks in these two
functions and simply calls 'command-completion-with-modes-p' from
'command-completion-using-modes-p'.  Now it works for me with one or
more (major or minor) modes in 'interactive'.

I'm very much looking forward to feedback on whether that's a "good"
solution and hope I gave all the information that's needed.

(I didn't see any tests for those functions, but I'm not sure how to go
about those yet.  Could probably have look into those, too.)

Thank you,
Johannes

[command-completion-using-modes-p.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50228; Package emacs. (Fri, 27 Aug 2021 15:33:02 GMT) Full text and rfc822 format available.

Message #8 received at 50228 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Johannes Maier <johannes.maier <at> mailbox.org>
Cc: 50228 <at> debbugs.gnu.org
Subject: Re: bug#50228: [PATCH] 'command-completion-using-modes-p' doesn't
 work with multiple modes
Date: Fri, 27 Aug 2021 17:31:41 +0200
Johannes Maier <johannes.maier <at> mailbox.org> writes:

> I've attached a patch that removes the duplicated checks in these two
> functions and simply calls 'command-completion-with-modes-p' from
> 'command-completion-using-modes-p'.  Now it works for me with one or
> more (major or minor) modes in 'interactive'.

Thanks, that does fix the problem.

However, the reason `command-completion-using-modes-p' is coded that way
is that `command-completion-with-modes-p' is slower in the common case,
and completion has to be fast.  But in the multiple-mode case, we can
indeed just call `command-completion-with-modes-p', so I've kept the
common case, but punted to `command-completion-with-modes-p' in the
multiple-mode case, and that seems to fix the issue.

> (I didn't see any tests for those functions, but I'm not sure how to go
> about those yet.  Could probably have look into those, too.)

Yes, there really should be tests in this area...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 28.1, send any further explanations to 50228 <at> debbugs.gnu.org and Johannes Maier <johannes.maier <at> mailbox.org> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 27 Aug 2021 15:33:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 25 Sep 2021 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 205 days ago.

Previous Next


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