doomemacs/modules/completion/corfu/autoload.el
Luigi Sartor Piucco a5db530622
feat(corfu): impl smart confirm in minibuffer
An issue when using corfu in the minibuffer was the need for pressing
RET twice, since the first only inserts the completion. This commit
aliviates that by providing C-RET to ignore completion and conclude the
minibuffer imediately and S-RET to insert completion then conclude.
2024-03-01 12:33:10 -03:00

33 lines
1.2 KiB
EmacsLisp

;;; completion/corfu/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +corfu-complete-and-exit-minibuffer ()
(interactive)
(if (>= corfu--index 0)
(corfu-complete)
(corfu-insert))
(exit-minibuffer))
;;;###autoload
(defun +corfu-move-to-minibuffer ()
;; Taken from corfu's README.
;; TODO: extend this to other completion front-ends.
(interactive)
(let ((completion-extra-properties corfu--extra)
(completion-cycle-threshold completion-cycling))
(apply #'consult-completion-in-region completion-in-region--data)))
;;;###autoload
(defun +corfu-smart-sep-toggle-escape ()
"Insert `corfu-separator' or toggle escape if it's already there."
(interactive)
(cond ((and (char-equal (char-before) corfu-separator)
(char-equal (char-before (1- (point))) ?\\))
(save-excursion (delete-char -2)))
((char-equal (char-before) corfu-separator)
(save-excursion (backward-char 1)
(insert-char ?\\)))
(t
;; Without this corfu quits immediately.
(setq this-command #'corfu-insert-separator)
(call-interactively #'corfu-insert-separator))))