From 1603c6c7dd43a80f70448c31017a38cd141af015 Mon Sep 17 00:00:00 2001 From: Luigi Sartor Piucco Date: Sun, 4 Feb 2024 17:17:13 -0300 Subject: [PATCH] feat(corfu): general move-to-minibuffer impl We relied directly on consult for this, meaning it needed the vertico module. Now, it should defer to the user's choice, including helm, ivy and ido. Note the convention for this indirection is using the `completing-read` API, which all such packages implement. This diverges from Corfu's suggestion of `completion-in-region`, which only vertico and ivy seem to implement. --- modules/completion/corfu/README.org | 11 +++++------ modules/completion/corfu/autoload.el | 11 ++++++----- modules/completion/corfu/config.el | 2 ++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/completion/corfu/README.org b/modules/completion/corfu/README.org index 39633da9f..642d83cb2 100644 --- a/modules/completion/corfu/README.org +++ b/modules/completion/corfu/README.org @@ -144,12 +144,11 @@ regarding your state. In normal-like states, enter insert then start corfu; in visual-like states, perform [[help:evil-change][evil-change]] (which leaves you in insert state) then start corfu; in insert-like states, start corfu immediatelly. -** Exporting to the minibuffer (requires [[doom-module::completion vertico]]) -When using the [[doom-module::completion vertico]] module, which pulls in the -[[doom-package:consult]] package, the entries shown in the completion popup can be -exported to a consult minibuffer, giving access to all the manipulations the -Vertico suite allows. For instance, one could use this to export with -[[doom-package:embark]] via [[kbd:][C-c C-l]] and get a buffer with all candidates. +** Exporting to the minibuffer +The entries shown in the completion popup can be exported to a ~completing-read~ +minibuffer, giving access to all the manipulations that suite allows. Using +Vertico for instance, one could use this to export with [[doom-package:embark]] via +[[kbd:][C-c C-l]] and get a buffer with all candidates. ** Manually call generic CAPFs Completion at point functions have the property that, when called interactively diff --git a/modules/completion/corfu/autoload.el b/modules/completion/corfu/autoload.el index 841802596..94b9fe6da 100644 --- a/modules/completion/corfu/autoload.el +++ b/modules/completion/corfu/autoload.el @@ -10,12 +10,13 @@ ;;;###autoload (defun +corfu-move-to-minibuffer () - ;; Taken from corfu's README. - ;; TODO: extend this to other completion front-ends. + ;; Adapted from Corfu's README. (interactive) - (let ((completion-extra-properties corfu--extra) - (completion-cycle-threshold completion-cycling)) - (apply #'consult-completion-in-region completion-in-region--data))) + (pcase completion-in-region--data + (`(,_ ,_ ,table ,pred ,extras) + (let ((completion-extra-properties extras) + completion-cycle-threshold completion-cycling) + (completing-read "Completion: " table pred nil nil 'corfu-history))))) ;;;###autoload (defun +corfu-smart-sep-toggle-escape () diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index e9ecbf69c..48448b2fa 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -33,6 +33,8 @@ tab-always-indent (if (modulep! +tng) 'complete tab-always-indent)) (add-to-list 'completion-category-overrides `(lsp-capf (styles ,@completion-styles))) + (add-to-list 'corfu-continue-commands #'+corfu-move-to-minibuffer) + (add-hook! 'minibuffer-setup-hook (defun +corfu-enable-in-minibuffer () "Enable Corfu in the minibuffer if `completion-at-point' is bound."