1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-04-01 03:33:28 -07:00
emacs/lisp
João Távora a0b5ff9bb7 Rewrite flex completion scoring 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.

It was inspired by the 'hotfuzz' style available at
https://github.com/axelf4/hotfuzz which is a modified version of Gotoh's
1982 dynamic programming algorithm (see: GOTOH, Osamu. An improved
algorithm for matching biological sequences. Journal of molecular
biology, 1982, 162.3: 705-708.).  That style is slightly more
sophisticated than 'flex' (has special rules for matching things at word
boundaries, a C module with multithreading support).  It's almost (but
not entirely) void of hacks so it'd make a good candidate to replace
'flex' entirely, but no progress has been made in getting it into
Emacs's core in over 2 years, so I thought I'd try my hand at it.

The new 'flex' implementation also uses Gotoh algorithm (apparently
a common choice for these kinds of task) and happens mostly in a new C
function.  It is strictly more correct than the "old" flex.  For
example, when matching the pattern 'goto' to, say, 'eglot--goto' and
'eglot--bol', no longer is the latter returned first, which was a
substantial annoyance.  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', but that's
mainly because this commit also includes changes to the Elisp code which
make faster regexp's for the filtering step.  It is slower than
'hotfuzz' when that style's C-module extension is leveraged.  'hotfuzz'
does the filtering and sorting steps together in C code and has
multithreaded workers there.  The matching and scoring algorithm itself
is not the bottleneck.

The flex style was completely decoupled from the pcm/substring styles in
lisp/minibuffer.el.  Test code were refactored and more tests were
added.

