Switch to corfu over company

This commit is contained in:
Kiana Sheibani 2024-06-13 14:30:06 -04:00
parent 97df2a30a6
commit 38af445c33
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -810,7 +810,7 @@ I'm a big fan of the Vertico ecosystem, as it's lightweight and easy to use. Let
#+begin_src emacs-lisp #+begin_src emacs-lisp
:completion :completion
(vertico +icons) (vertico +icons)
(company +childframe) (corfu +icons +orderless)
#+end_src #+end_src
** Checkers ** Checkers
@ -1441,81 +1441,16 @@ Our ~package!~ declarations go in ~packages.el~, which must not be byte-compiled
Everything else goes in ~config.el~, which is managed by [[*=confpkg=][confpkg]] as outlined earlier. Everything else goes in ~config.el~, which is managed by [[*=confpkg=][confpkg]] as outlined earlier.
** Company ** Corfu
#+call: confpkg("Pkg: company") #+call: confpkg("Pkg: corfu")
*** Bindings
When Company is active, its keybindings overshadow the default ones, meaning keys like =RET= no longer work. To prevent this from happening, let's rebind ~company-complete-selection~ to =TAB= (less useful in the middle of typing), and only allow =RET= to be used if Company has been explicitly interacted with.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(let ((item (after! corfu
`(menu-item nil company-complete-selection ;; I don't really use TAB very often, so prefer other actions
:filter ,(lambda (cmd) (setq +corfu-want-tab-prefer-navigating-snippets t
(when (company-explicit-action-p) +corfu-want-tab-prefer-expand-snippets t
cmd))))) +corfu-want-tab-prefer-navigating-org-tables t))
(map! :after company
:map company-active-map
"RET" item
"<return>" item
"TAB" #'company-complete-selection
"<tab>" #'company-complete-selection
"S-TAB" #'company-complete-common))
#+end_src
*** Spell Correction
#+call: confpkg("Pkg: company-spell")
I've been having problems with ~company-ispell~, mainly due to Ispell requiring a text-based dictionary (unlike Aspell, which uses a binary dictionary). So let's switch to ~company-spell~:
#+begin_src emacs-lisp :tangle packages.el
(package! company-spell)
#+end_src
#+begin_src emacs-lisp
(after! company-spell
(map! :map evil-insert-state-map
"C-x s" #'company-spell))
#+end_src
We should make sure that ~company-spell~ uses Ispell's personal dictionary too:
#+begin_src emacs-lisp
(after! (company-spell ispell)
(setq company-spell-args
(concat company-spell-args " -p " ispell-personal-dictionary)))
#+end_src
*** Icons
The ~company-box~ front-end adds support for icons, but there aren't many providers for them, especially in text. We'll add two new icon providers:
- ~~/company-box-icons--text~, which directly targets the output of ~company-spell~
- ~~/company-box-icons--spell~, which is a fallback for all text completions
#+begin_src emacs-lisp
;; Mark candidates from `company-spell' using a text property
(defadvice! ~/company-spell-text-property (words)
:filter-return #'company-spell-lookup-words
(dolist (word words)
(put-text-property 0 1 'spell-completion-item t word))
words)
(defun ~/company-box-icons--spell (candidate)
(when (get-text-property 0 'spell-completion-item candidate)
'Text))
(defun ~/company-box-icons--text (candidate)
(when (derived-mode-p 'text-mode) 'Text))
(after! company-box
(pushnew! company-box-icons-functions #'~/company-box-icons--text)
;; `~/company-box-icons--text' is a fallback, so it has to go at the end of
;; the list
(setq company-box-icons-functions
(append company-box-icons-functions '(~/company-box-icons--text))))
#+end_src #+end_src
** Eldoc ** Eldoc