The previous algorithm had two problems: it considered non-matches in
the beginning and end of the string as matching "holes" and failed to
penalize larger holes, making flex-score-match-tightness only
effective in some corner cases.
The new formula, which is described in code and in pseudo-code in the
comments, fixes these problems.
As a result, by default, C-h f flex now correctly bubbles up
"company-search-flex-regexp" to the top, in front of "file-exists-p".
With a flex-score-match-tightness smaller than 1.0, the situation is
reversed.
* lisp/minibuffer.el (flex-score-match-tightness): Adjust default
value. Improve docstring example.
(completion-pcm--hilit-commonality): Improve example. Remove unused
variable. Improve algorithm.
The previous commit titled "Rework face hints for partial-string
completion styles" contained a potentially controversial
backwards-incompatible change to this face's default value.
* lisp/minibuffer.el (completions-common-part): Restore empty
default value.
Don't use completions-first-difference for the 'substring', 'flex' and
'partial-completion' styles, since there can be really no reasonable
definition of a "first" difference there.
Make completions-common-part inherit from 'underline' so that it is
useful by default for all completion styles.
* lisp/minibuffer.el (completions-common-part): Adjust
description and change default value.
(completions-first-difference): Ajust docstring.
(completion-pcm--hilit-commonality): Don't use
completions-first-difference.
This commit re-does the now-reverted commit with the same title. That
version relied on generic functions, which cannot be used yet in files
such as lisp/minibuffer.el. This version uses a symbol property
completion--adjust-metadata instead.
The new facility allows completion styles to have a say in metadata
properties such as cycle-sort-function and display-sort-function.
This is especially useful for completion styles such as 'flex', which
generally produce many matches, including some potentially "obscure"
ones. The default sorting strategy would often bubble the latter to
the top of the list.
The sorting function for 'flex' considers pre-computed matching scores
and is thus much better than the default for this particular style.
Additionally, it overrides the completion table's cycle-sort-function
or display-sort-function properties if they exist, although it still
uses them to pre-sort the result, so that they are still relevant for
resolving ties.
* lisp/minibuffer.el (completion--nth-completion)
(completion--flex-adjust-metadata): New helper.
(flex): Put completion--adjust-metadata property.
The new facility, realized in the completion-adjust-metadata-for-style
generic, allows completion styles to have a say in metadata properties
such as cycle-sort-function and display-sort-function. This is
especially useful for completion styles such as 'flex', which
generally produce many matches, including some potentially "obscure"
ones. The default sorting strategy would often bubble the latter
to the top of the list.
The sorting function for 'flex' considers pre-computed matching scores
and is thus much better than the default for this particular style.
Additionally, it overrides the completion table's cycle-sort-function
or display-sort-function properties if they exist, although it still
uses them to pre-sort the result, so that they are still relevant for
resolving ties.
* lisp/minibuffer.el (completion--nth-completion): Call
completion-adjust-metadata-for-style.
(completion-adjust-metadata-for-style): New generic.
(completion-adjust-metadata-for-style 'flex): New method.
* doc/lispref/minibuf.texi (Completion Commands)
(Text from Minibuffer): Document it.
* lisp/minibuffer.el (minibuffer-beginning-of-buffer): New command
(bug#3447).
(map): Bind it.
(minibuffer-message): Use it to propertize message unless already
propertized by the caller.
* lisp/simple.el (minibuffer-error-function): Propertize the error.
* lisp/isearch.el (isearch-message-properties): New variable.
(isearch--momentary-message, isearch-message-prefix)
(isearch-message-suffix): Use it. (Bug#21112)
To hopefully resolve a long-running discussion
(https://lists.gnu.org/archive/html/emacs-devel/2019-05/msg00162.html).
* lisp/progmodes/project.el (project-read-file-name-function):
New variable.
(project--read-file-absolute, project--read-file-cpd-relative):
New functions, possible values for the above.
(project-find-file-in): Use the introduced variable.
(project--completing-read-strict): Retain just the logic that fits
the name.
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.
The new completion style needs to score completion matches so that we
can use it later on when sorting the completions. This is because
"foo" can flex-match "foobar", "frodo" and "barfromsober" but we
probably want "foobar" to appear at the top of the completion list.
This change introduces a scoring formula and adds scoring hints in the
candidate string's `completion-score' property.
* lisp/minibuffer.el (completion-pcm--hilit-commonality): Propertize
completion with 'completion-score
(flex-score-falloff): New variable.
Rather than let minibuffer-force-complete set up cycling and then undoing it,
better tell it directly not to setup cycling. Also be a bit more careful
to remove the transient map.
Additionally to bug#34077 and bug#34116, this also relates to bug#25644.
* lisp/minibuffer.el (completion--flush-all-sorted-completions):
Also take down the transient cycling map if applicable.
(minibuffer-force-complete): New arg dont-cycle.
Set completion-cycling to the actual function that takes down the
transient map rather than just t.
(minibuffer-force-complete-and-exit):
* lisp/icomplete.el (icomplete-force-complete): Use new dont-cycle arg.
(display-buffer--maybe-pop-up-frame)
(display-buffer--maybe-pop-up-window): New functions created from
display-buffer--maybe-pop-up-frame-or-window.
(display-buffer--maybe-pop-up-frame-or-window): Call
display-buffer--maybe-pop-up-frame or
display-buffer--maybe-pop-up-window.
(display-buffer-at-bottom): Fix parens.
* lisp/minibuffer.el (minibuffer-completion-help): Use
display-buffer--maybe-pop-up-frame instead of let-binding
pop-up-windows to nil.
* lisp/files.el (hack-local-variables-confirm)
(save-buffers-kill-emacs): Use display-buffer--maybe-at-bottom.
63b04c11d5 Fix copyright years by hand
5c7dd8a783 Update copyright year to 2018
220a9ecba1 Merge from Gnulib
312c565566 Don't add empty keyboard macro to macro ring (Bug#24992)
39ca289a7a Allow customization of decoding of "man" command
f8240815ea * etc/NEWS: Add security consideration note on passphrase ...
0c78822c70 Fix subtle problem with scroll-down when scroll-margin is ...
acd289c5a4 Fix problems with indexing in User manual
b240c7846b * lisp/help.el (describe-key): Only (copy-sequence elt) wh...
e879a5444a * src/buffer.c (Frestore_buffer_modified_p): Fix bug#29846
81b1028b63 Improve documentation of 'inhibit-modification-hooks' and ...
7175496d7a Fix doc string of 'enable-recursive-minibuffers'
5b38406491 Fix documentation of delsel and of killing text
# Conflicts:
# etc/NEWS
# etc/refcards/ru-refcard.tex
9533d76b0b Keep Man sections in natural order (bug#28998)
d63c9a96f5 * lisp/minibuffer.el: Install a workaround for bug#16274
7657a86709 Fix comparisons with tip_frame in GTK builds
603a0716a8 Improve the documentation of M-n for entering file names
72f813fb56 Fix desktop auto-save timer when linum-mode is used
44340b475f Fix "C-h k" in xterm-mouse-mode
05aa6d4a68 Fix off-by-1 bug in --enable-checking=stringbytes
096f638ddc Correct the indentation of C99's compound literals.
c52a2aa8f3 Improve the doc string of 'dired-isearch-filter-filenames'
e592b92482 * lisp/isearch.el (search-invisible): Doc fix. (Bug#29222)
f3e69a80ab Fix display of line numbers in GTK builds
e6f1fd4091 Fix previous change to flymake-diag-region (bug#29174)
89382780e1 flymake-diag-region really returns nil if region is invali...
535688a418 Flymake correctly highlights whole last line if eob (bug#2...
72e62d3fdb Protect Flymake checkdoc backend against checkdoc errors (...
b28de57411 Sort entries of the Flymake diagnostics buffer (bug#29175)
fc56bea142 Correctly indent C++14 brace lists which are a second argu...
9dde8be9cd Fix redisplay of overlay-arrows on GUI frames
0da08f2f8e Protect Flymake tests against older Ruby and Perl (bug#29187)
781f276cc1 Fix URL cookie expiration bug
255ba01148 Fix handling of nil PRED2 arg for completion-table-with-pr...
949b70a7d8 ; Minor comment copyedit in window.c
20f9bf30f0 Describe Lao rendering problem
3d61657694 Fix docstring of arabic-shaper-ZWNJ-handling
db949166ec Handle single-line comments correctly (Bug#26049)
795bb233a5 * test/lisp/net/tramp-tests.el (tramp-test16-file-expand-w...
ba00ea7d0d * etc/PROBLEMS: Add URL to relevant issues for xterm+evil bug
4a6015811e ; In text.texi fix typo spotted by Štěpán Němec
93cd8415b2 Document new treatment of 'comment-auto-fill-only-comments'
ca2d94ba61 Do not load Tramp unless `tramp-mode' is non-nil
709478eaa8 Prefer `customize-set-variable' in tramp.texi
5d36f2227f Fix last change in hscroll_window_tree
72d07d1950 Ediff: add some missing documentation
18af404ef3 Support python virtualenv on w32 (Bug#24464)
efd0371c23 Improve dired deletion error handling (Bug#28797)
5d744e032f Don't replace user input when completion prefix is empty (...
ec6cf35c5f ; Describe xt-mouse problems with Evil mode
c572e1f329 Return non-nil from gnutls-available-p under GnuTLS 2.x
a2cc6d74c5 Fix Flymake help-echo functions across windows (bug#29142)
58bb3462ee Add tests for Flymake backends for Ruby and Perl
58e742b21d Add a Flymake backend for Perl
9dee764165 Add a Flymake backend for Ruby
3ad712ebc9 Add a Flymake backend for Python (bug#28808)
8db2b3a79b Allow "%" in Tramp host names
8c50842790 ; Fix typo in test/file-organization.org
00fa4449cd ; Fix typo
918a2dda07 Use hybrid malloc for FreeBSD (Bug#28308)
725ab635d9 Add html-, mhtml- and python-mode support to semantic symref
369da28702 Improve documentation of 'window-scroll-functions'
93818eed8a Fix subtle problems in tabulated-list-mode with line numbers
1f1de8e872 Make gdb-non-stop-setting default to nil on MS-Windows
680e8e119b Fix gdb-mi prompt after "attach PID" command
ff33074546 Fix doc string of 'window-configuration-change-hook'
787b75ad71 Improve documentation of window hooks
d9be8704ae Fix hscroll suspension after cursor motion
6f43d29d29 ; * CONTRIBUTE, admin/make-tarball.txt: Doc tweaks re 'ema...
a0d30d6369 Introduce a function to CC Mode which displays the current...
383abc8898 ; Fix some comment typos
b02c2714c3 Fix typos in ediff-wind.el
4f38bdec74 Examine tex-chktex--process in the correct buffer
94b490529a * nt/INSTALL.W64: Update to current mingw64 install instru...
c25113d4ac Don't resignal errors in flymake-diag-region
e950f329c0 New xref-quit-and-goto-xref command bound to TAB (bug#28814)
5d34e1b288 Allow split-window-sensibly to split threshold in further ...
2a973edeac Honor window-switching intents in xref-find-definitions (b...
78e9065e9f * lisp/emacs-lisp/generator.el (iter-do): Add a debug decl...
caa63cc96c * lisp/progmodes/flymake.el (flymake-start): Fix dead buff...
9f4f130b79 Fix buffer name comparison in async shell-command
# Conflicts:
# etc/NEWS
# lisp/vc/ediff-wind.el
* lisp/minibuffer.el (completion-table-with-predicate): Don't act as
if strict is non-nil when pred2 is nil (Bug#27841).
* test/lisp/minibuffer-tests.el
(completion-table-with-predicate-test): Add a test for Bug#27841.