Skip to content

Commit 8511b78

Browse files
committed
consult--read: Better documentation for the completion table
We may want to use the boundaries feature at some point for improved completion when the async filtering is used. In that case the input string is split in two parts `#grep#filter`. We could return boundaries such that the completion filtering only takes the `filter` into account. Given that, we would not need our custom async-split completion style. This would then allow TAB cycling candidates for example. Unfortunately Selectrum does not yet have sufficient support for boundaries (radian-software/selectrum#448).
1 parent 704f6b9 commit 8511b78

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

consult.el

+28-7
Original file line numberDiff line numberDiff line change
@@ -1600,13 +1600,34 @@ KEYMAP is a command-specific keymap."
16001600
'consult--completion-candidate-hook)
16011601
(completing-read prompt
16021602
(lambda (str pred action)
1603-
(if (eq action 'metadata)
1604-
`(metadata
1605-
,@(when annotate `((annotation-function . ,annotate)))
1606-
,@(when category `((category . ,category)))
1607-
,@(unless sort '((cycle-sort-function . identity)
1608-
(display-sort-function . identity))))
1609-
(complete-with-action action (funcall async nil) str pred)))
1603+
(pcase action
1604+
('metadata
1605+
;; Return completion metadata
1606+
`(metadata
1607+
,@(when annotate `((annotation-function . ,annotate)))
1608+
,@(when category `((category . ,category)))
1609+
,@(unless sort '((cycle-sort-function . identity)
1610+
(display-sort-function . identity)))))
1611+
(`(boundaries . ,_)
1612+
;; Return completion boundaries; Currently unused by Consult.
1613+
;; The boundaries specify the part of the input string which is
1614+
;; supposed to be used for filtering. In the future we may want
1615+
;; to use boundaries in order to implement async filtering.
1616+
nil)
1617+
('nil
1618+
;; Try to complete `str' prefix and return completed string.
1619+
;; This is feature is only used by prefix completion styles
1620+
;; like `basic'.
1621+
(try-completion str (funcall async nil) pred))
1622+
('t
1623+
;; Return all candidates matching the prefix `str'.
1624+
;; Usually this called with the empty string, except
1625+
;; when using `basic' completion. For other completion
1626+
;; styles the actual filtering takes place later.
1627+
(all-completions str (funcall async nil) pred))
1628+
(_
1629+
;; Return t if the input `str' matches one of the candidates.
1630+
(test-completion str (funcall async nil) pred))))
16101631
predicate require-match initial
16111632
(if (symbolp history) history (cadr history))
16121633
default))))

0 commit comments

Comments
 (0)