From 8b36fd2adfb7cc3ffc14fa73da4c4f989ec286d4 Mon Sep 17 00:00:00 2001 From: Janis Date: Thu, 9 Jan 2025 14:29:13 +0100 Subject: [PATCH] corfu config --- init.org | 109 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 46 deletions(-) diff --git a/init.org b/init.org index 1694955..a5d8160 100644 --- a/init.org +++ b/init.org @@ -1188,6 +1188,7 @@ Auto-completion using =corfu=: #+begin_src emacs-lisp (use-package corfu :straight t + :hook ((prog-mode text-mode) . completion-preview-mode) :custom ;; Enable auto completion (corfu-auto t) @@ -1202,6 +1203,16 @@ Auto-completion using =corfu=: ;; Preselect the first suggestion (corfu-preselect 'first) (corfu-on-exact-match nil) + :custom + (lsp-completion-provider :none) + :init + (defun nemo/orderless-dispatch-flex-first (_pattern index _total) + (and (eq index 0) 'orderless-flex)) + + (defun nemo/lsp-mode-setup-completion () + (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults)) '(orderless)) + (add-hook 'orderless-style-dispatchers #'nemo/orderless-dispatch-flex-first nil 'local)) + :hook (lsp-completion-mode . nemo/lsp-mode-setup-completion) :config (global-corfu-mode)) @@ -1214,26 +1225,28 @@ Auto-completion using =corfu=: (if (display-graphic-p) -1 +1)))) ) -(use-package emacs - ;; :custom - ;; TODO - :init - ;; TAB cycle if there are only few candidates - ;; (setq completion-cycle-threshold 3) +;; (use-package emacs +;; ;; :custom +;; ;; TODO +;; :init +;; ;; TAB cycle if there are only few candidates +;; ;; (setq completion-cycle-threshold 3) - (setq enable-recursive-minibuffers t) - ;; Hide commands in M-x which do not apply to the current mode. Corfu - ;; commands are hidden, since they are not supposed to be used via M-x. - (setq read-extended-command-predicate - #'command-completion-default-include-p) +;; (setq enable-recursive-minibuffers t) +;; ;; Hide commands in M-x which do not apply to the current mode. Corfu +;; ;; commands are hidden, since they are not supposed to be used via M-x. +;; (setq read-extended-command-predicate +;; #'command-completion-default-include-p) - (setq text-mode-ispell-word-completion nil) +;; (setq text-mode-ispell-word-completion nil) - ;; Enable indentation+completion using the TAB key. - ;; `completion-at-point' is often bound to M-TAB. - (setq tab-always-indent 'complete)) +;; ;; Enable indentation+completion using the TAB key. +;; ;; `completion-at-point' is often bound to M-TAB. +;; (setq tab-always-indent 'complete) +;; ) #+end_src +*** kind-icon Use =kind-icon= to decorate corfu completion candidates: #+begin_src emacs-lisp (use-package kind-icon @@ -1243,45 +1256,47 @@ Use =kind-icon= to decorate corfu completion candidates: (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter)) #+end_src -This package seems to slow down search quite a bit in common buffers like find-file and exectue-extended-comand: -#+begin_src emacs-lisp :tangle no +*** Cape +This package seems to slow down search quite a bit in common buffers like =find-file= and =exectue-extended-comand=: +#+begin_src emacs-lisp (use-package cape :straight t ;; Bind dedicated completion commands ;; Alternative prefix keys: C-c p, M-p, M-+, ... - :bind (("C-c p p" . completion-at-point) ;; capf - ("C-c p t" . complete-tag) ;; etags - ("C-c p d" . cape-dabbrev) ;; or dabbrev-completion - ("C-c p h" . cape-history) - ("C-c p f" . cape-file) - ("C-c p k" . cape-keyword) - ("C-c p s" . cape-symbol) - ("C-c p a" . cape-abbrev) - ("C-c p l" . cape-line) - ("C-c p w" . cape-dict) - ("C-c p \\" . cape-tex) - ("C-c p _" . cape-tex) - ("C-c p ^" . cape-tex) - ("C-c p &" . cape-sgml) - ("C-c p r" . cape-rfc1345)) + ;; :bind (("C-c p p" . completion-at-point) ;; capf + ;; ("C-c p t" . complete-tag) ;; etags + ;; ("C-c p d" . cape-dabbrev) ;; or dabbrev-completion + ;; ("C-c p h" . cape-history) + ;; ("C-c p f" . cape-file) + ;; ("C-c p k" . cape-keyword) + ;; ("C-c p s" . cape-symbol) + ;; ("C-c p a" . cape-abbrev) + ;; ("C-c p l" . cape-line) + ;; ("C-c p w" . cape-dict) + ;; ("C-c p \\" . cape-tex) + ;; ("C-c p _" . cape-tex) + ;; ("C-c p ^" . cape-tex) + ;; ("C-c p &" . cape-sgml) + ;; ("C-c p r" . cape-rfc1345)) :init ;; Add `completion-at-point-functions', used by `completion-at-point'. ;; NOTE: The order matters! - (add-to-list 'completion-at-point-functions #'cape-dabbrev) - (add-to-list 'completion-at-point-functions #'cape-file) - (add-to-list 'completion-at-point-functions #'cape-elisp-block) - (add-to-list 'completion-at-point-functions #'cape-history) - (add-to-list 'completion-at-point-functions #'cape-keyword) - (add-to-list 'completion-at-point-functions #'cape-tex) - (add-to-list 'completion-at-point-functions #'cape-dict) - ;;(add-to-list 'completion-at-point-functions #'cape-sgml) - ;;(add-to-list 'completion-at-point-functions #'cape-rfc1345) - ;;(add-to-list 'completion-at-point-functions #'cape-abbrev) - ;;(add-to-list 'completion-at-point-functions #'cape-symbol) - ;;(add-to-list 'completion-at-point-functions #'cape-line) + ;; (add-to-list 'completion-at-point-functions #'cape-dabbrev) + ;; (add-to-list 'completion-at-point-functions #'cape-file) + ;; (add-to-list 'completion-at-point-functions #'cape-elisp-block) + ;; (add-to-list 'completion-at-point-functions #'cape-history) + ;; (add-to-list 'completion-at-point-functions #'cape-keyword) + ;; (add-to-list 'completion-at-point-functions #'cape-tex) + ;; (add-to-list 'completion-at-point-functions #'cape-dict) + ;; (add-to-list 'completion-at-point-functions #'cape-sgml) + ;; (add-to-list 'completion-at-point-functions #'cape-rfc1345) + ;; (add-to-list 'completion-at-point-functions #'cape-abbrev) + ;; (add-to-list 'completion-at-point-functions #'cape-symbol) + ;; (add-to-list 'completion-at-point-functions #'cape-line) ) #+end_src +*** Embark Use =embark= for in-mini-buffer actions: #+begin_src emacs-lisp :tangle no (use-package embark @@ -1297,6 +1312,7 @@ Use =embark= for in-mini-buffer actions: :hook (embark-collect-mode . consult-preview-at-point-mode)) #+end_src +*** COMMENT corfu + prescient Use =corfu-prescient= to sort completion candidates: #+begin_src emacs-lisp (use-package corfu-prescient @@ -1306,7 +1322,7 @@ Use =corfu-prescient= to sort completion candidates: ;; :hook (corfu-mode . corfu-prescient-mode) ;; :hook (text-mode . corfu-prescient-mode) :config - (setq corfu-prescient-completion-styles '(prescient orderless basic partial-completion)) + (setq corfu-prescient-completion-styles '(orderless prescient basic partial-completion)) (corfu-prescient-mode 1) ) @@ -1335,7 +1351,8 @@ Fuzzy and out-of-order completion matching using =orderless=: (add-to-list 'completion-styles 'orderless) (setq orderless-matching-styles '(orderless-flex) completion-category-overrides '((file (styles basic partial-completion))) - orderless-component-separator "[ |]")) + orderless-component-separator "[ |]") + ) #+end_src * Programming