@@ -937,10 +937,15 @@ prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
937
937
(inf-clojure-symbol-at-point))))
938
938
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-var-source-form) var))))
939
939
940
+ ; ;;; Response parsing
941
+ ; ;;; ================
942
+
943
+ (defvar inf-clojure--work-buffer-name " *Inf-Clojure Work Buffer*" )
944
+
940
945
; ; Originally from:
941
946
; ; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
942
- (defun inf-clojure-results-from- process (process command &optional beg-string end-string )
943
- " Send COMMAND to PROCESS.
947
+ (defun inf-clojure-- process-response (process command &optional beg-string end-string )
948
+ " Send to PROCESS the given COMMAND .
944
949
Return the result of COMMAND starting with BEG-STRING and ending
945
950
with END-STRING if non-nil. If BEG-STRING is nil, the result
946
951
string will start from (point) in the results buffer. If
@@ -973,16 +978,45 @@ the results buffer. It cuts out the output from
973
978
(when (and buffer-string (string-match inf-clojure-prompt buffer-string))
974
979
(substring buffer-string 0 (match-beginning 0 )))))))
975
980
981
+ (defun inf-clojure--nil-string-match-p (string )
982
+ " Return true iff STRING is not nil.
983
+ This function also takes into consideration weird escape
984
+ character and matches if nil is anywhere within the input
985
+ string."
986
+ (string-match-p " \\ Ca*nil\\ Ca*" string))
987
+
988
+ (defun inf-clojure--read-response (response )
989
+ " Common post-processing of a process RESPONSE."
990
+ ; ; The following reads the first LISP expression from the (string )
991
+ (let ((read-data (when response (ignore-errors (read response)))))
992
+ (cond
993
+ ((null read-data) nil )
994
+ ((and (stringp read-data) (inf-clojure--nil-string-match-p read-data)) nil )
995
+ ((listp read-data) read-data))))
996
+
997
+ (defun inf-clojure--process-response-match-p (match-p proc form )
998
+ " Eval MATCH-P on the response of sending to PROC the input FORM.
999
+ Note that this function will add a \n to the end (or )f the string
1000
+ for evaluation, therefore FORM should not include it."
1001
+ (when-let ((response (inf-clojure--process-response proc form)))
1002
+ (funcall match-p response)))
1003
+
1004
+ (defun inf-clojure--non-nil-response-p (proc form )
1005
+ " Return true iff PROC's response after evaluating FORM is not nil."
1006
+ (inf-clojure--process-response-match-p
1007
+ (lambda (string )
1008
+ (not (inf-clojure--nil-string-match-p string)))
1009
+ proc form))
1010
+
1011
+ ; ;;; Commands
1012
+ ; ;;; ========
1013
+
976
1014
(defun inf-clojure-arglists (fn )
977
1015
" Send a query to the inferior Clojure for the arglists for function FN.
978
1016
See variable `inf-clojure-arglists-form' ."
979
1017
(let* ((arglists-snippet (format (inf-clojure-arglists-form) fn))
980
- (arglists-result (inf-clojure-results-from-process (inf-clojure-proc) arglists-snippet))
981
- (arglists-data (when arglists-result (read arglists-result))))
982
- (cond
983
- ((null arglists-data) nil )
984
- ((stringp arglists-data) arglists-data)
985
- ((listp arglists-data) arglists-result))))
1018
+ (arglist-response (inf-clojure--process-response (inf-clojure-proc) arglists-snippet))
1019
+ (inf-clojure--read-response arglist-response))))
986
1020
987
1021
(defun inf-clojure-show-arglists (prompt-for-symbol )
988
1022
" Show the arglists for function FN in the mini-buffer.
@@ -1050,24 +1084,9 @@ See variable `inf-clojure-buffer'."
1050
1084
1051
1085
(defun inf-clojure-completions (expr )
1052
1086
" Return a list of completions for the Clojure expression starting with EXPR."
1053
- (let* ((proc (inf-clojure-proc))
1054
- (comint-filt (process-filter proc))
1055
- (kept " " )
1056
- completions)
1057
- (set-process-filter proc (lambda (_proc string ) (setq kept (concat kept string))))
1058
- (unwind-protect
1059
- (let ((completion-snippet
1060
- (format
1061
- (inf-clojure-completion-form) (substring-no-properties expr))))
1062
- (process-send-string proc completion-snippet)
1063
- (while (and (not (string-match inf-clojure-prompt kept))
1064
- (accept-process-output proc 2 )))
1065
- (setq completions (read kept))
1066
- ; ; Subprocess echoes output on Windows and OS X.
1067
- (when (and completions (string= (concat (car completions) " \n " ) completion-snippet))
1068
- (setq completions (cdr completions))))
1069
- (set-process-filter proc comint-filt))
1070
- completions))
1087
+ (let* ((compl-snippet (format (inf-clojure-completion-form) (substring-no-properties expr)))
1088
+ (compl-response (inf-clojure--process-response (inf-clojure-proc) compl-snippet)))
1089
+ (inf-clojure--read-response compl-response)))
1071
1090
1072
1091
(defconst inf-clojure-clojure-expr-break-chars " \t\n\"\' `><,;|&{(" )
1073
1092
@@ -1225,12 +1244,6 @@ to suppress the usage of the target buffer discovery logic."
1225
1244
(inf-clojure (inf-clojure-cmd (inf-clojure-project-type)))
1226
1245
(rename-buffer target-buffer-name)))
1227
1246
1228
- (defun inf-clojure--response-match-p (form match-p proc )
1229
- " Return MATCH-P on the result of sending FORM to PROC.
1230
- Note that this function will add a \n to the end of the string
1231
- for evaluation, therefore FORM should not include it."
1232
- (funcall match-p (inf-clojure-results-from-process proc form nil )))
1233
-
1234
1247
; ;;; Lumo
1235
1248
; ;;; ====
1236
1249
@@ -1240,14 +1253,6 @@ for evaluation, therefore FORM should not include it."
1240
1253
:type 'string
1241
1254
:package-version '(inf-clojure . " 2.0.0" ))
1242
1255
1243
- (defalias 'inf-clojure--lumo-p
1244
- (apply-partially 'inf-clojure--response-match-p
1245
- inf-clojure--lumo-repl-form
1246
- (lambda (string )
1247
- (string-match-p " \\ Ca*true\\ Ca*" string)))
1248
- " Ascertain that PROC is a Lumo REPL." )
1249
-
1250
-
1251
1256
; ;;; Planck
1252
1257
; ;;; ====
1253
1258
0 commit comments