GNU bug report logs - #19032
24.4; icomplete cannot select matches with C-x b with no input

Previous Next

Package: emacs;

Reported by: Ole Laursen <olau <at> iola.dk>

Date: Wed, 12 Nov 2014 16:42:03 UTC

Severity: normal

Tags: fixed, patch

Found in version 24.4

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

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 19032 in the body.
You can then email your comments to 19032 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#19032; Package emacs. (Wed, 12 Nov 2014 16:42:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ole Laursen <olau <at> iola.dk>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 12 Nov 2014 16:42:03 GMT) Full text and rfc822 format available.

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

From: Ole Laursen <olau <at> iola.dk>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4; icomplete cannot select matches with C-x b with no input
Date: Wed, 12 Nov 2014 13:31:33 +0100
Run emacs -Q, evaluate

  (icomplete-mode 1)
  (setq icomplete-show-matches-on-no-input t)

Make sure you have three buffers, e.g. by finding three files. Then
hit C-x b which should immediately show all buffers and use C-. or C-,
to select any other buffer than  what the modeline declares to be the
default, and hit C-j or RET.

Emacs then switches to the default buffer instead of the selected buffer.


Ole




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Sat, 15 Nov 2014 23:09:02 GMT) Full text and rfc822 format available.

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

From: Matthew Leach <matthew <at> mattleach.net>
To: Ole Laursen <olau <at> iola.dk>
Cc: 19032 <at> debbugs.gnu.org
Subject: Re: bug#19032: 24.4;
 icomplete cannot select matches with C-x b with no input
Date: Sat, 15 Nov 2014 23:08:12 +0000
[Message part 1 (text/plain, inline)]
Hello,

Ole Laursen <olau <at> iola.dk> writes:

> Run emacs -Q, evaluate
>
>   (icomplete-mode 1)
>   (setq icomplete-show-matches-on-no-input t)
>
> Make sure you have three buffers, e.g. by finding three files. Then
> hit C-x b which should immediately show all buffers and use C-. or C-,
> to select any other buffer than  what the modeline declares to be the
> default, and hit C-j or RET.
>
> Emacs then switches to the default buffer instead of the selected buffer.

I'm not sure if this is expected behaviour, since the "default" prompt
in the minibuffer doesn't disappear when cycling through results.
Nevertheless attached is a patch that fixes this.
-- 
Matt

lisp/ChangeLog:

2014-11-15  Matthew Leach  <matthew <at> mattleach.net>

	* minibuffer.el
	(completion-use-stored-completions-when-no-input): New.
	(completion--complete-and-exit): Use the above to decide whether
	to use the car of `completion-all-sorted-completions' as the
	candidate.

	* icomplete.el (icomplete-minibuffer-setup): set
	`completion-use-stored-completions-when-no-input' when
	`icomplete-show-matches-on-no-input' is t.

[icomplete-cycle-fix.patch (text/x-diff, inline)]
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 95a6e1b..dc90f0e 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -262,6 +262,7 @@ Usually run by inclusion in `minibuffer-setup-hook'."
     (add-hook 'post-command-hook #'icomplete-post-command-hook nil t)
     (run-hooks 'icomplete-minibuffer-setup-hook)
     (when icomplete-show-matches-on-no-input
+      (setq completion-use-stored-completions-when-no-input t)
       (icomplete-exhibit))))
 
 (defvar icomplete--in-region-buffer nil)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index c9ce381..4ea0530 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -969,6 +969,7 @@ completion candidates than this number."
 (defvar-local completion-all-sorted-completions nil)
 (defvar-local completion--all-sorted-completions-location nil)
 (defvar completion-cycling nil)
+(defvar completion-use-stored-completions-when-no-input nil)
 
 (defvar completion-fail-discreetly nil
   "If non-nil, stay quiet when there  is no match.")
