all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: sbaugh@catern.com
To: Eli Zaretskii <eliz@gnu.org>
Cc: 62700@debbugs.gnu.org, sbaugh@janestreet.com, juri@linkov.net
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)	[thread overview]
Message-ID: <874jourckv.fsf@catern.com> (raw)
In-Reply-To: <83jzy419bk.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 22 Apr 2023 13:48:47 +0300")

[-- Attachment #1: Type: text/plain, Size: 2341 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> From: sbaugh@catern.com
>> Date: Fri, 21 Apr 2023 18:56:35 +0000 (UTC)
>> Cc: Spencer Baugh <sbaugh@janestreet.com>, 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)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Handle-point-not-at-EOB-in-minibuffer-choose-complet.patch --]
[-- Type: text/x-patch, Size: 3363 bytes --]

From d446bec7d59944e25f478a63bd6c980ca7ce48d6 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@catern.com>
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


  parent reply	other threads:[~2023-05-02 15:13 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <b921ea5c-71a2-4e8f-b1cf-dd26831f8104@email.android.com>
2023-04-10 18:20 ` bug#62700: 29.0.60; minibuffer-{previous,next,choose}-completion behave unintuitively when point is not at end of buffer Juri Linkov
2023-04-20 16:52   ` Spencer Baugh
2023-04-20 18:18     ` Juri Linkov
2023-04-20 18:46       ` Spencer Baugh
2023-04-20 19:00         ` Eli Zaretskii
2023-04-21 18:56           ` sbaugh
2023-04-22 10:48             ` Eli Zaretskii
2023-04-22 12:57               ` sbaugh
2023-04-22 13:15                 ` Eli Zaretskii
2023-04-22 21:38                   ` sbaugh
2023-04-23  6:13                     ` Eli Zaretskii
2023-04-23 11:48                       ` sbaugh
2023-04-24 11:22                         ` Eli Zaretskii
2023-05-02 15:13               ` sbaugh [this message]
2023-05-02 17:57                 ` Eli Zaretskii
2023-05-08 15:48                   ` Juri Linkov
2023-05-08 16:11                     ` Eli Zaretskii
2023-06-03  0:58                       ` Spencer Baugh
2023-06-04  7:09                         ` Eli Zaretskii
2023-06-10 10:51                       ` Eli Zaretskii
2023-06-12 18:27                         ` Juri Linkov
2023-06-13  2:32                           ` Eli Zaretskii
2023-06-13 16:54                             ` Juri Linkov
2023-06-13 16:59                               ` Eli Zaretskii
2023-06-13 20:59                                 ` Spencer Baugh
2023-06-14 17:32                                   ` Juri Linkov
2023-09-03 17:37                                   ` Juri Linkov
2023-09-04  0:30                                     ` sbaugh
2023-09-04  6:51                                       ` Juri Linkov
2023-11-14  7:39                                     ` Juri Linkov
2023-11-15 17:42                                       ` Juri Linkov
2023-04-20 18:51       ` Eli Zaretskii
2023-04-06 17:56 Spencer Baugh
2023-04-06 18:22 ` Eli Zaretskii
2023-04-06 18:58   ` Spencer Baugh
2023-04-06 19:30     ` Eli Zaretskii
2023-04-06 20:42       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-06 18:55 ` Juri Linkov
2023-04-06 19:22   ` Spencer Baugh
2023-04-07 16:37     ` Juri Linkov
2023-04-07 21:02       ` sbaugh
2023-04-08  6:34         ` Eli Zaretskii
2023-04-08 10:58           ` sbaugh
2023-04-08 13:19             ` Eli Zaretskii
2023-04-08 18:36           ` Juri Linkov
2023-04-08 19:32             ` Eli Zaretskii
2023-04-09 16:40               ` Juri Linkov
2023-04-09 17:38                 ` Eli Zaretskii
2023-04-08 18:30         ` Juri Linkov
     [not found]   ` <ierbk6lup79.fsf@janestreet.com>
2024-04-07 17:16     ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874jourckv.fsf@catern.com \
    --to=sbaugh@catern.com \
    --cc=62700@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=juri@linkov.net \
    --cc=sbaugh@janestreet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.