docs(corfu): simplify and show how to add capfs

This commit is contained in:
Luigi Sartor Piucco 2023-09-20 10:54:28 -03:00
parent 787d040ba6
commit bc00a49475
No known key found for this signature in database
GPG key ID: 6FF1A01853A47A66
2 changed files with 15 additions and 5 deletions

View file

@ -128,6 +128,19 @@ A few variables may be set to change behavior of this module:
- [[var:+corfu-icon-mapping]] ::
Configures icons used for each completion. See its documentation for details.
** Adding CAPFs to a mode
To add other CAPFs on a mode-per-mode basis, put either of the following in your
~config.el~:
#+begin_src emacs-lisp
(add-hook! some-mode (add-to-list 'completion-at-point-functions #'some-capf))
;; OR, but note the different call signature
(add-hook 'some-mode-hook (lambda () (add-to-list 'completion-at-point-functions #'some-capf)))
#+end_src
Also see ~add-hook!~'s documentation for additional ways to call it.
~add-hook~ only accepts the quoted arguments form above.
* Troubleshooting
[[doom-report:][Report an issue?]]

View file

@ -153,14 +153,11 @@ Meant as :around advice for `corfu--recompute'."
(map! :map 'corfu-map "s-<down>" #'corfu-move-to-minibuffer
(:when (modulep! :editor evil) "s-j" #'corfu-move-to-minibuffer))))
(defmacro +corfu--add-capf! (capf)
"Create sexp to add CAPF to the list of CAPFs."
`(add-to-list 'completion-at-point-functions ,capf))
(use-package! cape
:after corfu
:config
(add-hook! prog-mode (+corfu--add-capf! #'cape-file))
(add-hook! (org-mode markdown-mode) (+corfu--add-capf! #'cape-elisp-block))
(add-hook! prog-mode (add-to-list 'completion-at-point-functions #'cape-file))
(add-hook! (org-mode markdown-mode) (add-to-list 'completion-at-point-functions #'cape-elisp-block))
(advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible))
(use-package! yasnippet-capf