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

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

[elpa] externals/corfu 205e7231d2 2/2: README: Document improved shell c


From: ELPA Syncer
Subject: [elpa] externals/corfu 205e7231d2 2/2: README: Document improved shell configuration, corfu-insert-and-send
Date: Tue, 8 Feb 2022 07:57:24 -0500 (EST)

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

    README: Document improved shell configuration, corfu-insert-and-send
---
 README.org | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/README.org b/README.org
index a56b5ea757..d76f83b6d7 100644
--- a/README.org
+++ b/README.org
@@ -186,10 +186,11 @@ completion UI, the following snippet should yield the 
desired result.
   (add-hook 'minibuffer-setup-hook #'corfu-enable-always-in-minibuffer 1)
 #+end_src
 
-** Completing with Corfu in the Shell or Eshell
+** Completing with Corfu in the Eshell or Shell
 
 When completing in the Eshell I recommend conservative local settings without
-auto completion.
+auto completion, such that the completion behavior is similar to widely used
+shells like Bash, Zsh or Fish.
 
 #+begin_src emacs-lisp
   (add-hook 'eshell-mode-hook
@@ -198,6 +199,32 @@ auto completion.
               (corfu-mode)))
 #+end_src
 
+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. In my
+configuration I define the command ~corfu-insert-and-send~ which performs the 
two
+steps at once.
+
+#+begin_src emacs-lisp
+  (defun corfu-insert-and-send ()
+    (interactive)
+    ;; 1. First insert the completed candidate
+    (corfu-insert)
+    ;; 2. Send the entire prompt input to the shell
+    (cond
+     ((and (derived-mode-p 'eshell-mode) (fboundp 'eshell-send-input))
+      (eshell-send-input))
+     ((derived-mode-p 'comint-mode)
+      (comint-send-input))))
+
+  (add-hook 'eshell-mode
+            (lambda ()
+              ;; Create a local copy of corfu-map
+              (setq-local corfu-map (copy-keymap corfu-map))
+              ;; Rebind RET to corfu-insert-and-send
+              (define-key corfu-map "\r" #'corfu-insert-and-send)))
+#+end_src
+
 Shell completion uses the flexible ~pcomplete~ mechanism internally, which 
allows
 you to program the completions per shell command. If you want to know more, 
look
 into this 
[[https://www.masteringemacs.org/article/pcomplete-context-sensitive-completion-emacs][blog
 post]], which shows how to configure pcomplete for git commands. I



reply via email to

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