Function: consult--in-region
consult--in-region is a byte-compiled function defined in consult.el.
Signature
(consult--in-region START END TABLE PREDICATE)
Documentation
Internal completion-in-region-function.
The arguments START, END, TABLE and PREDICATE and
expected return value are as specified for completion-in-region.
Source Code
;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
(defun consult--in-region (start end table predicate)
"Internal `completion-in-region-function'.
The arguments START, END, TABLE and PREDICATE and
expected return value are as specified for `completion-in-region'."
(barf-if-buffer-read-only)
(let* ((initial (buffer-substring-no-properties start end))
(metadata (completion-metadata initial table predicate))
;; bug#75910: category instead of `minibuffer-completing-file-name'
(minibuffer-completing-file-name
(eq 'file (completion-metadata-get metadata 'category)))
(threshold (completion--cycle-threshold metadata))
(all (completion-all-completions initial table predicate
(if (<= start (point) end)
(- (point) start)
(length initial))
metadata)))
;; Normalize improper list
(when-let* ((last (last all)))
(setcdr last nil))
(if (or (eq threshold t) (length< all (1+ (or threshold 1)))
(and completion-cycling completion-all-sorted-completions))
(let (completion-auto-help)
(completion--in-region start end table predicate))
;; Wrap all annotation functions to ensure that they are executed
;; in the original buffer.
(let* ((exit-fun (plist-get completion-extra-properties :exit-function))
(ann-fun (plist-get completion-extra-properties :annotation-function))
(aff-fun (plist-get completion-extra-properties :affixation-function))
(docsig-fun (plist-get completion-extra-properties :company-docsig))
(completion-extra-properties
`(,@(and ann-fun (list :annotation-function (consult--in-buffer ann-fun)))
,@(and aff-fun (list :affixation-function (consult--in-buffer aff-fun)))
;; Provide `:annotation-function' if `:company-docsig' is specified.
,@(and docsig-fun (not ann-fun) (not aff-fun)
(list :annotation-function
(consult--in-buffer
(lambda (cand)
(concat (propertize " " 'display '(space :align-to center))
(funcall docsig-fun cand))))))))
(completion
(consult--local-let ((enable-recursive-minibuffers t))
;; Evaluate completion table in the original buffer.
;; This is a reasonable thing to do and required by
;; some completion tables in particular by lsp-mode.
;; See gh:minad/vertico#61.
(consult--read
(consult--completion-table-in-buffer table)
:command #'consult-completion-in-region
:prompt (if (minibufferp)
;; Use existing minibuffer prompt and input
(let ((prompt (buffer-substring (point-min) start)))
(put-text-property
(max 0 (1- (minibuffer-prompt-end))) (length prompt)
'face 'shadow prompt)
prompt)
"Complete: ")
:state (consult--insertion-preview start end)
:predicate predicate
:initial initial))))
(completion--replace start end completion)
(when exit-fun
(funcall exit-fun completion
;; If completion is finished and cannot be further
;; completed, return `finished'. Otherwise return
;; `exact'.
(if (eq (try-completion completion table predicate) t)
'finished 'exact)))
t))))