@@ -1332,8 +1333,15 @@ If `minibuffer-completion-confirm' is `confirm-after-completion',
 COMPLETION-FUNCTION is called if the current buffer's content does not
 appear to be a match."
     (cond
-     ;; Allow user to specify null string
-   ((= beg end) (funcall exit-function))
+     ;; Allow user to specify null string.  In the case that
+     ;; `completion-use-stored-completions-when-no-input' is t, use
+     ;; the car of `completion-all-sorted-completions' as the
+     ;; candidate.
+     ((= beg end)
+      (when completion-use-stored-completions-when-no-input
+        (completion--replace beg end (car completion-all-sorted-completions)))
+      (funcall exit-function))
+
      ((test-completion (buffer-substring beg end)
                        minibuffer-completion-table
                        minibuffer-completion-predicate)

Added tag(s) patch. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Mon, 30 Sep 2019 01:35:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Thu, 13 Aug 2020 09:35:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Matthew Leach <matthew <at> mattleach.net>
Cc: Ole Laursen <olau <at> iola.dk>, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 19032 <at> debbugs.gnu.org
Subject: Re: bug#19032: 24.4; icomplete cannot select matches with C-x b
 with no input
Date: Thu, 13 Aug 2020 11:34:22 +0200
Matthew Leach <matthew <at> mattleach.net> writes:

>> Run emacs -Q, evaluate
>>
>>   (icomplete-mode 1)
>>   (setq icomplete-show-matches-on-no-input t)
>>
>> Make sure you have three buffers, e.g. by finding three files. Then
>> hit C-x b which should immediately show all buffers and use C-. or C-,
>> to select any other buffer than  what the modeline declares to be the
>> default, and hit C-j or RET.
>>
>> Emacs then switches to the default buffer instead of the selected buffer.
>
> I'm not sure if this is expected behaviour, since the "default" prompt
> in the minibuffer doesn't disappear when cycling through results.
> Nevertheless attached is a patch that fixes this.

I've respun the patch for Emacs 28, and I think the new behaviour makes
a lot more sense than the old behaviour, which I couldn't understand the
point of at all.

But I'm not an icomplete user, so perhaps the old behaviour is what
people want?

This also has possible ramifications for other completion styles
(although only icomplete enables it with this patch), so I wonder
whether Stefan has any comments here?

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 3747ae3d28..e3f7043e2c 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -432,6 +432,8 @@ icomplete-minibuffer-setup
     					 (current-local-map)))
     (add-hook 'pre-command-hook  #'icomplete-pre-command-hook  nil t)
     (add-hook 'post-command-hook #'icomplete-post-command-hook nil t)
