emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/inf-clojure 0bb2700 156/313: Introduce inf-clojure-log-act


From: ELPA Syncer
Subject: [nongnu] elpa/inf-clojure 0bb2700 156/313: Introduce inf-clojure-log-activity
Date: Wed, 11 Aug 2021 10:00:06 -0400 (EDT)

branch: elpa/inf-clojure
commit 0bb2700a9bd2dce43f740547cb16505860fab0fc
Author: Andrea Richiardi <a.richiardi.work@gmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>

    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.
---
 README.md      | 10 ++++++++++
 inf-clojure.el | 35 ++++++++++++++++++++++++++++++++---
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index bb60fdc..7fa0384 100644
--- a/README.md
+++ b/README.md
@@ -201,6 +201,16 @@ directory and add this line to that file:
 jline.terminal=unsupported
 ```
 
+### Log process activity
+
+Standard Emacs debugging turns out to be difficult when an asynchronous 
process is involved. In this case try to enable logging:
+
+```el
+(setq inf-clojure-log-activity t)
+```
+
+This creates `.inf-clojure.log` in the process root for you to `tail -f` on.
+
 ## License
 
 Copyright © 2014-2017 Bozhidar Batsov and [contributors][].
diff --git a/inf-clojure.el b/inf-clojure.el
index f72825f..b38735f 100644
--- a/inf-clojure.el
+++ b/inf-clojure.el
@@ -946,7 +946,33 @@ prefix argument PROMPT-FOR-SYMBOL, it prompts for a symbol 
name."
 ;;;; Response parsing
 ;;;; ================
 
-(defvar inf-clojure--redirect-buffer-name " *Inf-Clojure Redirect Buffer*")
+(defvar inf-clojure--redirect-buffer-name " *Inf-Clojure Redirect Buffer*"
+  "The name of the buffer used for process output redirection.")
+
+(defvar inf-clojure--log-file-name ".inf-clojure.log"
+  "The name of the file used to log process activity.")
+
+(defvar inf-clojure-log-activity nil
+  "Log process activity?.
+Inf-Clojure will create a log file in the project folder named
+`inf-clojure--log-file-name' and dump the process activity in it
+in case this is not nil." )
+
+(defun inf-clojure--log-string (string &optional type)
+  "Log STRING to file, according to `inf-clojure-log-response'.
+The optional TYPE will be converted to string and printed before
+STRING if present."
+  (when inf-clojure-log-activity
+    (write-region (concat "\n"
+                          (when type
+                            (concat (prin1-to-string type) " | "))
+                          (let ((print-escape-newlines t))
+                            (prin1-to-string string)))
+                  nil
+                  (expand-file-name inf-clojure--log-file-name
+                                    (inf-clojure-project-root))
+                  'append
+                  'no-annoying-write-file-in-minibuffer)))
 
 ;; Originally from:
 ;;   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
 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`."
+  (inf-clojure--log-string command :cmd)
   (let ((work-buffer inf-clojure--redirect-buffer-name))
     (save-excursion
       (set-buffer (get-buffer-create work-buffer))
@@ -978,8 +1005,10 @@ the `inf-clojure-prompt`."
                         (search-forward end-string nil t))
                       (point-max)))
              (prompt (when (search-forward inf-clojure-prompt nil t)
-                       (match-beginning 0))))
-        (buffer-substring-no-properties beg (or prompt end))))))
+                       (match-beginning 0)))
+             (buffer-string (buffer-substring-no-properties beg (or prompt 
end))))
+        (inf-clojure--log-string buffer-string :res)
+        buffer-string))))
 
 (defun inf-clojure--nil-string-match-p (string)
   "Return true iff STRING is not nil.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]