diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2023-10-25 22:31:28 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2023-10-25 22:44:25 +0200 |
| commit | 89eb3775daa53cfb52ad03015410c23f28c72d30 (patch) | |
| tree | 899680361cfd4b2bfd03d5dc2059be8c40a049d6 /orderless.el | |
| parent | 06b78701eae7a79c08de4264dcc52f66a5ac4f66 (diff) | |
Work around inconsistency of `completion-table-with-context'
The function `completion-table-with-context' modifies the predicate such that
the string arguments are prefixed. This behavior is inconsistent with the
`completion-file-name-table', where the strings returned by `all-completions'
are the same as the strings passed to the predicate. The behavior of
`all-completions' seems more intuitive at first sight. This could be an
unintended bug or oversight in `completion-table-with-context'.
In `orderless-try-completion' we work around the inconsistency by checking if a
prefix is already present in the string passed to the predicate. If not, the
prefix is added.
Fix #148
Diffstat (limited to 'orderless.el')
| -rw-r--r-- | orderless.el | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/orderless.el b/orderless.el index 38d73ab..9e1939e 100644 --- a/orderless.el +++ b/orderless.el @@ -477,10 +477,21 @@ This function is part of the `orderless' completion style." (setq one args) t))) (when one + ;; Prepend prefix if the candidate does not already have the same + ;; prefix. This workaround is needed since the predicate may either + ;; receive an unprefixed or a prefixed candidate as argument. Most + ;; completion tables consistently call the predicate with unprefixed + ;; candidates, for example `completion-file-name-table'. In contrast, + ;; `completion-table-with-context' calls the predicate with prefixed + ;; candidates. This could be an unintended bug or oversight in + ;; `completion-table-with-context'. + (let ((prefix (car (orderless--prefix+pattern string table pred)))) + (unless (or (equal prefix "") + (and (string-prefix-p prefix one) + (test-completion one table pred))) + (setq one (concat prefix one)))) (if (equal string one) t ;; unique exact match - (setq one (concat (car (orderless--prefix+pattern string table pred)) - one)) (cons one (length one))))))) ;;;###autoload |
