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: Tue, 02 May 2023 15:13:21 +0000 (UTC) Message-ID: <874jourckv.fsf@catern.com> References: <8635574n10.fsf@mail.linkov.net> <868rema032.fsf@mail.linkov.net> <83r0se4bwf.fsf@gnu.org> <87pm7xkqsd.fsf@catern.com> <83jzy419bk.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="12201"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 62700@debbugs.gnu.org, sbaugh@janestreet.com, juri@linkov.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 02 17:14:15 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 1ptrhm-0002yC-BG for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 May 2023 17:14:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ptrhc-0007y2-F3; Tue, 02 May 2023 11:14: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 1ptrha-0007xo-8J for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 11:14: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 1ptrhZ-0004yj-Vf for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 11:14:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ptrhZ-0007MH-QM for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 11:14: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: Tue, 02 May 2023 15:14: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.168304040928225 (code B ref 62700); Tue, 02 May 2023 15:14:01 +0000 Original-Received: (at 62700) by debbugs.gnu.org; 2 May 2023 15:13:29 +0000 Original-Received: from localhost ([127.0.0.1]:44827 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ptrh2-0007L8-Ip for submit@debbugs.gnu.org; Tue, 02 May 2023 11:13:29 -0400 Original-Received: from s.wrqvwxzv.outbound-mail.sendgrid.net ([149.72.154.232]:38680) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ptrh0-0007Km-GF for 62700@debbugs.gnu.org; Tue, 02 May 2023 11:13:27 -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=ZnNbtigu3k0Z/y0LGNq/fRyZR7sjjaFtj6GvUbkATik=; b=lDOl21K4LjX9zt03jESV1FY6/FxKc7CXPpqmAc2SRlCTE4/Cko8cU2Fn5w9Oe3iN4/W/ mnsOBDQJ6DgexxUCBwU17jyUQ+7mQ9bvyJu1iM4GkHVD2yfN3Wm9rIMuZi/k6Ws6gQQ3F4 JdyQeKhRokWwRFbfD1DgdIHo5pW556O11O8T1xEPW6LrQwmfClQ1jleGX6nb2bfIlOXHCK pDekTWkaDXB//JjY3jd8Yfv6PM993X8xeM4efRtfzk3pfIBveyIhBDBx63mqSs63mJUUFF sI200Qmx8+ltiMCpnfX7iwR15jQcxGsT8Q1p9PG/TIi2Ubx8y9pDzNVSYD3PCSkA== Original-Received: by filterdrecv-59cb65cf6d-4lbfg with SMTP id filterdrecv-59cb65cf6d-4lbfg-1-64512890-63 2023-05-02 15:13:20.991122311 +0000 UTC m=+4742398.070011593 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-15 (SG) with ESMTP id k1-ysBLKTeicTlcO7xc5CQ Tue, 02 May 2023 15:13:20.757 +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 2938260039; Tue, 2 May 2023 11:13:20 -0400 (EDT) In-Reply-To: <83jzy419bk.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 22 Apr 2023 13:48:47 +0300") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbKAsM+HLA4rmDqq/BwHmIPTg7x3e50VdOnU+cBNMinar0SLmr9l5xKXG/AgA1pIPabxEU02SqEtPVLtZ/gqCLX4o/krjoy1zgDTJhrOv46sbL4+oOygnF60s6JHyMkPymUlhdMnyU7zeWUmvwBHAPsMImjvCIZkXWZIx9eTPBE7mQ== 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:260938 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii writes: >> From: sbaugh@catern.com >> Date: Fri, 21 Apr 2023 18:56:35 +0000 (UTC) >> Cc: Spencer Baugh , 62700@debbugs.gnu.org, >> juri@linkov.net >> >> >> 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. > > Thanks, but I'd like to make this still safer for the release branch: > >> --- 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)))))) > > Here, the values used only when minibuffer-completion-auto-choose is > non-nil should be computed only when that variable is non-nil, > preferably inside the '(when auto-choose' clause. OK, here's the patch with this change. (As discussed elsewhere in the thread, the patch includes changes to minibuffer-choose-completion because that function also is affected by the bug and also needs to be fixed) --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Handle-point-not-at-EOB-in-minibuffer-choose-complet.patch >From d446bec7d59944e25f478a63bd6c980ca7ce48d6 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 | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 21d4607e7cf..f457ecfcf7d 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4460,13 +4460,25 @@ 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) + (buf (current-buffer))) (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) + ;; Backported fix for bug#62700 + (md + (with-current-buffer buf + (completion--field-metadata (minibuffer--completion-prompt-end)))) + (base-suffix + (if (eq (alist-get 'category (cdr md)) 'file) + (with-current-buffer buf + (buffer-substring (save-excursion (search-forward "/" nil t) (point)) + (point-max))) + "")) + (completion-base-affixes (list (car completion-base-affixes) base-suffix))) (choose-completion nil t t)))))) (defun minibuffer-previous-completion (&optional n) @@ -4485,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 --=-=-=--