GNU bug report logs - #49931
28.0.50; `choose-completion' submits incorrect string when minibuffer content changes after creation of the *Completions* buffer

Previous Next

Package: emacs;

Reported by: Visuwesh <visuwesh <at> tutanota.com>

Date: Sat, 7 Aug 2021 20:37:02 UTC

Severity: normal

Found in version 28.0.50

Fixed in version 29.0.50

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

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 49931 in the body.
You can then email your comments to 49931 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Sat, 07 Aug 2021 20:37:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Visuwesh <visuwesh <at> tutanota.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 07 Aug 2021 20:37:03 GMT) Full text and rfc822 format available.

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

From: Visuwesh <visuwesh <at> tutanota.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.50; `choose-completion' submits incorrect string when
 minibuffer content changes after creation of the *Completions* buffer
Date: Sat, 7 Aug 2021 19:20:35 +0200 (CEST)
When one edits the minibuffer content after the creation of
*Completions* buffer, `choose-completion' incorrectly submits the wrong
string to the command upon selecting a candidate.  To reproduce,

1. Start emacs -Q.
2. Type the following key sequence: C-h f emacs- TAB.
3. Type a.
4. Select `emacs-bzr-get-version' from the *Completions* buffer.
5. "user-error: Symbol’s function definition is void:
emacs-bzr-get-versiona" is shown in the echo area.

What I expected to happen:

I expected `choose-completion' to submit "emacs-bzr-get-version" to
describe-function, not "emacs-bzr-get-versiona".



Regards.

[  P.S. Please add me to the CCs since I'm not subscribed to the mailing
list.  ]



In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.27, cairo version 1.16.0)
Repository revision: 0b049fe71d73f6885a3c81ea31829e3befc18933
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: NixOS 21.11 (Porcupine)

Configured using:
'configure
--prefix=/nix/store/6gh7ijbrfaahs78syqhjc6f2y7gi76h2-emacs-git-20210806.0
--disable-build-details --with-modules --with-x-toolkit=gtk3 --with-xft
--with-cairo'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY
PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE
XIM XPM GTK3 ZLIB

Important settings:
  value of $EMACSLOADPATH:
  value of $EMACSNATIVELOADPATH: /nix/store/ld3lv1bbi9zx15k3h5hni467gyqxckjr-emacs-packages-deps/share/emacs/native-lisp::
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search seq byte-opt
gv bytecomp byte-compile cconv mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils time-date subr-x thingatpt
help-fns radix-tree help-mode cl-loaddefs cl-lib iso-transl tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 59485 9215)
(symbols 48 6917 1)
(strings 32 21260 1804)
(string-bytes 1 666531)
(vectors 16 14618)
(vector-slots 8 188838 7589)
(floats 8 21 50)
(intervals 56 398 0)
(buffers 992 11))





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Sun, 08 Aug 2021 05:15:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuwesh <at> tutanota.com>
Cc: 49931 <at> debbugs.gnu.org
Subject: Re: bug#49931: 28.0.50;
 `choose-completion' submits incorrect string when minibuffer content
 changes after creation of the *Completions* buffer
Date: Sun, 08 Aug 2021 08:14:35 +0300
> Date: Sat, 7 Aug 2021 19:20:35 +0200 (CEST)
> From:  Visuwesh via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> When one edits the minibuffer content after the creation of
> *Completions* buffer, `choose-completion' incorrectly submits the wrong
> string to the command upon selecting a candidate.  To reproduce,
> 
> 1. Start emacs -Q.
> 2. Type the following key sequence: C-h f emacs- TAB.
> 3. Type a.
> 4. Select `emacs-bzr-get-version' from the *Completions* buffer.
> 5. "user-error: Symbol’s function definition is void:
> emacs-bzr-get-versiona" is shown in the echo area.
> 
> What I expected to happen:
> 
> I expected `choose-completion' to submit "emacs-bzr-get-version" to
> describe-function, not "emacs-bzr-get-versiona".

You expected Emacs to ignore what you type?  Why?

What you type after TAB is used to narrow the list of candidates when
you type the next TAB, or continue typing after the first TAB
completed some of the name for you.  This is the intended behavior.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Sun, 08 Aug 2021 07:03:02 GMT) Full text and rfc822 format available.

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

From: Visuwesh <visuwesh <at> tutanota.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 49931 <at> debbugs.gnu.org
Subject: Re: bug#49931: 28.0.50; `choose-completion' submits incorrect
 string when minibuffer content changes after creation of the
 *Completions* buffer
