[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/inf-clojure 4a87862 161/313: Calculate response boundaries
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/inf-clojure 4a87862 161/313: Calculate response boundaries explicitly |
Date: |
Wed, 11 Aug 2021 10:00:07 -0400 (EDT) |
branch: elpa/inf-clojure
commit 4a87862a2cf418d4a3043a83caf66f37b14fadd5
Author: Andrea Richiardi <a.richiardi.work@gmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>
Calculate response boundaries explicitly
Change the way the response is calculated, not by search-forward the buffer
used for redirection but by parsing the raw response. Taking into
consideration
the optional regexps, a list is calculated with beginning, end and prompt
position (the logic is now in inf-clojure--string-boundaries, which can be
unit
tested).
This implicitly solves a hidden bug in inf-clojure--process-response, which
was
not able to identify the prompt in some cases because of the many
search-forward.
Finally, this new information is logged so that bugs can be detected more
easily.
---
inf-clojure.el | 48 +++++++++++++++++++++++++++++-------------------
1 file changed, 29 insertions(+), 19 deletions(-)
diff --git a/inf-clojure.el b/inf-clojure.el
index a803d1e..38ff07c 100644
--- a/inf-clojure.el
+++ b/inf-clojure.el
@@ -977,16 +977,27 @@ STRING if present."
'append
'no-annoying-write-file-in-minibuffer)))
+(defun inf-clojure--string-boundaries (string prompt &optional beg-regexp
end-regexp)
+ "Calculate the STRING boundaries, including PROMPT.
+Return a list of positions (beginning end prompt). If the
+optional BEG-REGEXP and END-REGEXP are present, the boundaries
+are going to match those."
+ (list (or (and beg-regexp (string-match beg-regexp string)) 0)
+ (or (and end-regexp (when (string-match end-regexp string)
+ (match-end 0)))
+ (length string))
+ (or (string-match prompt string) (length string))))
+
;; Originally from:
;; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
-(defun inf-clojure--process-response (command process &optional beg-string
end-string)
+(defun inf-clojure--process-response (command process &optional beg-regexp
end-regexp)
"Send COMMAND to PROCESS and return the response.
-Return the result of COMMAND starting with BEG-STRING and ending
-with END-STRING if non-nil. If BEG-STRING is nil, the result
-string will start from (point) in the results buffer. If
-END-STRING is nil, the result string will end at (point-max) in
-the results buffer. It cuts out the output from and including
-the `inf-clojure-prompt`."
+Return the result of COMMAND, filtering it from BEG-REGEXP to the
+end of the matching END-REGEXP if non-nil.
+If BEG-REGEXP is nil, the result string will start from (point)
+in the results buffer. If END-REGEXP is nil, the result string
+will end at (point-max) in the results buffer. It cuts out the
+output from and including the `inf-clojure-prompt`."
(inf-clojure--log-string command "----CMD->")
(let ((work-buffer inf-clojure--redirect-buffer-name))
(save-excursion
@@ -1002,17 +1013,16 @@ the `inf-clojure-prompt`."
;; Collect the output
(set-buffer work-buffer)
(goto-char (point-min))
- (let* ((beg (or (when (and beg-string (search-forward beg-string nil t))
- (match-beginning 0))
- (point-min)))
- (end (or (when end-string
- (search-forward end-string nil t))
- (point-max)))
- (prompt (when (search-forward inf-clojure-prompt nil t)
- (match-beginning 0)))
- (buffer-string (buffer-substring-no-properties beg (or prompt
end))))
- (inf-clojure--log-string buffer-string "<-RES----")
- buffer-string))))
+ (let* ((buffer-string (buffer-substring-no-properties (point-min)
(point-max)))
+ (boundaries (inf-clojure--string-boundaries buffer-string
inf-clojure-prompt beg-regexp end-regexp))
+ (beg-pos (car boundaries))
+ (end-pos (car (cdr boundaries)))
+ (prompt-pos (car (cdr (cdr boundaries))))
+ (response-string (substring buffer-string beg-pos (min end-pos
prompt-pos))))
+ (inf-clojure--log-string buffer-string "<-BUF----")
+ (inf-clojure--log-string boundaries "<-BND----")
+ (inf-clojure--log-string response-string "<-RES----")
+ response-string))))
(defun inf-clojure--nil-string-match-p (string)
"Return true iff STRING is not nil.
@@ -1044,7 +1054,7 @@ readable sexp only."
(defun inf-clojure--process-response-match-p (match-p proc form)
"Eval MATCH-P on the response of sending to PROC the input FORM.
-Note that this function will add a \n to the end (or )f the string
+Note that this function will add a \n to the end of the string
for evaluation, therefore FORM should not include it."
(when-let ((response (inf-clojure--process-response form proc)))
(funcall match-p response)))
- [nongnu] elpa/inf-clojure a36d2a0 111/313: Remove unwanted ansi chars from the REPL output, (continued)
- [nongnu] elpa/inf-clojure a36d2a0 111/313: Remove unwanted ansi chars from the REPL output, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 3929054 113/313: Modify CHANGELOG and README for REPL types, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure d265232 115/313: Fix a problem with pcase on inf-clojure-repl-type, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure ac74e20 117/313: Kill inf-clojure-var-at-point, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure cfad839 122/313: Officially support lumo -d (dumb terminal) only, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure dda0a43 125/313: Fix newline append on eval functions, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 896edd1 131/313: Handle inf-clojure-arglists corner cases, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure ebd1494 135/313: Support lumo's apropos, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 2341aa2 136/313: Support lumo's source, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 1014e24 141/313: Extend the README a bit, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 4a87862 161/313: Calculate response boundaries explicitly,
ELPA Syncer <=
- [nongnu] elpa/inf-clojure 15963ca 162/313: Trim the string before checking nil, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure aaaeef6 167/313: Set string safety for all the form defcustoms, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 864356a 172/313: [Fix #75] Remove compilation warnings (#109), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 5d76920 176/313: Introduce inf-clojure-project-type defcustom, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure f4478ad 183/313: Fix and reword docstring, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure d4010db 190/313: Add @ (deref) and ^ to the expression breaking chars, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 37b30be 157/313: Bind C-c M-c to inf-clojure-connect, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 49b8c4b 159/313: Restyle inf-clojure-log-activity output, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 21d3e97 171/313: Bump the development version to 2.1.0-snapshot, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 39e794c 168/313: Protect against empty commands, ELPA Syncer, 2021/08/11