diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2022-02-08 13:38:27 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2022-02-08 13:38:27 +0100 |
| commit | 205e7231d267d06618c1af07828989e5453e1dda (patch) | |
| tree | 92d5897a7a0a252adbe40cfa229c265f18c211e0 /README.org | |
| parent | 7f84ff41f11dbe7f521f9e4ec02af0a5dc4e9ed4 (diff) | |
README: Document improved shell configuration, corfu-insert-and-send
Diffstat (limited to 'README.org')
| -rw-r--r-- | README.org | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -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 |
