@@ -215,6 +215,12 @@ It requires a REPL PROC for inspecting the correct type."
215
215
(setq inf-clojure-repl-type (inf-clojure--detect-repl-type proc))
216
216
inf-clojure-repl-type))
217
217
218
+ (defun inf-clojure--sanitize-command (command )
219
+ " Sanitize COMMAND for sending it to a process.
220
+ An example of things that this function does is to add a final
221
+ newline at the end of the form."
222
+ (concat (string-trim-right command) " \n " ))
223
+
218
224
(defun inf-clojure--send-string (proc string )
219
225
" A custom `comint-input-sender` / `comint-send-string`.
220
226
It performs the required side effects on every send for PROC and
@@ -884,22 +890,47 @@ safe to call only from inside `inf-clojure-arglist`."
884
890
(and (string-match " (.+)" string input-end) (match-string 0 string))))
885
891
(_ (and (string-match " (.+)" string) (match-string 0 string)))))
886
892
893
+ ; ; Originally from:
894
+ ; ; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
895
+ (defun inf-clojure-results-from-process (process command &optional beg-string end-string )
896
+ " Send COMMAND to PROCESS.
897
+ Return the result of COMMAND starting with BEG-STRING and ending
898
+ with END-STRING if non-nil. If BEG-STRING is nil, the result
899
+ string will start from (point) in the results buffer. If
900
+ END-STRING is nil, the result string will end at (point-max) in
901
+ the results buffer. It cuts out the output from
902
+ `inf-clojure-prompt` onwards unconditionally."
903
+ (let ((work-buffer " *Inf-Clojure Redirect Work Buffer*" ))
904
+ (save-excursion
905
+ (set-buffer (get-buffer-create work-buffer))
906
+ (erase-buffer )
907
+ (comint-redirect-send-command-to-process
908
+ (inf-clojure--sanitize-command command) work-buffer process nil t )
909
+ ; ; Wait for the process to complete
910
+ (set-buffer (process-buffer process))
911
+ (while (null comint-redirect-completed)
912
+ (accept-process-output nil 1 ))
913
+ ; ; Collect the output
914
+ (set-buffer work-buffer)
915
+ (goto-char (point-min ))
916
+ ; ; Skip past the command, if it was echoed
917
+ (and (looking-at command)
918
+ (forward-line ))
919
+ (let* ((beg (if beg-string
920
+ (progn (search-forward beg-string nil t ) (match-beginning 0 ))
921
+ (point )))
922
+ (end (if end-string
923
+ (search-forward end-string nil t )
924
+ (point-max )))
925
+ (buffer-string (buffer-substring-no-properties beg end)))
926
+ (when (and buffer-string (string-match inf-clojure-prompt buffer-string))
927
+ (substring buffer-string 0 (match-beginning 0 )))))))
928
+
887
929
(defun inf-clojure-arglist (fn )
888
930
" Send a query to the inferior Clojure for the arglist for function FN.
889
931
See variable `inf-clojure-arglist-form' ."
890
- (let* ((proc (inf-clojure-proc))
891
- (comint-filt (process-filter proc))
892
- (kept " " )
893
- eldoc)
894
- (set-process-filter proc (lambda (_proc string ) (setq kept (concat kept string))))
895
- (unwind-protect
896
- (let ((eldoc-snippet (format (inf-clojure-arglists-form) fn)))
897
- (inf-clojure--send-string proc eldoc-snippet)
898
- (while (and (not (string-match inf-clojure-prompt kept))
899
- (accept-process-output proc 2 )))
900
- (setq eldoc (inf-clojure-match-arglists eldoc-snippet kept)))
901
- (set-process-filter proc comint-filt))
902
- eldoc))
932
+ (let ((eldoc-snippet (format (inf-clojure-arglists-form) fn)))
933
+ (inf-clojure-results-from-process (inf-clojure-proc) eldoc-snippet)))
903
934
904
935
(defun inf-clojure-show-arglist (prompt-for-symbol )
905
936
" Show the arglist for function FN in the mini-buffer.
@@ -1145,20 +1176,7 @@ to suppress the usage of the target buffer discovery logic."
1145
1176
" Return MATCH-P on the result of sending FORM to PROC.
1146
1177
Note that this function will add a \n to the end of the string
1147
1178
for evaluation, therefore FORM should not include it."
1148
- (let* ((kept " " )
1149
- (is-matching nil )
1150
- (prev-filter (process-filter proc)))
1151
- (set-process-filter proc (lambda (_ string ) (setq kept (concat kept string))))
1152
- (unwind-protect
1153
- ; ; use the real comind-send-string in order to avoid stack overflows
1154
- (comint-send-string proc (concat form " \n " ))
1155
- ; ; yey, loads of procedural code again
1156
- (while (and (not is-matching)
1157
- (not (string-match inf-clojure-prompt kept))
1158
- (accept-process-output proc 2 ))
1159
- (setq is-matching (funcall match-p kept)))
1160
- (set-process-filter proc prev-filter))
1161
- is-matching))
1179
+ (funcall match-p (inf-clojure-results-from-process proc form nil )))
1162
1180
1163
1181
; ;;; Lumo
1164
1182
; ;;; ====
0 commit comments