Skip to content

Commit 20015a1

Browse files
committed
Make inf-clojure-completions a defcustom
The motivation behind this change is that now the user can provide a custom parsing function and therefore has complete freedom in what to use for completion. I foresee a module that sets compliment completion for instance, or even use directly what cider provides.
1 parent ae43e2e commit 20015a1

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

inf-clojure.el

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ prefix argument PROMPT-FOR-NS, it prompts for a namespace name."
12101210

12111211
(defun inf-clojure-set-ns (prompt-for-ns)
12121212
"Set the ns of the inferior Clojure process to NS.
1213-
See variable `inf-clojure-set-ns-form`. It defaults to the ns of
1213+
See variable `inf-clojure-set-ns-form'. It defaults to the ns of
12141214
the current buffer. When invoked with a prefix argument
12151215
PROMPT-FOR-NS, it prompts for a namespace name."
12161216
(interactive "P")
@@ -1254,15 +1254,43 @@ See variable `inf-clojure-buffer'."
12541254
"Return DATA if and only if it is a list."
12551255
(when (listp data) data))
12561256

1257-
(defun inf-clojure-completions (expr)
1258-
"Return a list of completions for the Clojure expression starting with EXPR."
1257+
(defun inf-clojure-list-completions (expr)
1258+
"Return completions for the Clojure expression starting with EXPR.
1259+
1260+
Its only ability is to parse a list of candidate strings, every
1261+
other EXPR will be discarded and nil will be returned."
12591262
(when (not (string-blank-p expr))
12601263
(thread-first
12611264
(format (inf-clojure-completion-form) (substring-no-properties expr))
12621265
(inf-clojure--process-response (inf-clojure-proc) "(" ")")
12631266
(inf-clojure--read-or-nil)
12641267
(inf-clojure--list-or-nil))))
12651268

1269+
(defcustom inf-clojure-completions 'inf-clojure-list-completions
1270+
"The function that parses completion results.
1271+
1272+
It is a single-arity function that will receive the REPL
1273+
evaluation result of \\[inf-clojure-completion-form] as string and
1274+
should return elisp data compatible with your completion mode.
1275+
1276+
The easiest possible data passed in input is a list of
1277+
candidates (e.g.: (\"def\" \"defn\")) but more complex libraries
1278+
like `alexander-yakushev/compliment' can return other things like
1279+
edn.
1280+
1281+
The expected return depends on the mode that you use for
1282+
completion: `company-mode' for instance allows metadata along
1283+
with the candidates completion. See \\[completion-table-dynamic]
1284+
for more details.
1285+
1286+
The default value is the `inf-clojure-list-completions' function,
1287+
which is able to parse results in list form only. You can peek
1288+
at its implementation for getting to know some utility functions
1289+
you might want to use in your customization."
1290+
:type 'function
1291+
:safe #'functionp
1292+
:package-version '(inf-clojure . "2.1.0"))
1293+
12661294
(defconst inf-clojure-clojure-expr-break-chars " \t\n\"\'`><,;|&{()[]")
12671295

12681296
(defun inf-clojure-completion-bounds-of-expr-at-point ()
@@ -1288,8 +1316,8 @@ Returns the selected completion or nil."
12881316
(when bounds
12891317
(list (car bounds) (cdr bounds)
12901318
(if (fboundp 'completion-table-with-cache)
1291-
(completion-table-with-cache #'inf-clojure-completions)
1292-
(completion-table-dynamic #'inf-clojure-completions))))))
1319+
(completion-table-with-cache inf-clojure-completions)
1320+
(completion-table-dynamic inf-clojure-completions))))))
12931321

12941322
;;;; ElDoc
12951323
;;;; =====

0 commit comments

Comments
 (0)