From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Johannes Maier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#50228: [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> Reply-To: Johannes Maier Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6947"; mail-complaints-to="usenet@ciao.gmane.io" To: 50228@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 27 17:21:39 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJdfl-0001aA-Co for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 27 Aug 2021 17:21:37 +0200 Original-Received: from localhost ([::1]:49870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJdfj-0006Wr-Ik for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 27 Aug 2021 11:21:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJdcJ-0001bD-Pn for bug-gnu-emacs@gnu.org; Fri, 27 Aug 2021 11:18:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41180) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mJdcI-0002NB-IW for bug-gnu-emacs@gnu.org; Fri, 27 Aug 2021 11:18:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mJdcI-0000sD-Df for bug-gnu-emacs@gnu.org; Fri, 27 Aug 2021 11:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Johannes Maier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Aug 2021 15:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50228 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16300774683305 (code B ref -1); Fri, 27 Aug 2021 15:18:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Aug 2021 15:17:48 +0000 Original-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 Original-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 Original-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 Original-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 Original-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) Original-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 Original-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) Original-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) 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-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 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:212822 Archived-At: --=-=-= 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 --=-=-=--