* 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.
2026-02-07 21:23:19 +00:00
..
calc ; calc: Correct width of rules composed of Unicode glyphs 2026-01-17 14:51:01 +02:00
calendar Fix inconsistent definition and usage of 'calendar-buffer' 2026-01-24 14:09:59 +02:00
cedet Fix [More] buttons in tutorial and other buttons in Semantic 2026-02-03 05:14:59 +02:00
emacs-lisp shortdoc: Don't burp on missing docstrings 2026-02-04 10:59:23 -05:00
emulation
erc
eshell
gnus Call browser functions via `browse-url' 2026-01-20 10:31:03 +00:00
image
international ; Remove redundant cl-lib runtime dependencies across lisp/ 2026-01-17 15:32:15 +02:00
language
leim/quail ; Fix last change to iroquoian.el 2026-02-02 00:27:03 +01:00
mail ; Remove redundant cl-lib runtime dependencies across lisp/ 2026-01-17 15:32:15 +02:00
mh-e
net Organize tramp-adb-handle-make-process a little bit better 2026-01-27 18:25:05 +01:00
nxml
obsolete
org
play
progmodes Eglot: fix thinko in eglot--async-request 2026-02-05 22:39:19 +00:00
term (xterm--init): Fix probem in async mode (bug#80163) 2026-01-20 22:46:31 -05:00
textmodes (yaml-ts-mode-yamllint-options): Use a list of strings 2026-02-04 11:03:57 -05:00
url ; Remove redundant cl-lib runtime dependencies across lisp/ 2026-01-17 15:32:15 +02:00
use-package
vc ; diff--revert-kill-hunks: Hoist binding inhibit-read-only. 2026-02-05 12:24:05 +00:00
abbrev.el
align.el Fix last change in align.el 2026-02-05 10:56:51 +02:00
allout-widgets.el
allout.el
ansi-color.el
ansi-osc.el
apropos.el
arc-mode.el
array.el
auth-source-pass.el
auth-source.el
autoinsert.el
autorevert.el
avoid.el
battery.el
bind-key.el
bindings.el
bookmark.el
bs.el
buff-menu.el Fix buffer menu unmark (bug#80082) 2026-01-13 20:49:03 +02:00
button.el
calculator.el
case-table.el
ChangeLog.1
ChangeLog.2
ChangeLog.3
ChangeLog.4
ChangeLog.5
ChangeLog.6
ChangeLog.7
ChangeLog.8
ChangeLog.9
ChangeLog.10
ChangeLog.11
ChangeLog.12
ChangeLog.13
ChangeLog.14
ChangeLog.15
ChangeLog.16
ChangeLog.17
char-fold.el
chistory.el
cmuscheme.el
color.el
comint.el * lisp/comint.el (comint-redirect-hook): Defvar (bug#80313) 2026-02-04 11:14:10 -05:00
completion-preview.el
completion.el
composite.el
COPYING
cus-dep.el
cus-edit.el
cus-face.el
cus-start.el ; Improve last change 2026-01-26 14:29:47 +02:00
cus-theme.el
custom.el
dabbrev.el
delim-col.el
delsel.el
descr-text.el
desktop.el Fix desktop saving and restoring in daemon sessions 2026-02-01 08:49:57 +02:00
dframe.el
dired-aux.el
dired-x.el
dired.el Fix support of listing switches with whitespace in Dired 2026-01-24 15:39:11 +02:00
dirtrack.el
disp-table.el
display-fill-column-indicator.el
display-line-numbers.el
dnd.el
doc-view.el
dom.el
dos-fns.el
dos-vars.el
dos-w32.el
double.el
dynamic-setting.el
ebuff-menu.el
ecomplete.el
editorconfig-conf-mode.el
editorconfig-core-handle.el
editorconfig-core.el
editorconfig-fnmatch.el
editorconfig-tools.el ; Remove redundant cl-lib runtime dependencies across lisp/ 2026-01-17 15:32:15 +02:00
editorconfig.el
edmacro.el
ehelp.el
elec-pair.el
electric.el
elide-head.el
emacs-lock.el
env.el
epa-dired.el
epa-file.el
epa-hook.el
epa-ks.el
epa-mail.el
epa.el
epg-config.el
epg.el
expand.el
external-completion.el
ezimage.el
face-remap.el
facemenu.el
faces.el ; Fix a recent change of tab-bar/line faces 2026-01-12 15:10:59 +02:00
ffap.el
filecache.el
fileloop.el
filenotify.el
files-x.el
files.el ; * lisp/files.el (file-name-version-regexp): typo in doc string 2026-01-27 15:30:21 +01:00
filesets.el
find-cmd.el
find-dired.el
find-file.el
find-lisp.el
finder.el
flow-ctrl.el
foldout.el
follow.el
font-core.el
font-lock.el
format-spec.el
format.el
forms.el
frame.el Document frame id related commands and tweak a return value (Bug#80192) 2026-01-27 10:23:34 +01:00
frameset.el Fix desktop saving and restoring in daemon sessions 2026-02-01 08:49:57 +02:00
fringe.el
generic-x.el
help-at-pt.el
help-fns.el ; Fix documentation of 'help-fns-describe-function-functions' 2026-01-31 12:59:17 +02:00
help-macro.el
help-mode.el Fix [More] buttons in tutorial and other buttons in Semantic 2026-02-03 05:14:59 +02:00
help.el
hex-util.el
hexl.el
hfy-cmap.el
hi-lock.el
hilit-chg.el
hippie-exp.el
hl-line.el
htmlfontify.el
ibuf-ext.el
ibuf-macs.el (define-ibuffer-column): Fix corner case miscompilations (bug#80180) 2026-01-14 16:52:09 -05:00
ibuffer.el
icomplete.el New key 'M-j' for 'icomplete-mode' (bug#62108) 2026-01-30 09:27:12 +02:00
ido.el
ielm.el Fix behavior for ielm-dynamic-multiline-inputs (bug#80123) 2026-01-15 11:12:12 +00:00
iimage.el
image-file.el
image-mode.el
image.el Improve (WebP) image animation 2026-01-24 19:37:30 +01:00
imenu.el
indent-aux.el
indent.el
info-look.el
info-xref.el ; Remove redundant cl-lib runtime dependencies across lisp/ 2026-01-17 15:32:15 +02:00
info.el
informat.el
isearch.el isearch.el: Remove autoloads hacks 2026-02-02 17:42:40 -05:00
isearchb.el
jit-lock.el
jka-cmpr-hook.el
jka-compr.el
json.el
jsonrpc.el Jsonrpc: avoid redisplay_internal calls from jsonrpc-request 2026-01-26 22:57:09 +00:00
keymap.el
kmacro.el
ldefs-boot.el ; * lisp/ldefs-boot.el: Regenerate. 2026-01-29 17:03:58 +00:00
loadhist.el
loadup.el
locate.el
lpr.el
ls-lisp.el
macros.el
Makefile.in
man.el ; Fix messages in "M-x man" 2026-01-18 14:36:51 +02:00
master.el
mb-depth.el
md4.el
menu-bar.el
midnight.el
minibuf-eldef.el
minibuffer.el Rewrite flex completion scoring with Gotoh algorithm 2026-02-07 21:23:19 +00:00
misc.el
misearch.el
mouse-copy.el
mouse-drag.el
mouse.el
mpc.el
msb.el
mwheel.el
newcomment.el
notifications.el
novice.el
obarray.el
outline.el
paren.el
password-cache.el
pcmpl-cvs.el
pcmpl-git.el
pcmpl-gnu.el
pcmpl-linux.el
pcmpl-rpm.el
pcmpl-unix.el
pcmpl-x.el
pcomplete.el
pgtk-dnd.el
pixel-scroll.el pixel-scroll: Avoid loading `cua-base' 2026-01-31 11:01:02 +02:00
plstore.el
printing.el
proced.el
profiler.el
ps-bdf.el
ps-mule.el
ps-print.el
ps-samp.el
pulse.el
README
recentf.el
rect.el
register.el
registry.el
repeat.el
replace.el New key 'M-j' for 'icomplete-mode' (bug#62108) 2026-01-30 09:27:12 +02:00
reposition.el
reveal.el
rfn-eshadow.el
ring-bell-fns.el
rot13.el
rtree.el
ruler-mode.el
savehist.el
saveplace.el save-place-alist-to-file: Use prin1, not pp (bug#80183) 2026-01-12 09:59:40 +00:00
scroll-all.el
scroll-bar.el ; Remove redundant cl-lib runtime dependencies across lisp/ 2026-01-17 15:32:15 +02:00
scroll-lock.el
select.el
send-to.el
server.el
ses.el
shadowfile.el
shell.el
simple.el Support cons cell for 'line-spacing' 2026-01-24 13:32:44 +02:00
skeleton.el
so-long.el
sort.el
soundex.el
speedbar.el
sqlite-mode.el
sqlite.el
startup.el
strokes.el
subr.el ; * lisp/subr.el (take-while): bytecode micro-optimisation 2026-02-05 17:36:17 +01:00
svg.el
system-taskbar.el
t-mouse.el
tab-bar.el ; Remove "--" from the name of autoloaded 'window--get-split-combination' 2026-01-22 20:09:47 +02:00
tab-line.el ; Fix a recent change of tab-bar/line faces 2026-01-12 15:10:59 +02:00
tabify.el
talk.el
tar-mode.el
tempo.el
term.el Fix updating buffer menu after invoking "M-x term" 2026-01-21 17:37:33 +02:00
thingatpt.el
thread.el
time-stamp.el
time.el display-time: Add option to customize help-echo format 2026-01-31 12:12:21 +02:00
timezone.el
tmm.el
tool-bar.el
tooltip.el
touch-screen.el
transient.el
tree-widget.el
treesit-x.el
treesit.el
tty-tip.el
tutorial.el Fix [More] buttons in tutorial and other buttons in Semantic 2026-02-03 05:14:59 +02:00
type-break.el
uniquify.el
userlock.el
vcursor.el
version.el
view.el
visual-wrap.el
w32-fns.el
w32-vars.el
wdired.el
which-key.el
whitespace.el ; whitespace-global-modes: Replace "automagically". 2026-01-12 10:38:29 +00:00
wid-browse.el
wid-edit.el
widget.el
windmove.el
window-tool-bar.el
window-x.el ; Remove "--" from the name of autoloaded 'window--get-split-combination' 2026-01-22 20:09:47 +02:00
window.el ; * lisp/window.el (window--frame-landscape-p): Tweak wording. 2026-02-05 12:18:54 +00:00
winner.el
woman.el
x-dnd.el
xdg.el
xml.el
xt-mouse.el
xwidget.el ; Remove redundant cl-lib runtime dependencies across lisp/ 2026-01-17 15:32:15 +02:00
yank-media.el ; Remove redundant cl-lib runtime dependencies across lisp/ 2026-01-17 15:32:15 +02:00

This directory contains source code for the parts of Emacs that are
written in Emacs Lisp.  *.el files are Emacs Lisp source, and the
corresponding *.elc files are byte-compiled versions.  Byte-compiled
files are architecture-independent.

The term subdirectory contains Lisp files that customize Emacs for
certain terminal types.  When Emacs starts, it checks the TERM
environment variable to get the terminal type and loads
'term/${TERM}.el' if it exists.

The other subdirectories hold Lisp packages grouped by their general
purpose.