Subject: bug#34083: 27.0.50; Default completion, if it exists, should always sort to top

From: Drew Adams <[email-masked]>
Date: Tue, 15 Jan 2019 09:55:55 -0800 (PST)

> In completion-all-sorted-completions, completions are sorted according
> to recency of usage, which is a good idea.
> 
> However, for calls to completing-read that are given a DEFAULT
> (actually
> DEF) argument, the sort order isn't very useful.  It means that, when
> using icomplete for i.e. M-x describe-symbol on top of the symbol sort
> 
>    Describe symbol (default sort): { some-other-symbol | yet-another |
> sort }
>                                      ^^^^^^^^^^^^^^^^^
>                                         boldface
> 
> This is very confusing in icomplete as "some-other-symbol" in the
> previous example is boldface and gives the idea of a default.  It is
> the
> thing that minibuffer-force-complete-and-exit, bound to C-j, will
> complete to immediately.  But since no text has been entered, C-m will
> make completion consider "sort" instead.
> 
> Here's a recipe:
> 
>     Emacs -Q
>     M-x icomplete-mode
>     M-: (setq icomplete-show-matches-on-no-input t) RET
>     type "sort"
>     C-h o
> 
> Verify that "sort" is the default but it doesn't visually in the
> "propects list".  Instead "%" is made boldface and C-j and C-M-i will
> immediately complete to it.
> 
> This inconsistency is easy to fix in minibuffer.el, as attached in a
> patch.  After the patch, "sort" is sorted to the top.
> 
> I couldn't figure exactly if there is an impact on non-icomplete.el
> usage of completion-all-sorted-completions, because I'm not familiar
> with that code.  But since it was already using
> minibuffer-history-variable, I don't think this disturbs it much more
> than that.
> 
> Naturally, this could be coded to work in icomplete-mode only, but
> doing that patch cleanly is much harder.

Not a good idea, IMHO.  Do I really care?  My own code
sorts completions differently, so I don't care with
that in mind.  But for vanilla Emacs I do care.

The default value of `completing-read' has nothing
to do with the current sort order or the first
completion of that order.  If someone thinks that
Ido or Icomplete needs massaging in this way then
that's where it should be done.  Certainly not at
the level of `completing-read' or (even worse)
`minibuffer.el' (`completion-all-sorted-completions').

"boldface...gives the idea of a default" is an
Ido/Icomplete thing.  If their UIs need clarifying
in this case then that's where to concentrate efforts.
For example, perhaps a different face should be used
when the default is not the first candidate.  (No, I'm
not proposing that or any other change for these UIs.)

(I don't want to belabor this or put forth arguments
for why this is a bad idea.  If the why is not clear
to others who read this bug thread, too bad.)