@@ -977,16 +977,27 @@ STRING if present."
977
977
'append
978
978
'no-annoying-write-file-in-minibuffer )))
979
979
980
+ (defun inf-clojure--string-boundaries (string prompt &optional beg-regexp end-regexp )
981
+ " Calculate the STRING boundaries, including PROMPT.
982
+ Return a list of positions (beginning end prompt). If the
983
+ optional BEG-REGEXP and END-REGEXP are present, the boundaries
984
+ are going to match those."
985
+ (list (or (and beg-regexp (string-match beg-regexp string)) 0 )
986
+ (or (and end-regexp (when (string-match end-regexp string)
987
+ (match-end 0 )))
988
+ (length string))
989
+ (or (string-match prompt string) (length string))))
990
+
980
991
; ; Originally from:
981
992
; ; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
982
- (defun inf-clojure--process-response (command process &optional beg-string end-string )
993
+ (defun inf-clojure--process-response (command process &optional beg-regexp end-regexp )
983
994
" Send COMMAND to PROCESS and return the response.
984
- Return the result of COMMAND starting with BEG-STRING and ending
985
- with END-STRING if non-nil. If BEG-STRING is nil, the result
986
- string will start from (point) in the results buffer. If
987
- END-STRING is nil, the result string will end at (point-max) in
988
- the results buffer. It cuts out the output from and including
989
- the `inf-clojure-prompt`."
995
+ Return the result of COMMAND, filtering it from BEG-REGEXP to the
996
+ end of the matching END-REGEXP if non-nil.
997
+ If BEG-REGEXP is nil, the result string will start from (point)
998
+ in the results buffer. If END-REGEXP is nil, the result string
999
+ will end at (point-max) in the results buffer. It cuts out the
1000
+ output from and including the `inf-clojure-prompt`."
990
1001
(inf-clojure--log-string command " ----CMD->" )
991
1002
(let ((work-buffer inf-clojure--redirect-buffer-name))
992
1003
(save-excursion
@@ -1002,17 +1013,16 @@ the `inf-clojure-prompt`."
1002
1013
; ; Collect the output
1003
1014
(set-buffer work-buffer)
1004
1015
(goto-char (point-min ))
1005
- (let* ((beg (or (when (and beg-string (search-forward beg-string nil t ))
1006
- (match-beginning 0 ))
1007
- (point-min )))
1008
- (end (or (when end-string
1009
- (search-forward end-string nil t ))
1010
- (point-max )))
1011
- (prompt (when (search-forward inf-clojure-prompt nil t )
1012
- (match-beginning 0 )))
1013
- (buffer-string (buffer-substring-no-properties beg (or prompt end))))
1014
- (inf-clojure--log-string buffer-string " <-RES----" )
1015
- buffer-string))))
1016
+ (let* ((buffer-string (buffer-substring-no-properties (point-min ) (point-max )))
1017
+ (boundaries (inf-clojure--string-boundaries buffer-string inf-clojure-prompt beg-regexp end-regexp))
1018
+ (beg-pos (car boundaries))
1019
+ (end-pos (car (cdr boundaries)))
1020
+ (prompt-pos (car (cdr (cdr boundaries))))
1021
+ (response-string (substring buffer-string beg-pos (min end-pos prompt-pos))))
1022
+ (inf-clojure--log-string buffer-string " <-BUF----" )
1023
+ (inf-clojure--log-string boundaries " <-BND----" )
1024
+ (inf-clojure--log-string response-string " <-RES----" )
1025
+ response-string))))
1016
1026
1017
1027
(defun inf-clojure--nil-string-match-p (string )
1018
1028
" Return true iff STRING is not nil.
@@ -1044,7 +1054,7 @@ readable sexp only."
1044
1054
1045
1055
(defun inf-clojure--process-response-match-p (match-p proc form )
1046
1056
" Eval MATCH-P on the response of sending to PROC the input FORM.
1047
- Note that this function will add a \n to the end (or )f the string
1057
+ Note that this function will add a \n to the end of the string
1048
1058
for evaluation, therefore FORM should not include it."
1049
1059
(when-let ((response (inf-clojure--process-response form proc)))
1050
1060
(funcall match-p response)))
0 commit comments