Skip to content

Commit 46017aa

Browse files
[completion] Fix custom completion style and make it default for fuzzy matching
1 parent a38a92c commit 46017aa

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

cider-completion.el

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ in the buffer."
256256

257257
;; Fuzzy completion for company-mode
258258

259+
(defun cider-completion-try-completion (string table pred point)
260+
(try-completion string table pred))
261+
259262
(defun cider-company-unfiltered-candidates (string &rest _)
260263
"Return CIDER completion candidates for STRING as is, unfiltered."
261264
(cider-complete string))
@@ -268,17 +271,40 @@ in the buffer."
268271
;; which introduced `cider-company-enable-fuzzy-completion')
269272
(add-to-list 'completion-styles-alist
270273
'(cider
271-
cider-company-unfiltered-candidates
274+
cider-completion-try-completion
272275
cider-company-unfiltered-candidates
273276
"CIDER backend-driven completion style."))
274277

275278
(defun cider-company-enable-fuzzy-completion ()
276-
"Enable backend-driven fuzzy completion in the current buffer.
279+
"Enables `cider' completion style for CIDER in all buffers.
277280
278-
DEPRECATED: please use `cider-enable-flex-completion' instead."
279-
(setq-local completion-styles '(cider)))
281+
DEPRECATED: please use `cider-enable-cider-completion-style' instead."
282+
(interactive)
283+
(cider-enable-cider-completion-style))
280284

281-
(make-obsolete 'cider-company-enable-fuzzy-completion 'cider-enable-flex-completion "1.8.0")
285+
(defun cider-enable-cider-completion-style ()
286+
"Enables `cider' completion style for CIDER in all buffers.
287+
288+
This style supports non-prefix completion candidates returned by the
289+
completion backend. Only affects the `cider' completion category."
290+
(interactive)
291+
(let* ((cider (assq 'cider completion-category-overrides))
292+
(found-styles (assq 'styles cider))
293+
(new-styles (if found-styles
294+
(cons 'styles (cons 'cider (cdr found-styles)))
295+
'(styles cider basic)))
296+
(new-cider (if cider
297+
(cons 'cider
298+
(cons new-styles
299+
(seq-remove (lambda (x) (equal 'styles (car x)))
300+
(cdr cider))))
301+
(list 'cider new-styles)))
302+
(new-overrides (cons new-cider
303+
(seq-remove (lambda (x) (equal 'cider (car x)))
304+
completion-category-overrides))))
305+
(setq completion-category-overrides new-overrides)))
306+
307+
(make-obsolete 'cider-company-enable-fuzzy-completion 'cider-enable-cider-completion-style "1.17.0")
282308

283309
(defun cider-enable-flex-completion ()
284310
"Enables `flex' (fuzzy) completion for CIDER in all buffers.

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ CIDER defines a specialized completion category through the `cider-complete-at-p
4141
added to `completion-at-point-functions`, establishing a dedicated completion category named
4242
`cider`.
4343

44-
The CIDER completion at point function supports most completion styles, including
45-
`partial-completion`, `orderless` and `flex` (read more below).
46-
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]).
4750

4851
Sometimes the user may want to use a different completion style just for the CIDER
4952
complete at point function. That can be achieved by setting
@@ -58,8 +61,6 @@ complete at point function. The following snippet accomplishes that:
5861
This specifies that the `cider` completion category should employ the basic completion style by
5962
default.
6063

61-
You can also enable the `flex` completion style by activating xref:usage/code_completion.adoc#fuzzy-candidate-matching[fuzzy candidate matching].
62-
6364
== Auto-completion
6465

6566
While the standard Emacs tooling works just fine, we suggest that
@@ -146,15 +147,15 @@ emacs22)` since Emacs 23. For a better description of how those
146147
completion styles operates, refer to the official Emacs manual on
147148
https://www.gnu.org/software/emacs/manual/html_node/emacs/Completion-Styles.html[how completion alternatives are chosen].
148149

149-
CIDER provides a function to enable the `flex` completion style for CIDER-specific
150+
CIDER provides a function to enable the `cider` completion style for CIDER-specific
150151
completions. If you wish to enable that, you can add this to your config:
151152

152153
[source,lisp]
153154
----
154-
(cider-enable-flex-completion)
155+
(cider-enable-cider-completion-style)
155156
----
156157

157-
This adds the `flex` completion style, as introduced in Emacs 27.
158+
This adds the `cider` completion style for CIDER buffers.
158159

159160
Now, `company-mode` (and other completion packages like `corfu`) will
160161
accept certain fuzziness when matching candidates against the
@@ -163,8 +164,6 @@ the possible completion candidates and `cji` will complete to
163164
`clojure.java.io`. Different completion examples are shown
164165
https://github.com/alexander-yakushev/compliment/wiki/Examples[here].
165166

166-
NOTE: `cider-company-enable-fuzzy-completion` (now deprecated) should be used for Emacs < 27.
167-
168167
=== Completion annotations
169168

170169
Completion candidates will be annotated by default with an abbreviation

0 commit comments

Comments
 (0)