Date: Sun, 8 Aug 2021 09:02:31 +0200 (CEST)
8  Aug 2021, 10:44 by eliz <at> gnu.org:
>> Date: Sat, 7 Aug 2021 19:20:35 +0200 (CEST)
>> From: Visuwesh via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>
>>
>> When one edits the minibuffer content after the creation of
>> Completions* buffer, `choose-completion' incorrectly submits the wrong
>> string to the command upon selecting a candidate.  To reproduce,
>>
>>
>> 1. Start emacs -Q.
>> 2. Type the following key sequence: C-h f emacs- TAB.
>> 3. Type a.
>> 4. Select `emacs-bzr-get-version' from the *Completions* buffer.
>> 5. "user-error: Symbol’s function definition is void:
>> emacs-bzr-get-versiona" is shown in the echo area.
>>
>>
>> What I expected to happen:
>>
>>
>> I expected `choose-completion' to submit "emacs-bzr-get-version" to
>> describe-function, not "emacs-bzr-get-versiona".
>>
>>
> You expected Emacs to ignore what you type?

Yes, I expected Emacs to ignore 'a'.

> Why?

The name `choose-completion' leads one to think that the candidate
will be chosen regardless of whatever is in the minibuffer but that is
not the case.  I think the current behaviour is not intuitive.

> What you type after TAB is used to narrow the list of candidates when
> you type the next TAB, or continue typing after the first TAB
> completed some of the name for you. This is the intended behavior.

I do understand how the standard behaviour is supposed to be.  But I
believe the current behaviour is unnatural.  When I am offered
clickable text in a buffer which are advertised to complete the
command when clicked, I expect that to happen.  In my case, the text
visible in the *Completions* buffer did not have an extra 'a' but upon
choosing, it did.  I think this is misleading.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Sun, 08 Aug 2021 07:15:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuwesh <at> tutanota.com>
Cc: 49931 <at> debbugs.gnu.org
Subject: Re: bug#49931: 28.0.50; `choose-completion' submits incorrect
 string when minibuffer content changes after creation of the
 *Completions* buffer
Date: Sun, 08 Aug 2021 10:14:22 +0300
> Date: Sun, 8 Aug 2021 09:02:31 +0200 (CEST)
> From: Visuwesh <visuwesh <at> tutanota.com>
> Cc: 49931 <at> debbugs.gnu.org
> 
> Yes, I expected Emacs to ignore 'a'.
> 
> > Why?
> 
> The name `choose-completion' leads one to think that the candidate
> will be chosen regardless of whatever is in the minibuffer but that is
> not the case.  I think the current behaviour is not intuitive.
> 
> > What you type after TAB is used to narrow the list of candidates when
> > you type the next TAB, or continue typing after the first TAB
> > completed some of the name for you. This is the intended behavior.
> 
> I do understand how the standard behaviour is supposed to be.  But I
> believe the current behaviour is unnatural.  When I am offered
> clickable text in a buffer which are advertised to complete the
> command when clicked, I expect that to happen.  In my case, the text
> visible in the *Completions* buffer did not have an extra 'a' but upon
> choosing, it did.  I think this is misleading.

I think your expectations are incorrect, because they are based on
assumptions that are generally false in Emacs.  In particular,
depending on the context of the completion, typing more stuff after
selecting a candidate is what is actually needed, so ignoring that
would break valid use cases.

Therefore I think we will have to agree to disagree on this one.  I
see no bug in the behavior you described.  If it looks misleading to
you, you will have to get used to it.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Sun, 08 Aug 2021 07:32:02 GMT) Full text and rfc822 format available.

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

From: Visuwesh <visuwesh <at> tutanota.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 49931 <49931 <at> debbugs.gnu.org>
Subject: Re: bug#49931: 28.0.50; `choose-completion' submits incorrect
 string when minibuffer content changes after creation of the
 *Completions* buffer
Date: Sun, 8 Aug 2021 09:31:12 +0200 (CEST)
8 Aug 2021, 12:44 by eliz <at> gnu.org:

> In particular, depending on the context of the completion, typing
> more stuff after selecting a candidate is what is actually needed, so
> ignoring that would break valid use cases.

