branch: externals/orderless commit 89eb3775daa53cfb52ad03015410c23f28c72d30 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
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 --- orderless.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/orderless.el b/orderless.el index 38d73abc61..9e1939e5e6 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