Skip to content

Commit ed80b77

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

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

CHANGELOG.md

+4
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

+36-5
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ 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+
also pass PRED and POINT to `try-completion'.
262+
263+
This function is only needed to be a correct citizen in
264+
`completion-styles-alist'."
265+
(try-completion string table pred))
266+
259267
(defun cider-company-unfiltered-candidates (string &rest _)
260268
"Return CIDER completion candidates for STRING as is, unfiltered."
261269
(cider-complete string))
@@ -268,17 +276,40 @@ in the buffer."
268276
;; which introduced `cider-company-enable-fuzzy-completion')
269277
(add-to-list 'completion-styles-alist
270278
'(cider
271-
cider-company-unfiltered-candidates
279+
cider-completion-try-completion
272280
cider-company-unfiltered-candidates
273281
"CIDER backend-driven completion style."))
274282

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

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

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

+9-10
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)