[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu f8f38d2 2/3: Add corfu-preselect-first configurat
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu f8f38d2 2/3: Add corfu-preselect-first configuration option |
Date: |
Fri, 26 Nov 2021 06:57:13 -0500 (EST) |
branch: externals/corfu
commit f8f38d2e840c60ca01739688f435c06a55355783
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add corfu-preselect-first configuration option
---
README.org | 5 +++--
corfu.el | 16 +++++++++++-----
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/README.org b/README.org
index 013bd95..b0aee1f 100644
--- a/README.org
+++ b/README.org
@@ -75,9 +75,10 @@
;; (corfu-commit-predicate nil) ;; Do not commit selected candidates
on next input
;; (corfu-quit-at-boundary t) ;; Automatically quit at word boundary
;; (corfu-quit-no-match t) ;; Automatically quit if there is no
match
- ;; (corfu-echo-documentation nil) ;; Do not show documentation in the
echo area
+ ;; (corfu-preview-current nil) ;; Disable current candidate preview
+ ;; (corfu-preselect-first nil) ;; Disable candidate preselection
+ ;; (corfu-echo-documentation nil) ;; Disable documentation in the echo
area
;; (corfu-scroll-margin 5) ;; Use scroll margin
- ;; (corfu-preview-current nil) ;; Do not preview current candidate
;; Optionally use TAB for cycling, default is `corfu-complete'.
;; :bind (:map corfu-map
diff --git a/corfu.el b/corfu.el
index 8feab51..75f1ca9 100644
--- a/corfu.el
+++ b/corfu.el
@@ -79,6 +79,10 @@ The value should lie between 0 and corfu-count/2."
"Preview currently selected candidate."
:type 'boolean)
+(defcustom corfu-preselect-first t
+ "Preselect first candidate."
+ :type 'boolean)
+
(defcustom corfu-quit-at-boundary nil
"Automatically quit at completion field/word boundary.
If automatic quitting is disabled, Orderless filter strings with spaces
@@ -583,7 +587,7 @@ A scroll bar is displayed from LO to LO+BAR."
(list base all (length all) hl corfu--metadata
;; Select the prompt when the input is a valid completion
;; and if it is not equal to the first candidate.
- (if (or (not all)
+ (if (or (not corfu-preselect-first) (not all)
(and (not (equal field (car all)))
(not (and completing-file (equal (concat field "/")
(car all))))
(test-completion str table pred)))
@@ -966,10 +970,12 @@ there hasn't been any input, then quit."
(defun corfu--insert (status)
"Insert current candidate, exit with STATUS if non-nil."
- (pcase-let* ((`(,beg ,end . ,_) completion-in-region--data)
+ (pcase-let* ((`(,beg ,end ,table ,pred) completion-in-region--data)
(str (buffer-substring-no-properties beg end)))
- ;; Replace if candidate is selected.
- (when (>= corfu--index 0)
+ ;; 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)))
;; XXX There is a small bug here, depending on interpretation.
;; When completing "~/emacs/master/li|/calc" where "|" is the
;; cursor, then the candidate only includes the prefix
@@ -977,7 +983,7 @@ there hasn't been any input, then quit."
;; completion has the same problem when selecting in the
;; *Completions* buffer. See bug#48356.
(setq str (concat (substring str 0 corfu--base)
- (substring-no-properties (nth corfu--index
corfu--candidates))))
+ (substring-no-properties (nth (max 0 corfu--index)
corfu--candidates))))
(completion--replace beg end str)
(corfu--goto -1)) ;; Reset selection, but continue completion.
(when status (corfu--done str status)))) ;; Exit with status