@@ -1210,7 +1210,7 @@ prefix argument PROMPT-FOR-NS, it prompts for a namespace name."
1210
1210
1211
1211
(defun inf-clojure-set-ns (prompt-for-ns )
1212
1212
" 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
1214
1214
the current buffer. When invoked with a prefix argument
1215
1215
PROMPT-FOR-NS, it prompts for a namespace name."
1216
1216
(interactive " P" )
@@ -1254,14 +1254,52 @@ See variable `inf-clojure-buffer'."
1254
1254
" Return DATA if and only if it is a list."
1255
1255
(when (listp data) data))
1256
1256
1257
+ (defun inf-clojure-list-completions (response-str )
1258
+ " Parse completions from RESPONSE-STR.
1259
+
1260
+ Its only ability is to parse a Lisp list of candidate strings,
1261
+ every other EXPR will be discarded and nil will be returned."
1262
+ (thread-first
1263
+ response-str
1264
+ (inf-clojure--read-or-nil)
1265
+ (inf-clojure--list-or-nil)))
1266
+
1257
1267
(defun inf-clojure-completions (expr )
1258
- " Return a list of completions for the Clojure expression starting with EXPR."
1268
+ " Return completions for the Clojure expression starting with EXPR.
1269
+
1270
+ Under the hood it calls the function
1271
+ \\ [inf-clojure-completions-fn] passing in the result of
1272
+ evaluating \\ [inf-clojure-completion-form] at the REPL."
1259
1273
(when (not (string-blank-p expr))
1260
- (thread-first
1261
- (format (inf-clojure-completion-form) (substring-no-properties expr))
1262
- (inf-clojure--process-response (inf-clojure-proc) " (" " )" )
1263
- (inf-clojure--read-or-nil)
1264
- (inf-clojure--list-or-nil))))
1274
+ (let ((proc (inf-clojure-proc))
1275
+ (completion-form (format (inf-clojure-completion-form) (substring-no-properties expr))))
1276
+ (funcall inf-clojure-completions-fn
1277
+ (inf-clojure--process-response completion-form proc " (" " )" )))))
1278
+
1279
+ (defcustom inf-clojure-completions-fn 'inf-clojure-list-completions
1280
+ " The function that parses completion results.
1281
+
1282
+ It is a single-arity function that will receive the REPL
1283
+ evaluation result of \\ [inf-clojure-completion-form] as string and
1284
+ should return elisp data compatible with your completion mode.
1285
+
1286
+ The easiest possible data passed in input is a list of
1287
+ candidates (e.g.: (\" def\" \" defn\" )) but more complex libraries
1288
+ like `alexander-yakushev/compliment' can return other things like
1289
+ edn.
1290
+
1291
+ The expected return depends on the mode that you use for
1292
+ completion: usually it is something compatible with
1293
+ \\ [completion-at-point-functions] but other modes like
1294
+ `company-mode' allow an even higher level of sophistication.
1295
+
1296
+ The default value is the `inf-clojure-list-completions' function,
1297
+ which is able to parse results in list form only. You can peek
1298
+ at its implementation for getting to know some utility functions
1299
+ you might want to use in your customization."
1300
+ :type 'function
1301
+ :safe #'functionp
1302
+ :package-version '(inf-clojure . " 2.1.0" ))
1265
1303
1266
1304
(defconst inf-clojure-clojure-expr-break-chars " \t\n\"\' `><,;|&{()[]" )
1267
1305
0 commit comments