[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu 761d9f55ab 1/2: corfu-insert: Do not insert first
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu 761d9f55ab 1/2: corfu-insert: Do not insert first candidate if no candidate is selected (Fix #152) |
Date: |
Fri, 1 Apr 2022 11:57:23 -0400 (EDT) |
branch: externals/corfu
commit 761d9f55ab4ba68be6240c61a6dffae1c7cdc9a2
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
corfu-insert: Do not insert first candidate if no candidate is selected
(Fix #152)
This special behavior of corfu-insert occurred with corfu-preselect-first
set to
nil. The behavior was a remnant from before the introduction of the
corfu-preselect-first customization option. Since corfu-preselect-first has
been
introduced a long time ago and I haven't heard complaints about it, let's
now
remove the special behavior of corfu-insert. This change simplifies the
corfu--insert function slightly and makes the behavior of corfu-insert more
consistent with other Corfu behavior. If the new behavior conflicts with
your
workflow, please let me know and we can look into possible workarounds.
Feedback
on this issue is welcome.
---
README.org | 2 +-
corfu.el | 28 ++++++++++++----------------
2 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/README.org b/README.org
index c3be759714..cea9de1fa8 100644
--- a/README.org
+++ b/README.org
@@ -223,7 +223,7 @@ define the command ~corfu-insert-and-send~ which performs
the two steps at once.
(cond
((and (derived-mode-p 'eshell-mode) (fboundp 'eshell-send-input))
(eshell-send-input))
- ((derived-mode-p 'comint-mode)
+ ((and (derived-mode-p 'comint-mode) (fboundp 'comint-send-input))
(comint-send-input))))
(define-key corfu-map "\r" #'+corfu-insert-and-send)
diff --git a/corfu.el b/corfu.el
index c9e6436a4f..6eaeca013f 100644
--- a/corfu.el
+++ b/corfu.el
@@ -1017,22 +1017,18 @@ 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 ,table ,pred) completion-in-region--data)
+ (pcase-let* ((`(,beg ,end . ,_) completion-in-region--data)
(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)))
- ;; 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
- ;; "~/emacs/master/lisp/", but not the suffix "/calc". Default
- ;; 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 (max 0 corfu--index)
corfu--candidates))))
- (completion--replace beg end str)
- (corfu--goto -1)) ;; Reset selection, but continue completion.
+ ;; 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
+ ;; "~/emacs/master/lisp/", but not the suffix "/calc". Default
+ ;; 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))))
+ (completion--replace beg end str)
+ (corfu--goto -1) ;; Reset selection, but continue completion.
(when status (corfu--done str status)))) ;; Exit with status
(defun corfu--done (str status)
@@ -1048,7 +1044,7 @@ there hasn't been any input, then quit."
(defun corfu-insert ()
"Insert current candidate."
(interactive)
- (if (> corfu--total 0)
+ (if (>= corfu--index 0)
(corfu--insert 'finished)
(corfu-quit)))