From unknown Sat Sep 13 05:10:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#79377: [PATCH] Return case common to all completions in try-completion Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, dmitry@gutov.dev, bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Sep 2025 13:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 79377 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 79377@debbugs.gnu.org Cc: Stefan Monnier , Dmitry Gutov X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Stefan Monnier , Dmitry Gutov Received: via spool by submit@debbugs.gnu.org id=B.17569048661862 (code B ref -1); Wed, 03 Sep 2025 13:08:02 +0000 Received: (at submit) by debbugs.gnu.org; 3 Sep 2025 13:07:46 +0000 Received: from localhost ([127.0.0.1]:39353 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1utnDG-0000Tx-0S for submit@debbugs.gnu.org; Wed, 03 Sep 2025 09:07:46 -0400 Received: from lists.gnu.org ([2001:470:142::17]:58668) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1utnDB-0000Td-5J for submit@debbugs.gnu.org; Wed, 03 Sep 2025 09:07:43 -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 1utnD4-0003DP-V0 for bug-gnu-emacs@gnu.org; Wed, 03 Sep 2025 09:07:35 -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 1utnD2-0001Uf-64 for bug-gnu-emacs@gnu.org; Wed, 03 Sep 2025 09:07:34 -0400 From: Spencer Baugh Date: Wed, 03 Sep 2025 09:07:30 -0400 Message-ID: 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=1756904850; bh=9E6HWzByr6p/CFIVnlNGCtrxgyo9p4TTldeHUIh3j78=; h=From:To:Subject:Date; b=gVjSemE2FeLObgBaHxlAvVceZlHqtn6Crn0jkiWqTzMuF00fyKaLXv0g7/6pfwP07 y4beTRavpHyre5rh4owhrKm5kEiWMX5qca/G4YpssuQ1znMzzI5uGHIJD3Pzd8lG/e xxMSMKjflf00/503JmfV/OcIeleA6nvSf9M/y+v4AC0x1Gnv8vGyTnU8mVlfHQ2fcl YBIDKnlk9rhyIgUOYnhKv3srAsR/C5H21D7zN3hFLlo+RBiKeCr0yBv8QKkbeTi046 3mf5dSxCDIoY+57t/0L9Mbzgm53L06luD1SoOgxiv7N4zGaP21hc/7BzkP87h6IlkS 2OyjnjGqelVRQ== 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_H5=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-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 (/) --=-=-= Content-Type: text/plain Tags: patch There are a few bugs with completion-pcm-try-completion not returning text whose case matches the completions, even when the case is identical between all the completions. I added some tests covering them. Ultimately, these bugs are nicely fixed by an improvement to Ftry_completion; the removed conditional (and its associated comment) in Ftry_completion didn't actually improve behavior, but instead made case behavior worse. I believe the bad behavior which this conditional was originally attempting to stop was removed at some point by other enhancements to Ftry_completion's completion-ignore-case behavior, so the conditional isn't necessary anymore. In GNU Emacs 30.1.90 (build 43, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2025-09-03 built on igm-qws-u22796a Repository revision: 8a831d9c110ea4dd349444de8f99d7cee10c5273 Repository branch: emacs-30 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Rocky Linux 8.10 (Green Obsidian) Configured using: 'configure --with-x-toolkit=lucid --without-gpm --without-gconf --without-selinux --without-imagemagick --with-modules --with-gif=no --with-cairo --with-rsvg --without-compress-install --with-tree-sitter --with-native-compilation=aot PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Return-case-common-to-all-completions-in-try-complet.patch >From 1064a06c656bd10db29c2749ce7b87b1100a78b1 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Wed, 3 Sep 2025 08:48:05 -0400 Subject: [PATCH] Return case common to all completions in try-completion When completion-ignore-case is non-nil, if all completions share a common prefix ignoring case, try-completion has always returned that. Now, if all completions also share a common prefix including case, try-completion includes that common prefix in its return value. * lisp/minibuffer.el (completion-pcm--merge-completions): Always use return value from try-completion, which may change case. * src/minibuf.c (Ftry_completion): Return the common prefix which changes case. * test/lisp/minibuffer-tests.el (completion-pcm-bug4219) (completion-substring-test-5): New tests. --- lisp/minibuffer.el | 2 +- src/minibuf.c | 6 ------ test/lisp/minibuffer-tests.el | 28 +++++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index f3bca47f271..036e347ae22 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4705,7 +4705,7 @@ completion-pcm--merge-completions ;; `prefix' only wants to include the fixed part before the ;; wildcard, not the result of growing that fixed part. (when (seq-some (lambda (elem) (eq elem 'prefix)) wildcards) - (setq prefix fixed)) + (setq prefix (substring prefix 0 (length fixed)))) (push prefix res) ;; Push all the wildcards in this stretch, to preserve `point' and ;; `star' wildcards before ELEM. diff --git a/src/minibuf.c b/src/minibuf.c index 6d96160a851..53bc905af6f 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -1820,12 +1820,6 @@ DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0, if (NILP (bestmatch)) return Qnil; /* No completions found. */ - /* If we are ignoring case, and there is no exact match, - and no additional text was supplied, - don't change the case of what the user typed. */ - if (completion_ignore_case && bestmatchsize == SCHARS (string) - && SCHARS (bestmatch) > bestmatchsize) - return string; /* Return t if the supplied string is an exact match (counting case); it does not require any change to be made. */ diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index de1a98c8189..a0c6a2fb8d5 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el @@ -345,7 +345,24 @@ completion-pcm-bug4219 (should (equal (let ((completion-ignore-case t)) (completion-pcm-try-completion "a" '("ABC" "ABD") nil 1)) - '("AB" . 2)))) + '("AB" . 2))) + ;; Even when the text isn't growing. + (should (equal + (let ((completion-ignore-case t)) + (completion-pcm-try-completion "ab" '("ABC" "ABD") nil 2)) + '("AB" . 2))) + ;; Or when point is in the middle of the region changing case. + (should (equal + (let ((completion-ignore-case t)) + (completion-pcm-try-completion "ab" '("ABC" "ABD") nil 1)) + '("AB" . 2))) + ;; We don't change case if it doesn't match all of the completions, though. + (should (equal + (let ((completion-ignore-case t)) (try-completion "a" '("ax" "Ay"))) + "a")) + (should (equal + (let ((completion-ignore-case t)) (try-completion "a" '("Ay" "ax"))) + "a"))) (ert-deftest completion-substring-test-1 () ;; One third of a match! @@ -409,6 +426,15 @@ completion-substring-test-5 (should (equal (completion-pcm--merge-try '("a" prefix "b") '("axb" "ayb") "" "") '("ab" . 2))) + ;; Letter-casing from the completions on the common prefix is still applied. + (should (equal + (let ((completion-ignore-case t)) + (completion-pcm--merge-try '("a" prefix "b") '("Axb" "Ayb") "" "")) + '("Ab" . 2))) + (should (equal + (let ((completion-ignore-case t)) + (completion-pcm--merge-try '("a" prefix "b") '("AAxb" "AAyb") "" "")) + '("Ab" . 2))) ;; substring completion should successfully complete the entire string (should (equal (completion-substring-try-completion "b" '("ab" "ab") nil 0) -- 2.43.7 --=-=-=-- From unknown Sat Sep 13 05:10:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#79377: [PATCH] Return case common to all completions in try-completion Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Sep 2025 13:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 79377 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Spencer Baugh Cc: Dmitry Gutov , 79377@debbugs.gnu.org Received: via spool by 79377-submit@debbugs.gnu.org id=B79377.17569071009679 (code B ref 79377); Wed, 03 Sep 2025 13:45:02 +0000 Received: (at 79377) by debbugs.gnu.org; 3 Sep 2025 13:45:00 +0000 Received: from localhost ([127.0.0.1]:39449 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1utnnH-0002W3-Pt for submit@debbugs.gnu.org; Wed, 03 Sep 2025 09:45:00 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:51506) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1utnnC-0002Vk-3j for 79377@debbugs.gnu.org; Wed, 03 Sep 2025 09:44:58 -0400 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id DF58280A13; Wed, 3 Sep 2025 09:44:47 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1756907086; bh=0KvQKnUnw3ZW6jCGAYKDhqKzNRvDw252xPcg5JmOsD8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=mnl1JG6bjobBdHAvJErZjZepGlapBETUiQeK5mxMLBBlFwG3gxynLpe2pNrsi2Bd2 pMk39RGwb+CjA94FgtSuXSkYdkCS+tmAKt+0yNZ9x2q1JgJQWjqA+EPkZk8LrT3jl5 71tOw/p0cZnvvITJTAZT92JRwHVhfI+wLcNm5RqjLb+ykMnHme+er6CMlm/7+UjkF0 PJC5Wqy64YIzrRZdeYofk2DpdUHwA/wOF6L3yUCdQHnx6h44uWEF6rtSSyh1V6XCzx nkUgfwj+bb3nQzkTny68nYAkyWYrj65iob8g4BX3ziQi8SVpCt5f1BSiYbyaVNtC62 RY7vFLDXW0Q4A== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 936C9806D1; Wed, 3 Sep 2025 09:44:46 -0400 (EDT) Received: from pastel (69-165-161-194.dsl.teksavvy.com [69.165.161.194]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 688F1120342; Wed, 3 Sep 2025 09:44:46 -0400 (EDT) From: Stefan Monnier In-Reply-To: Message-ID: References: Date: Wed, 03 Sep 2025 09:44:45 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.299 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) 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 (---) > Ultimately, these bugs are nicely fixed by an improvement to > Ftry_completion; the removed conditional (and its associated comment) in > Ftry_completion didn't actually improve behavior, but instead made case > behavior worse. I believe the bad behavior which this conditional was > originally attempting to stop was removed at some point by other > enhancements to Ftry_completion's completion-ignore-case behavior, so > the conditional isn't necessary anymore. Hmm... the way I read the code (and its comment), this conditional does very purposefully what you don't want. I don't know why that was considered desirable, so I tend to agree with you here, but I don't know what you think was the "bad behavior which this conditional was originally attempting to stop". Stefan From unknown Sat Sep 13 05:10:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#79377: [PATCH] Return case common to all completions in try-completion Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Sep 2025 16:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 79377 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Stefan Monnier Cc: Dmitry Gutov , 79377@debbugs.gnu.org Received: via spool by 79377-submit@debbugs.gnu.org id=B79377.175691813815095 (code B ref 79377); Wed, 03 Sep 2025 16:49:01 +0000 Received: (at 79377) by debbugs.gnu.org; 3 Sep 2025 16:48:58 +0000 Received: from localhost ([127.0.0.1]:41293 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1utqfJ-0003vN-K2 for submit@debbugs.gnu.org; Wed, 03 Sep 2025 12:48:57 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:57149) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1utqfH-0003uu-9X for 79377@debbugs.gnu.org; Wed, 03 Sep 2025 12:48:56 -0400 From: Spencer Baugh In-Reply-To: (Stefan Monnier's message of "Wed, 03 Sep 2025 09:44:45 -0400") References: Date: Wed, 03 Sep 2025 12:48:49 -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=1756918129; bh=whgBZt7KjI2gcz+z4rA8YYIUq6bf+ry1ng9CKGJjoZ4=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=0jUefKyQd7vnhonu5ND93k++7qy6xPGl5QuN8aqrMRraIViqWRT3fQDoo+P0ziPN1 oBx3qncb1d1BxXn1lsGvJAp5V5JUoMmD7dyX+2vH8uAYE7ConVuDkfnqkvpMWVV9tg kvR+wwxJxsTYeCW99V1pqtPciJfeehAqSXscWpxROxBjjnltvMUJ8Q9sAx/nDT4EQS COjTwKM99xmUMxUjBKiOcauyRrejbnkmYrndp+Houyo9Y/evS1HgvZ7ZaPqmE/XPIK N7nFhdYsanmk6TFI7QjE7rOzyBIFuyZ3bYcJRocmar2+OTTLD6Ovi8lJi01Lprndt1 cXm+Hb2fTrpYQ== X-Spam-Score: -2.3 (--) 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 (---) Stefan Monnier writes: >> Ultimately, these bugs are nicely fixed by an improvement to >> Ftry_completion; the removed conditional (and its associated comment) in >> Ftry_completion didn't actually improve behavior, but instead made case >> behavior worse. I believe the bad behavior which this conditional was >> originally attempting to stop was removed at some point by other >> enhancements to Ftry_completion's completion-ignore-case behavior, so >> the conditional isn't necessary anymore. > > Hmm... the way I read the code (and its comment), this conditional does > very purposefully what you don't want. I don't know why that was > considered desirable, so I tend to agree with you here, but I don't > know what you think was the "bad behavior which this conditional was > originally attempting to stop". Ah, you're right. I just read through the history of this function and I can't see anything like that. So... yeah, I guess the "bad behavior which this conditional was originally attempting to stop" is exactly the behavior I want. Well, 34 years after it was originally written, I do think deleting this conditional is better :)