diff --git a/modules/completion/corfu/README.org b/modules/completion/corfu/README.org index e9354f8a2..39633da9f 100644 --- a/modules/completion/corfu/README.org +++ b/modules/completion/corfu/README.org @@ -103,6 +103,29 @@ following additional binds: | [[kbd:][S-TAB]] | (when completing) Go to previous candidate | | [[kbd:][DEL]] | (when completing) Reset completion DWIM-style | +*** Completion in the minibuffer +In the minibuffer, sometimes autocompletion can interfere with your goal; +Imagine you're composing a search pattern incrementally, and you find what you +want early, with only half the word. You then press [[kbd:RET]]. If completion +kicked in as you typed, you may lose the match, since it will complete the +first candidate. On the other hand, if you were paying attention to the +suggestions and selecting one appropriate, that's desired behavior, and you may +even desire to modify the prompt further (if you were composing a command +instead, you may want to extend it after the candidate). To allow better +control, there are 3 confirm bindings when Corfu appears in the minibuffer: + +| Keybind | Description | +|-----------+--------------------------------------------------------------------| +| [[kbd:RET]] | Accept the candidate only | +| [[kbd:C-RET]] | Confirm the current prompt only | +| [[kbd:S-RET]] | Accept the candidate then immediately confirm the completed prompt | + +- Use [[kbd:RET]] when you want to continue composing after completing; +- Use [[kbd:C-RET]] when you already have the desired string, and completing would + break it; +- Use [[kbd:S-RET]] when you know the composition will be finished after completion + (thus avoiding the need to type [[kbd:RET]] twice); + ** Searching with multiple keywords If the [[doom-module::completion corfu +orderless]] flag is enabled, users can perform code completion with multiple search keywords by use of space as the diff --git a/modules/completion/corfu/autoload.el b/modules/completion/corfu/autoload.el index 618aae42d..841802596 100644 --- a/modules/completion/corfu/autoload.el +++ b/modules/completion/corfu/autoload.el @@ -1,5 +1,13 @@ ;;; 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. diff --git a/modules/config/default/config.el b/modules/config/default/config.el index b8b8f2c91..1108190f9 100644 --- a/modules/config/default/config.el +++ b/modules/config/default/config.el @@ -480,8 +480,12 @@ Continues comments if executed from a commented line. Consults "C-S-p" #'corfu-popupinfo-scroll-down "C-S-n" #'corfu-popupinfo-scroll-up "C-S-u" (cmd! (funcall-interactively #'corfu-popupinfo-scroll-down corfu-popupinfo-min-height)) - "C-S-d" (cmd! (funcall-interactively #'corfu-popupinfo-scroll-up corfu-popupinfo-min-height)))) - + "C-S-d" (cmd! (funcall-interactively #'corfu-popupinfo-scroll-up corfu-popupinfo-min-height))) + (:map corfu-map + "C-" '(menu-item "Conclude the minibuffer" exit-minibuffer + :enable (minibufferp nil t)) + "S-" '(menu-item "Insert completion and conclude" +corfu-complete-and-exit-minibuffer + :enable (minibufferp nil t)))) (when-let ((cmds-del (and (modulep! :completion corfu +tng) '(menu-item "Reset completion" corfu-reset :enable (and (> corfu--index -1)