emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/corfu 01c9f12 1/3: corfu--insert: Simplify


From: Protesilaos Stavrou
Subject: [elpa] externals/corfu 01c9f12 1/3: corfu--insert: Simplify
Date: Mon, 19 Apr 2021 03:22:41 -0400 (EDT)

branch: externals/corfu
commit 01c9f127facb1d91ea82ea30caa79da58a5ce7c0
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    corfu--insert: Simplify
---
 corfu.el | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/corfu.el b/corfu.el
index 4b0711f..7b04df3 100644
--- a/corfu.el
+++ b/corfu.el
@@ -530,20 +530,20 @@ If `line-spacing/=nil' or in text-mode, the background 
color is used instead.")
 (defun corfu--insert (status)
   "Insert current candidate, exit with STATUS if non-nil."
   (pcase-let* ((`(,beg ,end ,table ,pred) completion-in-region--data)
-               (str (buffer-substring-no-properties beg end))
-               (newstr (if (and (< corfu--index 0) (not (equal str ""))
-                                (test-completion str table pred))
-                           ;; No candidate selected and current input is a 
valid completion.
-                           ;; For example str can be a valid path, e.g., 
~/dir/.
-                           str
-                         (concat (substring str 0 corfu--base)
-                                 (substring-no-properties (nth (max 0 
corfu--index) corfu--candidates))))))
-    (completion--replace beg end newstr)
+               (str (buffer-substring-no-properties beg end)))
+    ;; Replace if candidate is selected or if current input is not valid 
completion.
+    ;; For example str can be a valid path, e.g., ~/dir/.
+    (when (or (>= corfu--index 0) (equal str "")
+              (not (test-completion str table pred)))
+      (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 newstr status))
+        (funcall exit str status))
       (completion-in-region-mode -1))))
 
 (defun corfu-insert ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]