emacs/test/lisp
João Távora aa181cd352 Rewrite flex completion with Gotoh algorithm
The greedy regexp matching, broken scoring and broken highlight were
sources of frequent complaints about the 'flex' matching style.  This
commit fixes that.

Inspired by the 'hotfuzz' style (available at
https://github.com/axelf4/hotfuzz) it uses a modified version of Gotoh's
1982 dynamic programming algorithm. It is strictly more correct than the
"old" flex.  For example, when matching the pattern 'goto' to no longer
will 'eglot-format' be sorted before some hypothetical much better
'goobarbaz-goto'.  And of course the highlighting is also correctly
placed on the 'goto', not scattered across the candidate.

Regarding performance, it is faster than the naive 'flex', primarily
because of the Elisp rewrite in minibuffer.el.  The matching and costing
algorithm matters but is not the bottleneck.

The Elisp parts of the style were almost completely decoupled from the
pcm/substring styles in lisp/minibuffer.el.  Only
'completion-flex-try-completion' uses some of pcm's code for pattern
augmentation.

* src/minibuf.c (completion--flex-cost-gotoh): New function.

* lisp/minibuffer.el (completion-flex--pattern-str): New variable.
(flex-score-match-tightness): Make obsolete.
(completion--flex-all-completions-1): New helper function.
(completion-flex-try-completion, completion-flex-all-completions): Rewrite.
(completion-substring--all-completions): No longer take transform-pattern-fn.
(completion--flex-adjust-metadata): Tweak.
(completion--flex-score, completion--flex-score-1)
(completion--flex-score-last-md, completion-flex--make-flex-pattern): Delete.

* test/lisp/minibuffer-tests.el (completion--sorted-flex-completions):
New helper function.
(completion-flex-test-non-ascii): New test.
(completion--pcm-score): Delete.
(completion-pcm-test-3, completion-pcm-test-4)
(completion-substring-test-1, completion-substring-test-2)
(completion-flex-test-2, completion-flex-test-3): Tweak.

* etc/NEWS: Describe change.
2026-02-13 23:46:11 +00:00
..
align-resources Support lua-ts-mode in align.el 2023-10-21 12:25:25 +02:00
auth-source-resources
bookmark-resources
calc calc: Improve handling of invalid 'calc-string-maximum-character' 2026-01-17 14:48:06 +02:00
calendar Merge branch 'main' into icalendar 2026-02-08 16:05:31 -05:00
cedet ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
custom-resources
dabbrev-resources ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
dired-resources/insert-directory
emacs-lisp ; Fix package-vc-tests for older versions of Git 2026-01-29 10:29:40 +02:00
emulation ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
epg-resources
erc ; Don't use cl-letf with generic function in ERC test 2026-01-11 05:25:03 -08:00
eshell ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
faces-resources ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
files-resources Ensure .dir-locals-2.el behavior as documented (bug#75890) 2025-03-22 16:47:27 -04:00
gnus ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
hfy-cmap-resources
image ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
international ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
language ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
loadhist-resources ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
mail ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
mh-e ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
minibuffer-resources
net Tramp signals 'remote-file-error' consequently 2026-02-12 19:24:10 +01:00
nxml ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
obsolete ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
org ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
pcmpl-linux-resources
play ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
progmodes Fix new eglot test failure due to project cache 2026-02-13 05:22:15 +02:00
saveplace-resources
so-long-tests ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
term ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
textmodes ; Fix one of ispell-tests 2026-01-18 22:15:18 +02:00
time-resources
url ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
use-package ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
vc ; * test/lisp/vc/ediff-mult-tests.el: use ert-with-temp-directory 2026-02-05 17:36:18 +01:00
xdg-resources
abbrev-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
align-tests.el Fix aligning buffer regions containing multiple alignment sections 2026-02-05 10:51:16 +02:00
allout-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
allout-widgets-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
ansi-color-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
ansi-osc-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
apropos-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
arc-mode-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
auth-source-pass-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
auth-source-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
autoinsert-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
autorevert-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
battery-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
bookmark-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
buff-menu-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
button-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
calculator-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
char-fold-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
color-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
comint-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
completion-preview-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
completion-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
cus-edit-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
custom-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
dabbrev-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
delim-col-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
descr-text-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
desktop-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
dired-aux-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
dired-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
dired-x-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
dnd-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
dom-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
edmacro-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
electric-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
elide-head-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
env-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
epg-config-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
epg-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
faces-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
ffap-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
filenotify-tests.el ; Instrument filenotify test 2026-01-27 18:49:37 +01:00
files-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
files-x-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
find-cmd-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
follow-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
font-lock-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
format-spec-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
help-fns-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
help-mode-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
help-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
hfy-cmap-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
hi-lock-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
hl-line-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
htmlfontify-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
ibuffer-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
ido-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
image-file-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
image-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
imenu-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
info-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
info-xref-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
isearch-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
jit-lock-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
json-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
jsonrpc-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
kmacro-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
loadhist-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
lpr-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
ls-lisp-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
man-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
md4-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
minibuffer-tests.el Rewrite flex completion with Gotoh algorithm 2026-02-13 23:46:11 +00:00
misc-tests.el ; Minor changes to 'truncate-string-pixelwise' (bug#80244) 2026-02-07 14:49:15 +02:00
mouse-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
mwheel-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
newcomment-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
obarray-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
paren-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
password-cache-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
pcmpl-linux-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
pcomplete-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
proced-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
ps-print-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
register-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
repeat-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
replace-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
rot13-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
savehist-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
saveplace-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
scroll-lock-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
server-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
ses-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
shadowfile-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
shell-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
simple-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
sort-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
soundex-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
speedbar-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
sqlite-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
startup-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
subr-tests.el Support cons cell for 'line-spacing' 2026-01-24 13:32:44 +02:00
tab-bar-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
tabify-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
tar-mode-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
tempo-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
term-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
thingatpt-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
thread-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
time-stamp-tests.el time-stamp-helper-string-used: New test 2026-01-05 15:23:01 -08:00
time-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
timezone-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
uniquify-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
version-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
visual-wrap-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
wdired-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
which-key-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
whitespace-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
wid-edit-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
winner-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
x-dnd-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
xdg-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
xml-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
xt-mouse-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00
yank-media-tests.el ; Add 2026 to copyright years. 2026-01-01 12:54:34 +00:00