GNU bug report logs - #62700
29.0.60; minibuffer-{previous,next,choose}-completion behave unintuitively when point is not at end of buffer

Previous Next

Package: emacs;

Reported by: Spencer Baugh <sbaugh <at> janestreet.com>

Date: Thu, 6 Apr 2023 17:57:01 UTC

Severity: normal

Found in version 29.0.60

Fixed in version 30.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


Message #29 received at 62700 <at> debbugs.gnu.org (full text, mbox):

From: sbaugh <at> catern.com
To: Juri Linkov <juri <at> linkov.net>
Cc: 62700 <at> debbugs.gnu.org, Spencer Baugh <sbaugh <at> janestreet.com>
Subject: Re: 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)
Juri Linkov <juri <at> linkov.net> 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.




This bug report was last modified 1 year and 39 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.