]> git.eshelyaron.com Git - emacs.git/commit
Change scoring strategy for 'flex' completion style
authorJoão Távora <joaotavora@gmail.com>
Thu, 14 Feb 2019 23:33:49 +0000 (23:33 +0000)
committerJoão Távora <joaotavora@gmail.com>
Thu, 14 Feb 2019 23:33:49 +0000 (23:33 +0000)
commit0d19e08da647c42562428dd608e5284cf414415e
tree090e74e45424caa7632fce426d4f9626b65d5d88
parenta4c7de35decaace94eba678161b0d4c8266647d2
Change scoring strategy for 'flex' completion style

The previous strategy had problems comparing scores of matches to
strings of different lengths.  This one seems slightly more sensible,
and uses a new constant `flex-score-match-tightness' instead of the
more abstract `flex-score-falloff'.

It's not completely without problems, and I think it shouldn't count
"holes" at the front and at the back, but that needs a different
"pattern-to-regexp" conversion in completion-pcm--hilit-commonality.

(defun test ()
  (mapcar (lambda (a)
            (cons (substring-no-properties a)
                  (get-text-property 0 'completion-score a)))
          (sort (completion-pcm--hilit-commonality
                  '(prefix "f" star "o" star "o" point)
                  '("foo"
                    "barfoobaz"
                    "foobarbaz"
                    "barbazfoo"
                    "fabrobazo"
                    "foot"
                    "foto"
                    "fotttttttttttttttttttttttto"))
      (lambda (a b)
        (> (get-text-property 0 'completion-score a)
           (get-text-property 0 'completion-score b))))))

(let ((flex-score-match-tightness 100)) (test))
=> (("foo" . 1.0)
    ("foot" . 0.375)
    ("foto" . 0.375)
    ("foobarbaz" . 0.16260162601626016) ;; one hole
    ("barbazfoo" . 0.16260162601626016) ;; one hole
    ("barfoobaz" . 0.10964912280701755) ;; two holes
    ("fabrobazo" . 0.10964912280701755) ;; two holes
    ("fotttttttttttttttttttttttto" . 0.04982561036372696))

(let ((flex-score-match-tightness 0.1)) (test))
=> (("foo" . 1.0)
    ("foot" . 0.375)
    ("foto" . 0.375)
    ("barfoobaz" . 0.007751937984496124) ;; two holes
    ("fabrobazo" . 0.007751937984496124) ;; two holes
    ("foobarbaz" . 0.00641025641025641)  ;; one hole
    ("barbazfoo" . 0.00641025641025641)  ;; one hole
    ("fotttttttttttttttttttttttto" . 0.0004789272030651341))

* lisp/minibuffer.el (flex-score-falloff): Rename to
flex-score-match-tightness.
(completion-pcm--hilit-commonality): Update function.
lisp/minibuffer.el