emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: new-flex-completion-style


From: Drew Adams
Subject: RE: new-flex-completion-style
Date: Thu, 14 Feb 2019 22:32:28 -0800 (PST)

> >> I guess one could consider `flx` scoring as just another kind of
> >> sorting, but I'm pretty sure that it can give odd results when used
> >> with (say) regexp-style completion.
> > Depends on the regexp.  But sure, you wouldn't
> > want to sort based on scoring that privileges
> > substring match length for input that is a wild regexp.
> 
> My point is that flx scoring is usually based on the idea that the
> candidate does match using flx matching, whereas that might not be the
> case i[f] the matching was done some other way.  So the scoring result can
> be completely meaningless (or it could even signal an error).
> 
> IOW matching and scoring can be intimately linked because the scoring is
> based on *how* the candidate matched the input.

Yes.  And regexp matching is an outlier.  My point
about regexp matching was that for completion many
actual uses of regexp matching are substring matches
or close to it.  (`foobar' is a regexp.)

And besides this being the case for perhaps most
regexp-input matches (for completion), most other
match methods involve input chars that are also in
the candidates, so flx scoring even with non-flx
matching is generally not outlandish.

I think flx-score sorting is probably more useful
when you've typed relatively little and there are
many matches.  In a way it privileges, by sorting
(and hence for access by, e.g., cycling), candidates
that might match in two different ways, the optional
one being flx.

And yes, again, flx scoring is no doubt more useful
with some match methods than with others.  Finally,
I can't tell you how useful it might really be.
YMMV.  I can say that it's another sort order. ;-)

FWIW, the predicate I actually use for sorting by
`flx-score' just does alphabetical comparison if
the input doesn't return a `flx-score' for each of
the two candidates (i.e., if at least one does not
flx-match your input).

(defun icicle-flx-score-greater-p (s1 s2)
  "Non-nil means the `flx-score' of S1 is greater than that of S2.
That is, the cars of the `flx-score' values are compared.

If `flx-score' returns nil for either argument, then they are compared
using `icicle-case-string-less-p'.

This function requires library `flx.el'."
  (let* ((input   (if (and (icicle-file-name-input-p)
                           insert-default-directory)
                      (file-name-nondirectory
                        icicle-current-input)
                    icicle-current-input))
         (score1  (flx-score s1 input))
         (score2  (flx-score s2 input)))
    (if (and score1  score2)
        (> (car score1) (car score2))
      (icicle-case-string-less-p s1 s2))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]