[Top][All Lists]

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

Re: new-flex-completion-style

From: Stefan Monnier
Subject: Re: new-flex-completion-style
Date: Wed, 13 Feb 2019 13:54:27 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> I've removed this for now, I.e. there's absolutely no sorting yet before
> we agree on who should be doing it and where.  But why would the empty
> string be there anyway?

Don't know: you'd have to ask it.

> I don't "understand" it either :-)

My question wasn't to justify the idea behind the algorithm but just to
describe in words what the code is supposedly computing.  I.e. something
like what you wrote here:

> The formula assigns higher scores to "better" matches. It's bound by
> [0..1] and in the form of a quotient.  For the numerator, it counts the
> +++.  For the denominator, it takes counts the number of --- in each
> such group, exponentiates that number to a "falloff constant", adds it
> to the total, adds one to the final sum, and then multiples by the
> length of the string.

Making sure I understand:
- "counts the +++" will always return the length of the pattern, right?
  So this is used just to normalize the result to ]0..1].
- if the falloff constant is 0, the denominator is the number of places
  where a "star" had to be added (plus one).  And if the falloff
  constant is positive it prefers more insertions of shorter text
  chunks over fewer insertions of longer text chunks, and if it's
  negative it oddly prefers longer insertions over shorter ones.

> Anyway, what do you think?  Is this acceptable or so you have anything
> better?

Fine by me (tho maybe I wouldn't count the final "---", to more
closely match [no pun intended] the usual prefix completion).

FWIW, in my "forgive" completion style I used the equivalent of
a falloff constant of 0 (i.e. I didn't care about the length of the
"---" but only about their number).

> OK, I'll call it "last-b".

It'll be eternally indebted to you.

>>> +           (funcall update-score 0 start)
>>>             (while md
>>> -             (put-text-property start (pop md)
>>> +             (funcall update-score start (car md))
>>> +             (put-text-property start
>>> +                                (pop md)
>> The extra line-break after `start` seems spurious.
> Were you expecting it to have very deep, hidden meaning?  But OK.

I was actually bothered by the fact that the `diff` indicates a change
on an expression that's actually not modified (other than by insertion
of a line-break).  Anal retentiveness for ever!

>>> +           (put-text-property
>>> +            0 1 'completion-pcm-commonality-score
>>> +            (/ score-numerator (* len (1+ score-denominator)) 1.0) str))
>> This will signal an error when `str` is the empty string :-(
> Ooops, but that that happen?  Can an empty string be pcm-matched
> by some pattern?  There's 

I think it can if the pattern is empty.  So maybe all those
put/get-text-property are fine if you make sure this code is never even
called when the pattern is empty.

BTW, the patch below seems to improve the behavior (e.g. it lets
`.../emacs/cfi TAB` complete to `.../emacs/config` as it should since
all remaining matches also match "config").


diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 8ea70b14f1..f5171bb2d0 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3434,22 +3434,7 @@ completion-flex-try-completion
     (if minibuffer-completing-file-name
         (setq all (completion-pcm--filename-try-filter all)))
-    (cond ((not (consp all))
-           all)
-          ((not (consp (cdr all))) ; single completion
-           (if (equal string (car all))
-               t
-             (cons (car all) (length (car all)))))
-          (t
-           ;; If more than one completion, try some "merging".
-           ;; Meaning add as much as possible to the user's
-           ;; pattern without losing any possible matches in
-           ;; `all'.  If that fails, leave user input
-           ;; untouched.
-           (let ((probe (completion-pcm--merge-try pattern all prefix suffix)))
-             (if (stringp probe)
-                 (cons probe (length probe))
-               (cons string point)))))))
+    (completion-pcm--merge-try pattern all prefix suffix)))
 (defun completion-flex-all-completions (string table pred point)
   "Get flex-completions of STRING in TABLE, given PRED and POINT."

reply via email to

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