From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 25 11:11:12 2025 Received: (at submit) by debbugs.gnu.org; 25 Mar 2025 15:11:12 +0000 Received: from localhost ([127.0.0.1]:39633 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tx5vs-0001GJ-AB for submit@debbugs.gnu.org; Tue, 25 Mar 2025 11:11:12 -0400 Received: from lists.gnu.org ([2001:470:142::17]:49270) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tx5vn-0001Ff-SV for submit@debbugs.gnu.org; Tue, 25 Mar 2025 11:11:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tx5vh-00043c-I0 for bug-gnu-emacs@gnu.org; Tue, 25 Mar 2025 11:11:01 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tx5vf-0007rB-GB for bug-gnu-emacs@gnu.org; Tue, 25 Mar 2025 11:11:01 -0400 From: Spencer Baugh To: bug-gnu-emacs@gnu.org Subject: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys X-Debbugs-Cc: Date: Tue, 25 Mar 2025 11:10:57 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1742915457; bh=FKoIdbeyg0teG/4idUqUhvYMZzcg4b6KvhPf+kNLWFc=; h=From:To:Cc:Subject:Date; b=NuGhRy1jpZi+830BVTy98Hik2JkNlxSOKgH7D7n6g9E21YrKIYJuhegbQvPPl+FAd 6I8TekR0p3z2B+7cl9MGSqfnBT3GzN3Cpiqtb2oxLX5x62+dtliJmPJk+BjLSKys1s wS2pS+cErd2X8gS92BPPD0MpcmVD+AUPjShzelcLYmQ8yx/cSdeU+8fPSCFhw5plQZ Gfz534mQJgVv30f2To3t1XeScO5yLR6uo+PkS6UkT7VXMo60olIcrhkVjWTqYok+om kmNjHxi7OG84JOQ0HhQlff4n7WNrBUg98nAaroCtB4y1su5VmALqYL7xlUgI91w5gN JNBeXZoowUj5w== Received-SPF: pass client-ip=64.215.233.18; envelope-from=sbaugh@janestreet.com; helo=mxout5.mail.janestreet.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit Cc: juri@linkov.net 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: -0.1 (/) Right now, minibuffer-visible-completions does two things, only when *Completions* is visible: A. If there's a selected completion candidate, RET exits the minibuffer with it. B. The arrow keys move point in the *Completions* buffer instead of the minibuffer, to select completion candidates. These are really two separate things. A is a nice behavior for novice users, but B is difficult for novice users (who like to use the arrow keys for moving point) to deal with. We should make them separately configurable, or at least allow enabling the RET behavior without the arrow keys behavior. And with the addition of completion-auto-deselect, the RET behavior is actually a plausible default behavior: it only takes effect if the user has manually selected a completion candidate with M-/M-, and the selected candidate is automatically deselected if the user types more. So it won't affect anyone who isn't explicitly making use of M-/M-. So I suggest we should add a new defcustom to change the RET behavior in the presence of a selected completion candidate, and default it to t. From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 25 13:22:47 2025 Received: (at submit) by debbugs.gnu.org; 25 Mar 2025 17:22:47 +0000 Received: from localhost ([127.0.0.1]:39857 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tx7zC-0007sN-Ub for submit@debbugs.gnu.org; Tue, 25 Mar 2025 13:22:47 -0400 Received: from lists.gnu.org ([2001:470:142::17]:38064) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tx7yu-0007rG-91 for submit@debbugs.gnu.org; Tue, 25 Mar 2025 13:22:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tx7yU-0003F8-2O for bug-gnu-emacs@gnu.org; Tue, 25 Mar 2025 13:22:02 -0400 Received: from relay6-d.mail.gandi.net ([2001:4b98:dc4:8::226]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tx7yQ-0008Pa-9D for bug-gnu-emacs@gnu.org; Tue, 25 Mar 2025 13:22:00 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id A2D86442B0; Tue, 25 Mar 2025 17:21:52 +0000 (UTC) From: Juri Linkov To: Spencer Baugh Subject: Re: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: Organization: LINKOV.NET References: Date: Tue, 25 Mar 2025 19:19:38 +0200 Message-ID: <87jz8d6n9x.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieefvdefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepvddprhgtphhtthhopegsuhhgqdhgnhhuqdgvmhgrtghssehgnhhurdhorhhgpdhrtghpthhtohepshgsrghughhhsehjrghnvghsthhrvggvthdrtghomh X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=2001:4b98:dc4:8::226; envelope-from=juri@linkov.net; helo=relay6-d.mail.gandi.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: submit Cc: bug-gnu-emacs@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: -0.3 (/) > Right now, minibuffer-visible-completions does two things, only when > *Completions* is visible: > > A. If there's a selected completion candidate, RET exits the minibuffer > with it. > > B. The arrow keys move point in the *Completions* buffer instead of the > minibuffer, to select completion candidates. > > These are really two separate things. > > A is a nice behavior for novice users, but B is difficult for novice > users (who like to use the arrow keys for moving point) to deal with. Not sure why this would be difficult for novice users, but maybe adding a new value to the existing defcustom minibuffer-visible-completions would be sufficient? From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 25 13:25:18 2025 Received: (at 77253) by debbugs.gnu.org; 25 Mar 2025 17:25:18 +0000 Received: from localhost ([127.0.0.1]:39866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tx81d-00083C-Tv for submit@debbugs.gnu.org; Tue, 25 Mar 2025 13:25:18 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:54509) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tx81b-0007xe-IJ for 77253@debbugs.gnu.org; Tue, 25 Mar 2025 13:25:16 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: <87jz8d6n9x.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 25 Mar 2025 19:19:38 +0200") References: <87jz8d6n9x.fsf@mail.linkov.net> Date: Tue, 25 Mar 2025 13:25:09 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1742923510; bh=g7lVT5an1bwz1+cLQwI4TgdxPyjpWXrBmdCMEffhEeg=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=a8H+Q+Ge+ZCFgNvuNLujioAzFnmLIaejY9+l5MKV0HeGP+Sla1kddN7SsAvpJyKa1 KDbabr7uIUUNvHDfZzUgoa+5vlEfyub+eFgM5iiQEVCECF8aynKXPDvoStBuP/IO0A nqXoedhIKX+bejVBYKrxfgXjs1OVEzGfXJxzZguBxmQHPMPRfG0b6tsZDvdy2iNIUy uoAB5eKBtG3MBX8oF7bL7V1xXu7NrzCa+7WjL3Y7xafF6WxeQ7CnjS99ZWDLH+QTda YUotANgY7wgMGPaQT5g6YtVeoWBqlEXn/cRHetG6Q5AfzSb1RCHXvfNQ/Vs8qacvDs AD6Ej+kWOveuQ== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: 77253@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 (---) Juri Linkov writes: >> Right now, minibuffer-visible-completions does two things, only when >> *Completions* is visible: >> >> A. If there's a selected completion candidate, RET exits the minibuffer >> with it. >> >> B. The arrow keys move point in the *Completions* buffer instead of the >> minibuffer, to select completion candidates. >> >> These are really two separate things. >> >> A is a nice behavior for novice users, but B is difficult for novice >> users (who like to use the arrow keys for moving point) to deal with. > > Not sure why this would be difficult for novice users, Well, because they like using the arrow keys. :) > but maybe adding a new value to the existing defcustom > minibuffer-visible-completions would be sufficient? That would work, but I guess I also propose that we should change the implementation a bit. The use of a menu-item :filter binding is clever, but I think it would be nicer to have a normal binding for RET which just checks if *Completions* is shown/a completion candidate is selected. For one thing, then C-h k RET will behave more expectedly. From debbugs-submit-bounces@debbugs.gnu.org Wed Mar 26 03:53:32 2025 Received: (at 77253) by debbugs.gnu.org; 26 Mar 2025 07:53:32 +0000 Received: from localhost ([127.0.0.1]:41125 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1txLZs-00038p-Bd for submit@debbugs.gnu.org; Wed, 26 Mar 2025 03:53:32 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:51845) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1txLZo-00038V-Mo for 77253@debbugs.gnu.org; Wed, 26 Mar 2025 03:53:30 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 44421443D6; Wed, 26 Mar 2025 07:53:20 +0000 (UTC) From: Juri Linkov To: Spencer Baugh Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> Date: Wed, 26 Mar 2025 09:52:05 +0200 Message-ID: <87ldssz0t6.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieegleekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepvddprhgtphhtthhopeejjedvheefseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepshgsrghughhhsehjrghnvghsthhrvggvthdrtghomh X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: 77253@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: -1.7 (-) >>> Right now, minibuffer-visible-completions does two things, only when >>> *Completions* is visible: >>> >>> A. If there's a selected completion candidate, RET exits the minibuffer >>> with it. >>> >>> B. The arrow keys move point in the *Completions* buffer instead of the >>> minibuffer, to select completion candidates. >>> >>> These are really two separate things. >>> >>> A is a nice behavior for novice users, but B is difficult for novice >>> users (who like to use the arrow keys for moving point) to deal with. >> >> Not sure why this would be difficult for novice users, > > Well, because they like using the arrow keys. :) But they like using the arrow keys to select a completion candidate too. This is how they use arrow keys e.g. in a web browser in the address bar. At least up/down arrows navigate completions, while left/right arrows indeed move the cursor in the address bar. So we need separate values for up/down and left/right arrows? >> but maybe adding a new value to the existing defcustom >> minibuffer-visible-completions would be sufficient? > > That would work, but I guess I also propose that we should change the > implementation a bit. The use of a menu-item :filter binding is clever, > but I think it would be nicer to have a normal binding for RET which > just checks if *Completions* is shown/a completion candidate is > selected. For one thing, then C-h k RET will behave more expectedly. Removing the :filter binding would be fine, if it won't cause other problems. At least it would be nice to try to see how this works with :filter. From debbugs-submit-bounces@debbugs.gnu.org Wed Mar 26 10:06:34 2025 Received: (at 77253) by debbugs.gnu.org; 26 Mar 2025 14:06:34 +0000 Received: from localhost ([127.0.0.1]:43761 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1txROs-0006Hr-1s for submit@debbugs.gnu.org; Wed, 26 Mar 2025 10:06:34 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:51397) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1txROk-0006HR-TQ for 77253@debbugs.gnu.org; Wed, 26 Mar 2025 10:06:28 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: <87ldssz0t6.fsf@mail.linkov.net> (Juri Linkov's message of "Wed, 26 Mar 2025 09:52:05 +0200") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> Date: Wed, 26 Mar 2025 10:06:20 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1742997980; bh=O+PbwiKq83U1OKzlNZxjF8JN6p/YIb18+v4A5zwnUgM=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=M9eWJ+Fqt2RVSjD/C4igeuGbd2Oixuflbx5zvkQxKaYZrBmPmuTIdP7rj4Kbu76L2 vb3mLyUYbLSSaasc+m4vtxw2FkMx52+iM32ZK8M2u8jX6Gbr3jNv1RfNbtUkTZCUJb BQuHtUrwMFG5nEsk/USKb+wneOlBYRuclUUNfQ2zGRFSpVfbHQzXVa3CCaIj160DFi CQMZYfZE1b4lb5JT7MQnrpeyO2dFVkru++kVKZXNaaXNYKnPvRGbE0ZHJdDPYXSsbu OkkAe33yBgDldB6BcnwQcXITjuCKlqEvoH5Ld1QrHCAnGyTkfdwRevzzDI5EwL4nxS 1Xs+aHR2/zcYg== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: 77253@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 (---) Juri Linkov writes: >>>> Right now, minibuffer-visible-completions does two things, only when >>>> *Completions* is visible: >>>> >>>> A. If there's a selected completion candidate, RET exits the minibuffer >>>> with it. >>>> >>>> B. The arrow keys move point in the *Completions* buffer instead of the >>>> minibuffer, to select completion candidates. >>>> >>>> These are really two separate things. >>>> >>>> A is a nice behavior for novice users, but B is difficult for novice >>>> users (who like to use the arrow keys for moving point) to deal with. >>> >>> Not sure why this would be difficult for novice users, >> >> Well, because they like using the arrow keys. :) > > But they like using the arrow keys to select a completion candidate too. > This is how they use arrow keys e.g. in a web browser in the address bar. > At least up/down arrows navigate completions, while left/right arrows > indeed move the cursor in the address bar. That is true. > So we need separate values for up/down and left/right arrows? That would probably be good, yes. But, here's another factor: The *Completions* buffer by default contains a help message explaining to users that they can use M- and M- to select completions. There's no such message explaining to users that they can use C-b/C-f/C-n/C-p to move point. So: - If the arrow keys move point, users can still figure out how to select completions by reading the help text. - If the arrow keys select completions, users who don't know C-b/C-f/C-n/C-p are basically helpless. (This is sadly common at my site, because most of our users use evil-mode and don't know C-b/C-f/C-n/C-p) Also, rebinding the arrow keys by default to select completions is probably an unacceptable behavior change. But it's very possible to rebind RET to accept completions by default. So even if we disregard the "novice user" argument, I still think we should investigate binding RET without rebinding the arrow keys. >>> but maybe adding a new value to the existing defcustom >>> minibuffer-visible-completions would be sufficient? >> >> That would work, but I guess I also propose that we should change the >> implementation a bit. The use of a menu-item :filter binding is clever, >> but I think it would be nicer to have a normal binding for RET which >> just checks if *Completions* is shown/a completion candidate is >> selected. For one thing, then C-h k RET will behave more expectedly. > > Removing the :filter binding would be fine, if it won't cause other problems. > At least it would be nice to try to see how this works with :filter. I'm curious: Why do you prefer the :filter approach? Does it avoid some problems that happened in the past? It makes sense for the arrow keys, but if we are rebinding RET by default, :filter seems like an unusual thing to use. From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 27 14:00:35 2025 Received: (at 77253) by debbugs.gnu.org; 27 Mar 2025 18:00:35 +0000 Received: from localhost ([127.0.0.1]:51254 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1txrWs-0006kA-MW for submit@debbugs.gnu.org; Thu, 27 Mar 2025 14:00:35 -0400 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:59499) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1txrWY-0006eP-TS for 77253@debbugs.gnu.org; Thu, 27 Mar 2025 14:00:15 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 4CF05441B4; Thu, 27 Mar 2025 18:00:06 +0000 (UTC) From: Juri Linkov To: Spencer Baugh Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> Date: Thu, 27 Mar 2025 19:50:13 +0200 Message-ID: <87r02iuzni.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeltdejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepvddprhgtphhtthhopeejjedvheefseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepshgsrghughhhsehjrghnvghsthhrvggvthdrtghomh X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: 77253@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: -1.7 (-) > But, here's another factor: The *Completions* buffer by default contains > a help message explaining to users that they can use M- and M- > to select completions. There's no such message explaining to users that > they can use C-b/C-f/C-n/C-p to move point. So: > > - If the arrow keys move point, users can still figure out how to select > completions by reading the help text. > > - If the arrow keys select completions, users who don't know > C-b/C-f/C-n/C-p are basically helpless. (This is sadly common at my > site, because most of our users use evil-mode and don't know > C-b/C-f/C-n/C-p) When users need to move point with arrow keys, then they have to close the completions window. This is the purpose of 'minibuffer-visible-completions': to eliminate ambiguity whether arrows/RET apply to the visible completions window, or to the text in the minibuffer. > Also, rebinding the arrow keys by default to select completions is > probably an unacceptable behavior change. But it's very possible to > rebind RET to accept completions by default. So even if we disregard > the "novice user" argument, I still think we should investigate binding > RET without rebinding the arrow keys. Not sure if it's possible for RET to accept the selected candidate by default since users might prefer to accept text in the minibuffer. > I'm curious: Why do you prefer the :filter approach? Does it avoid some > problems that happened in the past? It makes sense for the arrow keys, > but if we are rebinding RET by default, :filter seems like an unusual > thing to use. :filter makes it easier to add conditional keybindings that share the same condition. I doubt if it would be possible to rebind RET by default. But need to try to see how it works. From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 27 16:42:38 2025 Received: (at 77253) by debbugs.gnu.org; 27 Mar 2025 20:42:38 +0000 Received: from localhost ([127.0.0.1]:51553 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1txu3i-0001dv-0u for submit@debbugs.gnu.org; Thu, 27 Mar 2025 16:42:38 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:49263) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1txu3f-0001df-TB for 77253@debbugs.gnu.org; Thu, 27 Mar 2025 16:42:36 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: <87r02iuzni.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 27 Mar 2025 19:50:13 +0200") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> Date: Thu, 27 Mar 2025 16:42:29 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1743108150; bh=fiZpxrYqvnjHmKJU46meSyUYMr+6BD/2w8j9hT6JKBQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=wr+dNUmOPhyfG3arHDtVR2Fkx8swYz7sU6DovPxp7QiEFb8/BvHr/s0yjg00BY/PH huJcc9jmN+F7NqwCE48IUk2X5LUpiinxXGYbXPaRrJ9g9tVqHNuexaYfW91aRUhpM8 cOVDO+xfWi/QO78HfMFSxeTTeTJTZ7wO5RO0oesXDeCsqUHB4ZjzRbFvuaTNpioLab bbI06m/9PxvrRRtl07bLsSGtYw9/1klmo7iuksKDu/s95RWKfo4XFSzpMMiVbEntEF DtG4e22ZV8t1Fa4L9/zUxtdV8tvGDZXU5LTAxedto1IeA6xuApOlqdpTNXbhphVscq QiWI4idTv1XyA== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: 77253@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 (---) Juri Linkov writes: >> But, here's another factor: The *Completions* buffer by default contains >> a help message explaining to users that they can use M- and M- >> to select completions. There's no such message explaining to users that >> they can use C-b/C-f/C-n/C-p to move point. So: >> >> - If the arrow keys move point, users can still figure out how to select >> completions by reading the help text. >> >> - If the arrow keys select completions, users who don't know >> C-b/C-f/C-n/C-p are basically helpless. (This is sadly common at my >> site, because most of our users use evil-mode and don't know >> C-b/C-f/C-n/C-p) > > When users need to move point with arrow keys, then they have > to close the completions window. This is the purpose of > 'minibuffer-visible-completions': to eliminate ambiguity > whether arrows/RET apply to the visible completions window, > or to the text in the minibuffer. Yes, and I'm definitely a fan of minibuffer-visible-completions, but just to name a few problems: - It's not necessarily obvious that closing the completions window will make the arrow keys operate in the minibuffer. Actually, maybe we should update the completion help text to say that? That might help a lot. - The new completion-eager-display makes *Completions* pop up immediately; when this happens, it can be surprising that the arrow keys don't work in the minibuffer from the very start of the minibuffer session. But again, I like minibuffer-visible-completions a lot, I'm just wondering about other points in the design space. >> Also, rebinding the arrow keys by default to select completions is >> probably an unacceptable behavior change. But it's very possible to >> rebind RET to accept completions by default. So even if we disregard >> the "novice user" argument, I still think we should investigate binding >> RET without rebinding the arrow keys. > > Not sure if it's possible for RET to accept the selected candidate > by default since users might prefer to accept text in the minibuffer. If there's a selected candidate, though, then users have already decided to use M-/M- to interact with completions. (Or they've switched to the completions buffer and selected one) If they decide they don't want the candidate they selected, and want to continue with text in the minibuffer, completion-auto-deselect will automatically deselect the candidate if they type anything. I think these two facts combined make it possible for RET to accept the selected candidate by default. >> I'm curious: Why do you prefer the :filter approach? Does it avoid some >> problems that happened in the past? It makes sense for the arrow keys, >> but if we are rebinding RET by default, :filter seems like an unusual >> thing to use. > > :filter makes it easier to add conditional keybindings that share > the same condition. I doubt if it would be possible to rebind RET > by default. But need to try to see how it works. Makes sense. I'll try. From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 28 03:32:29 2025 Received: (at 77253) by debbugs.gnu.org; 28 Mar 2025 07:32:29 +0000 Received: from localhost ([127.0.0.1]:52613 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ty4Ca-0002Jl-Ob for submit@debbugs.gnu.org; Fri, 28 Mar 2025 03:32:29 -0400 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:40979) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ty4CY-0002JS-CZ for 77253@debbugs.gnu.org; Fri, 28 Mar 2025 03:32:27 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id DBEBA442A7; Fri, 28 Mar 2025 07:32:16 +0000 (UTC) From: Juri Linkov To: Spencer Baugh Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> Date: Fri, 28 Mar 2025 09:20:43 +0200 Message-ID: <87ecyhskhg.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddujedtjedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepvddprhgtphhtthhopeejjedvheefseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepshgsrghughhhsehjrghnvghsthhrvggvthdrtghomh X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: 77253@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: -1.7 (-) > - It's not necessarily obvious that closing the completions window will > make the arrow keys operate in the minibuffer. Actually, maybe we > should update the completion help text to say that? That might help a > lot. Maybe it's possible to squeeze this help text just into one additional line? Something like: Type 'C-g' to close this window and restore arrows to move point. > - The new completion-eager-display makes *Completions* pop up > immediately; when this happens, it can be surprising that the arrow > keys don't work in the minibuffer from the very start of the > minibuffer session. Then another possible value for 'minibuffer-visible-completions' would be to not rebind left/right arrows when the completions window contains only one column (like on the browser's address bar). >> Not sure if it's possible for RET to accept the selected candidate >> by default since users might prefer to accept text in the minibuffer. > > If there's a selected candidate, though, then users have already decided > to use M-/M- to interact with completions. (Or they've > switched to the completions buffer and selected one) > > If they decide they don't want the candidate they selected, and want to > continue with text in the minibuffer, completion-auto-deselect will > automatically deselect the candidate if they type anything. > > I think these two facts combined make it possible for RET to accept the > selected candidate by default. Makes sense. So we need to try how well it performs. From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 03 13:52:53 2025 Received: (at 77253) by debbugs.gnu.org; 3 Apr 2025 17:52:53 +0000 Received: from localhost ([127.0.0.1]:35562 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u0OkG-00015S-Cs for submit@debbugs.gnu.org; Thu, 03 Apr 2025 13:52:52 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:36595) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u0OkD-00015D-My for 77253@debbugs.gnu.org; Thu, 03 Apr 2025 13:52:50 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: <87ecyhskhg.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 28 Mar 2025 09:20:43 +0200") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> Date: Thu, 03 Apr 2025 13:52:44 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1743702764; bh=IwG+066TPCnGbIUj5oVYvwIL/r5ZEzyjdSnmXWkZkuY=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=kC7d2EFaJb62T+I+bgpktH+Eupa0TerdLgTzfQbDsDZOjmVLTcou1uZuG40xdWnjT xbV/XucWw0SH43droahnud914ELprjVtxm9gX7y2TE9qIvclTTV/T0AOf1kVbzw+cT cjGiIR74jORMfAR9QyeiJXLSYjeRPDhgv662rqBnNcoZE+kn25AYO5kwVOSNT80VsE M4iISCKIlP/UstE6UQ3nikfk+ME0fAq92iJqJCdzuK0mNdY5EInohXmQJsGf7c5km4 3ljJQ2rn6b5eUnzVqZsr365jQTEzKsQ8We64rrP2lHMopCVna5zSgUuKtCH5kFsRBN EBVVxWuUr/opg== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: 77253@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 (---) Juri Linkov writes: >> - It's not necessarily obvious that closing the completions window will >> make the arrow keys operate in the minibuffer. Actually, maybe we >> should update the completion help text to say that? That might help a >> lot. > > Maybe it's possible to squeeze this help text just into one additional line? > Something like: > > Type 'C-g' to close this window and restore arrows to move point. Maybe we don't even need an additional line? How about: Click or type RET on a completion to select it, or C-g to close this window. Type , , , to move point between completions. >> - The new completion-eager-display makes *Completions* pop up >> immediately; when this happens, it can be surprising that the arrow >> keys don't work in the minibuffer from the very start of the >> minibuffer session. > > Then another possible value for 'minibuffer-visible-completions' > would be to not rebind left/right arrows when the completions window > contains only one column (like on the browser's address bar). True. Though I guess that could maybe be the default behavior when completions-format=one-column. >>> Not sure if it's possible for RET to accept the selected candidate >>> by default since users might prefer to accept text in the minibuffer. >> >> If there's a selected candidate, though, then users have already decided >> to use M-/M- to interact with completions. (Or they've >> switched to the completions buffer and selected one) >> >> If they decide they don't want the candidate they selected, and want to >> continue with text in the minibuffer, completion-auto-deselect will >> automatically deselect the candidate if they type anything. >> >> I think these two facts combined make it possible for RET to accept the >> selected candidate by default. > > Makes sense. So we need to try how well it performs. How about this? (BTW, after writing minibuffer--completions-visible, I'm wondering if most of the code which calls (get-buffer-window "*Completions*" 0) is actually buggy, because it's not checking completion-reference-buffer. Should we replace ~all the calls to (get-buffer-window "*Completions*" 0) with (minibuffer--completions-visible) which does check that?) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 404fa143194..c026e41a818 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3209,6 +3209,12 @@ completion-help-at-point (define-key map "\n" 'exit-minibuffer) (define-key map "\r" 'exit-minibuffer)) +(defun minibuffer-choose-completion-just-exit (&optional no-exit) + "Choose the selected completion from the minibuffer or call `exit-minibuffer'." + (interactive "P") + (or (minibuffer-choose-completion-if-selected no-exit) + (minibuffer-exit))) + (defvar-keymap minibuffer-local-completion-map :doc "Local keymap for minibuffer input with completion." :parent minibuffer-local-map @@ -3218,6 +3224,7 @@ minibuffer-local-completion-map ;; another binding for it. ;; "M-TAB" #'minibuffer-force-complete "SPC" #'minibuffer-complete-word + "RET" #'minibuffer-choose-completion-just-exit "?" #'minibuffer-completion-help "" #'switch-to-completions "M-v" #'switch-to-completions @@ -3229,7 +3236,7 @@ minibuffer-local-completion-map (defvar-keymap minibuffer-local-must-match-map :doc "Local keymap for minibuffer input with completion, for exact match." :parent minibuffer-local-completion-map - "RET" #'minibuffer-complete-and-exit + "RET" #'minibuffer-choose-completion-or-exit "C-j" #'minibuffer-complete-and-exit) (defvar-keymap minibuffer-local-filename-completion-map @@ -3326,18 +3333,34 @@ minibuffer-visible-completions (defvar minibuffer-visible-completions--always-bind nil "If non-nil, force the `minibuffer-visible-completions' bindings on.") +(defun minibuffer--completions-visible () + "Return the window where the *Completions* buffer for this minibuffer is visible." + (when-let ((window (get-buffer-window "*Completions*" 0))) + (when (eq (buffer-local-value 'completion-reference-buffer + (window-buffer window)) + (window-buffer (active-minibuffer-window))) + window))) + +(defun minibuffer-choose-completion-if-selected (&optional no-exit no-quit) + "Like `minibuffer-choose-completion', but do nothing if no candidate is selected. + +Return non-nil if a completion was chosen." + (when-let* ((window (minibuffer--completions-visible))) + (with-selected-window window + ;; Detect selection as if `choose-completion-deselect-if-after' is nil. + (when (get-text-property (point) 'completion--string) + (choose-completion nil no-exit no-quit) + t)))) + (defun minibuffer-visible-completions--filter (cmd) "Return CMD if `minibuffer-visible-completions' bindings should be active." (if minibuffer-visible-completions--always-bind cmd - (when-let ((window (get-buffer-window "*Completions*" 0))) - (when (and (eq (buffer-local-value 'completion-reference-buffer - (window-buffer window)) - (window-buffer (active-minibuffer-window))) - (if (eq cmd #'minibuffer-choose-completion-or-exit) - (with-current-buffer (window-buffer window) - (get-text-property (point) 'completion--string)) - t)) + (when-let ((window (minibuffer--completions-visible))) + (when (if (eq cmd #'minibuffer-choose-completion-or-exit) + (with-current-buffer (window-buffer window) + (get-text-property (point) 'completion--string)) + t) cmd)))) (defun minibuffer-visible-completions--bind (binding) @@ -5109,10 +5132,8 @@ minibuffer-choose-completion-or-exit in the completions window, then exit the minibuffer using its present contents." (interactive "P") - (condition-case nil - (let ((choose-completion-deselect-if-after t)) - (minibuffer-choose-completion no-exit no-quit)) - (error (minibuffer-complete-and-exit)))) + (or (minibuffer-choose-completion-if-selected no-exit no-quit) + (minibuffer-complete-and-exit))) (defun minibuffer-complete-history () "Complete as far as possible using the minibuffer history. From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 03 14:29:00 2025 Received: (at 77253) by debbugs.gnu.org; 3 Apr 2025 18:29:00 +0000 Received: from localhost ([127.0.0.1]:35642 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u0PJD-0002lA-PB for submit@debbugs.gnu.org; Thu, 03 Apr 2025 14:29:00 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:41511) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u0PJA-0002kv-Vg for 77253@debbugs.gnu.org; Thu, 03 Apr 2025 14:28:57 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id D14E8433EB; Thu, 3 Apr 2025 18:28:44 +0000 (UTC) From: Juri Linkov To: Spencer Baugh Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> Date: Thu, 03 Apr 2025 21:19:16 +0300 Message-ID: <87a58x3y6z.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddukeelvdekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepvddprhgtphhtthhopeejjedvheefseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepshgsrghughhhsehjrghnvghsthhrvggvthdrtghomh X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: 77253@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: -1.7 (-) >>> - It's not necessarily obvious that closing the completions window will >>> make the arrow keys operate in the minibuffer. Actually, maybe we >>> should update the completion help text to say that? That might help a >>> lot. >> >> Maybe it's possible to squeeze this help text just into one additional line? >> Something like: >> >> Type 'C-g' to close this window and restore arrows to move point. > > Maybe we don't even need an additional line? How about: > > Click or type RET on a completion to select it, or C-g to close this window. > Type , , , to move point between completions. Looks good. >>> - The new completion-eager-display makes *Completions* pop up >>> immediately; when this happens, it can be surprising that the arrow >>> keys don't work in the minibuffer from the very start of the >>> minibuffer session. >> >> Then another possible value for 'minibuffer-visible-completions' >> would be to not rebind left/right arrows when the completions window >> contains only one column (like on the browser's address bar). > > True. Though I guess that could maybe be the default behavior when > completions-format=one-column. Agreed. >>>> Not sure if it's possible for RET to accept the selected candidate >>>> by default since users might prefer to accept text in the minibuffer. >>> >>> If there's a selected candidate, though, then users have already decided >>> to use M-/M- to interact with completions. (Or they've >>> switched to the completions buffer and selected one) >>> >>> If they decide they don't want the candidate they selected, and want to >>> continue with text in the minibuffer, completion-auto-deselect will >>> automatically deselect the candidate if they type anything. >>> >>> I think these two facts combined make it possible for RET to accept the >>> selected candidate by default. >> >> Makes sense. So we need to try how well it performs. > > How about this? Thanks, will try to use for a while. > (BTW, after writing minibuffer--completions-visible, I'm wondering if > most of the code which calls (get-buffer-window "*Completions*" 0) is > actually buggy, because it's not checking completion-reference-buffer. > Should we replace ~all the calls to (get-buffer-window "*Completions*" > 0) with (minibuffer--completions-visible) which does check that?) Looks right, for example for the case of recursive minibuffers. > + (minibuffer-exit))) Typo: 'exit-minibuffer'. From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 17 16:34:34 2025 Received: (at 77253) by debbugs.gnu.org; 17 Jul 2025 20:34:34 +0000 Received: from localhost ([127.0.0.1]:57209 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ucVJJ-00042O-Vw for submit@debbugs.gnu.org; Thu, 17 Jul 2025 16:34:34 -0400 Received: from s.wrqvqsbb.outbound-mail.sendgrid.net ([149.72.70.187]:39808) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1ucVJG-00041l-TK for 77253@debbugs.gnu.org; Thu, 17 Jul 2025 16:34:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catern.com; h=from:subject:in-reply-to:references:date:mime-version:to:cc: content-type:content-transfer-encoding:cc:content-type:date:from:subject:to; s=s1; bh=GCi/ko2iWP56bWXf/f+EdH12W2PPsTzbmCk7wl5qdzQ=; b=tvMeb3pLnS/ZVrAg3WafGW8mp0f2z+Zpw9LwFX6m+ewLrMzUnWwR/lRvuEpaEH2cNO3I ZXxEwVnSOscFwT8t4+C1aAijJWnDohey1wj/vzvKMGmQsN2JTeTuet6AUjKjyJ8eJPzXO8 Y7dqW6ykws2MHNhgtEdS3xrTgNyCIlXL2iZsvwswKWeHaYbNyJIgUsLg54WuuqD+DtHRqZ 2UnxOLDJcYRxuVsl2q2OZLz8iHr7cS2np3NydfrEcfdXCnUHfBYk1xnR7VD1XQTvO6Au0S G1JkFpzqHcPireR9C/mw5ufdDmpou2ncfm/j9FIhxOnpf06Xwy7gX9qGyhP1QqJQ== Received: by recvd-canary-c75fff999-2czjn with SMTP id recvd-canary-c75fff999-2czjn-1-68795E50-27 2025-07-17 20:34:24.716406851 +0000 UTC m=+2579304.480397118 Received: from earth.catern.com (unknown) by geopod-ismtpd-51 (SG) with ESMTP id pL2XetTWQ4qYkFVp8oaQHA Thu, 17 Jul 2025 20:34:24.660 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by earth.catern.com (Postfix) with ESMTPSA id 459B462512; Thu, 17 Jul 2025 16:34:24 -0400 (EDT) From: sbaugh@catern.com Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: <87a58x3y6z.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 03 Apr 2025 21:19:16 +0300") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> Date: Thu, 17 Jul 2025 20:34:24 +0000 (UTC) Message-ID: <87freuzhdb.fsf@catern.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-SG-EID: =?us-ascii?Q?u001=2Ev6RTqHFpv1T6krEot6UFAVAJmQ+4h1t8=2FTfqqE2B07O5pjZyshpQqjJCf?= =?us-ascii?Q?m=2FDHzc6vdjhU=2FSNdfnagwU9bU3JQyvUQq5aK94U?= =?us-ascii?Q?LxAOU=2F5=2F=2FaaNRY4gqNRfHcoSlMAM9dtcsTL=2FSgx?= =?us-ascii?Q?UyfqwoDczzZuw3cs8pA3hxs4R6yzKiUd39nCG0o?= =?us-ascii?Q?rUMp1hCMHOqgbppDrCwAEnutvtbaOg=2FXwKWF6C1?= =?us-ascii?Q?w=3D=3D?= To: Juri Linkov X-Entity-ID: u001.oW4JupFKOzCccZAQN2OOFQ== Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 77253 Cc: Spencer Baugh , 77253@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: -1.0 (-) Juri Linkov writes: >>>>> Not sure if it's possible for RET to accept the selected candidate >>>>> by default since users might prefer to accept text in the minibuffer. >>>> >>>> If there's a selected candidate, though, then users have already decided >>>> to use M-/M- to interact with completions. (Or they've >>>> switched to the completions buffer and selected one) >>>> >>>> If they decide they don't want the candidate they selected, and want to >>>> continue with text in the minibuffer, completion-auto-deselect will >>>> automatically deselect the candidate if they type anything. >>>> >>>> I think these two facts combined make it possible for RET to accept the >>>> selected candidate by default. >>> >>> Makes sense. So we need to try how well it performs. >> >> How about this? > > Thanks, will try to use for a while. Any feedback on the patch? From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 18 02:51:37 2025 Received: (at 77253) by debbugs.gnu.org; 18 Jul 2025 06:51:37 +0000 Received: from localhost ([127.0.0.1]:59948 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ucewP-0007nC-0l for submit@debbugs.gnu.org; Fri, 18 Jul 2025 02:51:37 -0400 Received: from mout-y-111.mailbox.org ([91.198.250.236]:41400) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ucewK-0007mF-7o for 77253@debbugs.gnu.org; Fri, 18 Jul 2025 02:51:29 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-y-111.mailbox.org (Postfix) with ESMTPS id 4bk0nL2q7Zz9ygr; Fri, 18 Jul 2025 08:51:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1752821478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lVYJ5k1HK+qSGlkVZvtvUB+xQ4nH+N/vI72Y5xex6mg=; b=h1x7LxQ9c7MSM7Q3T6SgjAvwtFNRYpNrU87zJnLIO4AcpbEdOd5cTJF1RwcNV+LB0Py1n2 rXNOHpOPW4IqkPGSHDIOyjqjSb+7eg9yMRT/k/m3wcQiBaQdrP4237qGbIZrlTJsciyObe v4CNCxXsEv5l/TwiiRjG2XqTzeFY2WYhLJG81BxtJmx2ErQXky90QQBKDNi1ryZz7K5ymG fwXlZsz2YUfkbywTXsp6JoNtVx4O7CGHQNB6STrqcZxtB50NewgWfePI+OqjJrwGcuoNth OENQwmQClI+TJjFncHH5PLiNlyYq0uuLRqVLnWpLEreGGe7Qx4qFS4OjcoDTeg== From: Juri Linkov To: sbaugh@catern.com Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: <87freuzhdb.fsf@catern.com> Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> Date: Fri, 18 Jul 2025 09:38:33 +0300 Message-ID: <87h5zavwru.fsf@mail.linkov.net> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: Spencer Baugh , 77253@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: -1.7 (-) >>>>>> Not sure if it's possible for RET to accept the selected candidate >>>>>> by default since users might prefer to accept text in the minibuffer. >>>>> >>>>> If there's a selected candidate, though, then users have already decided >>>>> to use M-/M- to interact with completions. (Or they've >>>>> switched to the completions buffer and selected one) >>>>> >>>>> If they decide they don't want the candidate they selected, and want to >>>>> continue with text in the minibuffer, completion-auto-deselect will >>>>> automatically deselect the candidate if they type anything. >>>>> >>>>> I think these two facts combined make it possible for RET to accept the >>>>> selected candidate by default. >>>> >>>> Makes sense. So we need to try how well it performs. >>> >>> How about this? >> >> Thanks, will try to use for a while. > > Any feedback on the patch? Everything looks good. Could you send the final version of the patch? From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 21 12:24:28 2025 Received: (at 77253) by debbugs.gnu.org; 21 Jul 2025 16:24:28 +0000 Received: from localhost ([127.0.0.1]:58581 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1udtJT-0004YM-RF for submit@debbugs.gnu.org; Mon, 21 Jul 2025 12:24:28 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:42293) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1udtJR-0004Xt-Cj for 77253@debbugs.gnu.org; Mon, 21 Jul 2025 12:24:26 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: <87h5zavwru.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 18 Jul 2025 09:38:33 +0300") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> Date: Mon, 21 Jul 2025 12:24:19 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1753115059; bh=Iancq068tNIEY0VQaBPPNpm0IOMz9ni8pdJTyXmkAho=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=ji3R7NRywgpRasYARkNqV6hI0sB7gFEt+zVP07JrmlxaTI8tf5Qs4QW4K5t8ybhmv +DRxsHE1WMBpEMwZSzNFk9Agob5t292hyHmaiOycE1NN/cLE0w9k5ZaNOrJ7pDl5Dt N+YW5OVXM5PuY2UHdSxlZIQl1+g6rcW+xwqw1cfy7JbYhLnVylXCc2HOkOAFMLe6P0 UWJ9A4q9sgLw24EVzUZOL8bSSNNepqYPB8QwJVgqDY7776iqrzvvDZBsmAjbIwZvHg kesC4vEqxxYdH9a8xltg3bmTPZatDfeRckuNUHQnK7BqyMwd498Vqkqb4HL2ntsi2M eOg/GJkynGLfA== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: sbaugh@catern.com, 77253@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 (---) --=-=-= Content-Type: text/plain Juri Linkov writes: >>>>>>> Not sure if it's possible for RET to accept the selected candidate >>>>>>> by default since users might prefer to accept text in the minibuffer. >>>>>> >>>>>> If there's a selected candidate, though, then users have already decided >>>>>> to use M-/M- to interact with completions. (Or they've >>>>>> switched to the completions buffer and selected one) >>>>>> >>>>>> If they decide they don't want the candidate they selected, and want to >>>>>> continue with text in the minibuffer, completion-auto-deselect will >>>>>> automatically deselect the candidate if they type anything. >>>>>> >>>>>> I think these two facts combined make it possible for RET to accept the >>>>>> selected candidate by default. >>>>> >>>>> Makes sense. So we need to try how well it performs. >>>> >>>> How about this? >>> >>> Thanks, will try to use for a while. >> >> Any feedback on the patch? > > Everything looks good. Could you send the final version of the patch? Yes, attached. (Note that this doesn't do the change I mentioned earlier of replacing (get-buffer-window "*Completions*" 0) everywhere with minibuffer--completions-visible, which probably should be done in a separate patch, I can send that if you're up to install it now) --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Make-RET-in-minibuffer-choose-selected-completion.patch >From df5c9ffe4669bd8417bb5ae3d631723e21e70d68 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Mon, 21 Jul 2025 12:22:19 -0400 Subject: [PATCH] Make RET in minibuffer choose selected completion Previously, one could select a completion via M-/M-, but then RET would not actually select the chosen completion. With the addition of completion-auto-deselect, this is not actually necessary: we can reasonably assume that when a completion is selected, the user wants to use that, since their last action must have been to select it. So, just choose the selected completion on RET. * lisp/minibuffer.el (minibuffer--completions-visible) (minibuffer-choose-completion-if-selected): Add. (minibuffer-choose-completion-or-exit): Use the more reliable minibuffer-choose-completion-if-selected instead of a condition-case. (minibuffer-local-must-match-map): Bind RET to minibuffer-choose-completion-or-exit instead of minibuffer-complete-and-exit. (bug#77253) (minibuffer-choose-completion-just-exit): Add. (minibuffer-local-completion-map): Bind RET to minibuffer-choose-completion-just-exit instead of exit-minibuffer. (minibuffer-visible-completions--filter): Use minibuffer--completions-visible. --- lisp/minibuffer.el | 47 +++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 64e3ad53b42..7a7f6aae44b 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3232,6 +3232,12 @@ completion-help-at-point (define-key map "\n" 'exit-minibuffer) (define-key map "\r" 'exit-minibuffer)) +(defun minibuffer-choose-completion-just-exit (&optional no-exit) + "Choose the selected completion from the minibuffer or call `exit-minibuffer'." + (interactive "P") + (or (minibuffer-choose-completion-if-selected no-exit) + (exit-minibuffer))) + (defvar-keymap minibuffer-local-completion-map :doc "Local keymap for minibuffer input with completion." :parent minibuffer-local-map @@ -3241,6 +3247,7 @@ minibuffer-local-completion-map ;; another binding for it. ;; "M-TAB" #'minibuffer-force-complete "SPC" #'minibuffer-complete-word + "RET" #'minibuffer-choose-completion-just-exit "?" #'minibuffer-completion-help "" #'switch-to-completions "M-v" #'switch-to-completions @@ -3252,7 +3259,7 @@ minibuffer-local-completion-map (defvar-keymap minibuffer-local-must-match-map :doc "Local keymap for minibuffer input with completion, for exact match." :parent minibuffer-local-completion-map - "RET" #'minibuffer-complete-and-exit + "RET" #'minibuffer-choose-completion-or-exit "C-j" #'minibuffer-complete-and-exit) (defvar-keymap minibuffer-local-filename-completion-map @@ -3349,18 +3356,34 @@ minibuffer-visible-completions (defvar minibuffer-visible-completions--always-bind nil "If non-nil, force the `minibuffer-visible-completions' bindings on.") +(defun minibuffer--completions-visible () + "Return the window where the *Completions* buffer for this minibuffer is visible." + (when-let ((window (get-buffer-window "*Completions*" 0))) + (when (eq (buffer-local-value 'completion-reference-buffer + (window-buffer window)) + (window-buffer (active-minibuffer-window))) + window))) + +(defun minibuffer-choose-completion-if-selected (&optional no-exit no-quit) + "Like `minibuffer-choose-completion', but do nothing if no candidate is selected. + +Return non-nil if a completion was chosen." + (when-let* ((window (minibuffer--completions-visible))) + (with-selected-window window + ;; Detect selection as if `choose-completion-deselect-if-after' is non-nil. + (when (get-text-property (point) 'completion--string) + (choose-completion nil no-exit no-quit) + t)))) + (defun minibuffer-visible-completions--filter (cmd) "Return CMD if `minibuffer-visible-completions' bindings should be active." (if minibuffer-visible-completions--always-bind cmd - (when-let ((window (get-buffer-window "*Completions*" 0))) - (when (and (eq (buffer-local-value 'completion-reference-buffer - (window-buffer window)) - (window-buffer (active-minibuffer-window))) - (if (eq cmd #'minibuffer-choose-completion-or-exit) - (with-current-buffer (window-buffer window) - (get-text-property (point) 'completion--string)) - t)) + (when-let ((window (minibuffer--completions-visible))) + (when (if (eq cmd #'minibuffer-choose-completion-or-exit) + (with-current-buffer (window-buffer window) + (get-text-property (point) 'completion--string)) + t) cmd)))) (defun minibuffer-visible-completions--bind (binding) @@ -5211,10 +5234,8 @@ minibuffer-choose-completion-or-exit in the completions window, then exit the minibuffer using its present contents." (interactive "P") - (condition-case nil - (let ((choose-completion-deselect-if-after t)) - (minibuffer-choose-completion no-exit no-quit)) - (error (minibuffer-complete-and-exit)))) + (or (minibuffer-choose-completion-if-selected no-exit no-quit) + (minibuffer-complete-and-exit))) (defun minibuffer-complete-history () "Complete as far as possible using the minibuffer history. -- 2.39.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 21 12:26:41 2025 Received: (at 77253) by debbugs.gnu.org; 21 Jul 2025 16:26:41 +0000 Received: from localhost ([127.0.0.1]:58609 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1udtLc-0004nT-Sm for submit@debbugs.gnu.org; Mon, 21 Jul 2025 12:26:41 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:36699) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1udtLa-0004n3-8W for 77253@debbugs.gnu.org; Mon, 21 Jul 2025 12:26:38 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys, [PATCH] Make RET in minibuffer choose selected completion In-Reply-To: (Spencer Baugh's message of "Mon, 21 Jul 2025 12:24:19 -0400") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> Date: Mon, 21 Jul 2025 12:26:32 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1753115192; bh=NXC/wMbbxNFZ97on/cHlEnx7ITONTVQrvAsmWFJBxbg=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=DRXnRAE2400kP5yZ+6lD9eig2nIKAFqelbVKybJzm+fsjmDdD++Ob8byBiYC8EXem OPSzDThhARnQ0pm1DMvcQswp4fRL6nJb8hKIyeuSGPIJx+ZUcFjtrQoTFTwIWll2GH IQod/GUgZDbOpZIU7puJpA3LIBKSitO4gc7mMYvW77NIeNdGEKuo8h/mHwD4HC42dd ErGXVfKhFB6NYqliMojzQFQkN9388P0WquitjcZWE+FOnjofuHKcgUUZMB4nPtdYxg xiDHcK+uLSJdNOEuR1bPPUyYkfrsgUl4t2qHKJFM0rvyqV2quHV7BmKJYf4s5uUpGW pgNIcyZk0uopQ== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: sbaugh@catern.com, 77253@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 (---) --=-=-= Content-Type: text/plain Spencer Baugh writes: > Juri Linkov writes: > >>>>>>>> Not sure if it's possible for RET to accept the selected candidate >>>>>>>> by default since users might prefer to accept text in the minibuffer. >>>>>>> >>>>>>> If there's a selected candidate, though, then users have already decided >>>>>>> to use M-/M- to interact with completions. (Or they've >>>>>>> switched to the completions buffer and selected one) >>>>>>> >>>>>>> If they decide they don't want the candidate they selected, and want to >>>>>>> continue with text in the minibuffer, completion-auto-deselect will >>>>>>> automatically deselect the candidate if they type anything. >>>>>>> >>>>>>> I think these two facts combined make it possible for RET to accept the >>>>>>> selected candidate by default. >>>>>> >>>>>> Makes sense. So we need to try how well it performs. >>>>> >>>>> How about this? >>>> >>>> Thanks, will try to use for a while. >>> >>> Any feedback on the patch? >> >> Everything looks good. Could you send the final version of the patch? > > Yes, attached. > > (Note that this doesn't do the change I mentioned earlier of replacing > (get-buffer-window "*Completions*" 0) everywhere with > minibuffer--completions-visible, which probably should be done in a > separate patch, I can send that if you're up to install it now) Oops sorry, that was the emacs-30 version, attached is the proper version for installing on trunk. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Make-RET-in-minibuffer-choose-selected-completion.patch >From 1b969351e067982e6735574bc505ca52e31a8f11 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Mon, 21 Jul 2025 12:22:19 -0400 Subject: [PATCH] Make RET in minibuffer choose selected completion Previously, one could select a completion via M-/M-, but then RET would not actually select the chosen completion. With the addition of completion-auto-deselect, this is not actually necessary: we can reasonably assume that when a completion is selected, the user wants to use that, since their last action must have been to select it. So, just choose the selected completion on RET. * lisp/minibuffer.el (minibuffer--completions-visible) (minibuffer-choose-completion-if-selected): Add. (minibuffer-choose-completion-or-exit): Use the more reliable minibuffer-choose-completion-if-selected instead of a condition-case. (minibuffer-local-must-match-map): Bind RET to minibuffer-choose-completion-or-exit instead of minibuffer-complete-and-exit. (bug#77253) (minibuffer-choose-completion-just-exit): Add. (minibuffer-local-completion-map): Bind RET to minibuffer-choose-completion-just-exit instead of exit-minibuffer. (minibuffer-visible-completions--filter): Use minibuffer--completions-visible. --- lisp/minibuffer.el | 47 +++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 6f9e6c67541..12f66f57747 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3226,6 +3226,12 @@ completion-help-at-point (define-key map "\n" 'exit-minibuffer) (define-key map "\r" 'exit-minibuffer)) +(defun minibuffer-choose-completion-just-exit (&optional no-exit) + "Choose the selected completion from the minibuffer or call `exit-minibuffer'." + (interactive "P") + (or (minibuffer-choose-completion-if-selected no-exit) + (exit-minibuffer))) + (defvar-keymap minibuffer-local-completion-map :doc "Local keymap for minibuffer input with completion." :parent minibuffer-local-map @@ -3235,6 +3241,7 @@ minibuffer-local-completion-map ;; another binding for it. ;; "M-TAB" #'minibuffer-force-complete "SPC" #'minibuffer-complete-word + "RET" #'minibuffer-choose-completion-just-exit "?" #'minibuffer-completion-help "" #'switch-to-completions "M-v" #'switch-to-completions @@ -3246,7 +3253,7 @@ minibuffer-local-completion-map (defvar-keymap minibuffer-local-must-match-map :doc "Local keymap for minibuffer input with completion, for exact match." :parent minibuffer-local-completion-map - "RET" #'minibuffer-complete-and-exit + "RET" #'minibuffer-choose-completion-or-exit "C-j" #'minibuffer-complete-and-exit) (defvar-keymap minibuffer-local-filename-completion-map @@ -3343,18 +3350,34 @@ minibuffer-visible-completions (defvar minibuffer-visible-completions--always-bind nil "If non-nil, force the `minibuffer-visible-completions' bindings on.") +(defun minibuffer--completions-visible () + "Return the window where the *Completions* buffer for this minibuffer is visible." + (when-let ((window (get-buffer-window "*Completions*" 0))) + (when (eq (buffer-local-value 'completion-reference-buffer + (window-buffer window)) + (window-buffer (active-minibuffer-window))) + window))) + +(defun minibuffer-choose-completion-if-selected (&optional no-exit no-quit) + "Like `minibuffer-choose-completion', but do nothing if no candidate is selected. + +Return non-nil if a completion was chosen." + (when-let* ((window (minibuffer--completions-visible))) + (with-selected-window window + ;; Detect selection as if `choose-completion-deselect-if-after' is non-nil. + (when (get-text-property (point) 'completion--string) + (choose-completion nil no-exit no-quit) + t)))) + (defun minibuffer-visible-completions--filter (cmd) "Return CMD if `minibuffer-visible-completions' bindings should be active." (if minibuffer-visible-completions--always-bind cmd - (when-let* ((window (get-buffer-window "*Completions*" 0))) - (when (and (eq (buffer-local-value 'completion-reference-buffer - (window-buffer window)) - (window-buffer (active-minibuffer-window))) - (if (eq cmd #'minibuffer-choose-completion-or-exit) - (with-current-buffer (window-buffer window) - (get-text-property (point) 'completion--string)) - t)) + (when-let* ((window (minibuffer--completions-visible))) + (when (if (eq cmd #'minibuffer-choose-completion-or-exit) + (with-current-buffer (window-buffer window) + (get-text-property (point) 'completion--string)) + t) cmd)))) (defun minibuffer-visible-completions--bind (binding) @@ -5286,10 +5309,8 @@ minibuffer-choose-completion-or-exit in the completions window, then exit the minibuffer using its present contents." (interactive "P") - (condition-case nil - (let ((choose-completion-deselect-if-after t)) - (minibuffer-choose-completion no-exit no-quit)) - (error (minibuffer-complete-and-exit)))) + (or (minibuffer-choose-completion-if-selected no-exit no-quit) + (minibuffer-complete-and-exit))) (defun minibuffer-complete-history () "Complete as far as possible using the minibuffer history. -- 2.39.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 22 08:11:17 2025 Received: (at 77253) by debbugs.gnu.org; 22 Jul 2025 12:11:17 +0000 Received: from localhost ([127.0.0.1]:35975 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ueBq0-0002rj-Fs for submit@debbugs.gnu.org; Tue, 22 Jul 2025 08:11:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52874) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ueBpw-0002rE-Ea for 77253@debbugs.gnu.org; Tue, 22 Jul 2025 08:11:13 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ueBpp-0002uI-Ls; Tue, 22 Jul 2025 08:11:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=qCYoZfG8pUa17LEr1e8hlHoiN2zUh1YgemetzcMM9cI=; b=GY8EzVpPR1QD CHSQe/gIqz3Ph0hU+ncA9t+DiStcUoqI7L2QgtQyIMrRqesnPp1h63UOSrCYwkm4g0s3LGbGXn6X8 FCpCnoXtUbicbTJJQ/XGbmK+wROwVM8zE6FQ6n6MKFQkdR3smUdBeLY2XQjl4yPx/Jz3z4QOorXOx svKRXWTrrPVpIbYLLsdLuKkrJOmfmXsKeQIEu1J9gIFRYaaMOwRlm2wTVKFn1Osrf/TG6yMbZikwu bwXhYz6dR/9pFV90KYVfFGWRirtcY6CirIVoJj87uEgzt+yWHVe7zaljMqNqSf7U6GNlywYkHYjfQ dZA2NeKBmOCqmWH96iV6cQ==; Date: Tue, 22 Jul 2025 15:11:01 +0300 Message-Id: <86seioa0iy.fsf@gnu.org> From: Eli Zaretskii To: Spencer Baugh In-Reply-To: (bug-gnu-emacs@gnu.org) Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys, [PATCH] Make RET in minibuffer choose selected completion References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: sbaugh@catern.com, 77253@debbugs.gnu.org, juri@linkov.net 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 (---) > Cc: sbaugh@catern.com, 77253@debbugs.gnu.org > Date: Mon, 21 Jul 2025 12:26:32 -0400 > From: Spencer Baugh via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > @@ -3235,6 +3241,7 @@ minibuffer-local-completion-map > ;; another binding for it. > ;; "M-TAB" #'minibuffer-force-complete > "SPC" #'minibuffer-complete-word > + "RET" #'minibuffer-choose-completion-just-exit > "?" #'minibuffer-completion-help > "" #'switch-to-completions > "M-v" #'switch-to-completions > @@ -3246,7 +3253,7 @@ minibuffer-local-completion-map > (defvar-keymap minibuffer-local-must-match-map > :doc "Local keymap for minibuffer input with completion, for exact match." > :parent minibuffer-local-completion-map > - "RET" #'minibuffer-complete-and-exit > + "RET" #'minibuffer-choose-completion-or-exit > "C-j" #'minibuffer-complete-and-exit) Can we please not to change commands bound to keys? That will make the changes much more backward-compatible. In any case, this warrants a NEWS entry. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 24 13:16:48 2025 Received: (at 77253) by debbugs.gnu.org; 24 Jul 2025 17:16:48 +0000 Received: from localhost ([127.0.0.1]:58111 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uezYl-0004Ot-W7 for submit@debbugs.gnu.org; Thu, 24 Jul 2025 13:16:48 -0400 Received: from mout-y-111.mailbox.org ([91.198.250.236]:42710) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uezYi-0004OK-NB for 77253@debbugs.gnu.org; Thu, 24 Jul 2025 13:16:46 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-y-111.mailbox.org (Postfix) with ESMTPS id 4bnyN36d1Jz9y0b; Thu, 24 Jul 2025 19:16:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1753377395; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AMY8VDtvj82Yf32CiINO+g1OJiKSU+16wu/FZhXa6ZI=; b=sOsQS9TCDchjgfL/PFiWaZUdSs0BGBOvW7dt5fpq1TCCiHNKmpqjAEsaRccfWBZ4eDide6 KV2DXINvkWtFoCHXcR918e+wB6doZAa0UiuVQiT87SFjke7L86/TuNlm31h2PA4vpAhuOx 2hAmXTnSaJHKw8tUvL1pqlEmWIozZVtgkMWOl8EccB2vdGU4FUV5MCazc0G5Cj8Ru5jlgh uLeoyXTLB8lVXYGE0cx1IVShqLHyklFVZtVMDtmp/1B0m83FDzH5GVe+7VaLPrBCDZw/gs Pt8shQGVVHrYEC+/A4dRsK0QumTmLjSVxsg1oIwWU53B4/UoosZOO8QfPZPffA== From: Juri Linkov To: Eli Zaretskii Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys, [PATCH] Make RET in minibuffer choose selected completion In-Reply-To: <86seioa0iy.fsf@gnu.org> Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> <86seioa0iy.fsf@gnu.org> Date: Thu, 24 Jul 2025 20:10:41 +0300 Message-ID: <87bjp9v7ji.fsf@mail.linkov.net> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: Spencer Baugh , 77253@debbugs.gnu.org, sbaugh@catern.com 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: -1.7 (-) >> @@ -3235,6 +3241,7 @@ minibuffer-local-completion-map >> ;; another binding for it. >> ;; "M-TAB" #'minibuffer-force-complete >> "SPC" #'minibuffer-complete-word >> + "RET" #'minibuffer-choose-completion-just-exit >> "?" #'minibuffer-completion-help >> "" #'switch-to-completions >> "M-v" #'switch-to-completions >> @@ -3246,7 +3253,7 @@ minibuffer-local-completion-map >> (defvar-keymap minibuffer-local-must-match-map >> :doc "Local keymap for minibuffer input with completion, for exact match." >> :parent minibuffer-local-completion-map >> - "RET" #'minibuffer-complete-and-exit >> + "RET" #'minibuffer-choose-completion-or-exit >> "C-j" #'minibuffer-complete-and-exit) > > Can we please not to change commands bound to keys? That will make > the changes much more backward-compatible. First we discussed adding a new option like 'minibuffer-visible-completions' that affects only RET, not arrow keys. But now we arrived at a patch that rebinds the default keybindings. So I'm not sure how this would affect the current default behavior. IIUC, previously after selecting a candidate with M-down the user needed to type M-RET, and after applying the patch just RET will be sufficient? But it was already possible to use RET with 'minibuffer-completion-auto-choose' equal to t when M-down inserts the completion candidate to the minibuffer. From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 20 14:40:53 2025 Received: (at 77253) by debbugs.gnu.org; 20 Aug 2025 18:40:53 +0000 Received: from localhost ([127.0.0.1]:57671 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uonjx-0007kj-Ak for submit@debbugs.gnu.org; Wed, 20 Aug 2025 14:40:53 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:43449) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uonju-0007kP-8w for 77253@debbugs.gnu.org; Wed, 20 Aug 2025 14:40:51 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys, [PATCH] Make RET in minibuffer choose selected completion In-Reply-To: <87bjp9v7ji.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 24 Jul 2025 20:10:41 +0300") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> <86seioa0iy.fsf@gnu.org> <87bjp9v7ji.fsf@mail.linkov.net> Date: Wed, 20 Aug 2025 14:40:44 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1755715244; bh=sV7vuIHEJ2I5FZJcyskyfUi2VuyWLGIM2xvj2yfzAHs=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=die3aGQEM8iaV9Sv1dHz1iC7hb+lxFN8rUFC5Wv9N4s5Uz1vbVMJg+xbjvK1WleKd js73CJmM+BX373Rzvyckf0i+KW+jWx5LA/vWgbCknqGR+ZTr30vfx+gNC2UR8ApyOM p+5Qx+bxhhqxdwMKxzx0hF2hzigADjmVD9gZ7c6f7soENSxPYQzsv8LN+MLiZGkApq m5n79ijP8XkQVIJ49eXpE+KSuNJQT20kkAWi7W5z2kYljUWTcatNxu4bZ7EU0agOlI pNWoxTJDpU/6HDrBpC87qJHnds8XJIt+qbEu6XAzrpaBOpWpPQUlYqoSRibnXY/0Sk 7+3lGJ7TNC3Ww== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: sbaugh@catern.com, Eli Zaretskii , 77253@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 (---) Juri Linkov writes: >>> @@ -3235,6 +3241,7 @@ minibuffer-local-completion-map >>> ;; another binding for it. >>> ;; "M-TAB" #'minibuffer-force-complete >>> "SPC" #'minibuffer-complete-word >>> + "RET" #'minibuffer-choose-completion-just-exit >>> "?" #'minibuffer-completion-help >>> "" #'switch-to-completions >>> "M-v" #'switch-to-completions >>> @@ -3246,7 +3253,7 @@ minibuffer-local-completion-map >>> (defvar-keymap minibuffer-local-must-match-map >>> :doc "Local keymap for minibuffer input with completion, for exact match." >>> :parent minibuffer-local-completion-map >>> - "RET" #'minibuffer-complete-and-exit >>> + "RET" #'minibuffer-choose-completion-or-exit >>> "C-j" #'minibuffer-complete-and-exit) >> >> Can we please not to change commands bound to keys? That will make >> the changes much more backward-compatible. > > First we discussed adding a new option like 'minibuffer-visible-completions' > that affects only RET, not arrow keys. But now we arrived at a patch that > rebinds the default keybindings. So I'm not sure how this would affect > the current default behavior. IIUC, previously after selecting a candidate > with M-down the user needed to type M-RET, and after applying the patch > just RET will be sufficient? Yes. BTW, the patch can work either by changing commands bound to keys or by changing the commands themselves. I can produce either version, after some discussion. > But it was already possible to use RET with > 'minibuffer-completion-auto-choose' equal to t when M-down inserts the > completion candidate to the minibuffer. Ah, right, I forgot that that is on by default. Hmm... IMO, this patch supersedes that default. We would be able to turn minibuffer-completion-auto-choose off by default: - With this patch, the user would still be able to type RET in the minibuffer to choose a completion selected via M-, so that part wouldn't change. - Now additionally they will be able to more easily change their mind about selecting a completion: if they start using M- a few times, and then decide they want to do more completion, their minibuffer will be unchanged so they can just resume typing and hitting TAB as normal. This matches completion-in-region-mode better, since that has never had minibuffer-completion-auto-choose active. - If they do want to insert the selected completion into the minibuffer to edit it, as always they can do that with C-u M-, which also works in completion-in-region-mode. What do you think? I do think that this patch to make RET work by default is somewhat pointless if we can't combine it with turning minibuffer-completion-auto-choose off by default, so I'm hopefully we can do it. From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 20 14:41:52 2025 Received: (at 77253) by debbugs.gnu.org; 20 Aug 2025 18:41:52 +0000 Received: from localhost ([127.0.0.1]:57676 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uonks-0007mm-Vx for submit@debbugs.gnu.org; Wed, 20 Aug 2025 14:41:51 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:35141) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uonkq-0007mW-UO for 77253@debbugs.gnu.org; Wed, 20 Aug 2025 14:41:49 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: <87a58x3y6z.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 03 Apr 2025 21:19:16 +0300") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> Date: Wed, 20 Aug 2025 14:41:43 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1755715303; bh=8SS8qacf+UseOr7IXyQCUfPi3E2R24gm6ps9Or6YIf0=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=z1wj6LQ6B96oh0jy8Vo9LuJw5H5nVWWYFhDDMDU+tI6dLNHDkt8CWx0tcP7XXKtLr Kf0uM3ssKWWLk/1zHcXuCpyVv/tQfMPDBTCkq6Px0Q65E5vGdIrGjx+CXOKAiA6hR4 wk7BHG9yJVfTPS4V/Ymimp40Yt3mq5S2U7IG81KqfqF2gZfbXoJn5JEn/4NPNCjvdI QaRwS2pGYCWJgk3mkQ6aXhnqlTCRGs1dk9WW6jhD3BYJtOceSaua0UIJMw1osFqWX3 uZG7Lt+qDakeTMyFAAogPcMeemmAm+Cy6Nk53SKWSIB3tYNMceF49d9x4dqRonYava VgQ6SrXqsOWMg== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: 77253@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 (---) --=-=-= Content-Type: text/plain Juri Linkov writes: >> (BTW, after writing minibuffer--completions-visible, I'm wondering if >> most of the code which calls (get-buffer-window "*Completions*" 0) is >> actually buggy, because it's not checking completion-reference-buffer. >> Should we replace ~all the calls to (get-buffer-window "*Completions*" >> 0) with (minibuffer--completions-visible) which does check that?) > > Looks right, for example for the case of recursive minibuffers. Done in the attached patch. If it looks good I suggest we land this first, since it's a nice bugfix anyway. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-minibuffer-completions-visible-and-use-it.patch >From 59e63cf9970f3484047f9e3e3ef3517df5737255 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Wed, 20 Aug 2025 14:27:59 -0400 Subject: [PATCH] Add minibuffer--completions-visible and use it At various places, instead of just checking that there's any window displaying a buffer named *Completions*, we should additionally check that that *Completions* buffer is actually for the current completion session. minibuffer--completions-visible does that. * lisp/comint.el (comint-complete-input-ring) (comint-dynamic-list-completions): Call minibuffer--completions-visible. * lisp/minibuffer.el (minibuffer--completions-visible): Add. (bug#77253) (completion--do-completion, completions--post-command-update) (completions--after-change, minibuffer-hide-completions) (minibuffer-visible-completions) (minibuffer-visible-completions--always-bind) (minibuffer-visible-completions--filter) (with-minibuffer-completions-window, minibuffer-complete-history) (minibuffer-complete-defaults): Call minibuffer--completions-visible. * lisp/pcomplete.el (pcomplete-show-completions): Call minibuffer--completions-visible. * lisp/simple.el (switch-to-completions): Call minibuffer--completions-visible. * test/lisp/minibuffer-tests.el (completion-auto-help-test) (completion-auto-select-test): Call minibuffer--completions-visible. --- lisp/comint.el | 4 ++-- lisp/minibuffer.el | 39 +++++++++++++++++++++-------------- lisp/pcomplete.el | 2 +- lisp/simple.el | 4 ++-- test/lisp/minibuffer-tests.el | 14 ++++++------- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index b9c910eff43..bbb9820c16a 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -1197,7 +1197,7 @@ comint-complete-input-ring (ring-elements comint-input-ring) (user-error "No history available"))) (completion-in-region-mode-predicate - (lambda () (get-buffer-window "*Completions*" 0)))) + (lambda () (minibuffer--completions-visible)))) (completion-in-region (comint-line-beginning-position) (point-max) (completion-table-with-metadata @@ -3521,7 +3521,7 @@ comint-dynamic-list-completions specifying a common substring for adding the faces `completions-first-difference' and `completions-common-part' to the completions." - (let ((window (get-buffer-window "*Completions*" 0))) + (let ((window (minibuffer--completions-visible))) (setq completions (sort completions #'string-lessp)) (if (and (eq last-command this-command) window (window-live-p window) (window-buffer window) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index f453b2fee95..1769b98ac6f 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1628,7 +1628,7 @@ completion--do-completion ((or completed only-changed-boundaries) (cond ((pcase completion-auto-help - ('visible (get-buffer-window "*Completions*" 0)) + ('visible (minibuffer--completions-visible)) ('always t)) (minibuffer-completion-help beg end)) (t (minibuffer-hide-completions) @@ -2689,13 +2689,13 @@ completions--background-update (defun completions--post-command-update () "Update displayed *Completions* buffer after command, once." (remove-hook 'post-command-hook #'completions--post-command-update) - (when (and completion-eager-update (get-buffer-window "*Completions*" 0)) + (when (and completion-eager-update (minibuffer--completions-visible)) (completions--background-update))) (defun completions--after-change (_start _end _old-len) "Update displayed *Completions* buffer after change in buffer contents." (when (or completion-auto-deselect completion-eager-update) - (when-let* ((window (get-buffer-window "*Completions*" 0))) + (when-let* ((window (minibuffer--completions-visible))) (when completion-auto-deselect (with-selected-window window (completions--deselect))) @@ -2897,7 +2897,7 @@ minibuffer-hide-completions ;; FIXME: We could/should use minibuffer-scroll-window here, but it ;; can also point to the minibuffer-parent-window, so it's a bit tricky. (interactive) - (when-let* ((win (get-buffer-window "*Completions*" 0))) + (when-let* ((win (minibuffer--completions-visible))) (with-selected-window win ;; Move point off any completions, so we don't move point there ;; again the next time `minibuffer-completion-help' is called. @@ -3344,18 +3344,25 @@ minibuffer-visible-completions (defvar minibuffer-visible-completions--always-bind nil "If non-nil, force the `minibuffer-visible-completions' bindings on.") +(defun minibuffer--completions-visible () + "Return the window where the current *Completions* buffer is visible, if any." + (when-let* ((window (get-buffer-window "*Completions*" 0))) + (when (eq (buffer-local-value 'completion-reference-buffer + (window-buffer window)) + ;; If there's no active minibuffer, we call `window-buffer' on nil, assuming + ;; that completion is happening in the selected window. + (window-buffer (active-minibuffer-window))) + window))) + (defun minibuffer-visible-completions--filter (cmd) "Return CMD if `minibuffer-visible-completions' bindings should be active." (if minibuffer-visible-completions--always-bind cmd - (when-let* ((window (get-buffer-window "*Completions*" 0))) - (when (and (eq (buffer-local-value 'completion-reference-buffer - (window-buffer window)) - (window-buffer (active-minibuffer-window))) - (if (eq cmd #'minibuffer-choose-completion-or-exit) - (with-current-buffer (window-buffer window) - (get-text-property (point) 'completion--string)) - t)) + (when-let* ((window (minibuffer--completions-visible))) + (when (if (eq cmd #'minibuffer-choose-completion-or-exit) + (with-current-buffer (window-buffer window) + (get-text-property (point) 'completion--string)) + t) cmd)))) (defun minibuffer-visible-completions--bind (binding) @@ -5116,10 +5123,10 @@ with-minibuffer-completions-window When used in a minibuffer window, select the window with completions, and execute the forms." (declare (indent 0) (debug t)) - `(let ((window (or (get-buffer-window "*Completions*" 0) + `(let ((window (or (minibuffer--completions-visible) ;; Make sure we have a completions window. (progn (minibuffer-completion-help) - (get-buffer-window "*Completions*" 0))))) + (minibuffer--completions-visible))))) (when window (with-selected-window window (completion--lazy-insert-strings) @@ -5214,7 +5221,7 @@ minibuffer-complete-history (user-error "No history available")))) ;; FIXME: Can we make it work for CRM? (let ((completion-in-region-mode-predicate - (lambda () (get-buffer-window "*Completions*" 0)))) + (lambda () (minibuffer--completions-visible)))) (completion-in-region (minibuffer--completion-prompt-end) (point-max) (completion-table-with-metadata @@ -5232,7 +5239,7 @@ minibuffer-complete-defaults minibuffer-default (funcall minibuffer-default-add-function))) (let ((completions (ensure-list minibuffer-default)) (completion-in-region-mode-predicate - (lambda () (get-buffer-window "*Completions*" 0)))) + (lambda () (minibuffer--completions-visible)))) (completion-in-region (minibuffer--completion-prompt-end) (point-max) (completion-table-with-metadata diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index 43d149d5c90..c3b7f9d52d3 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -1150,7 +1150,7 @@ pcomplete-show-completions ((or (eq event 'tab) ;; Needed on a terminal (eq event 9)) - (let ((win (or (get-buffer-window "*Completions*" 0) + (let ((win (or (minibuffer--completions-visible) (display-buffer "*Completions*" 'not-this-window)))) (with-selected-window win diff --git a/lisp/simple.el b/lisp/simple.el index f7f059793ca..b0f6621b37e 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10598,10 +10598,10 @@ completion-setup-function (defun switch-to-completions () "Select the completion list window." (interactive) - (when-let* ((window (or (get-buffer-window "*Completions*" 0) + (when-let* ((window (or (minibuffer--completions-visible) ;; Make sure we have a completions window. (progn (minibuffer-completion-help) - (get-buffer-window "*Completions*" 0))))) + (minibuffer--completions-visible))))) (select-window window) (completion--lazy-insert-strings) (when (bobp) diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index 35cc67b770b..523f2cbf24e 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el @@ -458,21 +458,21 @@ completion-auto-help-test '("a" "ab" "ac") (execute-kbd-macro (kbd "a TAB TAB")) (should (equal (car messages) "Complete, but not unique")) - (should-not (get-buffer-window "*Completions*" 0)) + (should-not (minibuffer--completions-visible)) (execute-kbd-macro (kbd "b TAB")) (should (equal (car messages) "Sole completion")))) (let ((completion-auto-help t)) (completing-read-with-minibuffer-setup '("a" "ab" "ac") (execute-kbd-macro (kbd "a TAB TAB")) - (should (get-buffer-window "*Completions*" 0)) + (should (minibuffer--completions-visible)) (execute-kbd-macro (kbd "b TAB")) (should (equal (car messages) "Sole completion")))) (let ((completion-auto-help 'visible)) (completing-read-with-minibuffer-setup '("a" "ab" "ac" "achoo") (execute-kbd-macro (kbd "a TAB TAB")) - (should (get-buffer-window "*Completions*" 0)) + (should (minibuffer--completions-visible)) (execute-kbd-macro (kbd "ch TAB")) (should (equal (car messages) "Sole completion"))))))) @@ -481,19 +481,19 @@ completion-auto-select-test (completing-read-with-minibuffer-setup '("aa" "ab" "ac") (execute-kbd-macro (kbd "a TAB")) - (should (and (get-buffer-window "*Completions*" 0) + (should (and (minibuffer--completions-visible) (eq (current-buffer) (get-buffer "*Completions*")))) (execute-kbd-macro (kbd "TAB TAB TAB")) - (should (and (get-buffer-window "*Completions*" 0) + (should (and (minibuffer--completions-visible) (eq (current-buffer) (get-buffer " *Minibuf-1*")))) (execute-kbd-macro (kbd "S-TAB")) - (should (and (get-buffer-window "*Completions*" 0) + (should (and (minibuffer--completions-visible) (eq (current-buffer) (get-buffer "*Completions*")))))) (let ((completion-auto-select 'second-tab)) (completing-read-with-minibuffer-setup '("aa" "ab" "ac") (execute-kbd-macro (kbd "a TAB")) - (should (and (get-buffer-window "*Completions*" 0) + (should (and (minibuffer--completions-visible) (not (eq (current-buffer) (get-buffer "*Completions*"))))) (execute-kbd-macro (kbd "TAB TAB")) (should (eq (current-buffer) (get-buffer "*Completions*")))))) -- 2.43.7 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 21 02:54:48 2025 Received: (at 77253) by debbugs.gnu.org; 21 Aug 2025 06:54:48 +0000 Received: from localhost ([127.0.0.1]:58717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uozCB-0001yO-T6 for submit@debbugs.gnu.org; Thu, 21 Aug 2025 02:54:48 -0400 Received: from mout-p-102.mailbox.org ([2001:67c:2050:0:465::102]:33690) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uozC0-0001xt-RX for 77253@debbugs.gnu.org; Thu, 21 Aug 2025 02:54:38 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4c6vFH2FKjz9vMR; Thu, 21 Aug 2025 08:54:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1755759267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZGLbwv1rx7uSeCjxVW8zTV7niTzhxKhSqPL6sJcYLiI=; b=dsn4o1HHZlerCQ7HIMpj6TiaaJKKWmm9htj5my0jw53nDeOb0FRm70Ztk4PUfM/LzLBI8W /JbxBnzVG5ZGzh9IPGOjUK9QRvix3khW0eISAXXIDbnECGtmy6D+QUW9mkFTkIVLyTSc/Z WxP7FAZeZwYlhmW4n1mtetGBGLUTOfgG5Auqrbb9YaRAeDX6/yyP1b9JCEPduinPbrf7UM WOjz7W+v9w/zpen69VaSrsiwMsG+kGKn3nPzOS/XR9CB3SDfHMIi+yIEk5thCf0mY1tnWI eB+qOxKVVlJ9hMwLNvdORan2wrTXi0Hm8x23H6JeMyhEhIlJaHMjtm79ZD3qzw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of juri@linkov.net designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=juri@linkov.net From: Juri Linkov To: Spencer Baugh Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys, [PATCH] Make RET in minibuffer choose selected completion In-Reply-To: Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> <86seioa0iy.fsf@gnu.org> <87bjp9v7ji.fsf@mail.linkov.net> Date: Thu, 21 Aug 2025 09:51:22 +0300 Message-ID: <87qzx54179.fsf@mail.linkov.net> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 4c6vFH2FKjz9vMR X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: sbaugh@catern.com, Eli Zaretskii , 77253@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: -1.7 (-) >>>> @@ -3246,7 +3253,7 @@ minibuffer-local-completion-map >>>> (defvar-keymap minibuffer-local-must-match-map >>>> :doc "Local keymap for minibuffer input with completion, for exact match." >>>> :parent minibuffer-local-completion-map >>>> - "RET" #'minibuffer-complete-and-exit >>>> + "RET" #'minibuffer-choose-completion-or-exit >>>> "C-j" #'minibuffer-complete-and-exit) >>> >>> Can we please not to change commands bound to keys? That will make >>> the changes much more backward-compatible. >> >> First we discussed adding a new option like 'minibuffer-visible-completions' >> that affects only RET, not arrow keys. But now we arrived at a patch that >> rebinds the default keybindings. So I'm not sure how this would affect >> the current default behavior. IIUC, previously after selecting a candidate >> with M-down the user needed to type M-RET, and after applying the patch >> just RET will be sufficient? > > Yes. > > BTW, the patch can work either by changing commands bound to keys or by > changing the commands themselves. I can produce either version, after > some discussion. It looks like changing the commands themselves is more preferable than changing traditional keybindings. >> But it was already possible to use RET with >> 'minibuffer-completion-auto-choose' equal to t when M-down inserts the >> completion candidate to the minibuffer. > > Ah, right, I forgot that that is on by default. Hmm... > > IMO, this patch supersedes that default. We would be able to turn > minibuffer-completion-auto-choose off by default: > > - With this patch, the user would still be able to type RET in the > minibuffer to choose a completion selected via M-, so that part > wouldn't change. > > - Now additionally they will be able to more easily change their mind > about selecting a completion: if they start using M- a few times, > and then decide they want to do more completion, their minibuffer will > be unchanged so they can just resume typing and hitting TAB as normal. > This matches completion-in-region-mode better, since that has never had > minibuffer-completion-auto-choose active. > > - If they do want to insert the selected completion into the minibuffer > to edit it, as always they can do that with C-u M-, which also > works in completion-in-region-mode. > > What do you think? I do think that this patch to make RET work by > default is somewhat pointless if we can't combine it with turning > minibuffer-completion-auto-choose off by default, so I'm hopefully we > can do it. The default value t of minibuffer-completion-auto-choose was intended to emulate the behavior of completion in web browsers where navigating with up/down arrows inserts the completion candidates into the editing area that corresponds to the minibuffer. However, this doesn't prevent from disabling minibuffer-completion-auto-choose by default, provided there is an easy way to insert the completion candidate into the minibuffer. For example, in icomplete-mode 'C-M-i' (icomplete-force-complete) inserts the current completion candidate into the minibuffer. Since 'C-u RET' does the same for the completion buffer, it seems we can disable minibuffer-completion-auto-choose by default. From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 21 12:39:53 2025 Received: (at 77253) by debbugs.gnu.org; 21 Aug 2025 16:39:53 +0000 Received: from localhost ([127.0.0.1]:60968 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1up8KO-00089u-Og for submit@debbugs.gnu.org; Thu, 21 Aug 2025 12:39:53 -0400 Received: from mout-p-202.mailbox.org ([2001:67c:2050:0:465::202]:44552) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1up8KK-00089T-Hb for 77253@debbugs.gnu.org; Thu, 21 Aug 2025 12:39:50 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4c78DR5jRxz9tTc; Thu, 21 Aug 2025 18:39:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1755794375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zdFsAVamMSmhDxhd4BV2CpIh0Hpmwy9jIfusoc1FUhA=; b=TV4CSPhP095lVUefZVuvMcD5OOp8vYr1AZq+6RKmok9/eY6qSZ/3MnIKMeoLVNm1ghZHBr r5MHnrpyTkT4GnbPaYQlduli5y1wEHvt2WBhMUaRNiPPYIo7z4riGa+nnkcDgbWAg0B1XC hexEiU65/kJvnzO59KOYXMqjq6ayyUp9CfoSFXgjNDre4GvsYPmwZc0xsKowBjK02rQQot jw6sFToRdGO0jDu7JqU4R965QV5PJ/nKzlS1FAKuRuMSxLLoX68oHx+Sb1sYv2opkoSU4k QkJtuCil6TNMg6pZWMF5XgIfTWAEJDQ5HDrkeLisVCgDYj3RaTY4+ZWaOUTbnQ== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of juri@linkov.net designates 2001:67c:2050:b231:465::1 as permitted sender) smtp.mailfrom=juri@linkov.net From: Juri Linkov To: Spencer Baugh Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> Date: Thu, 21 Aug 2025 19:38:32 +0300 Message-ID: <87a53saauv.fsf@mail.linkov.net> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 4c78DR5jRxz9tTc X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: 77253@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: -1.7 (-) >>> (BTW, after writing minibuffer--completions-visible, I'm wondering if >>> most of the code which calls (get-buffer-window "*Completions*" 0) is >>> actually buggy, because it's not checking completion-reference-buffer. >>> Should we replace ~all the calls to (get-buffer-window "*Completions*" >>> 0) with (minibuffer--completions-visible) which does check that?) >> >> Looks right, for example for the case of recursive minibuffers. > > Done in the attached patch. If it looks good I suggest we land this > first, since it's a nice bugfix anyway. Sorry, the patch doesn't apply cleanly on current master. BTW, while updating the patch, please also fit the docstring and comments into 72 columns. From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 21 12:48:40 2025 Received: (at 77253) by debbugs.gnu.org; 21 Aug 2025 16:48:40 +0000 Received: from localhost ([127.0.0.1]:32770 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1up8St-0000Bz-Ei for submit@debbugs.gnu.org; Thu, 21 Aug 2025 12:48:40 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:38747) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1up8Sr-0000Bk-55 for 77253@debbugs.gnu.org; Thu, 21 Aug 2025 12:48:38 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: <87a53saauv.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 21 Aug 2025 19:38:32 +0300") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87a53saauv.fsf@mail.linkov.net> Date: Thu, 21 Aug 2025 12:48:31 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1755794911; bh=rFSSX3ioUcjohU/lNXRoY92pk+T/NNYJSYquaiELAPk=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=sn6SDfseEX4G7NN0BIJgNS8JO9j+mkFArIBejFgrGtAYJbzlWsZ/m1aWpr+tB/nJu rv7sQdzgFwWjmCnnZf6drZO2JTi22RS29MDNGy63u6riWO+xbjN2qar1CprS61yWzO e8QfilUJscoYVxzPy7wHYzu8ShJJSjH/PHyUT8P5ECy/y9fLNtvRHaMuCcdCeboiFV aIqsRtuVOzbJ5jsicdHr32RpRE6VSREU4K3NNfOt6mckhn0v3xXZqqPbX1Dt7zD1oj XVPzcQJarENS136T3kbaRPWz94BmFVXIjKjFmIneZ+LCSPn1ETcEJpoYwpHO2XAn9p FmNhYfjRrTvzg== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: 77253@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 (---) --=-=-= Content-Type: text/plain Juri Linkov writes: >>>> (BTW, after writing minibuffer--completions-visible, I'm wondering if >>>> most of the code which calls (get-buffer-window "*Completions*" 0) is >>>> actually buggy, because it's not checking completion-reference-buffer. >>>> Should we replace ~all the calls to (get-buffer-window "*Completions*" >>>> 0) with (minibuffer--completions-visible) which does check that?) >>> >>> Looks right, for example for the case of recursive minibuffers. >> >> Done in the attached patch. If it looks good I suggest we land this >> first, since it's a nice bugfix anyway. > > Sorry, the patch doesn't apply cleanly on current master. > BTW, while updating the patch, please also > fit the docstring and comments into 72 columns. Updated and filled that long comment, sorry. (The docstring is still over 72 columns, but it's under 80 characters in the first line, so I think it's still within the usual style) --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-minibuffer-completions-visible-and-use-it.patch >From 379e427cb6b3828b47fbf4f1cb6b1a1d1ac88827 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Wed, 20 Aug 2025 14:27:59 -0400 Subject: [PATCH] Add minibuffer--completions-visible and use it At various places, instead of just checking that there's any window displaying a buffer named *Completions*, we should additionally check that that *Completions* buffer is actually for the current completion session. minibuffer--completions-visible does that. * lisp/comint.el (comint-complete-input-ring) (comint-dynamic-list-completions): Call minibuffer--completions-visible. * lisp/minibuffer.el (minibuffer--completions-visible): Add. (bug#77253) (completion--do-completion, completions--post-command-update) (completions--after-change, minibuffer-hide-completions) (minibuffer-visible-completions) (minibuffer-visible-completions--always-bind) (minibuffer-visible-completions--filter) (with-minibuffer-completions-window, minibuffer-complete-history) (minibuffer-complete-defaults): Call minibuffer--completions-visible. * lisp/pcomplete.el (pcomplete-show-completions): Call minibuffer--completions-visible. * lisp/simple.el (switch-to-completions): Call minibuffer--completions-visible. * test/lisp/minibuffer-tests.el (completion-auto-help-test) (completion-auto-select-test): Call minibuffer--completions-visible. --- lisp/comint.el | 4 ++-- lisp/minibuffer.el | 40 +++++++++++++++++++++-------------- lisp/pcomplete.el | 2 +- lisp/simple.el | 4 ++-- test/lisp/minibuffer-tests.el | 14 ++++++------ 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/lisp/comint.el b/lisp/comint.el index b9c910eff43..bbb9820c16a 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -1197,7 +1197,7 @@ comint-complete-input-ring (ring-elements comint-input-ring) (user-error "No history available"))) (completion-in-region-mode-predicate - (lambda () (get-buffer-window "*Completions*" 0)))) + (lambda () (minibuffer--completions-visible)))) (completion-in-region (comint-line-beginning-position) (point-max) (completion-table-with-metadata @@ -3521,7 +3521,7 @@ comint-dynamic-list-completions specifying a common substring for adding the faces `completions-first-difference' and `completions-common-part' to the completions." - (let ((window (get-buffer-window "*Completions*" 0))) + (let ((window (minibuffer--completions-visible))) (setq completions (sort completions #'string-lessp)) (if (and (eq last-command this-command) window (window-live-p window) (window-buffer window) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index f453b2fee95..37af93c3ae8 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1628,7 +1628,7 @@ completion--do-completion ((or completed only-changed-boundaries) (cond ((pcase completion-auto-help - ('visible (get-buffer-window "*Completions*" 0)) + ('visible (minibuffer--completions-visible)) ('always t)) (minibuffer-completion-help beg end)) (t (minibuffer-hide-completions) @@ -2689,13 +2689,13 @@ completions--background-update (defun completions--post-command-update () "Update displayed *Completions* buffer after command, once." (remove-hook 'post-command-hook #'completions--post-command-update) - (when (and completion-eager-update (get-buffer-window "*Completions*" 0)) + (when (and completion-eager-update (minibuffer--completions-visible)) (completions--background-update))) (defun completions--after-change (_start _end _old-len) "Update displayed *Completions* buffer after change in buffer contents." (when (or completion-auto-deselect completion-eager-update) - (when-let* ((window (get-buffer-window "*Completions*" 0))) + (when-let* ((window (minibuffer--completions-visible))) (when completion-auto-deselect (with-selected-window window (completions--deselect))) @@ -2897,7 +2897,7 @@ minibuffer-hide-completions ;; FIXME: We could/should use minibuffer-scroll-window here, but it ;; can also point to the minibuffer-parent-window, so it's a bit tricky. (interactive) - (when-let* ((win (get-buffer-window "*Completions*" 0))) + (when-let* ((win (minibuffer--completions-visible))) (with-selected-window win ;; Move point off any completions, so we don't move point there ;; again the next time `minibuffer-completion-help' is called. @@ -3344,18 +3344,26 @@ minibuffer-visible-completions (defvar minibuffer-visible-completions--always-bind nil "If non-nil, force the `minibuffer-visible-completions' bindings on.") +(defun minibuffer--completions-visible () + "Return the window where the current *Completions* buffer is visible, if any." + (when-let* ((window (get-buffer-window "*Completions*" 0))) + (when (eq (buffer-local-value 'completion-reference-buffer + (window-buffer window)) + ;; If there's no active minibuffer, we call + ;; `window-buffer' on nil, assuming that completion is + ;; happening in the selected window. + (window-buffer (active-minibuffer-window))) + window))) + (defun minibuffer-visible-completions--filter (cmd) "Return CMD if `minibuffer-visible-completions' bindings should be active." (if minibuffer-visible-completions--always-bind cmd - (when-let* ((window (get-buffer-window "*Completions*" 0))) - (when (and (eq (buffer-local-value 'completion-reference-buffer - (window-buffer window)) - (window-buffer (active-minibuffer-window))) - (if (eq cmd #'minibuffer-choose-completion-or-exit) - (with-current-buffer (window-buffer window) - (get-text-property (point) 'completion--string)) - t)) + (when-let* ((window (minibuffer--completions-visible))) + (when (if (eq cmd #'minibuffer-choose-completion-or-exit) + (with-current-buffer (window-buffer window) + (get-text-property (point) 'completion--string)) + t) cmd)))) (defun minibuffer-visible-completions--bind (binding) @@ -5116,10 +5124,10 @@ with-minibuffer-completions-window When used in a minibuffer window, select the window with completions, and execute the forms." (declare (indent 0) (debug t)) - `(let ((window (or (get-buffer-window "*Completions*" 0) + `(let ((window (or (minibuffer--completions-visible) ;; Make sure we have a completions window. (progn (minibuffer-completion-help) - (get-buffer-window "*Completions*" 0))))) + (minibuffer--completions-visible))))) (when window (with-selected-window window (completion--lazy-insert-strings) @@ -5214,7 +5222,7 @@ minibuffer-complete-history (user-error "No history available")))) ;; FIXME: Can we make it work for CRM? (let ((completion-in-region-mode-predicate - (lambda () (get-buffer-window "*Completions*" 0)))) + (lambda () (minibuffer--completions-visible)))) (completion-in-region (minibuffer--completion-prompt-end) (point-max) (completion-table-with-metadata @@ -5232,7 +5240,7 @@ minibuffer-complete-defaults minibuffer-default (funcall minibuffer-default-add-function))) (let ((completions (ensure-list minibuffer-default)) (completion-in-region-mode-predicate - (lambda () (get-buffer-window "*Completions*" 0)))) + (lambda () (minibuffer--completions-visible)))) (completion-in-region (minibuffer--completion-prompt-end) (point-max) (completion-table-with-metadata diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index 43d149d5c90..c3b7f9d52d3 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -1150,7 +1150,7 @@ pcomplete-show-completions ((or (eq event 'tab) ;; Needed on a terminal (eq event 9)) - (let ((win (or (get-buffer-window "*Completions*" 0) + (let ((win (or (minibuffer--completions-visible) (display-buffer "*Completions*" 'not-this-window)))) (with-selected-window win diff --git a/lisp/simple.el b/lisp/simple.el index f7f059793ca..b0f6621b37e 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10598,10 +10598,10 @@ completion-setup-function (defun switch-to-completions () "Select the completion list window." (interactive) - (when-let* ((window (or (get-buffer-window "*Completions*" 0) + (when-let* ((window (or (minibuffer--completions-visible) ;; Make sure we have a completions window. (progn (minibuffer-completion-help) - (get-buffer-window "*Completions*" 0))))) + (minibuffer--completions-visible))))) (select-window window) (completion--lazy-insert-strings) (when (bobp) diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index 35cc67b770b..523f2cbf24e 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el @@ -458,21 +458,21 @@ completion-auto-help-test '("a" "ab" "ac") (execute-kbd-macro (kbd "a TAB TAB")) (should (equal (car messages) "Complete, but not unique")) - (should-not (get-buffer-window "*Completions*" 0)) + (should-not (minibuffer--completions-visible)) (execute-kbd-macro (kbd "b TAB")) (should (equal (car messages) "Sole completion")))) (let ((completion-auto-help t)) (completing-read-with-minibuffer-setup '("a" "ab" "ac") (execute-kbd-macro (kbd "a TAB TAB")) - (should (get-buffer-window "*Completions*" 0)) + (should (minibuffer--completions-visible)) (execute-kbd-macro (kbd "b TAB")) (should (equal (car messages) "Sole completion")))) (let ((completion-auto-help 'visible)) (completing-read-with-minibuffer-setup '("a" "ab" "ac" "achoo") (execute-kbd-macro (kbd "a TAB TAB")) - (should (get-buffer-window "*Completions*" 0)) + (should (minibuffer--completions-visible)) (execute-kbd-macro (kbd "ch TAB")) (should (equal (car messages) "Sole completion"))))))) @@ -481,19 +481,19 @@ completion-auto-select-test (completing-read-with-minibuffer-setup '("aa" "ab" "ac") (execute-kbd-macro (kbd "a TAB")) - (should (and (get-buffer-window "*Completions*" 0) + (should (and (minibuffer--completions-visible) (eq (current-buffer) (get-buffer "*Completions*")))) (execute-kbd-macro (kbd "TAB TAB TAB")) - (should (and (get-buffer-window "*Completions*" 0) + (should (and (minibuffer--completions-visible) (eq (current-buffer) (get-buffer " *Minibuf-1*")))) (execute-kbd-macro (kbd "S-TAB")) - (should (and (get-buffer-window "*Completions*" 0) + (should (and (minibuffer--completions-visible) (eq (current-buffer) (get-buffer "*Completions*")))))) (let ((completion-auto-select 'second-tab)) (completing-read-with-minibuffer-setup '("aa" "ab" "ac") (execute-kbd-macro (kbd "a TAB")) - (should (and (get-buffer-window "*Completions*" 0) + (should (and (minibuffer--completions-visible) (not (eq (current-buffer) (get-buffer "*Completions*"))))) (execute-kbd-macro (kbd "TAB TAB")) (should (eq (current-buffer) (get-buffer "*Completions*")))))) -- 2.43.7 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 21 13:12:17 2025 Received: (at 77253) by debbugs.gnu.org; 21 Aug 2025 17:12:18 +0000 Received: from localhost ([127.0.0.1]:32809 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1up8pl-00048c-L0 for submit@debbugs.gnu.org; Thu, 21 Aug 2025 13:12:17 -0400 Received: from mout-p-102.mailbox.org ([2001:67c:2050:0:465::102]:45610) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1up8pi-00048H-5o for 77253@debbugs.gnu.org; Thu, 21 Aug 2025 13:12:15 -0400 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4c78xw33Tsz9tyN; Thu, 21 Aug 2025 19:12:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1755796324; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XH6sJJ5YLTxIfRwUjSwwHYmiZ63O6S9b9fBWhSZLRMs=; b=efHrNORq1LlZtgfrEiR3Nt+nPm1JLXm8s025YXoQnOm84GzL+WTf17y819pyY/0XSFF+rE nOeok4h8CHgacTrNgVtAb2InrmIbz2W7RZPkKbBuwKA4mUVmvogK47EPYjRlQfCvkQrwjo /zmFNQadbf1sK6742Qs+j+yq1a6AEsKf0jwHBtgHXqJ/jmG6wNbwyzuiY4/+QF2cVHKg/j FDt496OI85gkbTSwdwgSoUN261loET8NAj9kGg31Mv931CVVo4zLe/WIgGdhMk3FpmpY7u X923+sSxdFu8qUhq7XyJQa/ogn7c5Iv0+BdofTMHcK3YXSV+xKGJY5VmPYJ0qw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of juri@linkov.net designates 2001:67c:2050:b231:465::202 as permitted sender) smtp.mailfrom=juri@linkov.net From: Juri Linkov To: Spencer Baugh Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys In-Reply-To: Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87a53saauv.fsf@mail.linkov.net> Date: Thu, 21 Aug 2025 20:11:08 +0300 Message-ID: <875xeg8us3.fsf@mail.linkov.net> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 4c78xw33Tsz9tyN X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: 77253@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: -1.7 (-) >>>>> (BTW, after writing minibuffer--completions-visible, I'm wondering if >>>>> most of the code which calls (get-buffer-window "*Completions*" 0) is >>>>> actually buggy, because it's not checking completion-reference-buffer. >>>>> Should we replace ~all the calls to (get-buffer-window "*Completions*" >>>>> 0) with (minibuffer--completions-visible) which does check that?) >>>> >>>> Looks right, for example for the case of recursive minibuffers. >>> >>> Done in the attached patch. If it looks good I suggest we land this >>> first, since it's a nice bugfix anyway. >> >> Sorry, the patch doesn't apply cleanly on current master. >> BTW, while updating the patch, please also >> fit the docstring and comments into 72 columns. > > Updated and filled that long comment, sorry. Now pushed. Thanks for submitting a separate patch for this bugfix. From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 21 14:45:14 2025 Received: (at 77253) by debbugs.gnu.org; 21 Aug 2025 18:45:15 +0000 Received: from localhost ([127.0.0.1]:32975 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1upAHi-0005hB-04 for submit@debbugs.gnu.org; Thu, 21 Aug 2025 14:45:14 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:45249) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1upAHf-0005dV-07 for 77253@debbugs.gnu.org; Thu, 21 Aug 2025 14:45:12 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys, [PATCH] Make RET in minibuffer choose selected completion In-Reply-To: <87qzx54179.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 21 Aug 2025 09:51:22 +0300") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> <86seioa0iy.fsf@gnu.org> <87bjp9v7ji.fsf@mail.linkov.net> <87qzx54179.fsf@mail.linkov.net> Date: Thu, 21 Aug 2025 14:45:05 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1755801905; bh=h3mtWlybwMqfEy0xWI2BkNQtoTeRqH88TnObgpeH9DA=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=V4W1kp2u4eu+ku22nO/lGvfqsODWqVYWDotTH+3lXBbemmKrBDuT2uD2Pq7XcGvSL apbZTBUKhguxoU93t+HeIK7QtZGVr9F65IxIIgjgjmlDcrDewI3uF90zyTAM0yHgK2 Hzrbf7Su8LDqUIVOc0Dttr2yA3HVsd9UiCWMVkJMfBwgCmeqlaHk9P4UAB1VTAlAos 89yxOq8akmPswliUyc8HgSSKoSFZxhL7+yHShVAdV+pjIV7pnmU4E3fgQ32gfnpjZy Jyp78bjy97NA4uba55Nn8K9l8l3SVU0H0S3D6jR6PER6hCDPBnKBqoxMUQE6IWOgqx 8/8puoqWB+tog== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: sbaugh@catern.com, Eli Zaretskii , 77253@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 (---) --=-=-= Content-Type: text/plain Juri Linkov writes: >>>>> @@ -3246,7 +3253,7 @@ minibuffer-local-completion-map >>>>> (defvar-keymap minibuffer-local-must-match-map >>>>> :doc "Local keymap for minibuffer input with completion, for exact match." >>>>> :parent minibuffer-local-completion-map >>>>> - "RET" #'minibuffer-complete-and-exit >>>>> + "RET" #'minibuffer-choose-completion-or-exit >>>>> "C-j" #'minibuffer-complete-and-exit) >>>> >>>> Can we please not to change commands bound to keys? That will make >>>> the changes much more backward-compatible. >>> >>> First we discussed adding a new option like 'minibuffer-visible-completions' >>> that affects only RET, not arrow keys. But now we arrived at a patch that >>> rebinds the default keybindings. So I'm not sure how this would affect >>> the current default behavior. IIUC, previously after selecting a candidate >>> with M-down the user needed to type M-RET, and after applying the patch >>> just RET will be sufficient? >> >> Yes. >> >> BTW, the patch can work either by changing commands bound to keys or by >> changing the commands themselves. I can produce either version, after >> some discussion. > > It looks like changing the commands themselves is more preferable > than changing traditional keybindings. For minibuffers with require-match completion, this can be done by changing the existing command bound to RET: minibuffer-complete-and-exit. For minibuffers with nil require-match completion, RET is bound to exit-minibuffer, and changing exit-minibuffer to have this logic is risky, I think. I can handle that case by adding a new minibuffer-completion-exit which wraps exit-minibuffer and bind RET to it. Done in the attached patch. >>> But it was already possible to use RET with >>> 'minibuffer-completion-auto-choose' equal to t when M-down inserts the >>> completion candidate to the minibuffer. >> >> Ah, right, I forgot that that is on by default. Hmm... >> >> IMO, this patch supersedes that default. We would be able to turn >> minibuffer-completion-auto-choose off by default: >> >> - With this patch, the user would still be able to type RET in the >> minibuffer to choose a completion selected via M-, so that part >> wouldn't change. >> >> - Now additionally they will be able to more easily change their mind >> about selecting a completion: if they start using M- a few times, >> and then decide they want to do more completion, their minibuffer will >> be unchanged so they can just resume typing and hitting TAB as normal. >> This matches completion-in-region-mode better, since that has never had >> minibuffer-completion-auto-choose active. >> >> - If they do want to insert the selected completion into the minibuffer >> to edit it, as always they can do that with C-u M-, which also >> works in completion-in-region-mode. >> >> What do you think? I do think that this patch to make RET work by >> default is somewhat pointless if we can't combine it with turning >> minibuffer-completion-auto-choose off by default, so I'm hopefully we >> can do it. > > The default value t of minibuffer-completion-auto-choose > was intended to emulate the behavior of completion in web browsers > where navigating with up/down arrows inserts the completion candidates > into the editing area that corresponds to the minibuffer. > > However, this doesn't prevent from disabling minibuffer-completion-auto-choose > by default, provided there is an easy way to insert the completion > candidate into the minibuffer. > > For example, in icomplete-mode 'C-M-i' (icomplete-force-complete) > inserts the current completion candidate into the minibuffer. > > Since 'C-u RET' does the same for the completion buffer, it seems > we can disable minibuffer-completion-auto-choose by default. How about this patch? It doesn't add support for C-u RET inserting the completion, you have to use C-u M-RET as you already can today. Do you think that's fine? It seems a bit safer. Also no NEWS entry still, will add one once we settle on a patch. It occurs to me now that we could maybe also make RET choose the selected completion by default in completion-in-region-mode, though that would require a :filter keymap entry like minibuffer-visible-completions has. completion-auto-deselect makes this viable, by the same reasoning I mentioned earlier in the bug. So maybe that's also interesting to do? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Make-RET-in-minibuffer-choose-selected-completion.patch >From 9b1988e3836952e9d954325d8004aa89f1d7f282 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Thu, 21 Aug 2025 14:33:23 -0400 Subject: [PATCH] Make RET in minibuffer choose selected completion Previously, one could select a completion via M-/M-, but then RET would not actually select the chosen completion. With the addition of completion-auto-deselect, this is not actually necessary: we can reasonably assume that when a completion is selected, the user wants to use that, since their last action must have been to select it. So, just choose the selected completion on RET. This lets us default minibuffer-completion-auto-choose to nil. For minibuffers with require-match completion, this can be done by changing the existing command bound to RET. For minibuffers with nil require-match completion, RET was previously bound to exit-minibuffer, and changing exit-minibuffer to have this logic is risky. We handle that case by adding a new minibuffer-completion-exit which wraps exit-minibuffer and bind RET to it. * lisp/minibuffer.el (minibuffer-insert-completion-if-selected): Add. (minibuffer-complete-and-exit): Call minibuffer-insert-completion-if-selected. (bug#77253) (minibuffer-completion-exit): Add, just calling minibuffer-insert-completion-if-selected before exit-minibuffer. (minibuffer-local-completion-map): Bind RET to minibuffer-completion-exit, overriding exit-minibuffer. (minibuffer-completion-auto-choose): Default to nil. --- lisp/minibuffer.el | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 37af93c3ae8..c786c1b0948 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2009,6 +2009,7 @@ minibuffer-complete-and-exit `minibuffer-confirm-exit-commands', and accept the input otherwise." (interactive) + (minibuffer-insert-completion-if-selected) (completion-complete-and-exit (minibuffer--completion-prompt-end) (point-max) #'exit-minibuffer)) @@ -3227,6 +3228,12 @@ completion-help-at-point (define-key map "\n" 'exit-minibuffer) (define-key map "\r" 'exit-minibuffer)) +(defun minibuffer-completion-exit () + "Call `exit-minibuffer', inserting the selected completion first if any." + (interactive) + (minibuffer-insert-completion-if-selected) + (exit-minibuffer)) + (defvar-keymap minibuffer-local-completion-map :doc "Local keymap for minibuffer input with completion." :parent minibuffer-local-map @@ -3236,6 +3243,7 @@ minibuffer-local-completion-map ;; another binding for it. ;; "M-TAB" #'minibuffer-force-complete "SPC" #'minibuffer-complete-word + "RET" #'minibuffer-completion-exit "?" #'minibuffer-completion-help "" #'switch-to-completions "M-v" #'switch-to-completions @@ -3355,6 +3363,17 @@ minibuffer--completions-visible (window-buffer (active-minibuffer-window))) window))) +(defun minibuffer-insert-completion-if-selected () + "Like `minibuffer-choose-completion', but do nothing if no candidate is selected. + +Return non-nil if a completion was chosen." + (when-let* ((window (minibuffer--completions-visible))) + (with-selected-window window + ;; Detect selection as if `choose-completion-deselect-if-after' is non-nil. + (when (get-text-property (point) 'completion--string) + (choose-completion nil t t) + t)))) + (defun minibuffer-visible-completions--filter (cmd) "Return CMD if `minibuffer-visible-completions' bindings should be active." (if minibuffer-visible-completions--always-bind @@ -5133,13 +5152,13 @@ with-minibuffer-completions-window (completion--lazy-insert-strings) ,@body)))) -(defcustom minibuffer-completion-auto-choose t +(defcustom minibuffer-completion-auto-choose nil "Non-nil means to automatically insert completions to the minibuffer. When non-nil, then `minibuffer-next-completion' and `minibuffer-previous-completion' will insert the completion selected by these commands to the minibuffer." :type 'boolean - :version "29.1") + :version "31.1") (defun minibuffer-next-completion (&optional n vertical) "Move to the next item in its completions window from the minibuffer. -- 2.43.7 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 22 02:52:34 2025 Received: (at 77253) by debbugs.gnu.org; 22 Aug 2025 06:52:34 +0000 Received: from localhost ([127.0.0.1]:34457 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1upLda-0000PR-Bo for submit@debbugs.gnu.org; Fri, 22 Aug 2025 02:52:34 -0400 Received: from mout-p-201.mailbox.org ([2001:67c:2050:0:465::201]:38812) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1upLdV-0000P9-Pk for 77253@debbugs.gnu.org; Fri, 22 Aug 2025 02:52:31 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4c7W8P4Z81z9sdW; Fri, 22 Aug 2025 08:52:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1755845541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RQUFy6MqW2yDAHUcvezzBG58psGL2xcbLGZoaPwkXGs=; b=G77ygr/CicCAezrjUtIjIWWlXj2icNGp7k5JZjCE3GjcKDk/WGOhwtm+xpXTia6t3/Lvco fBkSCgAyIGjexdzCJjm2nhfl8221aM+C3HvQmBGokGSTdciXk/u1mRpKz/uNHQGxQ2Xzi9 WR+LS2N03Or4AndpgdebV4Vg09MaswFDx0Gd9Xtw2Y0RIy+q2ueXS8zMEaGQClqjv9jk/b BjcYdQFrgyyKeP8gUCYysSrwfxKVTlQw3mRBfJ2fEzrBj2KrMahs7mfIt6YFgKLt6Ysc67 NL3CNR5fzuU/QtHHMI9XRjv7wfwMBN2s5xVO+FJr2g70t6AyK496ZVKLU0oJMA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of juri@linkov.net designates 2001:67c:2050:b231:465::1 as permitted sender) smtp.mailfrom=juri@linkov.net From: Juri Linkov To: Spencer Baugh Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys, [PATCH] Make RET in minibuffer choose selected completion In-Reply-To: Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> <86seioa0iy.fsf@gnu.org> <87bjp9v7ji.fsf@mail.linkov.net> <87qzx54179.fsf@mail.linkov.net> Date: Fri, 22 Aug 2025 09:48:12 +0300 Message-ID: <87y0rbkg2b.fsf@mail.linkov.net> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 4c7W8P4Z81z9sdW X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: sbaugh@catern.com, Eli Zaretskii , 77253@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: -1.7 (-) > How about this patch? Thanks, I tested your patch, and the new behavior of RET is more intuitive. Does this make M-RET mostly obsolete? Or at least supersedes it? Then we could replace M-RET with RET in the completion help text: Click or type M-RET on a completion to select it. > It doesn't add support for C-u RET inserting the completion, you have to > use C-u M-RET as you already can today. Do you think that's fine? It > seems a bit safer. It's possible to add a prefix argument to the commands bound to RET. Or maybe the existing 'C-u M-RET' would be sufficient? Unless we decide to make M-RET obsolete. > Also no NEWS entry still, will add one once we settle on a patch. It would be interesting to see how would you describe this change in NEWS for users. > It occurs to me now that we could maybe also make RET choose the > selected completion by default in completion-in-region-mode, though that > would require a :filter keymap entry like minibuffer-visible-completions > has. completion-auto-deselect makes this viable, by the same reasoning > I mentioned earlier in the bug. So maybe that's also interesting to do? Definitely, this would be needed for consistency with the minibuffer behavior. From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 22 15:07:44 2025 Received: (at 77253) by debbugs.gnu.org; 22 Aug 2025 19:07:44 +0000 Received: from localhost ([127.0.0.1]:37634 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1upX70-0003xF-Se for submit@debbugs.gnu.org; Fri, 22 Aug 2025 15:07:43 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:41289) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1upX6u-0003wv-8F for 77253@debbugs.gnu.org; Fri, 22 Aug 2025 15:07:37 -0400 From: Spencer Baugh To: Juri Linkov Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys, [PATCH] Make RET in minibuffer choose selected completion In-Reply-To: <87y0rbkg2b.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 22 Aug 2025 09:48:12 +0300") References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> <86seioa0iy.fsf@gnu.org> <87bjp9v7ji.fsf@mail.linkov.net> <87qzx54179.fsf@mail.linkov.net> <87y0rbkg2b.fsf@mail.linkov.net> Date: Fri, 22 Aug 2025 15:07:29 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1755889649; bh=UHJKoyLxdN9w181G1O8KtEnecsjLosWk3NNAsMMSdB8=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=JFOyMJLlNc0fs9twixV8Yx0kjE4MNDwDzQrnL65zrxnipOrHnZlxEzGmJ0DTZbvKx owcEu/lyFA2WXvdGIhbo+UEzPr2rf9gDh9rFVhqZ75bqGIyEpfd+qUEOjbeNgujTGk m62STq1cS5QpkOES7EW58TIGg/NAjkje0631R54bwERidbdyUH6TkYlNk80WdnZMIZ m2mTFNhAOF9oTKerILGQ6ZmXgeL1GuZh2Dp0TTO0o55iCSASOQqQKgS33Fc9rGtG9G nVutHqB1P7LKo+3S88pvjoBnyd3Qt9VDhc7w9iN9QPwfTfqQxQJDVqb2EF3bMjGCkn o3uUBPEh/YOPQ== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77253 Cc: sbaugh@catern.com, Eli Zaretskii , 77253@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 (---) --=-=-= Content-Type: text/plain Juri Linkov writes: >> How about this patch? > > Thanks, I tested your patch, and the new behavior of RET is more intuitive. > > Does this make M-RET mostly obsolete? Or at least supersedes it? It does, though of course we should keep the binding around for compatibility - it doesn't hurt to have it, and also it's sometimes a bit convenient to hold M- down while hitting RET. > Then we could replace M-RET with RET in the completion help text: > > Click or type M-RET on a completion to select it. True. Did this partially in the attached patch. Now in-buffer completion says RET in the completion help text. (And the code to render the completion help text is also a bit simpler) minibuffer completion still says M-RET, because it's a bit trickier, since it has some different commands bound to RET... doesn't seem too bad, anyway, M-RET still works and we can fix it up more later if we think of a good way. >> It doesn't add support for C-u RET inserting the completion, you have to >> use C-u M-RET as you already can today. Do you think that's fine? It >> seems a bit safer. > > It's possible to add a prefix argument to the commands bound to RET. > Or maybe the existing 'C-u M-RET' would be sufficient? > Unless we decide to make M-RET obsolete. Added support for this to my new/changed commands. >> Also no NEWS entry still, will add one once we settle on a patch. > > It would be interesting to see how would you describe this change > in NEWS for users. Done. >> It occurs to me now that we could maybe also make RET choose the >> selected completion by default in completion-in-region-mode, though that >> would require a :filter keymap entry like minibuffer-visible-completions >> has. completion-auto-deselect makes this viable, by the same reasoning >> I mentioned earlier in the bug. So maybe that's also interesting to do? > > Definitely, this would be needed for consistency with the minibuffer behavior. Agreed, done. In fact, now that the RET binding is provided also for in-buffer completion, I think the RET binding provided by minibuffer-visible-completions can be dropped. So I did that in the latest version of the patch. Also included some new tests. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Make-RET-choose-the-selected-completion.patch >From 2270c2181abe5cd83b9e33763b7af9a9d975caaf Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Thu, 21 Aug 2025 14:33:23 -0400 Subject: [PATCH] Make RET choose the selected completion Previously, one could select a completion via M-/M-, but then RET would not actually select the chosen completion. With the addition of completion-auto-deselect, this is not actually necessary: we can reasonably assume that when a completion is selected, the user wants to use that, since their last action must have been to select it. So, just choose the selected completion on RET. This lets us default minibuffer-completion-auto-choose to nil. For minibuffers with require-match completion, this can be done by changing the existing command bound to RET. For minibuffers with nil require-match completion, RET was previously bound to exit-minibuffer, and changing exit-minibuffer to have this logic is risky. We handle that case by adding a new minibuffer-completion-exit which wraps exit-minibuffer and bind RET to it. * lisp/minibuffer.el (minibuffer-insert-completion-if-selected) (minibuffer-completion-exit, completion--selected-candidate): Add. (minibuffer-complete-and-exit): Call minibuffer-choose-completion. (bug#77253) (minibuffer-local-completion-map): Bind RET to minibuffer-completion-exit, overriding exit-minibuffer. (completion-in-region-mode-map): Bind RET to minibuffer-choose-completion when there's a selected candidate. (minibuffer-completion-auto-choose): Default to nil. (minibuffer-visible-completions--filter) (minibuffer-visible-completions-map): Delete RET binding, no longer necessary. * lisp/simple.el (completion-setup-function): Update completion help text to show more correct bindings. * test/lisp/minibuffer-tests.el (completions-header-format-test) (minibuffer-next-completion): Set minibuffer-completion-auto-choose=t explicitly. (with-minibuffer-setup, minibuffer-completion-RET-prefix) (completion-in-region-next-completion): Add new tests. * etc/NEWS: Announce. --- etc/NEWS | 8 ++++++ lisp/minibuffer.el | 50 +++++++++++++++++++++++++-------- lisp/simple.el | 32 +++++++++------------ test/lisp/minibuffer-tests.el | 53 ++++++++++++++++++++++++++++++++++- 4 files changed, 112 insertions(+), 31 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 27244565d19..058f0e896eb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -183,6 +183,14 @@ different completion categories by customizing be updated as you type, or nil to suppress this always. Note that for large or inefficient completion tables this can slow down typing. +--- +*** RET chooses the completion selected with M-/M- +If a completion candidate is selected with M- or M-, hitting +RET will exit completion with that as the result. This works both in +minibuffer completion and in-buffer completion. This supersedes +'minibuffer-completion-auto-choose', which previously provided similar +behavior; that variable is now nil by default. + +++ *** New user option 'completion-pcm-leading-wildcard'. This option configures how the partial-completion style does completion. diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 37bfbdc0765..8a617b7168f 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1994,12 +1994,17 @@ minibuffer--require-match (defvar minibuffer--original-buffer nil "Buffer that was current when `completing-read' was called.") -(defun minibuffer-complete-and-exit () +(defun minibuffer-complete-and-exit (&optional no-exit) "Exit if the minibuffer contains a valid completion. Otherwise, try to complete the minibuffer contents. If completion leads to a valid completion, a repetition of this command will exit. +If a completion candidate is selected in the *Completions* buffer, it +will be inserted in the minibuffer first. If NO-EXIT is non-nil, don't +actually exit the minibuffer, just insert the selected completion if +any. + If `minibuffer-completion-confirm' is `confirm', do not try to complete; instead, ask for confirmation and accept any input if confirmed. @@ -2008,9 +2013,12 @@ minibuffer-complete-and-exit preceding minibuffer command was a member of `minibuffer-confirm-exit-commands', and accept the input otherwise." - (interactive) - (completion-complete-and-exit (minibuffer--completion-prompt-end) (point-max) - #'exit-minibuffer)) + (interactive "P") + (when (completion--selected-candidate) + (minibuffer-choose-completion t t)) + (unless no-exit + (completion-complete-and-exit (minibuffer--completion-prompt-end) (point-max) + #'exit-minibuffer))) (defun completion-complete-and-exit (beg end exit-function) (completion--complete-and-exit @@ -3021,6 +3029,11 @@ completion-in-region-mode-map ;; completion-at-point called directly. "M-?" #'completion-help-at-point "TAB" #'completion-at-point + ;; If a completion is selected, RET will choose it. + "RET" `(menu-item "" minibuffer-choose-completion :filter + ,(lambda (cmd) + (when (completion--selected-candidate) + cmd))) "M-" #'minibuffer-previous-completion "M-" #'minibuffer-next-completion "M-RET" #'minibuffer-choose-completion) @@ -3227,6 +3240,17 @@ completion-help-at-point (define-key map "\n" 'exit-minibuffer) (define-key map "\r" 'exit-minibuffer)) +(defun minibuffer-completion-exit (&optional no-exit) + "Call `exit-minibuffer', inserting the selected completion first if any. + +If NO-EXIT is non-nil, don't `exit-minibuffer', just insert the selected +completion." + (interactive "P") + (when (completion--selected-candidate) + (minibuffer-choose-completion t t)) + (unless no-exit + (exit-minibuffer))) + (defvar-keymap minibuffer-local-completion-map :doc "Local keymap for minibuffer input with completion." :parent minibuffer-local-map @@ -3236,6 +3260,7 @@ minibuffer-local-completion-map ;; another binding for it. ;; "M-TAB" #'minibuffer-force-complete "SPC" #'minibuffer-complete-word + "RET" #'minibuffer-completion-exit "?" #'minibuffer-completion-help "" #'switch-to-completions "M-v" #'switch-to-completions @@ -3355,16 +3380,18 @@ minibuffer--completions-visible (window-buffer (active-minibuffer-window))) window))) +(defun completion--selected-candidate () + "Return the selected completion candidate if any." + (when-let* ((window (minibuffer--completions-visible))) + (with-current-buffer (window-buffer window) + (get-text-property (point) 'completion--string)))) + (defun minibuffer-visible-completions--filter (cmd) "Return CMD if `minibuffer-visible-completions' bindings should be active." (if minibuffer-visible-completions--always-bind cmd (when-let* ((window (minibuffer--completions-visible))) - (when (if (eq cmd #'minibuffer-choose-completion-or-exit) - (with-current-buffer (window-buffer window) - (get-text-property (point) 'completion--string)) - t) - cmd)))) + cmd))) (defun minibuffer-visible-completions--bind (binding) "Use BINDING when completions are visible. @@ -3380,7 +3407,6 @@ minibuffer-visible-completions-map "" (minibuffer-visible-completions--bind #'minibuffer-next-completion) "" (minibuffer-visible-completions--bind #'minibuffer-previous-line-completion) "" (minibuffer-visible-completions--bind #'minibuffer-next-line-completion) - "RET" (minibuffer-visible-completions--bind #'minibuffer-choose-completion-or-exit) "C-g" (minibuffer-visible-completions--bind #'minibuffer-hide-completions)) ;;; Completion tables. @@ -5147,13 +5173,13 @@ with-minibuffer-completions-window (completion--lazy-insert-strings) ,@body)))) -(defcustom minibuffer-completion-auto-choose t +(defcustom minibuffer-completion-auto-choose nil "Non-nil means to automatically insert completions to the minibuffer. When non-nil, then `minibuffer-next-completion' and `minibuffer-previous-completion' will insert the completion selected by these commands to the minibuffer." :type 'boolean - :version "29.1") + :version "31.1") (defun minibuffer-next-completion (&optional n vertical) "Move to the next item in its completions window from the minibuffer. diff --git a/lisp/simple.el b/lisp/simple.el index b0f6621b37e..2a13d59e5cd 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10570,28 +10570,24 @@ completion-setup-function ;; Maybe insert help string. (when completion-show-help (goto-char (point-min)) - (if minibuffer-visible-completions - (let ((helps - (with-current-buffer (window-buffer (active-minibuffer-window)) - (let ((minibuffer-visible-completions--always-bind t)) - (list - (substitute-command-keys - (if (display-mouse-p) - "Click or type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n" - "Type \\[minibuffer-choose-completion-or-exit] on a completion to select it.\n")) + (let ((helps + (with-current-buffer (window-buffer (active-minibuffer-window)) + (let ((minibuffer-visible-completions--always-bind t)) + (list + (substitute-command-keys + (if (display-mouse-p) + "Click or type \\[minibuffer-choose-completion] on a completion to select it.\n" + "Type \\[minibuffer-choose-completion] on a completion to select it.\n")) + (if minibuffer-visible-completions (substitute-command-keys "Type \\[minibuffer-next-completion], \\[minibuffer-previous-completion], \ \\[minibuffer-next-line-completion], \\[minibuffer-previous-line-completion] \ -to move point between completions.\n\n")))))) - (dolist (help helps) - (insert help))) - (insert (substitute-command-keys - (if (display-mouse-p) - "Click or type \\[minibuffer-choose-completion] on a completion to select it.\n" - "Type \\[minibuffer-choose-completion] on a completion to select it.\n"))) - (insert (substitute-command-keys - "Type \\[minibuffer-next-completion] or \\[minibuffer-previous-completion] \ +to move point between completions.\n\n") + (substitute-command-keys + "Type \\[minibuffer-next-completion] or \\[minibuffer-previous-completion] \ to move point between completions.\n\n"))))))) + (dolist (help helps) + (insert help))))))) (add-hook 'completion-setup-hook #'completion-setup-function) diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index e5868351619..7a6480f0392 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el @@ -441,6 +441,17 @@ completion-flex-test-3 15))) +(defmacro with-minibuffer-setup (completing-read &rest body) + (declare (indent 1) (debug (collection body))) + `(catch 'result + (minibuffer-with-setup-hook + (lambda () + (let ((redisplay-skip-initial-frame nil) + (executing-kbd-macro nil)) ; Don't skip redisplay + (throw 'result (progn . ,body)))) + (let ((executing-kbd-macro t)) ; Force the real minibuffer + ,completing-read)))) + (defmacro completing-read-with-minibuffer-setup (collection &rest body) (declare (indent 1) (debug (collection body))) `(catch 'result @@ -577,6 +588,7 @@ completion-next-line-multline-test (ert-deftest completions-header-format-test () (let ((completion-show-help nil) + (minibuffer-completion-auto-choose t) (completions-header-format nil)) (completing-read-with-minibuffer-setup '("aa" "ab" "ac") @@ -726,11 +738,50 @@ completion-cycle (should (equal (minibuffer-contents) "ccc"))))) (ert-deftest minibuffer-next-completion () - (let ((default-directory (ert-resource-directory))) + (let ((default-directory (ert-resource-directory)) + (minibuffer-completion-auto-choose t)) (completing-read-with-minibuffer-setup #'read-file-name-internal (insert "d/") (execute-kbd-macro (kbd "M- M- M-")) (should (equal "data/minibuffer-test-cttq$$tion" (minibuffer-contents)))))) +(ert-deftest minibuffer-completion-RET-prefix () + ;; REQUIRE-MATCH=nil + (with-minibuffer-setup + (completing-read ":" '("aaa" "bbb" "ccc") nil nil) + (execute-kbd-macro (kbd "M- M- C-u RET")) + (should (equal "bbb" (minibuffer-contents)))) + ;; REQUIRE-MATCH=t + (with-minibuffer-setup + (completing-read ":" '("aaa" "bbb" "ccc") nil t) + (execute-kbd-macro (kbd "M- M- C-u RET")) + (should (equal "bbb" (minibuffer-contents))))) + +(defun test/completion-at-point () + (list (point-min) (point) '("test:a" "test:b"))) + +(ert-deftest completion-in-region-next-completion () + (with-current-buffer (get-buffer-create "*test*") + ;; Put this buffer in the selected window so + ;; `minibuffer--completions-visible' works. + (pop-to-buffer (current-buffer)) + (setq-local completion-at-point-functions (list #'test/completion-at-point)) + (insert "test:") + (completion-help-at-point) + (should (minibuffer--completions-visible)) + ;; C-u RET and RET have basically the same behavior for + ;; completion-in-region-mode, since they both dismiss *Completions* + ;; while leaving completion-in-region-mode still active. + (execute-kbd-macro (kbd "M-")) + (should (equal (completion--selected-candidate) "test:a")) + (execute-kbd-macro (kbd "C-u RET")) + (should (equal (buffer-string) "test:a")) + (delete-char -1) + (completion-help-at-point) + (execute-kbd-macro (kbd "M- M-")) + (should (equal (completion--selected-candidate) "test:b")) + (execute-kbd-macro (kbd "RET")) + (should (equal (buffer-string) "test:b")))) + (provide 'minibuffer-tests) ;;; minibuffer-tests.el ends here -- 2.43.7 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 27 14:25:30 2025 Received: (at 77253) by debbugs.gnu.org; 27 Aug 2025 18:25:30 +0000 Received: from localhost ([127.0.0.1]:34884 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1urKpu-0001sh-7J for submit@debbugs.gnu.org; Wed, 27 Aug 2025 14:25:30 -0400 Received: from mout-p-202.mailbox.org ([80.241.56.172]:41682) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1urKpq-0001sI-5r; Wed, 27 Aug 2025 14:25:27 -0400 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4cBtHd6Nc7z9tQL; Wed, 27 Aug 2025 20:25:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; t=1756319117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ieLmhKhsEJkCqPqBwtdIw19fUToxwY8i7//0UoJEprM=; b=qiY/Hb4N9WAOgc1bRblEhUFTeDIx22lZRQLY8j+ZYJjGDU5tZEEsII2xNOttU0dZCc0gXY MYtMhUkPqw7+l7ktCopAwaX/LAuUgGWYvOO+cZ2rlPbfumysnHnug6NGyNPGib+pjEym81 dWqCFnTw4nyyvA1OjkEnGfDLqc0TRcQiQpeow8a50pAGd1OjVBdXGik72ADbIZ06v5IZL7 9GMJRqEo2wANKHD5ET7J2KslXaV9ia+D6XbVn82/Dnnpa3F5e1VILbKFbSE7EPWOqJ4+kb MUlg+B0ge9PwO+FSL6Bzpiy0vrrVU/cACUWVYkDEuds2fXPJISOxDHYq13+11w== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of juri@linkov.net designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=juri@linkov.net From: Juri Linkov To: Spencer Baugh Subject: Re: bug#77253: 30.1.50; Support RET choosing the selected completion without rebinding arrow keys, [PATCH] Make RET in minibuffer choose selected completion In-Reply-To: Organization: LINKOV.NET References: <87jz8d6n9x.fsf@mail.linkov.net> <87ldssz0t6.fsf@mail.linkov.net> <87r02iuzni.fsf@mail.linkov.net> <87ecyhskhg.fsf@mail.linkov.net> <87a58x3y6z.fsf@mail.linkov.net> <87freuzhdb.fsf@catern.com> <87h5zavwru.fsf@mail.linkov.net> <86seioa0iy.fsf@gnu.org> <87bjp9v7ji.fsf@mail.linkov.net> <87qzx54179.fsf@mail.linkov.net> <87y0rbkg2b.fsf@mail.linkov.net> Date: Wed, 27 Aug 2025 21:23:38 +0300 Message-ID: <87v7m87hed.fsf@mail.linkov.net> MIME-Version: 1.0 Content-Type: text/plain X-Rspamd-Queue-Id: 4cBtHd6Nc7z9tQL X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 77253 Cc: sbaugh@catern.com, Eli Zaretskii , 77253@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: -1.7 (-) close 77253 31.0.50 thanks > In fact, now that the RET binding is provided also for in-buffer > completion, I think the RET binding provided by > minibuffer-visible-completions can be dropped. So I did that in the > latest version of the patch. > > Also included some new tests. Thanks, I tested everything and RET works consistently, so now pushed and closed.