diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2022-09-08 00:39:29 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2022-09-08 00:49:22 +0200 |
| commit | 684c5e493c6b0c5cfe5119f7ad6b7c790669900a (patch) | |
| tree | ca983a446c9bfbcc4d3ab1a80e92858daea16c25 | |
| parent | 8b9af2796fa0eb87eea4140bc08d16880a493803 (diff) | |
Improve orderless-try-completion (Fix #118)
orderless-try-completion abuses a "predicate" which throws as a fast loop over
the completion candidate.
- The predicate returns t such that all-completions returns a list (instead of
nil as before). This fixes completion-table-with-predicate.
- If multiple candidates match, we check that the matches are actually
different. This ensures that we don't get incorrect results if the predicate
is called twice on the same candidate or if duplicates exists.
| -rw-r--r-- | orderless.el | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/orderless.el b/orderless.el index d1b47e9..bcc0d4c 100644 --- a/orderless.el +++ b/orderless.el @@ -423,18 +423,19 @@ This function is part of the `orderless' completion style." (catch 'orderless--many (let (one) ;; Abuse all-completions/orderless-filter as a fast search loop. - ;; Should be more or less allocation-free since our "predicate" - ;; always returns nil. + ;; Should be almost allocation-free since our "predicate" is not + ;; called more than two times. (orderless-filter string table ;; key/value for hash tables (lambda (&rest args) (when (or (not pred) (apply pred args)) - (when one + (setq args (car args) ;; first argument is key + args (if (consp args) (car args) args) ;; alist + args (if (symbolp args) (symbol-name args) args)) + (when (and one (not (equal one args))) (throw 'orderless--many (cons string point))) - (setq one (car args) ;; first argument is key - one (if (consp one) (car one) one) ;; alist - one (if (symbolp one) (symbol-name one) one))) - nil)) + (setq one args) + t))) (when one (if (equal string one) t ;; unique exact match |