Indeed, this makes sense when selecting a candidate that does not exit
the minibuffer, like `find-file'.  I, for one, do not think that the
current behaviour of `choose-completion' wherein it completely ignores
whatever typed after the creation of the *Completions* buffer is
unexpected when it comes to commands like `describe-function' which
exits the minibuffer upon selecting the candidate.


> Therefore I think we will have to agree to disagree on this one. I
> see no bug in the behavior you described. If it looks misleading to
> you, you will have to get used to it.

If the above still does not convince you, then we will have to agree
to disagree.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Sun, 08 Aug 2021 08:20:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuwesh <at> tutanota.com>
Cc: 49931 <at> debbugs.gnu.org
Subject: Re: bug#49931: 28.0.50; `choose-completion' submits incorrect
 string when minibuffer content changes after creation of the
 *Completions* buffer
Date: Sun, 08 Aug 2021 11:19:10 +0300
> Date: Sun, 8 Aug 2021 09:31:12 +0200 (CEST)
> From: Visuwesh <visuwesh <at> tutanota.com>
> Cc: 49931 <49931 <at> debbugs.gnu.org>
> 
> 8 Aug 2021, 12:44 by eliz <at> gnu.org:
> 
> > In particular, depending on the context of the completion, typing
> > more stuff after selecting a candidate is what is actually needed, so
> > ignoring that would break valid use cases.
> 
> Indeed, this makes sense when selecting a candidate that does not exit
> the minibuffer, like `find-file'.  I, for one, do not think that the
> current behaviour of `choose-completion' wherein it completely ignores
> whatever typed after the creation of the *Completions* buffer is
> unexpected when it comes to commands like `describe-function' which
> exits the minibuffer upon selecting the candidate.

Even though the command exits the minibuffer, the stuff you typed
before selection shouldn't necessarily be ignored, since you could be
completing on stuff that doesn't yield complete function names.

> > Therefore I think we will have to agree to disagree on this one. I
> > see no bug in the behavior you described. If it looks misleading to
> > you, you will have to get used to it.
> 
> If the above still does not convince you, then we will have to agree
> to disagree.

Yes.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Tue, 10 Aug 2021 07:25:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Visuwesh <visuwesh <at> tutanota.com>
Cc: 49931 <at> debbugs.gnu.org
Subject: Re: bug#49931: 28.0.50; `choose-completion' submits incorrect
 string when minibuffer content changes after creation of the *Completions*
 buffer
Date: Tue, 10 Aug 2021 10:07:25 +0300
> When one edits the minibuffer content after the creation of
> *Completions* buffer, `choose-completion' incorrectly submits the wrong
> string to the command upon selecting a candidate.  To reproduce,
>
> 1. Start emacs -Q.
> 2. Type the following key sequence: C-h f emacs- TAB.
> 3. Type a.
> 4. Select `emacs-bzr-get-version' from the *Completions* buffer.
> 5. "user-error: Symbol’s function definition is void:
> emacs-bzr-get-versiona" is shown in the echo area.
>
> What I expected to happen:
>
> I expected `choose-completion' to submit "emacs-bzr-get-version" to
> describe-function, not "emacs-bzr-get-versiona".

The same problem was reported in https://debbugs.gnu.org/34517#14
that also contains a possible solution, still unimplemented.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Tue, 10 Aug 2021 09:02:02 GMT) Full text and rfc822 format available.

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

From: Visuwesh <visuwesh <at> tutanota.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 49931 <49931 <at> debbugs.gnu.org>
Subject: Re: bug#49931: 28.0.50; `choose-completion' submits incorrect
 string when minibuffer content changes after creation of the
 *Completions* buffer
Date: Tue, 10 Aug 2021 11:00:59 +0200 (CEST)
10 Aug 2021, 12:37 by juri <at> linkov.net:

>> When one edits the minibuffer content after the creation of
>> *Completions* buffer, `choose-completion' incorrectly submits the wrong
>> string to the command upon selecting a candidate.  To reproduce,
>>
>> 1. Start emacs -Q.
>> 2. Type the following key sequence: C-h f emacs- TAB.
>> 3. Type a.
>> 4. Select `emacs-bzr-get-version' from the *Completions* buffer.
>> 5. "user-error: Symbol’s function definition is void:
>> emacs-bzr-get-versiona" is shown in the echo area.
>>
>> What I expected to happen:
>>
>> I expected `choose-completion' to submit "emacs-bzr-get-version" to
>> describe-function, not "emacs-bzr-get-versiona".
>>
>
> The same problem was reported in https://debbugs.gnu.org/34517#14
> that also contains a possible solution, still unimplemented.
>
Thanks for linking me that bug report.  I tried searching for similar terms in 
bug-gnu-emacs and emacs-devel but the hits were too much for me to go
through them.  Stefan's explanation made things clear.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Sat, 12 Mar 2022 19:14:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 49931 <at> debbugs.gnu.org
Subject: Re: bug#49931: 28.0.50; `choose-completion' submits incorrect
 string when minibuffer content changes after creation of the *Completions*
 buffer
