From unknown Sat Jun 14 03:54:50 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#50228 <50228@debbugs.gnu.org> To: bug#50228 <50228@debbugs.gnu.org> Subject: Status: [PATCH] 'command-completion-using-modes-p' doesn't work with multiple modes Reply-To: bug#50228 <50228@debbugs.gnu.org> Date: Sat, 14 Jun 2025 10:54:50 +0000 retitle 50228 [PATCH] 'command-completion-using-modes-p' doesn't work with = multiple modes reassign 50228 emacs submitter 50228 Johannes Maier severity 50228 normal tag 50228 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 27 11:17:48 2021 Received: (at submit) by debbugs.gnu.org; 27 Aug 2021 15:17:48 +0000 Received: from localhost ([127.0.0.1]:52721 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJdbz-0000r9-6e for submit@debbugs.gnu.org; Fri, 27 Aug 2021 11:17:48 -0400 Received: from lists.gnu.org ([209.51.188.17]:36376) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJZG7-00029n-JG for submit@debbugs.gnu.org; Fri, 27 Aug 2021 06:38:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJZG7-00048I-CO for bug-gnu-emacs@gnu.org; Fri, 27 Aug 2021 06:38:51 -0400 Received: from mout-p-201.mailbox.org ([2001:67c:2050::465:201]:43528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1mJZG5-0004DC-9P for bug-gnu-emacs@gnu.org; Fri, 27 Aug 2021 06:38:51 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [80.241.60.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Gwx5b0vYVzQk4K for ; Fri, 27 Aug 2021 12:38:43 +0200 (CEST) Received: from spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) by smtp102.mailbox.org (Postfix) with ESMTP id 526B3266 for ; Fri, 27 Aug 2021 12:38:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1630060721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=ADEu0wOjDQQMEoas39gdNbaOi3GZQsI9sOwPYnJeyAQ=; b=iaz+SoTJoUFFjRr5foOQcQ6Mv/6+vLWUb5891X74WV1D8X47ylPf2jJU83ZEiuOL3UPoDG iv4XkrfUS4z0Vr1fxjsvGVyYRVp6jaHeHdTBrHQFGVOBKbrWUHAeFKtpAoVan7dUjuEKRo koIQqTM7DAKlA2+hIxbkrM+QzNcnhc1yEZlXXwIelY7Y3qC5u7VNrLy5sBN0kOs9WbW4TF 8ZCyZZJ9tYCfQMXD+rWfhEqMV+InfGXHAAd2DugMQmOFjkkqOuZ8pDGJLc/C04J6QHAqcY HwhDga1ku7K8a/5ErqT6v1WrtfSZzDPZqGyood8mlgqM5uDbzU5lZW+Sj/h/YA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mailbox.org; h= content-type:content-type:mime-version:message-id:date:date :subject:subject:from:from:received:received; s=mail20150812; t= 1630060720; bh=h6REIeFUDifCHpCRHRvvjH/HvWVW98AYn381QzmxoZ4=; b=w V4woM+wbTTV4LWsHAnbEpRPOWhNoqqjOQB4Fchpw4ZS/O7+d1P2tWD86STbRNLwQ GejJa4IFa29WjZUeei2avJ5uzj3g76UP9SDuX7kOtHOHYXjss4y0LkWHO1UmPCMe dAKVPmj3oqosuXUz9DL6DqBeL1eEefbe3sLUklXKg+eIJuj3jIEHj1LHfW3gTpyc NNko8yUW1PmcENEGivLp9zCyhZ/4KIJ33hk8huqA5yftb1SUCt95dLWnQuInmyTd 6ZET46oWHUHH/CwbaJubO32GjMQnyT8HW1OF+8bEmlllpMyqoOyk9PaCO4i8nw2i iY+1j7vK7qyClPUKKcQ8g== X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp102.mailbox.org ([80.241.60.233]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id DMDE2b_ZQhHi for ; Fri, 27 Aug 2021 12:38:40 +0200 (CEST) Received: from localhost (200116b82b18040005e05f60bb6adf27.dip.versatel-1u1.de [IPv6:2001:16b8:2b18:400:5e0:5f60:bb6a:df27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp102.mailbox.org (Postfix) with ESMTPSA id BD588271 for ; Fri, 27 Aug 2021 12:38:39 +0200 (CEST) From: Johannes Maier To: bug-gnu-emacs@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-ID: <87pmtzmatt.fsf@mailbox.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Rspamd-Queue-Id: 526B3266 X-Rspamd-UID: e46867 Received-SPF: pass client-ip=2001:67c:2050::465:201; envelope-from=johannes.maier@mailbox.org; helo=mout-p-201.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 27 Aug 2021 11:17:42 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=command-completion-using-modes-p.patch >From 08d6f48b4f7a295d3fd590ad6e5723beb3f0eadf Mon Sep 17 00:00:00 2001 From: Johannes Maier Date: Fri, 27 Aug 2021 09:40:08 +0200 Subject: [PATCH] Fix 'command-completion-using-modes-p' in case of multiple modes * lisp/simple.el: Use `command-completion-with-modes-p' inside of `command-completion-using-modes-p' instead of performing a faulty check (`or' was missing) in the case where `command-modes' returns multiple modes. --- lisp/simple.el | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index db083cfc25..82ab8927a7 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2067,24 +2067,9 @@ read-extended-command t nil 'extended-command-history)))) (defun command-completion-using-modes-p (symbol buffer) - "Say whether SYMBOL has been marked as a mode-specific command in BUFFER." - ;; Check the modes. - (let ((modes (command-modes symbol))) - ;; Common case: Just a single mode. - (if (null (cdr modes)) - (or (provided-mode-derived-p - (buffer-local-value 'major-mode buffer) (car modes)) - (memq (car modes) - (buffer-local-value 'local-minor-modes buffer)) - (memq (car modes) global-minor-modes)) - ;; Uncommon case: Multiple modes. - (apply #'provided-mode-derived-p - (buffer-local-value 'major-mode buffer) - modes) - (seq-intersection modes - (buffer-local-value 'local-minor-modes buffer) - #'eq) - (seq-intersection modes global-minor-modes #'eq)))) + "Say whether SYMBOL has been marked as a mode-specific command in +BUFFER." + (command-completion-with-modes-p (command-modes symbol) buffer)) (defun command-completion-default-include-p (symbol buffer) "Say whether SYMBOL should be offered as a completion. -- 2.32.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 27 11:32:03 2021 Received: (at 50228) by debbugs.gnu.org; 27 Aug 2021 15:32:03 +0000 Received: from localhost ([127.0.0.1]:52769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJdpm-0002vs-RN for submit@debbugs.gnu.org; Fri, 27 Aug 2021 11:32:03 -0400 Received: from quimby.gnus.org ([95.216.78.240]:33346) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJdpg-0002nK-S4 for 50228@debbugs.gnu.org; Fri, 27 Aug 2021 11:31:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=9GyjNsOQabKFy3DD7b1teHhBgWr/4TMXI1KJO4uMqi0=; b=Jy+3NP+vlbSB/Ww71d5DUhlNvZ mJWDB6wUAUBFuMn3sVSrdorieeU5Siewet2Eg0dBrUKDO8osNBJyHJrc8RLS6sHhqcqjZeInt5++u 5ja568xCmw9e91h4AqibVpE1XAnHahzyT/jdAZfFGKu14evNyJV45K0LdPkp/yK+BEC4=; Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJdpW-0003zK-93; Fri, 27 Aug 2021 17:31:46 +0200 From: Lars Ingebrigtsen To: Johannes Maier Subject: Re: bug#50228: [PATCH] 'command-completion-using-modes-p' doesn't work with multiple modes References: <87pmtzmatt.fsf@mailbox.org> Date: Fri, 27 Aug 2021 17:31:41 +0200 In-Reply-To: <87pmtzmatt.fsf@mailbox.org> (Johannes Maier's message of "Fri, 27 Aug 2021 12:38:38 +0200") Message-ID: <877dg6oqea.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Johannes Maier 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 wi [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 50228 Cc: 50228@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Johannes Maier 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 From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 27 11:32:07 2021 Received: (at control) by debbugs.gnu.org; 27 Aug 2021 15:32:07 +0000 Received: from localhost ([127.0.0.1]:52771 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJdpr-0002zs-BH for submit@debbugs.gnu.org; Fri, 27 Aug 2021 11:32:07 -0400 Received: from quimby.gnus.org ([95.216.78.240]:33370) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJdpl-0002qk-K0 for control@debbugs.gnu.org; Fri, 27 Aug 2021 11:32:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=IfAT5a+qKodUmGRnWd8kIeK561MevRHos4iTDMsKrmQ=; b=CVD2s4NSCrjg1yaodOAawGEYum wl7O6hf3kn1ydbXi4UVxGm+yyYies6YddrbUnaR0KzKTflgfR2IXE4NHnDhD0hBHPKQQmYIrupkCF ViNC3aEsxVZlJrphV7EZdgYlX/ysD63Oxqx+qTgh8ZlTDJD/5pJ3GYT8i7ZC0h20WYMc=; Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJdpd-0003zV-MW for control@debbugs.gnu.org; Fri, 27 Aug 2021 17:31:51 +0200 Date: Fri, 27 Aug 2021 17:31:49 +0200 Message-Id: <875yvqoqe2.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #50228 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: close 50228 28.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) close 50228 28.1 quit From unknown Sat Jun 14 03:54:50 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 25 Sep 2021 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator