Skip to content

Commit 3d4908b

Browse files
[completion] Fix custom completion style and make it default for fuzzy matching
1 parent be4b4ac commit 3d4908b

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### Changes
6+
7+
- [#3746](https://github.com/clojure-emacs/cider/issues/3746): Bring back `cider` completion style for activating backend-driven completion.
8+
59
### Bugs fixed
610

711
- [#3742](https://github.com/clojure-emacs/cider/issues/3742): Restore syntax highlighting in result minibuffer.

cider-completion.el

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

257257
;; Fuzzy completion for company-mode
258258

259+
(defun cider-completion-try-completion (string collection pred point)
260+
"Return longest common substring of all completions of STRING in COLLECTION.
261+
262+
This function is only needed to be a correct citizen in
263+
`completion-styles-alist'."
264+
(try-completion string table pred))
265+
259266
(defun cider-company-unfiltered-candidates (string &rest _)
260267
"Return CIDER completion candidates for STRING as is, unfiltered."
261268
(cider-complete string))
@@ -268,17 +275,40 @@ in the buffer."
268275
;; which introduced `cider-company-enable-fuzzy-completion')
269276
(add-to-list 'completion-styles-alist
270277
'(cider
271-
cider-company-unfiltered-candidates
278+
cider-completion-try-completion
272279
cider-company-unfiltered-candidates
273280
"CIDER backend-driven completion style."))
274281

275282
(defun cider-company-enable-fuzzy-completion ()
276-
"Enable backend-driven fuzzy completion in the current buffer.
283+
"Enables `cider' completion style for CIDER in all buffers.
277284
278-
DEPRECATED: please use `cider-enable-flex-completion' instead."
279-
(setq-local completion-styles '(cider)))
285+
DEPRECATED: please use `cider-enable-cider-completion-style' instead."
286+
(interactive)
287+
(cider-enable-cider-completion-style))
288+
289+
(defun cider-enable-cider-completion-style ()
290+
"Enables `cider' completion style for CIDER in all buffers.
280291
281-
(make-obsolete 'cider-company-enable-fuzzy-completion 'cider-enable-flex-completion "1.8.0")
292+
This style supports non-prefix completion candidates returned by the
293+
completion backend. Only affects the `cider' completion category."
294+
(interactive)
295+
(let* ((cider (assq 'cider completion-category-overrides))
296+
(found-styles (assq 'styles cider))
297+
(new-styles (if found-styles
298+
(cons 'styles (cons 'cider (cdr found-styles)))
299+
'(styles cider basic)))
300+
(new-cider (if cider
301+
(cons 'cider
302+
(cons new-styles
303+
(seq-remove (lambda (x) (equal 'styles (car x)))
304+
(cdr cider))))
305+
(list 'cider new-styles)))
306+
(new-overrides (cons new-cider
307+
(seq-remove (lambda (x) (equal 'cider (car x)))
308+
completion-category-overrides))))
309+
(setq completion-category-overrides new-overrides)))
310+
311+
(make-obsolete 'cider-company-enable-fuzzy-completion 'cider-enable-cider-completion-style "1.17.0")
282312

283313
(defun cider-enable-flex-completion ()
284314
"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)