+    (when icomplete-show-matches-on-no-input
+      (setq-local completion-use-stored-completions-when-no-input t))
     (run-hooks 'icomplete-minibuffer-setup-hook)))
 
 (defvar icomplete--in-region-buffer nil)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index d2c3f9045e..c3e5440956 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1126,6 +1126,7 @@ completion--cycle-threshold
 (defvar-local completion-all-sorted-completions nil)
 (defvar-local completion--all-sorted-completions-location nil)
 (defvar completion-cycling nil)      ;Function that takes down the cycling map.
+(defvar completion-use-stored-completions-when-no-input nil)
 
 (defvar completion-fail-discreetly nil
   "If non-nil, stay quiet when there  is no match.")
@@ -1510,8 +1511,15 @@ completion--complete-and-exit
 COMPLETION-FUNCTION is called if the current buffer's content does not
 appear to be a match."
     (cond
-     ;; Allow user to specify null string
-   ((= beg end) (funcall exit-function))
+     ;; Allow user to specify null string.  In the case that
+     ;; `completion-use-stored-completions-when-no-input' is t, use
+     ;; the car of `completion-all-sorted-completions' as the
+     ;; candidate.
+     ((= beg end)
+      (when completion-use-stored-completions-when-no-input
+        (completion--replace beg end (car completion-all-sorted-completions)))
+      (funcall exit-function))
+
      ((test-completion (buffer-substring beg end)
                        minibuffer-completion-table
                        minibuffer-completion-predicate)


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Thu, 13 Aug 2020 10:01:02 GMT) Full text and rfc822 format available.

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

From: Ole Laursen <olau <at> iola.dk>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Matthew Leach <matthew <at> mattleach.net>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, 19032 <at> debbugs.gnu.org
Subject: Re: bug#19032: 24.4; icomplete cannot select matches with C-x b with
 no input
Date: Thu, 13 Aug 2020 12:00:07 +0200
Thanks!

I'm a former iswitchb user, and this problem keeps me from switching
to icomplete (I'm currently on ido-switch-buffer), even though I would
like to have access to more advanced completion.


Ole

Den tor. 13. aug. 2020 kl. 11.34 skrev Lars Ingebrigtsen <larsi <at> gnus.org>:
>
> Matthew Leach <matthew <at> mattleach.net> writes:
>
> >> Run emacs -Q, evaluate
> >>
> >>   (icomplete-mode 1)
> >>   (setq icomplete-show-matches-on-no-input t)
> >>
> >> Make sure you have three buffers, e.g. by finding three files. Then
> >> hit C-x b which should immediately show all buffers and use C-. or C-,
> >> to select any other buffer than  what the modeline declares to be the
> >> default, and hit C-j or RET.
> >>
> >> Emacs then switches to the default buffer instead of the selected buffer.
> >
> > I'm not sure if this is expected behaviour, since the "default" prompt
> > in the minibuffer doesn't disappear when cycling through results.
> > Nevertheless attached is a patch that fixes this.
>
> I've respun the patch for Emacs 28, and I think the new behaviour makes
> a lot more sense than the old behaviour, which I couldn't understand the
> point of at all.
>
> But I'm not an icomplete user, so perhaps the old behaviour is what
> people want?
>
> This also has possible ramifications for other completion styles
> (although only icomplete enables it with this patch), so I wonder
> whether Stefan has any comments here?
>
> diff --git a/lisp/icomplete.el b/lisp/icomplete.el
> index 3747ae3d28..e3f7043e2c 100644
> --- a/lisp/icomplete.el
> +++ b/lisp/icomplete.el
> @@ -432,6 +432,8 @@ icomplete-minibuffer-setup
>                                          (current-local-map)))
>      (add-hook 'pre-command-hook  #'icomplete-pre-command-hook  nil t)
>      (add-hook 'post-command-hook #'icomplete-post-command-hook nil t)
> +    (when icomplete-show-matches-on-no-input
> +      (setq-local completion-use-stored-completions-when-no-input t))
>      (run-hooks 'icomplete-minibuffer-setup-hook)))
>
>  (defvar icomplete--in-region-buffer nil)
> diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
> index d2c3f9045e..c3e5440956 100644
> --- a/lisp/minibuffer.el
> +++ b/lisp/minibuffer.el
> @@ -1126,6 +1126,7 @@ completion--cycle-threshold
>  (defvar-local completion-all-sorted-completions nil)
>  (defvar-local completion--all-sorted-completions-location nil)
>  (defvar completion-cycling nil)      ;Function that takes down the cycling map.
> +(defvar completion-use-stored-completions-when-no-input nil)
>
>  (defvar completion-fail-discreetly nil
>    "If non-nil, stay quiet when there  is no match.")
> @@ -1510,8 +1511,15 @@ completion--complete-and-exit
>  COMPLETION-FUNCTION is called if the current buffer's content does not
>  appear to be a match."
>      (cond
> -     ;; Allow user to specify null string
> -   ((= beg end) (funcall exit-function))
> +     ;; Allow user to specify null string.  In the case that
> +     ;; `completion-use-stored-completions-when-no-input' is t, use
> +     ;; the car of `completion-all-sorted-completions' as the
> +     ;; candidate.
> +     ((= beg end)
> +      (when completion-use-stored-completions-when-no-input
> +        (completion--replace beg end (car completion-all-sorted-completions)))
> +      (funcall exit-function))
> +
>       ((test-completion (buffer-substring beg end)
>                         minibuffer-completion-table
>                         minibuffer-completion-predicate)
>
>
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Thu, 13 Aug 2020 13:44:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Matthew Leach <matthew <at> mattleach.net>, 19032 <at> debbugs.gnu.org,
 Ole Laursen <olau <at> iola.dk>
Subject: Re: bug#19032: 24.4; icomplete cannot select matches with C-x b
 with no input
Date: Thu, 13 Aug 2020 09:43:41 -0400
> +(defvar completion-use-stored-completions-when-no-input nil)
>  (defvar completion-fail-discreetly nil
>    "If non-nil, stay quiet when there  is no match.")
> @@ -1510,8 +1511,15 @@ completion--complete-and-exit
>  COMPLETION-FUNCTION is called if the current buffer's content does not
>  appear to be a match."
>      (cond
> -     ;; Allow user to specify null string
> -   ((= beg end) (funcall exit-function))
> +     ;; Allow user to specify null string.  In the case that
> +     ;; `completion-use-stored-completions-when-no-input' is t, use
> +     ;; the car of `completion-all-sorted-completions' as the
> +     ;; candidate.
> +     ((= beg end)
> +      (when completion-use-stored-completions-when-no-input
> +        (completion--replace beg end (car completion-all-sorted-completions)))
> +      (funcall exit-function))

Would it be cleaner to have the following instead?

      ;; Allow user to specify null string.  Obey `completion-content-when-empty`.
      ((= beg end)
       (when completion-content-when-empty
         (completion--replace beg end completion-content-when-empty))
       (funcall exit-function))

So icomplete would be in charge of setting that var to the `car` of
`completion-all-sorted-completions`.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Fri, 14 Aug 2020 11:04:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Matthew Leach <matthew <at> mattleach.net>, 19032 <at> debbugs.gnu.org,
 Ole Laursen <olau <at> iola.dk>
Subject: Re: bug#19032: 24.4; icomplete cannot select matches with C-x b
 with no input
Date: Fri, 14 Aug 2020 13:03:14 +0200
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> Would it be cleaner to have the following instead?
>
>       ;; Allow user to specify null string.  Obey `completion-content-when-empty`.
>       ((= beg end)
>        (when completion-content-when-empty
>          (completion--replace beg end completion-content-when-empty))
>        (funcall exit-function))
>
> So icomplete would be in charge of setting that var to the `car` of
> `completion-all-sorted-completions`.

Yeah, that makes sense.  I'll take a stab at implementing it that way.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Fri, 14 Aug 2020 11:32:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Matthew Leach <matthew <at> mattleach.net>, 19032 <at> debbugs.gnu.org,
 Ole Laursen <olau <at> iola.dk>
Subject: Re: bug#19032: 24.4; icomplete cannot select matches with C-x b
 with no input
Date: Fri, 14 Aug 2020 13:30:54 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Yeah, that makes sense.  I'll take a stab at implementing it that way.

I think I found where in the icomplete machinery to set this variable,
so I've now pushed this change.  It would be nice if others could test
this, too, and see whether it works.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 14 Aug 2020 11:32:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 19032 <at> debbugs.gnu.org and Ole Laursen <olau <at> iola.dk> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 14 Aug 2020 11:32:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Fri, 14 Aug 2020 12:35:02 GMT) Full text and rfc822 format available.

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

From: Ole Laursen <olau <at> iola.dk>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Matthew Leach <matthew <at> mattleach.net>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, 19032 <at> debbugs.gnu.org
Subject: Re: bug#19032: 24.4; icomplete cannot select matches with C-x b with
 no input
Date: Fri, 14 Aug 2020 14:33:59 +0200
I just built from trunk, and it now works! Flawless victory. :)

Thanks again to all involved!


Ole

Den fre. 14. aug. 2020 kl. 13.31 skrev Lars Ingebrigtsen <larsi <at> gnus.org>:
>
> Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>
> > Yeah, that makes sense.  I'll take a stab at implementing it that way.
>
> I think I found where in the icomplete machinery to set this variable,
> so I've now pushed this change.  It would be nice if others could test
> this, too, and see whether it works.  :-)
>
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Fri, 14 Aug 2020 12:36:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Ole Laursen <olau <at> iola.dk>
Cc: Matthew Leach <matthew <at> mattleach.net>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, 19032 <at> debbugs.gnu.org
Subject: Re: bug#19032: 24.4; icomplete cannot select matches with C-x b
 with no input
Date: Fri, 14 Aug 2020 14:35:26 +0200
Ole Laursen <olau <at> iola.dk> writes:

> I just built from trunk, and it now works! Flawless victory. :)

Thanks for testing.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Tue, 18 Aug 2020 18:01:02 GMT) Full text and rfc822 format available.

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

From: Matthew Leach <matthew <at> mattleach.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Ole Laursen <olau <at> iola.dk>, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 19032 <at> debbugs.gnu.org
Subject: Re: bug#19032: 24.4;
 icomplete cannot select matches with C-x b with no input
Date: Tue, 18 Aug 2020 19:00:51 +0100
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>
>> Yeah, that makes sense.  I'll take a stab at implementing it 
>> that way.
>
> I think I found where in the icomplete machinery to set this 
> variable,
> so I've now pushed this change.  It would be nice if others 
> could test
> this, too, and see whether it works.  :-)

Thanks for fixing this Lars.  Much appreciated!
--
Matt




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Sun, 06 Sep 2020 18:28:01 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 43120 <at> debbugs.gnu.org, 19032 <at> debbugs.gnu.org,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Sun, 06 Sep 2020 19:26:47 +0100
[Message part 1 (text/plain, inline)]
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Sean Whitton <spwhitton <at> spwhitton.name> writes:
>
>> On Sat 05 Sep 2020 at 02:25PM +02, Lars Ingebrigtsen wrote:
>>
>>> In which case -- does the following fix this problem?
>>
>> It does indeed.  Hope this patch can be applied.
>
> Thanks for testing; I've now applied the patch.

I've had a look at the original problem that triggered this, and I
wonder if this much simpler patch wouldn't be preferable.  For one, it
doesn't touch the minibuffer.el machinery (which is complicated as it
is) or has any kind of complicated caching semantics.  It just binds a
different command to RET in icomplete-minibuffer-map, presumably solving
19032 (in my limited testing).  It's also guaranteed not to affect
fido-mode.

I think something like this is the way to go for a behaviour change such
as this.

João

[0001-Change-icomplete-show-matches-on-no-input-behaviour-.patch (text/x-diff, inline)]
From f4dc81e0c7be75ace3766ca16e2be8bdcc8f0627 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= <joaotavora <at> gmail.com>
Date: Sun, 6 Sep 2020 19:03:52 +0100
Subject: [PATCH] Change icomplete-show-matches-on-no-input behaviour for
 Icomplete only

Fixes: bug#19032, bug#43120

Previous fixes to bug#19032 introduced bugs in Fido mode.  This fix
relies on a new command bound to RET.

* etc/NEWS (Miscellaneous): Mention icomplete-show-matches-on-no-input.

* lisp/icomplete.el (icomplete-show-matches-on-no-input): Add comment.
(icomplete-minibuffer-map): Bind icomplete-ret.
(icomplete-ret): New command.
---
 etc/NEWS          |  6 ++++++
 lisp/icomplete.el | 16 +++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 749b28ac3f..d40a4807ec 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -938,6 +938,12 @@ window after starting).  This variable defaults to nil.
 
 ** Miscellaneous
 
