@@ -937,9 +937,14 @@ 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 )
947
+ (defun inf-clojure-- process-response (process command &optional beg-string end-string )
943
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
@@ -973,17 +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
- ; ; The following reads the first LISP expression from the string
982
- (arglists-data (when arglists-result (ignore-errors (read arglists-result)))))
983
- (cond
984
- ((null arglists-data) nil )
985
- ((stringp arglists-data) arglists-data)
986
- ((listp arglists-data) arglists-result))))
1018
+ (arglist-response (inf-clojure--process-response (inf-clojure-proc) arglists-snippet))
1019
+ (inf-clojure--read-response arglist-response))))
987
1020
988
1021
(defun inf-clojure-show-arglists (prompt-for-symbol )
989
1022
" Show the arglists for function FN in the mini-buffer.
@@ -1051,24 +1084,9 @@ See variable `inf-clojure-buffer'."
1051
1084
1052
1085
(defun inf-clojure-completions (expr )
1053
1086
" Return a list of completions for the Clojure expression starting with EXPR."
1054
- (let* ((proc (inf-clojure-proc))
1055
- (comint-filt (process-filter proc))
1056
- (kept " " )
1057
- completions)
1058
- (set-process-filter proc (lambda (_proc string ) (setq kept (concat kept string))))
1059
- (unwind-protect
1060
- (let ((completion-snippet
1061
- (format
1062
- (inf-clojure-completion-form) (substring-no-properties expr))))
1063
- (process-send-string proc completion-snippet)
1064
- (while (and (not (string-match inf-clojure-prompt kept))
1065
- (accept-process-output proc 2 )))
1066
- (setq completions (read kept))
1067
- ; ; Subprocess echoes output on Windows and OS X.
1068
- (when (and completions (string= (concat (car completions) " \n " ) completion-snippet))
1069
- (setq completions (cdr completions))))
1070
- (set-process-filter proc comint-filt))
1071
- 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)))
1072
1090
1073
1091
(defconst inf-clojure-clojure-expr-break-chars " \t\n\"\' `><,;|&{(" )
1074
1092
@@ -1226,13 +1244,6 @@ to suppress the usage of the target buffer discovery logic."
1226
1244
(inf-clojure (inf-clojure-cmd (inf-clojure-project-type)))
1227
1245
(rename-buffer target-buffer-name)))
1228
1246
1229
- (defun inf-clojure--response-match-p (form match-p proc )
1230
- " Return MATCH-P on the result of sending FORM to PROC.
1231
- Note that this function will add a \n to the end of the string
1232
- for evaluation, therefore FORM should not include it."
1233
- (when-let* ((response (inf-clojure-results-from-process proc form)))
1234
- (funcall match-p response)))
1235
-
1236
1247
; ;;; Lumo
1237
1248
; ;;; ====
1238
1249
@@ -1242,14 +1253,6 @@ for evaluation, therefore FORM should not include it."
1242
1253
:type 'string
1243
1254
:package-version '(inf-clojure . " 2.0.0" ))
1244
1255
1245
- (defalias 'inf-clojure--lumo-p
1246
- (apply-partially 'inf-clojure--response-match-p
1247
- inf-clojure--lumo-repl-form
1248
- (lambda (string )
1249
- (string-match-p " \\ Ca*true\\ Ca*" string)))
1250
- " Ascertain that PROC is a Lumo REPL." )
1251
-
1252
-
1253
1256
; ;;; Planck
1254
1257
; ;;; ====
1255
1258
0 commit comments