feat(corfu): vim-like C-n/C-p keybinds

In vim/evil, C-n/C-p invokes dabbrev, so we're doing the same, but
powered by cape-dabbrev, falling back to corfu-next/corfu-prev is a
corfu popup is already open.

Close: #7748
Co-authored-by: 45mg <45mg@users.noreply.github.com>
Co-authored-by: LemonBreezes <LemonBreezes@users.noreply.github.com>
This commit is contained in:
Henrik Lissner 2024-08-28 22:43:05 -04:00
parent 4a4a9a1ada
commit 08f8f57e2f
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 30 additions and 0 deletions

View file

@ -60,4 +60,32 @@
(message "Corfu auto-complete %s" (if corfu-auto "disabled" "enabled"))) (message "Corfu auto-complete %s" (if corfu-auto "disabled" "enabled")))
(setq corfu-auto (not corfu-auto))) (setq corfu-auto (not corfu-auto)))
;;;###autoload
(defun +corfu/dabbrev-or-next (&optional arg)
"Trigger corfu popup and select the first candidate.
Intended to mimic `evil-complete-next', unless the popup is already open."
(interactive "p")
(if corfu--candidates
(corfu-next arg)
(require 'cape)
(let ((cape-dabbrev-check-other-buffers (not evil-complete-all-buffers)))
(cape-dabbrev t)
(when (> corfu--total 0)
(corfu--goto (or arg 0))))))
;;;###autoload
(defun +corfu/dabbrev-or-last (&optional arg)
"Trigger corfu popup and select the first candidate.
Intended to mimic `evil-complete-previous', unless the popup is already open."
(interactive "p")
(if corfu--candidates
(corfu-previous arg)
(require 'cape)
(let ((cape-dabbrev-check-other-buffers (not evil-complete-all-buffers)))
(cape-dabbrev t)
(when (> corfu--total 0)
(corfu--goto (- corfu--total (or arg 1)))))))
;;; end of autoload.el ;;; end of autoload.el

View file

@ -192,6 +192,8 @@
(:after corfu (:after corfu
(:map corfu-mode-map (:map corfu-mode-map
:i "C-SPC" #'completion-at-point :i "C-SPC" #'completion-at-point
:i "C-n" #'+corfu/dabbrev-or-next
:i "C-p" #'+corfu/dabbrev-or-last
:n "C-SPC" (cmd! (call-interactively #'evil-insert-state) :n "C-SPC" (cmd! (call-interactively #'evil-insert-state)
(call-interactively #'completion-at-point)) (call-interactively #'completion-at-point))
:v "C-SPC" (cmd! (call-interactively #'evil-change) :v "C-SPC" (cmd! (call-interactively #'evil-change)