Skip to content

Commit 0bb2700

Browse files
arichiardibbatsov
authored andcommitted
Introduce inf-clojure-log-activity
Log commands and responses from/to the inf-clojure process. It can be enabled with (setq inf-clojure-log-activity t). Vital for debugging.
1 parent db7bfaf commit 0bb2700

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ directory and add this line to that file:
201201
jline.terminal=unsupported
202202
```
203203

204+
### Log process activity
205+
206+
Standard Emacs debugging turns out to be difficult when an asynchronous process is involved. In this case try to enable logging:
207+
208+
```el
209+
(setq inf-clojure-log-activity t)
210+
```
211+
212+
This creates `.inf-clojure.log` in the process root for you to `tail -f` on.
213+
204214
## License
205215

206216
Copyright © 2014-2017 Bozhidar Batsov and [contributors][].

inf-clojure.el

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,33 @@ prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol name."
946946
;;;; Response parsing
947947
;;;; ================
948948

949-
(defvar inf-clojure--redirect-buffer-name " *Inf-Clojure Redirect Buffer*")
949+
(defvar inf-clojure--redirect-buffer-name " *Inf-Clojure Redirect Buffer*"
950+
"The name of the buffer used for process output redirection.")
951+
952+
(defvar inf-clojure--log-file-name ".inf-clojure.log"
953+
"The name of the file used to log process activity.")
954+
955+
(defvar inf-clojure-log-activity nil
956+
"Log process activity?.
957+
Inf-Clojure will create a log file in the project folder named
958+
`inf-clojure--log-file-name' and dump the process activity in it
959+
in case this is not nil." )
960+
961+
(defun inf-clojure--log-string (string &optional type)
962+
"Log STRING to file, according to `inf-clojure-log-response'.
963+
The optional TYPE will be converted to string and printed before
964+
STRING if present."
965+
(when inf-clojure-log-activity
966+
(write-region (concat "\n"
967+
(when type
968+
(concat (prin1-to-string type) " | "))
969+
(let ((print-escape-newlines t))
970+
(prin1-to-string string)))
971+
nil
972+
(expand-file-name inf-clojure--log-file-name
973+
(inf-clojure-project-root))
974+
'append
975+
'no-annoying-write-file-in-minibuffer)))
950976

951977
;; Originally from:
952978
;; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
@@ -958,6 +984,7 @@ string will start from (point) in the results buffer. If
958984
END-STRING is nil, the result string will end at (point-max) in
959985
the results buffer. It cuts out the output from and including
960986
the `inf-clojure-prompt`."
987+
(inf-clojure--log-string command :cmd)
961988
(let ((work-buffer inf-clojure--redirect-buffer-name))
962989
(save-excursion
963990
(set-buffer (get-buffer-create work-buffer))
@@ -978,8 +1005,10 @@ the `inf-clojure-prompt`."
9781005
(search-forward end-string nil t))
9791006
(point-max)))
9801007
(prompt (when (search-forward inf-clojure-prompt nil t)
981-
(match-beginning 0))))
982-
(buffer-substring-no-properties beg (or prompt end))))))
1008+
(match-beginning 0)))
1009+
(buffer-string (buffer-substring-no-properties beg (or prompt end))))
1010+
(inf-clojure--log-string buffer-string :res)
1011+
buffer-string))))
9831012

9841013
(defun inf-clojure--nil-string-match-p (string)
9851014
"Return true iff STRING is not nil.

0 commit comments

Comments
 (0)