+---
+*** 'icomplete-show-matches-on-no-input' behavior change
+Previously, choosing a different completion with commands like 'C-.'
+and then hitting enter would choose the default completion.  Doing
+this will now choose the completion under point.
+
 +++
 *** The user can now customize how "default" values are prompted for.
 The new utility function 'format-prompt' has been added which uses the
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index f76ab28fb8..c4d5012af9 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -75,7 +75,11 @@ icomplete-tidy-shadowed-file-names
 selection process starts again from the user's $HOME.")
 
 (defcustom icomplete-show-matches-on-no-input nil
-  "When non-nil, show completions when first prompting for input."
+  "When non-nil, show completions when first prompting for input.
+This also means that if you traverse the list of completions with
+commands like `C-.' and just hit RET without typing any
+characters, the match under point will be chosen instead of the
+default."
   :type 'boolean
   :version "24.4")
 
@@ -153,12 +157,22 @@ icomplete-post-command-hook
 (defvar icomplete-minibuffer-map
   (let ((map (make-sparse-keymap)))
     (define-key map [?\M-\t] 'icomplete-force-complete)
+    (define-key map (kbd "RET") 'icomplete-ret)
     (define-key map [?\C-j]  'icomplete-force-complete-and-exit)
     (define-key map [?\C-.]  'icomplete-forward-completions)
     (define-key map [?\C-,]  'icomplete-backward-completions)
     map)
   "Keymap used by `icomplete-mode' in the minibuffer.")
 
+(defun icomplete-ret ()
+  "Exit minibuffer for icomplete."
+  (interactive)
+  (if (and icomplete-show-matches-on-no-input
+           (car completion-all-sorted-completions)
+           (eql (icomplete--field-end) (icomplete--field-beg)))
+      (icomplete-force-complete-and-exit)
+    (exit-minibuffer)))
+
 (defun icomplete-force-complete-and-exit ()
   "Complete the minibuffer with the longest possible match and exit.
 Use the first of the matches if there are any displayed, and use
-- 
2.25.1


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Mon, 07 Sep 2020 10:31:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: João Távora <joaotavora <at> gmail.com>
Cc: 43120 <at> debbugs.gnu.org, 19032 <at> debbugs.gnu.org,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Mon, 07 Sep 2020 12:30:12 +0200
João Távora <joaotavora <at> gmail.com> writes:

> I've had a look at the original problem that triggered this, and I
> wonder if this much simpler patch wouldn't be preferable.  For one, it
> doesn't touch the minibuffer.el machinery (which is complicated as it
> is) or has any kind of complicated caching semantics.  It just binds a
> different command to RET in icomplete-minibuffer-map, presumably solving
> 19032 (in my limited testing).  It's also guaranteed not to affect
> fido-mode.

That does look like a much simpler and less invasive way to implement
this; yes.  (And you'd presumably remove the stuff that was added for
19032 already?)

But I was wondering whether there were any other use cases where the
newly added stuff would be useful...  but perhaps not?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Mon, 07 Sep 2020 10:38:01 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 19032 <at> debbugs.gnu.org, Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Mon, 7 Sep 2020 11:37:01 +0100
[Message part 1 (text/plain, inline)]
On Mon, Sep 7, 2020 at 11:30 AM Lars Ingebrigtsen <larsi <at> gnus.org> wrote:

> That does look like a much simpler and less invasive way to implement
> this; yes.  (And you'd presumably remove the stuff that was added for
> 19032 already?)

Yes, I'd revert both the original patch and the fixup.

> But I was wondering whether there were any other use cases where the
> newly added stuff would be useful...  but perhaps not?

This is for Stefan to say: he's the "owner" of minibuffer.el.  Sorry Stefan
if
you're not, I just nominated you.  Anyway, I kind of screech at any
added complexity there, hence this simple suggestion.

Anyway, I'd risk committing my patch to master while we evaluate
this. Or maybe let's hear from Stefan first.

João

[Also I'm moving this to 19032's thread exclusively, since 43120 is fixed]
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Mon, 07 Sep 2020 11:44:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: João Távora <joaotavora <at> gmail.com>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 19032 <at> debbugs.gnu.org,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Mon, 07 Sep 2020 13:43:34 +0200
João Távora <joaotavora <at> gmail.com> writes:

> Anyway, I'd risk committing my patch to master while we evaluate
> this. Or maybe let's hear from Stefan first.

Let's wait for Stefan to chime in.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Mon, 07 Sep 2020 17:31:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: João Távora <joaotavora <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 43120 <at> debbugs.gnu.org,
 19032 <at> debbugs.gnu.org, Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Mon, 07 Sep 2020 13:30:38 -0400
> I think something like this is the way to go for a behaviour change such
> as this.

Looks fine to me.

> +    (define-key map (kbd "RET") 'icomplete-ret)

Maybe use a `remap`ping instead?


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Tue, 08 Sep 2020 06:53:01 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 43120 <at> debbugs.gnu.org,
 19032 <at> debbugs.gnu.org, Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Tue, 08 Sep 2020 07:52:21 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> I think something like this is the way to go for a behaviour change such
>> as this.
>
> Looks fine to me.
>
>> +    (define-key map (kbd "RET") 'icomplete-ret)
>
> Maybe use a `remap`ping instead?

Yes, maybe makes sense.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Tue, 08 Sep 2020 09:01:02 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 43120 <at> debbugs.gnu.org,
 19032 <at> debbugs.gnu.org, Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Tue, 08 Sep 2020 09:59:56 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> I think something like this is the way to go for a behaviour change such
>> as this.
>
> Looks fine to me.

Thanks, pushed.

>> +    (define-key map (kbd "RET") 'icomplete-ret)
>
> Maybe use a `remap`ping instead?

I did that, too.

João




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 14:02:02 GMT) Full text and rfc822 format available.

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

From: OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>
To: João Távora <joaotavora <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, Sean Whitton <spwhitton <at> spwhitton.name>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 09 Sep 2020 23:01:22 +0900
João Távora <joaotavora <at> gmail.com> writes:

> Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>
>>> I think something like this is the way to go for a behaviour change such
>>> as this.
>>
>> Looks fine to me.
>
> Thanks, pushed.
>
>>> +    (define-key map (kbd "RET") 'icomplete-ret)
>>
>> Maybe use a `remap`ping instead?
>
> I did that, too.

> +(defun icomplete-ret ()
> +  "Exit minibuffer for icomplete."
> +  (interactive)
> +  (if (and icomplete-show-matches-on-no-input
> +           (car completion-all-sorted-completions)
> +           (eql (icomplete--field-end) (icomplete--field-beg)))
> +      (icomplete-force-complete-and-exit)
> +    (exit-minibuffer)))

This changed the behavior of RET from `minibuffer-complete-and-exit' to
`exit-minibuffer'. Was that intention? What I noticed is the following.

[before]
	emacs -Q
        M-x icomplete-mode
        C-xd /usr
        C-xk u		;; shows "Kill buffer (default usr): u(sr)"
        RET
        killed "usr" buffer

[after]
	emacs -Q
        M-x icomplete-mode
        C-xd /usr
        C-xk u		;; shows "Kill buffer (default usr): u(sr)"
        RET
        No buffer named u

Thanks.
-- 
OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 16:13:01 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, Sean Whitton <spwhitton <at> spwhitton.name>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 9 Sep 2020 17:11:43 +0100
[Message part 1 (text/plain, inline)]
On Wed, Sep 9, 2020 at 3:01 PM OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>
wrote:

> João Távora <joaotavora <at> gmail.com> writes:
>
> > Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
> >
> >>> I think something like this is the way to go for a behaviour change
> such
> >>> as this.
> >>
> >> Looks fine to me.
> >
> > Thanks, pushed.
> >
> >>> +    (define-key map (kbd "RET") 'icomplete-ret)
> >>
> >> Maybe use a `remap`ping instead?
> >
> > I did that, too.
>
> > +(defun icomplete-ret ()
> > +  "Exit minibuffer for icomplete."
> > +  (interactive)
> > +  (if (and icomplete-show-matches-on-no-input
> > +           (car completion-all-sorted-completions)
> > +           (eql (icomplete--field-end) (icomplete--field-beg)))
> > +      (icomplete-force-complete-and-exit)
> > +    (exit-minibuffer)))
>
> This changed the behavior of RET from `minibuffer-complete-and-exit' to
> `exit-minibuffer'. Was that intention?
>

Nope, sorry. You're right. It should read minibuffer-complete-and-exit there
of course.

João
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 17:53:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: João Távora <joaotavora <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org, OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 09 Sep 2020 13:52:10 -0400
> Nope, sorry. You're right. It should read minibuffer-complete-and-exit there
> of course.

IIRC this depends on whether the completion is `require-match` or not.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 19:05:03 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>
Cc: 19032 <at> debbugs.gnu.org, 43120 <at> debbugs.gnu.org,
 João Távora <joaotavora <at> gmail.com>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 09 Sep 2020 21:58:03 +0300
>> +(defun icomplete-ret ()
>> +  "Exit minibuffer for icomplete."
>> +  (interactive)
>> +  (if (and icomplete-show-matches-on-no-input
>> +           (car completion-all-sorted-completions)
>> +           (eql (icomplete--field-end) (icomplete--field-beg)))
>> +      (icomplete-force-complete-and-exit)
>> +    (exit-minibuffer)))
>
> This changed the behavior of RET from `minibuffer-complete-and-exit' to
> `exit-minibuffer'. Was that intention? What I noticed is the following.

I confirm that this change broke icomplete-mode.  Here is a test case
that shows regression:

M-x icomplete-mode RET
M-x rgr RET

  Lisp error: (error "‘rgr’ is not a valid command name")

Until yesterday it used to run 'rgrep'.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 19:14:02 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org, OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 09 Sep 2020 20:13:28 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> Nope, sorry. You're right. It should read minibuffer-complete-and-exit there
>> of course.
>
> IIRC this depends on whether the completion is `require-match` or not.

If so, shouldn't minibuffer-complete-and-exit take care of that?  I
mean, I've remapped the binding to _that_ command, so unless it's making
some "(interactive)" magic, which it is not, calling it from lisp in the
normal case as it should be completely equivalent.

I've gone ahead and commited the fix, as it fixes Hirofumi's problem, as
he described it.

João




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 19:53:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: João Távora <joaotavora <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org, OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 09 Sep 2020 15:52:38 -0400
>>> Nope, sorry. You're right. It should read minibuffer-complete-and-exit there
>>> of course.
>> IIRC this depends on whether the completion is `require-match` or not.
> If so, shouldn't minibuffer-complete-and-exit take care of that?

Yes and no: IIRC depending on `require-match`, RET is bound either
to `minibuffer-complete-and-exit` or to `exit-minibuffer`.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 19:55:02 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org, OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 9 Sep 2020 20:54:39 +0100
[Message part 1 (text/plain, inline)]
On Wed, Sep 9, 2020 at 8:52 PM Stefan Monnier <monnier <at> iro.umontreal.ca>
wrote:

> >>> Nope, sorry. You're right. It should read minibuffer-complete-and-exit
> there
> >>> of course.
> >> IIRC this depends on whether the completion is `require-match` or not.
> > If so, shouldn't minibuffer-complete-and-exit take care of that?
>
> Yes and no: IIRC depending on `require-match`, RET is bound either
> to `minibuffer-complete-and-exit` or to `exit-minibuffer`.


Bah, so the remap you suggested wouldn't work anyway.  What to do?
The good 'ol :filter trick? How does it go again?

João
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 19:59:01 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org, OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 9 Sep 2020 20:57:47 +0100
[Message part 1 (text/plain, inline)]
On Wed, Sep 9, 2020 at 8:54 PM João Távora <joaotavora <at> gmail.com> wrote:

> On Wed, Sep 9, 2020 at 8:52 PM Stefan Monnier <monnier <at> iro.umontreal.ca>
> wrote:
>
>> >>> Nope, sorry. You're right. It should read
>> minibuffer-complete-and-exit there
>> >>> of course.
>> >> IIRC this depends on whether the completion is `require-match` or not.
>> > If so, shouldn't minibuffer-complete-and-exit take care of that?
>>
>> Yes and no: IIRC depending on `require-match`, RET is bound either
>> to `minibuffer-complete-and-exit` or to `exit-minibuffer`.
>
>
> Bah, so the remap you suggested wouldn't work anyway.  What to do?
> The good 'ol :filter trick? How does it go again?
>

Alternatively (and a bit sillily), two remaps for two different commands:
one for exit-minibuffer and one for minibuffer-complete-and-exit.  Or
check minibuffer-require-match which was recently added. Pick your
poison.

João
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 20:37:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: João Távora <joaotavora <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org, OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 09 Sep 2020 16:35:52 -0400
> Alternatively (and a bit sillily), two remaps for two different commands:
> one for exit-minibuffer and one for minibuffer-complete-and-exit.

I'd go with that, yes,

Also, because it will handle the case where the user has added a binding
to `minibuffer-complete-and-exit` to the keymap where RET is bound to
`exit-minibuffer`.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Wed, 09 Sep 2020 22:09:01 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org, OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Wed, 09 Sep 2020 23:08:44 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> Alternatively (and a bit sillily), two remaps for two different commands:
>> one for exit-minibuffer and one for minibuffer-complete-and-exit.
>
> I'd go with that, yes,
>
> Also, because it will handle the case where the user has added a binding
> to `minibuffer-complete-and-exit` to the keymap where RET is bound to
> `exit-minibuffer`.

OK, how's this look?

Though I'm starting to think that when require-match is nil, an
icomplete user wouldn't want the new icomplete-show-matches-on-no-input
behaviour anyway.  But I'm not one of those.  Else, if she does, doesn't
it mean she wants fido-mode instead?

The question is thus: remap exit-minibuffer or not?  It means usually:
exit with whatever has been input, which may well be the empty string.

João

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 4e546807b7..6d48aa84d4 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -157,21 +157,31 @@ icomplete-post-command-hook
 (defvar icomplete-minibuffer-map
   (let ((map (make-sparse-keymap)))
     (define-key map [?\M-\t] 'icomplete-force-complete)
-    (define-key map [remap minibuffer-complete-and-exit] 'icomplete-ret)
+    (define-key map [remap minibuffer-complete-and-exit] 'icomplete-complete-and-exit)
+    (define-key map [remap exit-minibuffer] 'icomplete-exit)
     (define-key map [?\C-j]  'icomplete-force-complete-and-exit)
     (define-key map [?\C-.]  'icomplete-forward-completions)
     (define-key map [?\C-,]  'icomplete-backward-completions)
     map)
   "Keymap used by `icomplete-mode' in the minibuffer.")
 
-(defun icomplete-ret ()
-  "Exit minibuffer for icomplete."
-  (interactive)
+(defun icomplete--maybe-force (fallback)
+  "Helper for `icomplete-complete-and-exit' and `icomplete-exit'."
   (if (and icomplete-show-matches-on-no-input
            (car completion-all-sorted-completions)
            (eql (icomplete--field-end) (icomplete--field-beg)))
       (icomplete-force-complete-and-exit)
-    (minibuffer-complete-and-exit)))
+    (funcall fallback)))
+
+(defun icomplete-complete-and-exit ()
+  "Complete, then exit minibuffer for icomplete."
+  (interactive)
+  (icomplete--maybe-force #'minibuffer-complete-and-exit))
+
+(defun icomplete-exit ()
+  "Exit minibuffer for icomplete."
+  (interactive)
+  (icomplete--maybe-force #'exit-minibuffer))
 
 (defun icomplete-force-complete-and-exit ()
   "Complete the minibuffer with the longest possible match and exit.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Thu, 10 Sep 2020 04:37:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: João Távora <joaotavora <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 19032 <at> debbugs.gnu.org,
 43120 <at> debbugs.gnu.org, OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Thu, 10 Sep 2020 00:36:39 -0400
> The question is thus: remap exit-minibuffer or not?

Good question.  I think if there is a default value (i.e. if
exit-minibuffer would return that non-nil default when the minibuffer
is empty), then I think it makes sense to use the new
icomplete-show-matches-on-no-input, but if not, indeed we probably
should return "" (otherwise we're making it impossible to return "").


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Thu, 10 Sep 2020 18:54:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: João Távora <joaotavora <at> gmail.com>
Cc: 19032 <at> debbugs.gnu.org, 43120 <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, Lars Ingebrigtsen <larsi <at> gnus.org>,
 OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Thu, 10 Sep 2020 21:51:34 +0300
> Though I'm starting to think that when require-match is nil, an
> icomplete user wouldn't want the new icomplete-show-matches-on-no-input
> behaviour anyway.

This is confusing, I don't understand why behaviour of
icomplete-show-matches-on-no-input should depend on require-match.

Here are two examples that produce a different result.

The first example is from hi-lock-read-face-name:

(defvar hi-history nil)
(icomplete-mode)
(let ((icomplete-show-matches-on-no-input t)
      (defaults '("hi-yellow" "hi-green"))
      (hi-history '("hi-blue")))
  (completing-read
   (format-prompt "Highlight using face" (car defaults))
   obarray 'facep t nil 'hi-history defaults))

displays this prompt:

  Highlight using face (default hi-yellow): {link | menu | bold ...

Typing RET returns "link" (and sometimes returns "hi-blue" from the history),
but never returns the expected default value "hi-yellow".

Whereas the second example from tab-bar-switch-to-tab
works correctly since its arg require-match is nil:

(let ((icomplete-show-matches-on-no-input t)
      (defaults '("yellow" "green"))
      (hi-history '("blue")))
  (completing-read
   (format-prompt "Switch to tab by name" (car defaults))
   defaults nil nil nil 'hi-history defaults))

displays this prompt:

  Switch to tab by name (default yellow): {green | yellow}

Typing RET returns the default value "yellow", not the first candidate "green".

This makes the behaviour of icomplete-show-matches-on-no-input
unpredictable, and thus in some cases dangerous.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19032; Package emacs. (Thu, 10 Sep 2020 19:16:02 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 19032 <at> debbugs.gnu.org, 43120 <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, Lars Ingebrigtsen <larsi <at> gnus.org>,
 OGAWA Hirofumi <hirofumi <at> mail.parknet.co.jp>,
 Sean Whitton <spwhitton <at> spwhitton.name>
Subject: Re: bug#43120: 28.0.50; fido-mode: M-j before completions appear
 selects wrong choice
Date: Thu, 10 Sep 2020 20:15:25 +0100
Juri Linkov <juri <at> linkov.net> writes:

>> Though I'm starting to think that when require-match is nil, an
>> icomplete user wouldn't want the new icomplete-show-matches-on-no-input
>> behaviour anyway.
>
> This is confusing, I don't understand why behaviour of
> icomplete-show-matches-on-no-input should depend on require-match.
>
> Here are two examples that produce a different result.



>
> The first example is from hi-lock-read-face-name:
>
> (defvar hi-history nil)
> (icomplete-mode)
> (let ((icomplete-show-matches-on-no-input t)
>       (defaults '("hi-yellow" "hi-green"))
>       (hi-history '("hi-blue")))
>   (completing-read
>    (format-prompt "Highlight using face" (car defaults))
>    obarray 'facep t nil 'hi-history defaults))
>
> displays this prompt:
>
>   Highlight using face (default hi-yellow): {link | menu | bold ...
>
> Typing RET returns "link" (and sometimes returns "hi-blue" from the history),
> but never returns the expected default value "hi-yellow".
>
> Whereas the second example from tab-bar-switch-to-tab
> works correctly since its arg require-match is nil:
>
> (let ((icomplete-show-matches-on-no-input t)
>       (defaults '("yellow" "green"))
>       (hi-history '("blue")))
>   (completing-read
>    (format-prompt "Switch to tab by name" (car defaults))
>    defaults nil nil nil 'hi-history defaults))
>
> displays this prompt:
>
>   Switch to tab by name (default yellow): {green | yellow}
>
> Typing RET returns the default value "yellow", not the first candidate "green".
>
> This makes the behaviour of icomplete-show-matches-on-no-input
> unpredictable, and thus in some cases dangerous.

I think I agree, but I've just tested this with the version of
icomplete.el before I started messing with this stuff (commit
c8472cc69d4bce7f53c9a62966245a4de3d99fbd) and I get exactly the same
results as you.  So I'd leave my work here for someone else to pick up
on: To be clear, I just wanted to simplify/refactor the code to be less
intrusive on minibuffer.el.

I'm not much of an icomplete-mode user, more of a fido-mode user where
these discrepancies are "fixed" by copying ido-mode's behaviour.

João




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

This bug report was last modified 4 years and 279 days ago.

Previous Next


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