[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu f74d3e7b5a 1/2: Add new command corfu-send
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu f74d3e7b5a 1/2: Add new command corfu-send |
Date: |
Sat, 13 Jul 2024 09:57:47 -0400 (EDT) |
branch: externals/corfu
commit f74d3e7b5aa658663705035aaac2c321bb8ed5cc
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add new command corfu-send
---
CHANGELOG.org | 1 +
README.org | 24 ++++++------------------
corfu.el | 10 ++++++++++
3 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 9417ef0956..a3c07d9cee 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -10,6 +10,7 @@
=<tab>= instead of =TAB=, as was the case in old versions of Org. If you use
such
a mode, please report this as a bug for this mode. In the meantime you can
use
=(keymap-set corfu-map "<tab>" #'corfu-complete)=.
+- Add new command ~corfu-send~ as alternative to ~corfu-insert~.
* Version 1.4 (2024-05-23)
diff --git a/README.org b/README.org
index b3bdcc5970..ceb284f51d 100644
--- a/README.org
+++ b/README.org
@@ -315,19 +315,11 @@ When pressing =RET= while the Corfu popup is visible, the
~corfu-insert~ command
will be invoked. This command does inserts the currently selected candidate,
but
it does not send the prompt input to Eshell or the Comint process. Therefore
you
often have to press =RET= twice which feels like an unnecessary double
-confirmation. Fortunately it is easy to improve this! In my configuration I
-define the advice ~corfu-send-shell~ which sends the candidate after insertion.
+confirmation. Fortunately it is easy to improve this by using the command
+~corfu-send~ instead.
#+begin_src emacs-lisp
-(defun corfu-send-shell (&rest _)
- "Send completion candidate when inside comint/eshell."
- (cond
- ((and (derived-mode-p 'eshell-mode) (fboundp 'eshell-send-input))
- (eshell-send-input))
- ((and (derived-mode-p 'comint-mode) (fboundp 'comint-send-input))
- (comint-send-input))))
-
-(advice-add #'corfu-insert :after #'corfu-send-shell)
+(keymap-set corfu-map "RET" #'corfu-send)
#+end_src
Shell completion uses the flexible Pcomplete mechanism internally, which allows
@@ -438,19 +430,15 @@ modes.
;; Option 1: Unbind RET completely
;;; ("RET" . nil)
;; Option 2: Use RET only in shell modes
- ("RET" . (menu-item "" nil :filter corfu-insert-shell-filter)))
+ ("RET" . (menu-item "" nil :filter corfu-send-filter)))
:init
(global-corfu-mode))
-(defun corfu-insert-shell-filter (&optional _)
+(defun corfu-send-filter (&optional _)
"Insert completion candidate and send when inside comint/eshell."
(when (or (derived-mode-p 'eshell-mode) (derived-mode-p 'comint-mode))
- (lambda ()
- (interactive)
- (corfu-insert)
- ;; `corfu-send-shell' was defined above
- (corfu-send-shell))))
+ #'corfu-send))
#+end_src
** TAB-and-Go completion
diff --git a/corfu.el b/corfu.el
index 51b03b8c3c..0da299e79d 100644
--- a/corfu.el
+++ b/corfu.el
@@ -1325,6 +1325,16 @@ Quit if no candidate is selected."
(corfu--insert 'finished)
(corfu-quit)))
+(defun corfu-send ()
+ "Insert current candidate and send it when inside comint or eshell."
+ (interactive)
+ (corfu-insert)
+ (cond
+ ((and (derived-mode-p 'eshell-mode) (fboundp 'eshell-send-input))
+ (eshell-send-input))
+ ((and (derived-mode-p 'comint-mode) (fboundp 'comint-send-input))
+ (comint-send-input))))
+
;;;###autoload
(define-minor-mode corfu-mode
"COmpletion in Region FUnction."