branch: externals/corfu commit 205e7231d267d06618c1af07828989e5453e1dda Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@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