Subject: Re: bug#48545: 28.0.50; `icomplete-vertical-mode` does not support the `group-function`

From: Dmitry Gutov <[email-masked]>
Date: Thu, 19 Aug 2021 18:02:57 +0300

On 19.08.2021 14:18, João Távora wrote:
> I noticed a quirk, though.  If I add '-l etags' to the 'emacs -Q' line,
> one gets 6 matches instead of 5 (due to etags having another
> xref-location-marker).  That's fine, but due to the default
> alphanumeric/length sorting, it gets shoved into the group of xref.el
> matches and thus we get two xref.el groups.  I.e. it looks like
> 
>      xref.el
>      (cl-defgeneric xref-location-marker)
>      (cl-defmethod xref-location-marker ((l xref-file-location)))
>      (cl-defmethod xref-location-marker ((l xref-bogus-location)))
>      etags.el
>      (cl-defmethod xref-location-marker ((l xref-etags-location)))
>      xref.el
>      (cl-defmethod xref-location-marker ((l xref-buffer-location)))
>      elisp-mode.el
>      (cl-defmethod xref-location-marker ((l xref-elisp-location)))
> 
> I don't use completions-group so I don't care strongly for this, but I
> believe that this is generally undesired, for non-filtering scenarios.
> All the entries from the xref.el group should probably be clumped
> together.  If a user were flex-matching and thus expecting certain sort
> score-based order, it_would_  make sense to me, but here no flexy things
> were happening at all.
> 
> To fix this, perhaps the default sorting methods should be turned off in
> completion-all-sorted-completions in minibuffer.el if a table supplies
> `group-function`.  A patch for this is after my sig.

We discussed this problem when group-function was introduced. Another 
approach is to just change the method of grouping: first the completions 
are sorted, and then they are sorted into groups.

The group that goes first is the group to which the first completion in 
the sorted list belongs to. It doesn't matter whether some of the 
subsequent items in it are sorted at the end of the list: as long as 
they return the same value for "group", they get put into that first group.

I wonder which strategy Daniel ultimately chose to use in Consult. 
Perhaps we should document it in the API, so that the implementations 
stay consistent.