Allow completion styles to adjust completion metadata
The new facility, realized in the completion-adjust-metadata-for-style
generic, allows completion styles to have a say in metadata properties
such as cycle-sort-function and display-sort-function. This is
especially useful for completion styles such as 'flex', which
generally produce many matches, including some potentially "obscure"
ones. The default sorting strategy would often bubble the latter
to the top of the list.
The sorting function for 'flex' considers pre-computed matching scores
and is thus much better than the default for this particular style.
Additionally, it overrides the completion table's cycle-sort-function
or display-sort-function properties if they exist, although it still
uses them to pre-sort the result, so that they are still relevant for
resolving ties.
* lisp/minibuffer.el (completion--nth-completion): Call
completion-adjust-metadata-for-style.
(completion-adjust-metadata-for-style): New generic.
(completion-adjust-metadata-for-style 'flex): New method.