@@ -884,22 +884,46 @@ safe to call only from inside `inf-clojure-arglist`."
884884 (and (string-match " (.+)" string input-end) (match-string 0 string))))
885885 (_ (and (string-match " (.+)" string) (match-string 0 string)))))
886886
887+ ; ; Originally from:
888+ ; ; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
889+ (defun inf-clojure-results-from-process (process command &optional beg-string end-string )
890+ " Send COMMAND to PROCESS.
891+ Return the result of COMMAND starting with BEG-STRING and ending
892+ with END-STRING if non-nil. If BEG-STRING is nil, the result
893+ string will start from (point) in the results buffer. If
894+ END-STRING is nil, the result string will end at (point-max) in
895+ the results buffer. It cuts out the output from
896+ `inf-clojure-prompt` onwards unconditionally."
897+ (let ((work-buffer " *Inf-Clojure Redirect Work Buffer*" ))
898+ (save-excursion
899+ (set-buffer (get-buffer-create work-buffer))
900+ (erase-buffer )
901+ (comint-redirect-send-command-to-process command work-buffer process nil t )
902+ ; ; Wait for the process to complete
903+ (set-buffer (process-buffer process))
904+ (while (null comint-redirect-completed)
905+ (accept-process-output nil 1 ))
906+ ; ; Collect the output
907+ (set-buffer work-buffer)
908+ (goto-char (point-min ))
909+ ; ; Skip past the command, if it was echoed
910+ (and (looking-at command)
911+ (forward-line ))
912+ (let* ((beg (if beg-string
913+ (progn (search-forward beg-string nil t ) (match-beginning 0 ))
914+ (point )))
915+ (end (if end-string
916+ (search-forward end-string nil t )
917+ (point-max )))
918+ (buffer-string (buffer-substring-no-properties beg end)))
919+ (when (and buffer-string (string-match inf-clojure-prompt buffer-string))
920+ (substring buffer-string 0 (match-beginning 0 )))))))
921+
887922(defun inf-clojure-arglist (fn )
888923 " Send a query to the inferior Clojure for the arglist for function FN.
889924See 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))
925+ (let ((eldoc-snippet (format (inf-clojure-arglists-form) fn)))
926+ (inf-clojure-results-from-process (inf-clojure-proc) (concat eldoc-snippet " \n " ))))
903927
904928(defun inf-clojure-show-arglist (prompt-for-symbol )
905929 " Show the arglist for function FN in the mini-buffer.
@@ -1145,20 +1169,9 @@ to suppress the usage of the target buffer discovery logic."
11451169 " Return MATCH-P on the result of sending FORM to PROC.
11461170Note that this function will add a \n to the end of the string
11471171for 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))
1172+ (thread-last
1173+ (inf-clojure-results-from-process proc (concat form " \n " ) nil )
1174+ (funcall match-p)))
11621175
11631176; ;;; Lumo
11641177; ;;; ====
0 commit comments