[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu fa8a43e 1/4: Exit from `corfu-complete`
From: |
Protesilaos Stavrou |
Subject: |
[elpa] externals/corfu fa8a43e 1/4: Exit from `corfu-complete` |
Date: |
Tue, 20 Apr 2021 14:03:08 -0400 (EDT) |
branch: externals/corfu
commit fa8a43e1e7497930d9db2274833877629f423abb
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Exit from `corfu-complete`
When no further completion is possible and the current
string is a valid match, exit with status 'finished.
See #11
---
corfu.el | 45 +++++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 18 deletions(-)
diff --git a/corfu.el b/corfu.el
index e56d839..9a26324 100644
--- a/corfu.el
+++ b/corfu.el
@@ -334,7 +334,7 @@ If `line-spacing/=nil' or in text-mode, the background
color is used instead.")
(setq corfu--overlays nil)
(unless (or (< corfu--index 0)
(string-match-p corfu--keep-alive (prin1-to-string
this-command)))
- (corfu--insert 'exact))) ;; Complete with "exact" input
+ (corfu--insert 'exact)))
(defun corfu-abort ()
"Abort Corfu completion."
@@ -517,16 +517,29 @@ If `line-spacing/=nil' or in text-mode, the background
color is used instead.")
(defun corfu-complete ()
"Try to complete current input."
(interactive)
- (if (>= corfu--index 0)
- (corfu--insert nil) ;; Continue completion
- (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)
- ((and `(,newstr . ,newpt) (guard (not (equal str newstr))))
- (completion--replace beg end newstr)
- (goto-char (+ beg newpt)))))))
+ (pcase-let ((`(,beg ,end ,table ,pred) completion-in-region--data))
+ (if (>= corfu--index 0)
+ (corfu--insert nil)
+ (let* ((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)
+ ((and `(,newstr . ,newpt) (guard (not (equal str newstr))))
+ (completion--replace beg end newstr)
+ (goto-char (+ beg newpt))))))
+ ;; When no further completion is possible and the current
+ ;; string is a valid match, exit with status 'finished.
+ (let ((str (buffer-substring-no-properties beg end)))
+ (when (and (not (stringp (try-completion str table pred)))
+ (test-completion str table pred))
+ (corfu--done str 'finished)))))
+
+(defun corfu--done (str status)
+ "Call the `:exit-function' with STR and STATUS and exit completion."
+ ;; XXX Is the :exit-function handling sufficient?
+ (when-let (exit (plist-get corfu--extra-properties :exit-function))
+ (funcall exit str status))
+ (completion-in-region-mode -1))
(defun corfu--insert (status)
"Insert current candidate, exit with STATUS if non-nil."
@@ -545,13 +558,9 @@ If `line-spacing/=nil' or in text-mode, the background
color is used instead.")
(setq str (concat (substring str 0 corfu--base)
(substring-no-properties
(nth (max 0 corfu--index) corfu--candidates))))
- (completion--replace beg end str))
- (if (not status)
- (setq corfu--index -1) ;; Reset selection, but continue completion.
- ;; XXX Is the :exit-function handling sufficient?
- (when-let (exit (plist-get corfu--extra-properties :exit-function))
- (funcall exit str status))
- (completion-in-region-mode -1))))
+ (completion--replace beg end str)
+ (setq corfu--index -1)) ;; Reset selection, but continue completion.
+ (when status (corfu--done str status)))) ;; Exit with status
(defun corfu-insert ()
"Insert current candidate."