branch: externals/corfu
commit a16282939c94375a01df3cb2bbecd47d7aa018c3
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>

    Revert "Exit from `corfu-complete`"
    
    This reverts commit fa8a43e1e7497930d9db2274833877629f423abb.
---
 corfu.el | 45 ++++++++++++++++++---------------------------
 1 file changed, 18 insertions(+), 27 deletions(-)

diff --git a/corfu.el b/corfu.el
index 9a26324..e56d839 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)))
+    (corfu--insert 'exact))) ;; Complete with "exact" input
 
 (defun corfu-abort ()
   "Abort Corfu completion."
@@ -517,29 +517,16 @@ If `line-spacing/=nil' or in text-mode, the background 
color is used instead.")
 (defun corfu-complete ()
   "Try to complete current input."
   (interactive)
-  (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))
+  (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)))))))
 
 (defun corfu--insert (status)
   "Insert current candidate, exit with STATUS if non-nil."
@@ -558,9 +545,13 @@ 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)
-      (setq corfu--index -1)) ;; Reset selection, but continue completion.
-    (when status (corfu--done str status)))) ;; Exit with status
+      (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))))
 
 (defun corfu-insert ()
   "Insert current candidate."

Reply via email to