blob: 6960abb67d8455a464d8e85d35e043270c685c02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#+title: cape.el - Let your completions fly!
#+author: Daniel Mendler
#+language: en
#+export_file_name: cape.texi
#+texinfo_dir_category: Emacs
#+texinfo_dir_title: Cape: (cape).
#+texinfo_dir_desc: Completion At Point Extensions
#+html: <a href="https://melpa.org/#/cape"><img alt="MELPA" src="https://melpa.org/packages/cape-badge.svg"/></a>
#+html: <a href="https://stable.melpa.org/#/cape"><img alt="MELPA Stable" src="https://stable.melpa.org/packages/cape-badge.svg"/></a>
#+html: <img src="https://upload.wikimedia.org/wikipedia/en/3/35/Supermanflying.png" align="right">
* Introduction
Cape provides a bunch of Completion At Point Extensions which can be used in
combination with my [[https://github.com/minad/corfu][Corfu]] completion UI or the default completion UI. The
completion backends used by ~completion-at-point~ are so called
~completion-at-point-functions~ (Capfs).
You can register the ~cape-*-capf~ functions in the ~completion-at-point-functions~
list. This makes the backends available for completion, which is usually invoked
by pressing ~TAB~ or ~M-TAB~. Furthermore there are a handful of dedicated
completion commands ~cape-*~, which you can bind directly to a key in your user
configuration.
On the more experimental side, Cape has the super power to transform Company
backends into Capfs and merge multiple Capfs into a Super-Capf!
* Configuration
Cape is available from MELPA. In the long term some of the Capfs provided by
this package should be upstreamed into Emacs itself.
#+begin_src emacs-lisp
;; Enable Corfu completion UI
;; See the Corfu README for more configuration tips.
(use-package corfu
:init
(corfu-global-mode))
;; Add extensions
(use-package cape
;; Bind dedicated completion commands
:bind (("C-c p p" . completion-at-point) ;; capf
("C-c p d" . dabbrev-completion) ;; dabbrev
("C-c p t" . complete-tag) ;; etags
("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 i" . cape-ispell)
("C-c p w" . cape-dict))
:init
;; Add `completion-at-point-functions', used by `completion-at-point'.
(add-to-list 'completion-at-point-functions #'cape-file-capf)
(add-to-list 'completion-at-point-functions #'cape-dabbrev-capf)
(add-to-list 'completion-at-point-functions #'cape-keyword-capf)
;;(add-to-list 'completion-at-point-functions #'cape-abbrev-capf)
;;(add-to-list 'completion-at-point-functions #'cape-ispell-capf)
;;(add-to-list 'completion-at-point-functions #'cape-dict-capf)
)
#+end_src
* Experimental features
** Company adapter
/Wrap your Company backend in a Cape and turn it into a Capf!/
Cape provides an adapter for Company backends ~cape-company-to-capf~. The adapter
transforms Company backends to Capfs which are understood by the built-in Emacs
completion mechanism. The adapter is still experimental and may have certain
edge cases. In particular, asynchronous completions are forcibly synchronized,
but we are investigating possible Capf extensions to support asynchronous Capfs.
The adapter can be used as follows:
#+begin_src emacs-lisp
;; Use Company backends as Capfs.
(setq-local completion-at-point-functions
(mapcar #'cape-company-to-capf
(list #'company-files #'company-ispell #'company-dabbrev)))
#+end_src
** Merging multiple Capfs
/Throw multiple Capfs under the Cape and get a Super-Capf!/
Cape supports merging multiple Capfs using the function ~cape-merge-capfs~. This
feature is experimental and works only for well-behaved Capfs and static
completion tables. But it is a start to emulate the corresponding Company
feature. Maybe it is possible to extend the capabilities of the completion table
merging in the future.
#+begin_src emacs-lisp
;; Merge the dabbrev, dict and keyword capfs, display candidates together.
(setq-local completion-at-point-functions
(list (cape-merge-capfs #'cape-dabbrev-capf #'cape-dict-capf #'cape-keyword-capf)))
#+end_src
|