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

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

[elpa] externals/corfu 9cebcfedca 3/3: Refactoring, Simplify handling of


From: ELPA Syncer
Subject: [elpa] externals/corfu 9cebcfedca 3/3: Refactoring, Simplify handling of corfu-on-exact-match=show
Date: Fri, 22 Dec 2023 12:57:34 -0500 (EST)

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

    Refactoring, Simplify handling of corfu-on-exact-match=show
---
 CHANGELOG.org |  3 +++
 corfu.el      | 59 +++++++++++++++++++++++++++++------------------------------
 2 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index b04d6d4833..6d5f13b77a 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -11,6 +11,9 @@
   properties, when possible. The properties are guaranteed to exist when a
   candidate is selected explicitly, but may be missing when candidates are
   completed in a stepwise manner.
+- ~corfu-on-exact-match~: Add value ~show~ to the customization option. With 
this
+  setting the Corfu popup will be shown even if there is only a single matching
+  candidate.
 
 * Version 1.0 (2023-12-01)
 
diff --git a/corfu.el b/corfu.el
index ef22616a3a..a0cd40798f 100644
--- a/corfu.el
+++ b/corfu.el
@@ -72,7 +72,11 @@ The value should lie between 0 and corfu-count/2."
   :type 'boolean)
 
 (defcustom corfu-on-exact-match 'insert
-  "Configure how a single exact match should be handled."
+  "Configure how a single exact match should be handled.
+- nil: No special handling, continue completion.
+- insert: Insert candidate, quit and call the `:exit-function'.
+- quit: Quit completion without further action.
+- show: Initiate completion even for a single match only."
   :type '(choice (const insert) (const show) (const quit) (const nil)))
 
 (defcustom corfu-continue-commands
@@ -852,9 +856,13 @@ Lookup STR in CANDS to restore text properties."
     (corfu-quit)
     (corfu--exit-function str status cands)))
 
-(defun corfu--setup ()
-  "Setup Corfu completion state."
-  (setq corfu--extra completion-extra-properties)
+(defun corfu--setup (beg end table pred)
+  "Setup Corfu completion state.
+See `completion-in-region' for the arguments BEG, END, TABLE, PRED."
+  (setq beg (if (markerp beg) beg (copy-marker beg))
+        end (if (and (markerp end) (marker-insertion-type end)) end 
(copy-marker end t))
+        completion-in-region--data (list beg end table pred)
+        corfu--extra completion-extra-properties)
   (completion-in-region-mode 1)
   (activate-change-group (setq corfu--change-group (prepare-change-group)))
   (setcdr (assq #'completion-in-region-mode minor-mode-overriding-map-alist) 
corfu-map)
@@ -899,19 +907,15 @@ Lookup STR in CANDS to restore text properties."
       ('nil (corfu--message "No match") nil)
       ('t (goto-char end)
           (corfu--message "Sole match")
-          (if (not (eq corfu-on-exact-match 'show))
-              (corfu--exit-function
-               str 'finished
-               (alist-get 'corfu--candidates (corfu--recompute str pt table 
pred)))
-            (unless (markerp beg) (setq beg (copy-marker beg)))
-            (setq end (copy-marker end t)
-                  completion-in-region--data (list beg end table pred))
-            (corfu--setup))
+          (if (eq corfu-on-exact-match 'show)
+              (corfu--setup beg end table pred)
+            (corfu--exit-function
+             str 'finished
+             (alist-get 'corfu--candidates (corfu--recompute str pt table 
pred))))
           t)
       (`(,newstr . ,newpt)
-       (unless (markerp beg) (setq beg (copy-marker beg)))
-       (setq end (copy-marker end t)
-             completion-in-region--data (list beg end table pred))
+       (setq beg (if (markerp beg) beg (copy-marker beg))
+             end (copy-marker end t))
        (corfu--replace beg end newstr)
        (goto-char (+ beg newpt))
        (let* ((state (corfu--recompute newstr newpt table pred))
@@ -919,24 +923,24 @@ Lookup STR in CANDS to restore text properties."
               (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 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)
+                 (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)))
-               (corfu--setup)
+               (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)))))
+               (corfu--setup beg end table pred)))))
        t))))
 
 (defun corfu--message (&rest msg)
@@ -972,12 +976,7 @@ See `completion-in-region' for the arguments BEG, END, 
TABLE, PRED."
                 (when-let ((newbeg (car-safe (funcall fun))))
                   (= newbeg beg))))
              (completion-extra-properties plist))
-         (setq completion-in-region--data
-               (list (if (markerp beg) beg (copy-marker beg))
-                     (copy-marker end t)
-                     table
-                     (plist-get plist :predicate)))
-         (corfu--setup)
+         (corfu--setup beg end table (plist-get plist :predicate))
          (corfu--exhibit 'auto))))))
 
 (defun corfu--auto-post-command ()
@@ -1131,10 +1130,10 @@ AUTO is non-nil when initializing auto completion."
     (cond
      ;; 1) Single exactly matching candidate and no further completion is 
possible.
      ((and (not (equal str ""))
-           (not (eq corfu-on-exact-match 'show))
            (equal (car corfu--candidates) str) (not (cdr corfu--candidates))
-           (not (consp (completion-try-completion str table pred pt 
corfu--metadata)))
-           (or auto corfu-on-exact-match))
+           (not (eq corfu-on-exact-match 'show))
+           (or auto corfu-on-exact-match)
+           (not (consp (completion-try-completion str table pred pt 
corfu--metadata))))
       ;; Quit directly when initializing auto completion.
       (if (or auto (eq corfu-on-exact-match 'quit))
           (corfu-quit)



reply via email to

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