From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#65137: 29.1; completion-substring-try-completion doesn't return the longest common substring Date: Tue, 08 Aug 2023 14:04:09 +0300 Message-ID: <83a5v1okwm.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12548"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65137@debbugs.gnu.org To: Spencer Baugh , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 08 13:04:14 2023 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 1qTKVZ-000318-ST for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Aug 2023 13:04:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTKVR-0003xc-1O; Tue, 08 Aug 2023 07:04:05 -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 1qTKVP-0003xI-IQ for bug-gnu-emacs@gnu.org; Tue, 08 Aug 2023 07:04:03 -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 1qTKVP-0004cJ-68 for bug-gnu-emacs@gnu.org; Tue, 08 Aug 2023 07:04:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qTKVO-0007lk-Fz for bug-gnu-emacs@gnu.org; Tue, 08 Aug 2023 07:04:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Aug 2023 11:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65137 X-GNU-PR-Package: emacs Original-Received: via spool by 65137-submit@debbugs.gnu.org id=B65137.169149263729854 (code B ref 65137); Tue, 08 Aug 2023 11:04:02 +0000 Original-Received: (at 65137) by debbugs.gnu.org; 8 Aug 2023 11:03:57 +0000 Original-Received: from localhost ([127.0.0.1]:35345 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qTKVI-0007lR-Ia for submit@debbugs.gnu.org; Tue, 08 Aug 2023 07:03:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42924) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qTKVG-0007lE-In for 65137@debbugs.gnu.org; Tue, 08 Aug 2023 07:03:55 -0400 Original-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 1qTKVA-0004Yq-TX; Tue, 08 Aug 2023 07:03:48 -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=xurk2vtUEMSDHuAfnrN6nTr2Orqg1mIJnUg7CXS0E2Q=; b=oiD+eu4RCojg nsLIR9QENDf1QEepUfzUC4OG2zyinBUyI9BFwXC6JwcbFt/eaxz4yLE/hQwoMb3aNJva78ZQ+k0fF 4uO0wv2Xidox9gS2aRYf+LGnuOAsitCkW2oIM+hAsLDJFH+g7BGrhV7V1hRAy8lbUCyySjSwrdZJG 73kGJ4mV+2fXRWZJtwdPVg0mFBGaEdIdWihXY0bWkqcz7O4ildwPpoaIrQrQbxDf8pu1h1ChTcyRV cGgGIVBDvJrKnObnqu2dT3eXmjg0CA3h0Ua4tMshoolscgLazBuEll9XV8GrdptPXx5nyqtY54iii 3mi4Xu144f3aRJWMtVlWLg==; In-Reply-To: (message from Spencer Baugh on Mon, 07 Aug 2023 19:24:15 -0400) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:266937 Archived-At: > From: Spencer Baugh > Date: Mon, 07 Aug 2023 19:24:15 -0400 > > > The substring completion style differs from the "basic" style by > performing completion at the start of the input string. So for example, > both of these are valid completions for "bar": > > (completion-substring-all-completions "bar" '("foobar" "foobarbaz") #'identity (length "bar")) > -> ("foobarbaz" "foobar" . 0) > > However, the substring completion style's try-completion implementation > does not reflect this. Since "foobar" is a prefix of all the valid > completions, it should be returned by try-completion. But it is not, > regardless of the location of point: > > (completion-substring-try-completion "bar" '("foobar" "foobarbaz") #'identity 0) > -> ("bar" . 3) > > (completion-substring-try-completion "bar" '("foobar" "foobarbaz") #'identity (length "bar")) > -> ("bar" . 3) > > This breaks completion when one completion candidate is a prefix of > other completion candidates. The recourse is moving point to the start > of the input, so that the "basic" completion style takes over, which > will correctly insert the common prefix: > > (completion-basic-try-completion "bar" '("foobar" "foobarbaz") #'identity 0) > -> ("foobar" . 6) > > However, even this does not work in the project-file and xref-location > completion categories, for which the "basic" style is not included in > completion-category-defaults. For such completion categories, there's > simply no way to use completion to insert a common prefix. This is bad, > because a filename or identifier might easily be a prefix of another > filename or identifier. > > The solution is completion-substring-try-completion to be fixed to > insert these common prefixes. I'll try and fix this, although the code > is a bit intimidating. Adding Stefan, in case he has some comments or ideas.