From 915b6e45183be28648ddff1dccda044014a302f9 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Fri, 15 Nov 2024 04:08:42 +0100 Subject: Improve README --- README.org | 72 +++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/README.org b/README.org index 038fb81..8cc82fd 100644 --- a/README.org +++ b/README.org @@ -221,24 +221,55 @@ want to cycle with TAB and some with the arrow keys. In case you like auto completion settings, where the completion popup appears immediately, better use a cheap completion style like =basic=, which performs -prefix filtering. In this case Corfu completion should still be fast in buffers -with efficient completion backends. You can try the following settings in an -Elisp buffer or the Emacs scratch buffer. Note that such settings can slow down -Emacs due to the high load on the Lisp runtime and garbage collector. +prefix filtering. See the next section about setting Corfu-only completion +styles. In this case Corfu completion should still be fast in buffers with +efficient completion backends. You can try the following settings in an Elisp +buffer or the Emacs scratch buffer. Note that such settings can slow down Emacs +due to the high load on the Lisp runtime and garbage collector. #+begin_src emacs-lisp -(setq-local corfu-auto t - corfu-auto-delay 0 ;; TOO SMALL - NOT RECOMMENDED - corfu-auto-prefix 1 ;; TOO SMALL - NOT RECOMMENDED - completion-styles '(basic)) +(setq corfu-auto t + corfu-auto-delay 0 ;; TOO SMALL - NOT RECOMMENDED! + corfu-auto-prefix 1) ;; TOO SMALL - NOT RECOMMENDED! + +(add-hook 'corfu-mode-hook + (lambda () + ;; Settings only for Corfu + (setq-local completion-styles '(basic) + completion-category-overrides nil + completion-category-defaults nil))) +#+end_src + +** 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: + +#+begin_src emacs-lisp +(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))) #+end_src 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. Note -that such a setup is advanced. Please refer to the Orderless documentation and -source code for further details. +enables efficient prefix filtering for input shorter than 4 characters. #+begin_src emacs-lisp (defun orderless-fast-dispatch (word index total) @@ -249,24 +280,13 @@ source code for further details. (orderless-style-dispatchers '(orderless-fast-dispatch)) (orderless-matching-styles '(orderless-literal orderless-regexp))) -(setq-local corfu-auto t - corfu-auto-delay 0 ;; TOO SMALL - NOT RECOMMENDED - corfu-auto-prefix 1 ;; TOO SMALL - NOT RECOMMENDED - completion-styles '(orderless-fast basic)) -#+end_src +(setq corfu-auto t + corfu-auto-delay 0 ;; TOO SMALL - NOT RECOMMENDED + corfu-auto-prefix 1) ;; TOO SMALL - NOT RECOMMENDED -** Buffer-local/Corfu-only completion settings - -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 Orderless completion, while for Corfu prefix -completion is sufficient. Such a configuration is possible by setting the -~completion-styles~ variables buffer-locally, as follows: - -#+begin_src emacs-lisp (add-hook 'corfu-mode-hook (lambda () - (setq-local completion-styles '(basic) + (setq-local completion-styles '(orderless-fast basic) completion-category-overrides nil completion-category-defaults nil))) #+end_src -- cgit v1.0