Date: Sat, 12 Mar 2022 20:49:58 +0200
[Message part 1 (text/plain, inline)]
[This is continuation of the unfinished fix from bug#34517]

>> Stefan, please advise shouldn't selecting a completion from the
>> *Completions* buffer clear the minibuffer's content before
>> inserting the selected completion?
>
> No, for example when you complete file name "C-x C-f ~/.e TAB"  the
> *Completions* buffer will only show ".emacs" so we should clear the
> minibuffer before inserting ".emacs" because that would lose the leading
> "~/".  There are other circumstances where trailing text needs to
> be preserved.

Another example that occurred to me is shell-command M-! minibuffer
where TAB can complete on commands and file names.

> The completion code handles this with `completion-base-position` which
> holds the beginning and end of the text that should be replaced when you
> choose an item in *Completions*.
>
>>> 0. emacs -Q
>>> 1. ‘C-h f TAB’ displays a list of completions
>>> 2. type a nonexistent function name, i.e. some random text
>>>    in the minibuffer, e.g. “blabla”
>
> The *Completions* content is now "out of date" compared to the minibuffer.
>
>>> 3. click on an existing valid completion in the *Completions* buffer,
>>>    e.g. on “append”
>
> completion-base-position was set at step (1) to cover the empty text
> after the prompt, so this empty text (which is now right in front of
> "blabla") is replaced with "append" resulting in "appendblabla".
>
> Obviously, the result is not what we want.
> Now sure how to change which part, tho.  Maybe instead of
> completion-base-position we should store the prefix and suffix strings,
> so when you select an entry from *Completions* we just clear the
> minibuffer and replace it with (concat prefix selection suffix)?

Now I tried this, and it works correctly.  But not sure how to make
this change as backward-compatible as possible.  One variant
would be to save '("prefix" "suffix") instead of '(10 11)
in 'completion-base-position' but this might fail in some existing code.

So maybe better to add a new variable 'completion-base-affixes'.
Then whether to use 'completion-base-position'
or 'completion-base-affixes' could be defined by the new user option
'completion-use-base-affixes'.

Then it can be used in the new command from emacs-devel:

```
(defun minibuffer-completion-choose (&optional arg)
  "Run `choose-completion' from the minibuffer in its scrolling window."
  (interactive "P")
  (with-minibuffer-scroll-window
    (let ((completion-use-base-affixes t))
      (choose-completion nil arg))))
```

[completion-base-affixes.patch (text/x-diff, inline)]
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 0262424b87..4cc050ff86 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2290,6 +2290,8 @@ minibuffer-completion-help
   (let* ((start (or start (minibuffer--completion-prompt-end)))
          (end (or end (point-max)))
          (string (buffer-substring start end))
+         (base-prefix (buffer-substring (minibuffer--completion-prompt-end) start))
+         (base-suffix (buffer-substring end (point-max)))
          (md (completion--field-metadata start))
          (completions (completion-all-completions
                        string
@@ -2405,11 +2407,16 @@ minibuffer-completion-help
                                    ;; completion-all-completions does not give us the
                                    ;; necessary information.
                                    end))
+                        (setq-local completion-base-affixes (list base-prefix base-suffix))
                         (setq-local completion-list-insert-choice-function
                              (let ((ctable minibuffer-completion-table)
                                    (cpred minibuffer-completion-predicate)
                                    (cprops completion-extra-properties))
                                (lambda (start end choice)
+                                 (if (and (stringp start) (stringp end))
+                                     (progn
+                                       (delete-region (minibuffer-prompt-end) (point-max))
+                                       (insert start choice end))
                                  (unless (or (zerop (length prefix))
                                              (equal prefix
                                                     (buffer-substring-no-properties
@@ -2418,7 +2425,7 @@ minibuffer-completion-help
                                                      start)))
                                    (message "*Completions* out of date"))
                                  ;; FIXME: Use `md' to do quoting&terminator here.
