diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2024-07-13 15:27:35 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2024-07-13 15:27:35 +0200 |
| commit | f74d3e7b5aa658663705035aaac2c321bb8ed5cc (patch) | |
| tree | 6090d50e389cabefbf09c7c1e595f1416ef03b22 | |
| parent | 1641b1d5c1a101dc32d11dcc174d7b9c6783d25b (diff) | |
Add new command corfu-send
| -rw-r--r-- | CHANGELOG.org | 1 | ||||
| -rw-r--r-- | README.org | 24 | ||||
| -rw-r--r-- | corfu.el | 10 |
3 files changed, 17 insertions, 18 deletions
diff --git a/CHANGELOG.org b/CHANGELOG.org index 9417ef0..a3c07d9 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) @@ -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 @@ -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." |
