Function: corfu--in-region-1
corfu--in-region-1 is a byte-compiled function defined in corfu.el.
Signature
(corfu--in-region-1 BEG END TABLE PRED)
Documentation
Complete in region, see completion-in-region for BEG, END, TABLE, PRED.
Source Code
;; Defined in ~/.emacs.d/elpa/corfu-20260813.950/corfu.el
(defun corfu--in-region-1 (beg end table pred)
"Complete in region, see `completion-in-region' for BEG, END, TABLE, PRED."
(barf-if-buffer-read-only)
;; Restart the completion. This can happen for example if C-M-/
;; (`dabbrev-completion') is pressed while the Corfu popup is already open.
(when completion-in-region-mode (corfu-quit))
(let* ((pt (max 0 (- (point) beg)))
(str (buffer-substring-no-properties beg end))
(input (cons str pt))
(md (completion-metadata (substring str 0 pt) table pred))
(threshold (completion--cycle-threshold md))
(completion-in-region-mode-predicate
(or completion-in-region-mode-predicate #'always)))
(pcase (corfu--try-completion str table pred pt md)
('nil (corfu--message "No match") nil)
('t (goto-char end)
(corfu--message "Sole match")
(if (eq corfu-on-exact-match 'show)
(corfu--setup beg end table pred)
(corfu--exit-function
str 'finished
(alist-get 'corfu--candidates (corfu--compute input table pred))))
t)
((and newinp `(,newstr . ,newpt))
(setq end (copy-marker end t))
(corfu--replace beg end newstr)
(goto-char (+ beg newpt))
(let* ((state (corfu--compute newinp table pred))
(base (alist-get 'corfu--base state))
(total (alist-get 'corfu--total state))
(cands (alist-get 'corfu--candidates state)))
(cond
((= total 0)
(when (test-completion newstr table pred)
(corfu--exit-function newstr 'finished nil)))
((= total 1)
;; Setup popup if `corfu-on-exact-match' is `show' or if completion
;; can continue.
(if (or (eq corfu-on-exact-match 'show)
(consp (corfu--try-completion newstr table pred newpt)))
(corfu--setup beg end table pred)
(corfu--exit-function (car cands) 'finished nil)))
;; Too many candidates for cycling -> Setup popup.
((or (not threshold) (and (not (eq threshold t)) (< threshold total)))
(corfu--setup beg end table pred))
(t
;; Cycle through candidates.
(corfu--cycle-candidates total cands (+ (length base) beg) end)
;; Do not show Corfu when completion is finished after the candidate.
(unless (equal (completion-boundaries (car cands) table pred "") '(0 . 0))
(corfu--setup beg end table pred)))))
t))))