Function: orderless-try-completion
orderless-try-completion is an autoloaded and byte-compiled function
defined in orderless.el.
Signature
(orderless-try-completion STRING TABLE PRED POINT)
Documentation
Complete STRING to unique matching entry in TABLE.
This uses orderless-all-completions to find matches for STRING
in TABLE among entries satisfying PRED. If there is only one
match, it completes to that match. If there are no matches, it
returns nil. In any other case it "completes" STRING to
itself, without moving POINT.
This function is part of the orderless completion style.
Source Code
;; Defined in ~/.emacs.d/elpa/orderless-20260519.1029/orderless.el
;;;###autoload
(defun orderless-try-completion (string table pred point)
"Complete STRING to unique matching entry in TABLE.
This uses `orderless-all-completions' to find matches for STRING
in TABLE among entries satisfying PRED. If there is only one
match, it completes to that match. If there are no matches, it
returns nil. In any other case it \"completes\" STRING to
itself, without moving POINT.
This function is part of the `orderless' completion style."
(or
(pcase orderless-expand-substring
('nil nil)
('prefix (completion-emacs21-try-completion string table pred point))
(_ (completion-substring-try-completion string table pred point)))
(catch 'orderless--many
(pcase-let ((`(,prefix ,regexps ,ignore-case ,pred)
(orderless--compile string table pred))
(one nil))
;; Abuse all-completions/orderless--filter as a fast search loop.
;; Should be almost allocation-free since our "predicate" is not
;; called more than two times.
(orderless--filter
prefix regexps ignore-case table
(orderless--predicate-normalized-and
pred
(lambda (arg)
;; Check if there is more than a single match (= many).
(when (and one (not (equal one arg)))
(throw 'orderless--many (cons string point)))
(setq one arg)
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'.
(unless (or (equal prefix "")
(and (string-prefix-p prefix one)
(test-completion one table pred)))
(setq one (concat prefix one)))
(or (equal string one) ;; Return t for unique exact match
(cons one (length one))))))))