summaryrefslogtreecommitdiff
path: root/corfu.el
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2024-12-20 22:53:06 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2024-12-20 23:00:50 +0100
commit2050453a7ea5734fe85cdfd276e946ad59b1dd56 (patch)
tree72864e85bd689c2fee9568e46d2e285075bbe053 /corfu.el
parentf17fe365d288d4cb00337ae194009e7b3d924edc (diff)
corfu--in-region-1: Handle zero candidates after try-completion
Fix #538
Diffstat (limited to 'corfu.el')
-rw-r--r--corfu.el42
1 files changed, 23 insertions, 19 deletions
diff --git a/corfu.el b/corfu.el
index cbe7aa6..34af31a 100644
--- a/corfu.el
+++ b/corfu.el
@@ -943,26 +943,30 @@ See `completion-in-region' for the arguments BEG, END, TABLE, PRED."
(let* ((state (corfu--recompute newstr newpt table pred))
(base (alist-get 'corfu--base state))
(total (alist-get 'corfu--total state))
- (candidates (alist-get 'corfu--candidates state)))
- (if (= total 1)
- ;; If completion is finished and cannot be further completed, and
- ;; the value of `corfu-on-exact-match' is not 'show, return
- ;; 'finished. Otherwise setup the Corfu popup.
- (if (or (eq corfu-on-exact-match 'show)
- (consp (completion-try-completion
- newstr table pred newpt
- (completion-metadata newstr table pred))))
- (corfu--setup beg end table pred)
- (corfu--exit-function newstr 'finished candidates))
- (if (or (= total 0) (not threshold)
- (and (not (eq threshold t)) (< threshold total)))
+ (cands (alist-get 'corfu--candidates state)))
+ (cond
+ ((= total 0)
+ ;; No candidates found for `newstr' -> Completion is finished.
+ (corfu--exit-function newstr 'finished nil))
+ ((= total 1)
+ ;; If completion is finished and cannot be extended further and
+ ;; `corfu-on-exact-match' is not 'show, return 'finished. Otherwise
+ ;; setup the popup.
+ (if (or (eq corfu-on-exact-match 'show)
+ (consp (completion-try-completion
+ newstr table pred newpt
+ (completion-metadata newstr table pred))))
(corfu--setup beg end table pred)
- (corfu--cycle-candidates total candidates (+ (length base) beg) end)
- ;; Do not show Corfu when "trivially" cycling, i.e.,
- ;; when the completion is finished after the candidate.
- (unless (equal (completion-boundaries (car candidates) table pred "")
- '(0 . 0))
- (corfu--setup beg end table pred)))))
+ (corfu--exit-function newstr 'finished cands)))
+ ;; 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))))
(defun corfu--message (&rest msg)