Buffer-local/Corfu-only completion styles
Sometimes it makes sense to use separate completion style settings for minibuffer completion and in-buffer Corfu completion. For example inside the minibuffer you may prefer advanced Orderless completion, while for Corfu, faster prefix completion is needed or literal-only completion is sufficient.
This matters in particular if you use aggressive auto completion settings, where the completion popup appears immediately. Then a cheap completion style like ‘basic’ should be used, which performs prefix filtering only.
Such Corfu-only configurations are possible by setting the completion-styles variables buffer-locally, as follows:
(orderless-define-completion-style orderless-literal-only
(orderless-style-dispatchers nil)
(orderless-matching-styles '(orderless-literal)))
(add-hook 'corfu-mode-hook
(lambda ()
(setq-local completion-styles '(orderless-literal-only basic)
completion-category-overrides nil
completion-category-defaults nil)))If you want to combine fast prefix filtering and Orderless filtering you can still do that by defining a custom Orderless completion style via ‘orderless-define-completion-style’. We use a custom style dispatcher, which enables efficient prefix filtering for input shorter than 4 characters.
(defun orderless-fast-dispatch (word index total)
(and (= index 0) (= total 1) (length< word 4)
(cons 'orderless-literal-prefix word)))
(orderless-define-completion-style orderless-fast
(orderless-style-dispatchers '(orderless-fast-dispatch))
(orderless-matching-styles '(orderless-literal orderless-regexp)))
(setq corfu-auto t
corfu-auto-delay 0 ;; TOO SMALL - NOT RECOMMENDED
corfu-auto-prefix 0) ;; TOO SMALL - NOT RECOMMENDED
(add-hook 'corfu-mode-hook
(lambda ()
(setq-local completion-styles '(orderless-fast basic)
completion-category-overrides nil
completion-category-defaults nil)))