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, 21 Apr 2023 18:56:35 +0000 (UTC) Message-ID: <87pm7xkqsd.fsf@catern.com> References: <8635574n10.fsf@mail.linkov.net> <868rema032.fsf@mail.linkov.net> <83r0se4bwf.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33252"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 62700@debbugs.gnu.org, Spencer Baugh , juri@linkov.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 21 20:57:25 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 1ppvwh-0008Oc-Ry for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 21 Apr 2023 20:57:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppvwP-00088Y-Iz; Fri, 21 Apr 2023 14:57: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 1ppvwM-00088C-Kn for bug-gnu-emacs@gnu.org; Fri, 21 Apr 2023 14:57: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 1ppvwM-0000Di-CA for bug-gnu-emacs@gnu.org; Fri, 21 Apr 2023 14:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ppvwL-0001TT-Sr for bug-gnu-emacs@gnu.org; Fri, 21 Apr 2023 14:57: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, 21 Apr 2023 18:57: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.16821034035644 (code B ref 62700); Fri, 21 Apr 2023 18:57:01 +0000 Original-Received: (at 62700) by debbugs.gnu.org; 21 Apr 2023 18:56:43 +0000 Original-Received: from localhost ([127.0.0.1]:41157 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ppvw2-0001Sx-T0 for submit@debbugs.gnu.org; Fri, 21 Apr 2023 14:56:43 -0400 Original-Received: from s.wrqvtbkv.outbound-mail.sendgrid.net ([149.72.123.24]:11200) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ppvw0-0001Sj-Bh for 62700@debbugs.gnu.org; Fri, 21 Apr 2023 14:56:41 -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: cc:content-type:from:subject:to; s=s1; bh=bUXVRemgsl+C9gZCPflR5Q3quOclMnX4vvEpbs4hTwk=; b=FQ1a31vc5p9VWmZ1D5kIFshjoKX2QPoj8kdTgPlzRPbn1hYeEapX9jKx/97RhLD/jXr+ cl91O/7FYsbitdRxrlQq0toMZpwM8oR5hDahqQ0yD3an37YNbociqa9h1dp7//OO/GpY2G vzLFX7j/E1EKvKbswOR5zBAc0HwiC6oqh5pL4IoOWAdNovssmaGc0mfSf8NLxdrYMOdF6c l0lFAXXbkw4P9vlXDy+Anfp3d1PWs8HI7CSh9Tc+7l8m8yKPqq6DnLaKSO+XOnAIBbFF1A nmZPp8H1pnecQRYEpYtaT4gkeKVZO06O5I3Ej24WMArAs1rVVI11TZwW4ZO1eoHw== Original-Received: by filterdrecv-68f8d557c9-5hs8d with SMTP id filterdrecv-68f8d557c9-5hs8d-1-6442DC63-A 2023-04-21 18:56:35.081827422 +0000 UTC m=+5081104.936067886 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-16 (SG) with ESMTP id C9-qPoW-QSmR0Uq0LN6sPg Fri, 21 Apr 2023 18:56:34.912 +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 4BF22600AA; Fri, 21 Apr 2023 14:56:34 -0400 (EDT) In-Reply-To: <83r0se4bwf.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 20 Apr 2023 22:00:16 +0300") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbJc8QAZRidaYgdF8l6hSJ5NFnZnp1MG/cUBGqSxXJUjsXktJX/6WrEGAYgcyK69TTxb5gZolmMHiA7wx7CKIp0GAHJZy3jNzfWFxgr4K1AD5dCV1gC2f+Vijwpk8rQe4Tdk678ILI9i3Z7kZqXba9BjQ2dmQj130/lvCuJADZ9Qcw== 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:260411 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii writes: >> Cc: 62700@debbugs.gnu.org, Spencer Baugh >> From: Spencer Baugh >> Date: Thu, 20 Apr 2023 14:46:45 -0400 >> >> Juri Linkov writes: >> >>>>> It just needs more testing for different categories of completion. >> >>>> >> >>>> Which categories do you have in mind? >> >>> >> >>> Actually, I can't find categories where it could fail. >> >>> So your patch looks safe to push. >> >> >> >> Can we go ahead and push it to Emacs master, then? I will work on the >> >> changing-only-new-code backport for Emacs 29 as Eli requested. >> > >> > But your patch changes only new code. >> >> Ah, I thought Eli still wanted a backport version because this changes >> code which has been on Emacs 29 for over a year. > > Indeed, that's what I would like to see on the release branch. Mainly > because even if this is deemed a bug, it happens in a relatively rare > situation, so I'd like to avoid risking breakage in code which affects > other situations. Here's the backport for the release branch. (FYI, my papers have been signed and the FSF copyright clerk has approved accepting my contributions again) --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Handle-point-not-at-EOB-in-minibuffer-choose-complet.patch >From a159cfb8ee80e24de180d002caa61119edc7afc1 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Fri, 21 Apr 2023 14:55:00 -0400 Subject: [PATCH] Handle point not at EOB in minibuffer-choose-completion Without this change, only the minibuffer contents before point are cleared when a completion is chosen, which results in stray text when point is in the middle of the minibuffer. After this change, we heuristically decide either to clear the whole buffer or only part of it, taking into account the location of point. This is a backport for the Emacs 29 release branch of a simpler fix in minibuffer-completion-help. * lisp/minibuffer.el (minibuffer-next-completion): (minibuffer-choose-completion): Recalculate completion-base-affixes with point --- lisp/minibuffer.el | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index dfb06b5b88f..86946ec9ce1 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4464,13 +4464,21 @@ minibuffer-next-completion When `minibuffer-completion-auto-choose' is non-nil, then also insert the selected completion to the minibuffer." (interactive "p") - (let ((auto-choose minibuffer-completion-auto-choose)) + (let* ((auto-choose minibuffer-completion-auto-choose) + ;; Backported fix for bug#62700 + (md (completion--field-metadata (minibuffer--completion-prompt-end))) + (base-suffix + (if (eq (alist-get 'category (cdr md)) 'file) + (buffer-substring (save-excursion (search-forward "/" nil t) (point)) + (point-max)) + ""))) (with-minibuffer-completions-window (when completions-highlight-face (setq-local cursor-face-highlight-nonselected-window t)) (next-completion (or n 1)) (when auto-choose - (let ((completion-use-base-affixes t)) + (let ((completion-use-base-affixes t) + (completion-base-affixes (list (car completion-base-affixes) base-suffix))) (choose-completion nil t t)))))) (defun minibuffer-previous-completion (&optional n) @@ -4489,9 +4497,17 @@ minibuffer-choose-completion If NO-QUIT is non-nil, insert the completion at point to the minibuffer, but don't quit the completions window." (interactive "P") - (with-minibuffer-completions-window - (let ((completion-use-base-affixes t)) - (choose-completion nil no-exit no-quit)))) + ;; Backported fix for bug#62700 + (let* ((md (completion--field-metadata (minibuffer--completion-prompt-end))) + (base-suffix + (if (eq (alist-get 'category (cdr md)) 'file) + (buffer-substring (save-excursion (search-forward "/" nil t) (point)) + (point-max)) + ""))) + (with-minibuffer-completions-window + (let ((completion-use-base-affixes t) + (completion-base-affixes (list (car completion-base-affixes) base-suffix))) + (choose-completion nil no-exit no-quit))))) (defun minibuffer-complete-history () "Complete the minibuffer history as far as possible. -- 2.38.0 --=-=-=--