[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu 68ea28e 1/2: corfu-complete: Insert first candida
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu 68ea28e 1/2: corfu-complete: Insert first candidate, when try-completion did not make progress |
Date: |
Tue, 10 Aug 2021 05:57:08 -0400 (EDT) |
branch: externals/corfu
commit 68ea28e987f4079f45916800f1a7b9530600a198
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
corfu-complete: Insert first candidate, when try-completion did not make
progress
Check if last-command=corfu-complete
---
corfu.el | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/corfu.el b/corfu.el
index 38c0113..7364887 100644
--- a/corfu.el
+++ b/corfu.el
@@ -799,16 +799,28 @@ completion began less than that number of seconds ago."
"Try to complete current input."
(interactive)
(cond
- (completion-cycling (completion-at-point)) ;; Proceed with cycling
- ((>= corfu--index 0) (corfu--insert nil)) ;; Continue completion
+ ;; Proceed with cycling
+ (completion-cycling (completion-at-point))
+ ;; Continue completion with selected candidate
+ ((>= corfu--index 0) (corfu--insert nil))
+ ;; Try to complete the current input string
(t (pcase-let* ((`(,beg ,end ,table ,pred) completion-in-region--data)
(pt (max 0 (- (point) beg)))
(str (buffer-substring-no-properties beg end))
(metadata (completion-metadata (substring str 0 pt) table
pred)))
(pcase (completion-try-completion str table pred pt metadata)
+ ;; Prefix completion made progress.
((and `(,newstr . ,newpt) (guard (not (equal str newstr))))
(completion--replace beg end newstr)
- (goto-char (+ beg newpt))))))))
+ (goto-char (+ beg newpt)))
+ ;; When the last command was `corfu-complete' and we didn't make
progress,
+ ;; insert the first candidate.
+ ((guard (and (eq last-command #'corfu-complete) (> corfu--total 0)))
+ (completion--replace beg end
+ (concat (substring str 0 corfu--base)
+ (substring-no-properties
+ (car corfu--candidates))))))))))
+
(defun corfu--insert (status)
"Insert current candidate, exit with STATUS if non-nil."