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