Skip to content

Commit 2d86379

Browse files
[docs] Update user manual about completion
1 parent dbc1a6f commit 2d86379

File tree

1 file changed

+41
-45
lines changed

1 file changed

+41
-45
lines changed

doc/modules/ROOT/pages/usage/code_completion.adoc

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,6 @@ Normally kbd:[TAB] only indents, but now it will also do completion if the code
3535
is already properly indented.
3636
====
3737

38-
== Completion styles
39-
40-
CIDER defines a specialized completion category through the `cider-complete-at-point` function,
41-
added to `completion-at-point-functions`, establishing a dedicated completion category named
42-
`cider`.
43-
44-
The CIDER completion at point function supports most completion styles,
45-
including `partial-completion`, `orderless` and `flex`. It also supports a
46-
custom completion style that is confusingly named `cider` too. Activating it
47-
provides a richer set of completion candidates (see
48-
xref:usage/code_completion.adoc#fuzzy-candidate-matching[fuzzy candidate
49-
matching]).
50-
51-
Sometimes the user may want to use a different completion style just for the CIDER
52-
complete at point function. That can be achieved by setting
53-
`completion-category-overrides`, overwriting the completion style of the CIDER
54-
complete at point function. The following snippet accomplishes that:
55-
56-
[source,lisp]
57-
----
58-
(add-to-list 'completion-category-overrides '(cider (styles basic)))
59-
----
60-
61-
This specifies that the `cider` completion category should employ the basic completion style by
62-
default.
63-
6438
== Auto-completion
6539

6640
While the standard Emacs tooling works just fine, we suggest that
@@ -139,31 +113,30 @@ without needing to hit an extra key, please customize:
139113
(custom-set-variables '(company-auto-update-doc t))
140114
----
141115

142-
=== Fuzzy candidate matching
116+
=== Rich candidate matching
117+
118+
Starting with version 1.18, CIDER by default enables a custom completion style
119+
that provides richer and more useful candidate matching, for example:
143120

144-
By default, CIDER will use the completion styles defined in
145-
`completion-styles`, the defaults being `(basic partial-completion
146-
emacs22)` since Emacs 23. For a better description of how those
147-
completion styles operates, refer to the official Emacs manual on
148-
https://www.gnu.org/software/emacs/manual/html_node/emacs/Completion-Styles.html[how completion alternatives are chosen].
121+
- Long vars that contain dashes by first characters of individual parts, e.g.
122+
`mi` or `mai` complete to `map-indexed`.
123+
- Namespaces by first characters of parts, e.g. `cji` completes to
124+
`clojure.java.io`.
125+
- Not imported classnames by their short name prefixes, e.g. `BiFun` completes
126+
to `java.util.function.BiFunction`.
127+
128+
You can learn all completion scenarios and features
129+
https://github.com/alexander-yakushev/compliment/wiki/Examples[here].
149130

150-
CIDER provides a function to enable the `cider` completion style for CIDER-specific
151-
completions. If you wish to enable that, you can add this to your config:
131+
If you only want to receive standard prefix-restricted completions (where the
132+
candidate must contain the prefix at the beginning verbatim), you can disable
133+
this feature by adding this to your config:
152134

153135
[source,lisp]
154136
----
155-
(cider-enable-cider-completion-style)
137+
(cider-enable-cider-completion-style -1)
156138
----
157139

158-
This adds the `cider` completion style for CIDER buffers.
159-
160-
Now, `company-mode` (and other completion packages like `corfu`) will
161-
accept certain fuzziness when matching candidates against the
162-
prefix. For example, typing `mi` will show you `map-indexed` as one of
163-
the possible completion candidates and `cji` will complete to
164-
`clojure.java.io`. Different completion examples are shown
165-
https://github.com/alexander-yakushev/compliment/wiki/Examples[here].
166-
167140
=== Completion annotations
168141

169142
Completion candidates will be annotated by default with an abbreviation
@@ -178,6 +151,29 @@ image::completion-annotations.png[Completion Annotations]
178151
TIP: Completion annotations can be disabled by setting
179152
`cider-annotate-completion-candidates` to `nil`.
180153

154+
=== Completion styles
155+
156+
The CIDER completion at point function supports most completion styles,
157+
including `partial-completion`, `orderless`, `flex`, and its own custom
158+
completion style named `cider`. The latter is enabled by default. Sometimes the
159+
user may want to use a different completion style for the CIDER complete at
160+
point function. That can be achieved by setting `completion-category-overrides`,
161+
overwriting the completion style of the CIDER complete at point function. The
162+
following snippet accomplishes that:
163+
164+
[source,lisp]
165+
----
166+
(add-to-list 'completion-category-overrides '(cider (styles basic)))
167+
----
168+
169+
For a better description of how those completion styles operates, refer to the
170+
official Emacs manual on
171+
https://www.gnu.org/software/emacs/manual/html_node/emacs/Completion-Styles.html[how
172+
completion alternatives are chosen].
173+
174+
This specifies that the `cider` completion category should employ the basic completion style by
175+
default.
176+
181177
=== Notes on class disambiguation
182178

183179
Sometimes, the completion user experience may be interrupted by a `completing-read`
@@ -212,6 +208,6 @@ NOTE: You don't really need to know any of this if you're using only `cider-jack
212208

213209
The bulk of the code completion logic resides in `cider-nrepl` https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/complete.clj[completion middleware]. Internally it delegates to `compliment` for the Clojure completion and `clj-suitable` for the ClojureScript completion.
214210

215-
Starting with nREPL 0.8, there's also a built-in `completions` nREPL op that CIDER will fallback to, in the absence of `cider-nrepl`. Its API is similar to that of the `complete` op in `cider-nrepl` and it can be configured to use different completion functions. The built-in op currently supports only Clojure. See the https://nrepl.org/nrepl/usage/misc.html#code-completion[nREPL docs] for more details.
211+
nREPL also has a built-in `completions` op that CIDER will fallback to, in the absence of `cider-nrepl`. Its API is similar to that of the `complete` op in `cider-nrepl` and it can be configured to use different completion functions. The built-in op currently supports only Clojure. See the https://nrepl.org/nrepl/usage/misc.html#code-completion[nREPL docs] for more details.
216212

217213
Basically, you'll get great code completion in the presence of `cider-nrepl` and basic completion otherwise.

0 commit comments

Comments
 (0)