-                                 (completion--replace start end choice)
+                                 (completion--replace start end choice))
                                  (let* ((minibuffer-completion-table ctable)
                                         (minibuffer-completion-predicate cpred)
                                         (completion-extra-properties cprops)
diff --git a/lisp/simple.el b/lisp/simple.el
index 9601e6cd76..bf9d8c8830 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9072,6 +9072,19 @@ completion-base-position
 where the completion should be inserted and END (if non-nil) is the end
 of the text to replace.  If END is nil, point is used instead.")
 
+(defvar completion-base-affixes nil
+  "Base context of the text corresponding to the shown completions.
+This variable is used in the *Completions* buffers.
+Its value is a list of the form (PREFIX SUFFIX) where PREFIX is the text
+before the place where completion should be inserted and SUFFIX is the text
+after the completion.")
+
+(defcustom completion-use-base-affixes nil
+  "Non-nil means to restore original prefix and suffix in the minibuffer."
+  :type 'boolean
+  :version "29.1"
+  :group 'completion)
+
 (defvar completion-list-insert-choice-function #'completion--replace
   "Function to use to insert the text chosen in *Completions*.
 Called with three arguments (BEG END TEXT), it should replace the text
@@ -9164,6 +9181,7 @@ choose-completion
   (with-current-buffer (window-buffer (posn-window (event-start event)))
     (let ((buffer completion-reference-buffer)
           (base-position completion-base-position)
+          (base-affixes completion-base-affixes)
           (insert-function completion-list-insert-choice-function)
          (completion-no-auto-exit (if arg t completion-no-auto-exit))
           (choice
@@ -9184,7 +9202,8 @@ choose-completion
       (with-current-buffer buffer
         (choose-completion-string
          choice buffer
-         (or base-position
+         (or (and completion-use-base-affixes base-affixes)
+             base-position
              ;; If all else fails, just guess.
              (list (choose-completion-guess-base-position choice)))
          insert-function)))))
@@ -9357,9 +9377,11 @@ completion-setup-function
                 (buffer-substring (minibuffer-prompt-end) (point)))))))
     (with-current-buffer standard-output
       (let ((base-position completion-base-position)
+            (base-affixes completion-base-affixes)
             (insert-fun completion-list-insert-choice-function))
         (completion-list-mode)
         (setq-local completion-base-position base-position)
+        (setq-local completion-base-affixes base-affixes)
         (setq-local completion-list-insert-choice-function insert-fun))
       (setq-local completion-reference-buffer mainbuf)
       (if base-dir (setq default-directory base-dir))

Forcibly Merged 48356 49931. Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Sun, 13 Mar 2022 18:14:03 GMT) Full text and rfc822 format available.

Disconnected #49931 from all other report(s). Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Tue, 05 Apr 2022 18:29:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#49931; Package emacs. (Tue, 05 Apr 2022 19:24:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 49931 <at> debbugs.gnu.org
Subject: Re: bug#49931: 28.0.50; `choose-completion' submits incorrect
 string when minibuffer content changes after creation of the *Completions*
 buffer
Date: Tue, 05 Apr 2022 21:54:27 +0300
close 49931 29.0.50
thanks

>>>> 3. click on an existing valid completion in the *Completions* buffer,
>>>>    e.g. on “append”
>>
>> completion-base-position was set at step (1) to cover the empty text
>> after the prompt, so this empty text (which is now right in front of
>> "blabla") is replaced with "append" resulting in "appendblabla".
>>
>> Obviously, the result is not what we want.
>> Now sure how to change which part, tho.  Maybe instead of
>> completion-base-position we should store the prefix and suffix strings,
>> so when you select an entry from *Completions* we just clear the
>> minibuffer and replace it with (concat prefix selection suffix)?
>
> Now I tried this, and it works correctly.  But not sure how to make
> this change as backward-compatible as possible.  One variant
> would be to save '("prefix" "suffix") instead of '(10 11)
> in 'completion-base-position' but this might fail in some existing code.
>
> So maybe better to add a new variable 'completion-base-affixes'.
> Then whether to use 'completion-base-position'
> or 'completion-base-affixes' could be defined by the new user option
> 'completion-use-base-affixes'.

Now this patched is pushed to master, and the bug report is closed.




bug marked as fixed in version 29.0.50, send any further explanations to 49931 <at> debbugs.gnu.org and Visuwesh <visuwesh <at> tutanota.com> Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Tue, 05 Apr 2022 19:24:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 04 May 2022 11:24:08 GMT) Full text and rfc822 format available.

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

Previous Next


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