@@ -703,7 +703,10 @@ If you are using REPL types, it will pickup the most approapriate
703
703
(define-obsolete-variable-alias 'inf-clojure-arglist-command 'inf-clojure-arglists-form " 2.0.0" )
704
704
705
705
(defcustom inf-clojure-arglists-form-lumo
706
- " (pr-str (lumo.repl/get-arglists \" %s\" ))"
706
+ " (let [old-value lumo.repl/*pprint-results*]
707
+ (set! lumo.repl/*pprint-results* false)
708
+ (js/setTimeout #(set! lumo.repl/*pprint-results* old-value) 0)
709
+ (lumo.repl/get-arglists \" %s\" ))"
707
710
" Lumo form to query inferior Clojure for a function's arglists."
708
711
:type 'string
709
712
:package-version '(inf-clojure . " 2.0.0" ))
@@ -726,7 +729,7 @@ If you are using REPL types, it will pickup the most approapriate
726
729
(define-obsolete-variable-alias 'inf-clojure-completion-command 'inf-clojure-completion-form " 2.0.0" )
727
730
728
731
(defcustom inf-clojure-completion-form-lumo
729
- " (let [ret (atom)]
732
+ " (let [ret (atom nil )]
730
733
(lumo.repl/get-completions \" %s\"
731
734
(fn [res] (reset! ret (map str res))))
732
735
@ret)"
@@ -940,17 +943,22 @@ prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
940
943
(inf-clojure-symbol-at-point))))
941
944
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-var-source-form) var))))
942
945
946
+ ; ;;; Response parsing
947
+ ; ;;; ================
948
+
949
+ (defvar inf-clojure--redirect-buffer-name " *Inf-Clojure Redirect Buffer*" )
950
+
943
951
; ; Originally from:
944
952
; ; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
945
- (defun inf-clojure-results-from- process ( process command &optional beg-string end-string )
946
- " Send COMMAND to PROCESS.
953
+ (defun inf-clojure-- process-response ( command process &optional beg-string end-string )
954
+ " Send COMMAND to PROCESS and return the response .
947
955
Return the result of COMMAND starting with BEG-STRING and ending
948
956
with END-STRING if non-nil. If BEG-STRING is nil, the result
949
957
string will start from (point) in the results buffer. If
950
958
END-STRING is nil, the result string will end at (point-max) in
951
- the results buffer. It cuts out the output from
952
- `inf-clojure-prompt` onwards unconditionally ."
953
- (let ((work-buffer " *Inf-Clojure Redirect Work Buffer* " ))
959
+ the results buffer. It cuts out the output from and including
960
+ the `inf-clojure-prompt`."
961
+ (let ((work-buffer inf-clojure--redirect-buffer-name ))
954
962
(save-excursion
955
963
(set-buffer (get-buffer-create work-buffer))
956
964
(erase-buffer )
@@ -963,29 +971,68 @@ the results buffer. It cuts out the output from
963
971
; ; Collect the output
964
972
(set-buffer work-buffer)
965
973
(goto-char (point-min ))
966
- ; ; Skip past the command, if it was echoed
967
- (and (looking-at command)
968
- (forward-line ))
969
- (let* ((beg (if beg-string
970
- (progn (search-forward beg-string nil t ) (match-beginning 0 ))
971
- (point )))
972
- (end (if end-string
973
- (search-forward end-string nil t )
974
- (point-max )))
975
- (buffer-string (buffer-substring-no-properties beg end)))
976
- (when (and buffer-string (string-match inf-clojure-prompt buffer-string))
977
- (substring buffer-string 0 (match-beginning 0 )))))))
974
+ (let* ((beg (or (when (and beg-string (search-forward beg-string nil t ))
975
+ (match-beginning 0 ))
976
+ (point-min )))
977
+ (end (or (when end-string
978
+ (search-forward end-string nil t ))
979
+ (point-max )))
980
+ (prompt (when (search-forward inf-clojure-prompt nil t )
981
+ (match-beginning 0 ))))
982
+ (buffer-substring-no-properties beg (or prompt end))))))
983
+
984
+ (defun inf-clojure--nil-string-match-p (string )
985
+ " Return true iff STRING is not nil.
986
+ This function also takes into consideration weird escape
987
+ character and matches if nil is anywhere within the input
988
+ string."
989
+ (string-match-p " \\ Ca*nil\\ Ca*" string))
990
+
991
+ (defun inf-clojure--some (data )
992
+ " Return DATA unless nil or includes \" nil\" as string."
993
+ (cond
994
+ ((null data) nil )
995
+ ((and (stringp data)
996
+ (inf-clojure--nil-string-match-p data)) nil )
997
+ (t data)))
998
+
999
+ (defun inf-clojure--read-or-nil (response )
1000
+ " Read RESPONSE and return it as data.
1001
+
1002
+ If response is nil or includes the \" nil\" string return nil
1003
+ instead.
1004
+
1005
+ Note that the read operation will always return the first
1006
+ readable sexp only."
1007
+ ; ; The following reads the first LISP expression
1008
+ (inf-clojure--some
1009
+ (when response
1010
+ (ignore-errors (read response)))))
1011
+
1012
+ (defun inf-clojure--process-response-match-p (match-p proc form )
1013
+ " Eval MATCH-P on the response of sending to PROC the input FORM.
1014
+ Note that this function will add a \n to the end (or )f the string
1015
+ for evaluation, therefore FORM should not include it."
1016
+ (when-let ((response (inf-clojure--process-response form proc)))
1017
+ (funcall match-p response)))
1018
+
1019
+ (defun inf-clojure--some-response-p (proc form )
1020
+ " Return true iff PROC's response after evaluating FORM is not nil."
1021
+ (inf-clojure--process-response-match-p
1022
+ (lambda (string )
1023
+ (not (inf-clojure--nil-string-match-p string)))
1024
+ proc form))
1025
+
1026
+ ; ;;; Commands
1027
+ ; ;;; ========
978
1028
979
1029
(defun inf-clojure-arglists (fn )
980
1030
" Send a query to the inferior Clojure for the arglists for function FN.
981
1031
See variable `inf-clojure-arglists-form' ."
982
- (let* ((arglists-snippet (format (inf-clojure-arglists-form) fn))
983
- (arglists-result (inf-clojure-results-from-process (inf-clojure-proc) arglists-snippet))
984
- (arglists-data (when arglists-result (read arglists-result))))
985
- (cond
986
- ((null arglists-data) nil )
987
- ((stringp arglists-data) arglists-data)
988
- ((listp arglists-data) arglists-result))))
1032
+ (thread-first
1033
+ (format (inf-clojure-arglists-form) fn)
1034
+ (inf-clojure--process-response (inf-clojure-proc) " (" " )" )
1035
+ (inf-clojure--some)))
989
1036
990
1037
(defun inf-clojure-show-arglists (prompt-for-symbol )
991
1038
" Show the arglists for function FN in the mini-buffer.
@@ -1051,26 +1098,18 @@ See variable `inf-clojure-buffer'."
1051
1098
(or proc
1052
1099
(error " No Clojure subprocess; see variable `inf-clojure-buffer' " ))))
1053
1100
1101
+ (defun inf-clojure--list-or-nil (data )
1102
+ " Return DATA if and only if it is a list."
1103
+ (when (listp data) data))
1104
+
1054
1105
(defun inf-clojure-completions (expr )
1055
1106
" Return a list of completions for the Clojure expression starting with EXPR."
1056
- (let* ((proc (inf-clojure-proc))
1057
- (comint-filt (process-filter proc))
1058
- (kept " " )
1059
- completions)
1060
- (set-process-filter proc (lambda (_proc string ) (setq kept (concat kept string))))
1061
- (unwind-protect
1062
- (let ((completion-snippet
1063
- (format
1064
- (inf-clojure-completion-form) (substring-no-properties expr))))
1065
- (process-send-string proc completion-snippet)
1066
- (while (and (not (string-match inf-clojure-prompt kept))
1067
- (accept-process-output proc 2 )))
1068
- (setq completions (read kept))
1069
- ; ; Subprocess echoes output on Windows and OS X.
1070
- (when (and completions (string= (concat (car completions) " \n " ) completion-snippet))
1071
- (setq completions (cdr completions))))
1072
- (set-process-filter proc comint-filt))
1073
- completions))
1107
+ (when (not (string-blank-p expr))
1108
+ (thread-first
1109
+ (format (inf-clojure-completion-form) (substring-no-properties expr))
1110
+ (inf-clojure--process-response (inf-clojure-proc) " (" " )" )
1111
+ (inf-clojure--read-or-nil)
1112
+ (inf-clojure--list-or-nil))))
1074
1113
1075
1114
(defconst inf-clojure-clojure-expr-break-chars " \t\n\"\' `><,;|&{(" )
1076
1115
@@ -1232,7 +1271,7 @@ to suppress the usage of the target buffer discovery logic."
1232
1271
" Return MATCH-P on the result of sending FORM to PROC.
1233
1272
Note that this function will add a \n to the end of the string
1234
1273
for evaluation, therefore FORM should not include it."
1235
- (funcall match-p (inf-clojure-results-from- process proc form nil )))
1274
+ (funcall match-p (inf-clojure-- process-response form proc nil )))
1236
1275
1237
1276
; ;;; Lumo
1238
1277
; ;;; ====
0 commit comments