From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: sbaugh@catern.com Newsgroups: gmane.emacs.bugs Subject: bug#62700: 29.0.60; minibuffer-{previous,next,choose}-completion behave unintuitively when point is not at end of buffer Date: Fri, 07 Apr 2023 21:02:47 +0000 (UTC) Message-ID: <87sfdbmmmh.fsf@catern.com> References: <864jpsrgaz.fsf@mail.linkov.net> <86h6tr4pi8.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18207"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 62700@debbugs.gnu.org, Spencer Baugh To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 07 23:03:29 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 1pktF1-0004Qv-2m for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 07 Apr 2023 23:03:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pktEe-0001FF-Ik; Fri, 07 Apr 2023 17:03:04 -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 1pktEc-0001Ez-MY for bug-gnu-emacs@gnu.org; Fri, 07 Apr 2023 17:03:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pktEc-0002uR-EC for bug-gnu-emacs@gnu.org; Fri, 07 Apr 2023 17:03:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pktEb-0007lz-Sj for bug-gnu-emacs@gnu.org; Fri, 07 Apr 2023 17:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: sbaugh@catern.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 07 Apr 2023 21:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62700 X-GNU-PR-Package: emacs Original-Received: via spool by 62700-submit@debbugs.gnu.org id=B62700.168090137629867 (code B ref 62700); Fri, 07 Apr 2023 21:03:01 +0000 Original-Received: (at 62700) by debbugs.gnu.org; 7 Apr 2023 21:02:56 +0000 Original-Received: from localhost ([127.0.0.1]:57296 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pktEV-0007lf-Ji for submit@debbugs.gnu.org; Fri, 07 Apr 2023 17:02:55 -0400 Original-Received: from s.wrqvtzvf.outbound-mail.sendgrid.net ([149.72.126.143]:38654) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pktET-0007lQ-LM for 62700@debbugs.gnu.org; Fri, 07 Apr 2023 17:02:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catern.com; h=from:subject:in-reply-to:references:mime-version:to:cc:content-type: content-transfer-encoding:cc:content-type:from:subject:to; s=s1; bh=IKZRQ/Sb6oY9hAncGw8mCt5QtAasOHcCjASRRmFCp6Y=; b=v2fAO3tKfFkCa0d2SIh4bRz2zoJJ9Mt8YlEJPiu9XAebllbn0y4MYK7h0wRKHv6Nm7aT W2ZF2Orcops81n7FkkdzL9cnEJcMdK0mYv59sM7bkOJmzv7EMaOnALP+3Ec5FufdxIL2ZE wF7Rz3CGn/TWMAC+oNtP7t+6eG9+wMESWzvIEGt/+1cwKDnhQB9LQtFK17+50HOF301LbY 53pJNVYeW38WyAMSvgjwrhw0PtjBx0lC5h2gx/2ZFZFjPYnx8vTWKDOWQ6GIr9U7AhxfI0 J0eOH+cnAQtq2Exn4kvdcby1kqUqnye+z5cQyxLsgp/AmPcUBaPe3Utt+EAidviQ== Original-Received: by filterdrecv-7946957d94-bqdbw with SMTP id filterdrecv-7946957d94-bqdbw-1-643084F7-61 2023-04-07 21:02:47.552718378 +0000 UTC m=+3879070.604264158 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-11 (SG) with ESMTP id JO6dp9n1QlKqyCDZDQxW0g Fri, 07 Apr 2023 21:02:47.213 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=::1; helo=localhost; envelope-from=sbaugh@catern.com; receiver= Original-Received: from localhost (localhost [IPv6:::1]) by earth.catern.com (Postfix) with ESMTPSA id A604E60087; Fri, 7 Apr 2023 17:02:46 -0400 (EDT) In-Reply-To: <86h6tr4pi8.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 07 Apr 2023 19:37:51 +0300") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbLf9xoDvZI/sjLbat9p99rIMSCWUuMOEJBUt+p8e4ouUNyZ2rEwGmbs257BhoVrZyg/bRxx07rLJrfGGTyOP/i523qZr0f/vGuIK5/ggOmpcP5+HRir4gq9INUc9Q99kDbGoYMki1SWm/sG6B6KAwse7PrftWKNoZPrGQvdJKM+dA== X-Entity-ID: d/0VcHixlS0t7iB1YKCv4Q== 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:259436 Archived-At: Juri Linkov writes: > Changing the API will definitely cause problems with backwards-compatibility. > But maybe you could find a simple heuristic that would decide what base-suffix > to set in minibuffer-completion-help? Then no API changes will be needed. Thank you for the guidance and suggestion. Here's one heuristic which works decently well: diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 21d4607e7cf..dfb06b5b88f 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2374,7 +2374,11 @@ minibuffer-completion-help (prefix (unless (zerop base-size) (substring string 0 base-size))) (base-prefix (buffer-substring (minibuffer--completion-prompt-end) (+ start base-size))) - (base-suffix (buffer-substring (point) (point-max))) + (base-suffix + (if (eq (alist-get 'category (cdr md)) 'file) + (buffer-substring (save-excursion (search-forward "/" nil t) (point)) + (point-max)) + "")) (all-md (completion--metadata (buffer-substring-no-properties start (point)) base-size md The reasoning here is that if completion returns the full string which should be in the minibuffer, then we should replace the minibuffer with that string, so base-suffix should be "". But if we're completing only part of the string, base-suffix should be something else. AFAIK only file completion falls into the latter category, and it always completes just one component of a path, so I set base-suffix to not include the component of the path that point is in, so that completion replaces it entirely. I think this is basically a satisfactory heuristic, although I'm sure I'm missing some categories of completion besides file completion which complete only part of the string. Regardless of whether this is a satisfactory heuristic, it's revealed to me an unexpected behavior of a solution to this bug using base-suffix, which may or may not be fine: Point is moved to the end of the completion inserted. So e.g. if point is at | and I'm completing |-path, then when I choose the completion load-path, point will be at load-path| rather than load|-path. This isn't a huge issue but it might be a little annoying? I don't know if there's any way to fix this.