From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#72176: 30.0.60; icomplete-vertical-mode failed to work with Error Date: Sun, 21 Jul 2024 17:42:24 -0400 Message-ID: References: <86cynag9db.fsf@gnu.org> <874j8mc1b7.fsf@gmail.com> <87le1ybwh3.fsf@gmail.com> <868qxyg1dg.fsf@gnu.org> <87h6clc0nu.fsf@gmail.com> <86wmlgegyr.fsf@gnu.org> <86ttgkcqtc.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29505"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: rpluim@gmail.com, Dmitry Gutov , =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , visuweshm@gmail.com, 72176@debbugs.gnu.org, Eli Zaretskii , aqua0210@foxmail.com To: Eshel Yaron Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 21 23:43:28 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sVeL2-0007V1-HR for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Jul 2024 23:43:28 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVeKb-00058E-Nj; Sun, 21 Jul 2024 17:43:01 -0400 Original-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 1sVeKa-000581-89 for bug-gnu-emacs@gnu.org; Sun, 21 Jul 2024 17:43:00 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sVeKa-0003tw-01 for bug-gnu-emacs@gnu.org; Sun, 21 Jul 2024 17:43:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sVeKc-0004Lo-4u for bug-gnu-emacs@gnu.org; Sun, 21 Jul 2024 17:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Jul 2024 21:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72176 X-GNU-PR-Package: emacs Original-Received: via spool by 72176-submit@debbugs.gnu.org id=B72176.172159815716690 (code B ref 72176); Sun, 21 Jul 2024 21:43:02 +0000 Original-Received: (at 72176) by debbugs.gnu.org; 21 Jul 2024 21:42:37 +0000 Original-Received: from localhost ([127.0.0.1]:56236 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sVeKD-0004L8-3h for submit@debbugs.gnu.org; Sun, 21 Jul 2024 17:42:37 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:26330) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sVeKC-0004Kt-0l for 72176@debbugs.gnu.org; Sun, 21 Jul 2024 17:42:36 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 6CA07100043; Sun, 21 Jul 2024 17:42:27 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1721598146; bh=uRqLUg9la7kcarYX5XBBT8MFB1WlzsmhTOzWqGkZTdo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=cU7K1qmVH1tr9bLcrdXieop96xl1E5ve0ZH66QnsZKKskrSk7LA8MRHj21JCtvcWm 27amrK5ukbb4Q3fvAGGn6zLzrGE3Hlg6eE5HYerAF3TMLtlx56HZmHClZaYjJ+cGXv fEL406dPQLAjCKirU167dUheyDugcQgXPfhsIcL1SwSDgpun7U21X/OrchESgPI/53 etjGyHeUu05TGmy0BLiI/GaT+eU9BffiKCOq/VwkDEAtcA57SxAvWkrSUaweqDQVzK f4NS0XD7knO3seGjqTy/wapUH9hhlbdktTl4n4RbV2f0vgpE5t48CkUtEd+MjEArer 7GiME5wK3xzkQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 3DB35100035; Sun, 21 Jul 2024 17:42:26 -0400 (EDT) Original-Received: from pastel (unknown [45.72.245.253]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E43CF1206B0; Sun, 21 Jul 2024 17:42:25 -0400 (EDT) In-Reply-To: (Eshel Yaron's message of "Sat, 20 Jul 2024 18:48:22 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:289095 Archived-At: > I'm afraid you missed your mark, because AFAICT it is Stefan Monnier > that's behind the root cause of this issue, which goes back way before > Dmitry's change or mine :) How do you dare to put in doubt the perfection of my code! > The following diff fixes this for me (including the icomplete symptom), > although I can't claim to fully understand completion--sifn-requote yet: > > diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el > index 31c365bf850..d0eb6b43c80 100644 > --- a/lisp/minibuffer.el > +++ b/lisp/minibuffer.el > @@ -3855,13 +3855,13 @@ completion--sifn-requote > ;; Second assumptions: If qpos is far from the end this can be a bit slow, > ;; so we speed it up by doing a first loop that skips a word at a time. > ;; This word-sized loop is careful not to cut in the middle of env-vars. > - (while (let ((boundary (string-match "\\(\\$+{?\\)?\\w+\\W*\\'" qstr))) > - (and boundary > - (progn > - (setq qprefix (substring qstr 0 boundary)) > - (string-prefix-p uprefix > - (substitute-in-file-name qprefix))))) > - (setq qstr qprefix)) > + ;; (while (let ((boundary (string-match "\\(\\$+{?\\)?\\w+\\W*\\'" qstr))) > + ;; (and boundary > + ;; (progn > + ;; (setq qprefix (substring qstr 0 boundary)) > + ;; (string-prefix-p uprefix > + ;; (substitute-in-file-name qprefix))))) > + ;; (setq qstr qprefix)) > (let ((qpos (length qstr))) > (while (and (> qpos 0) > (string-prefix-p uprefix That's helpful. So the "main assumption" is valid. Indeed in your recipe the problem is that the while loop you comment out (which implements the shortcut based on the "second assumption") ends up throwing away the chunk we need. This is by nature very hackish, and there will still be cases where it back-fires. Maybe indeed we should just get rid of this shortcut, and maybe the resulting performance is good enough. Otherwise, the patch below should fix this particular occurrence. BTW, while there's no doubt that the behavior displayed in your recipe is undesirable, I consider it technically as "suboptimal" rather than incorrect: the displayed completions are too verbose and confusing but using them still ends up selecting the right file. [ Which is why I changed the comment to clarify we want "the largest" QPOS: in your recipe we end up returning a valid QPOS but not the largest one. ] Stefan diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 9ad072daaf5..6fa04e9a062 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3556,7 +3556,7 @@ completion-file-name-table (file-error nil))) ;PCM often calls with invalid directories. (defun completion--sifn-requote (upos qstr) - ;; We're looking for `qpos' such that: + ;; We're looking for (the largest) `qpos' such that: ;; (equal (substring (substitute-in-file-name qstr) 0 upos) ;; (substitute-in-file-name (substring qstr 0 qpos))) ;; Big problem here: we have to reverse engineer substitute-in-file-name to @@ -3586,11 +3586,12 @@ completion--sifn-requote ;; Main assumption: nothing after qpos should affect the text before upos, ;; so we can work our way backward from the end of qstr, one character ;; at a time. - ;; Second assumptions: If qpos is far from the end this can be a bit slow, + ;; Second assumption: If qpos is far from the end this can be a bit slow, ;; so we speed it up by doing a first loop that skips a word at a time. ;; This word-sized loop is careful not to cut in the middle of env-vars. (while (let ((boundary (string-match "\\(\\$+{?\\)?\\w+\\W*\\'" qstr))) (and boundary + (not (string-match-p "/[/~]" qstr boundary)) (progn (setq qprefix (substring qstr 0 boundary)) (string-prefix-p uprefix