branch: elpa/geiser-stklos
commit 364d922b392589d0e9915273bd1c7d9947e9e9e9
Author: Jeronimo Pellegrini <[email protected]>
Commit: Jeronimo Pellegrini <[email protected]>
Implement logging (STklos side only)
geiser-stklos-log-file can now be used to customize the name of the
log file used for the STklos process.
The Emacs side is still missing.
---
geiser-stklos.el | 19 +++++++++++++++----
geiser.stk | 15 ++++++++++++---
2 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/geiser-stklos.el b/geiser-stklos.el
index 5f8566f2d8..bc21528ac8 100644
--- a/geiser-stklos.el
+++ b/geiser-stklos.el
@@ -130,8 +130,10 @@ option."
(geiser-custom--defcustom geiser-stklos-log-file
""
"Name of the file where the STklos part of the system will log its
-actions. FOR GEISER-STKLOS DEVELOPMENT ONLY -- currently there is no
-effect for the common user."
+actions. Note that forms are sent from emacs to STklos, and then
+from STklos back to Emacs. This is the file where *only* the
+STklos process will show the forms it receives, and the answer it
+gives back to Emacs. Leave empty for no logging."
:type 'string
:group 'geiser-stklos)
@@ -362,11 +364,20 @@ Argument BINARY is a string containing the binary name."
"Hook for startup. The argument is ignored."
(let ((geiser-log-verbose-p t))
(compilation-setup t)
+
+ ;; If the user wants to log the forms that STklos receives, and the
+ ;; answer it gives back, we send to STklos the form
+ ;;
+ ;; (geiser:eval "GEISER" (geiser:set-log-file FILENAME))
+ ;;
+ ;; besides (newline), which we always send.
+ ;; This is *only* the STklos part of logging. The STklos process will
+ ;; log the forms received and sent back.
(let ((c (if (zerop (length geiser-stklos-log-file))
"(newline)"
- (concat "(begin (geiser:eval \"GEISER\" geiser:set-log-file "
+ (concat "(begin (geiser:eval \"GEISER\" (geiser:set-log-file
\""
geiser-stklos-log-file
- ") (newline))"))))
+ "\")) (newline))"))))
(geiser-eval--send/wait c))))
(defconst geiser-stklos-builtin-keywords
diff --git a/geiser.stk b/geiser.stk
index 84b6add19f..863b8639cc 100644
--- a/geiser.stk
+++ b/geiser.stk
@@ -32,10 +32,16 @@
(when (string? name)
(set! geiser-log-file (open-output-file name))))
+;; The variable geiser-log-file may be a port, but it may also
+;; be #f when no logging is going on, so this wrapper is used to
+;; flush it.
+(define (flush-when-port p)
+ (when (output-port? p) (flush-output-port p)))
+
(define (geiser-format port . rest)
(when (output-port? port)
(apply format (cons port rest))
- (flush-output-port port)))
+ (flush-when-port port)))
;; executes thunk, with all its output (standar and error) redirected
;; to a string.
@@ -88,7 +94,8 @@
`((result ,@result)
(output . ,output))))
(write out-form)
- (geiser-format geiser-log-file "call-with-result response: ~s~%"
out-form))
+ (geiser-format geiser-log-file "call-with-result response: ~s~%"
out-form)
+ (flush-when-port geiser-log-file))
(newline)))
@@ -112,7 +119,8 @@
(define (geiser:eval module-name form . rest)
(geiser-format geiser-log-file "_________________~%")
(geiser-format geiser-log-file "geiser:eval form: ~s~%" form)
-
+ (flush-when-port geiser-log-file)
+
;; All calls start at toplevel
(let ((module (or (and (symbol? module-name )
(find-module module-name))
@@ -124,6 +132,7 @@
(lambda () (eval form module)))))
(let ((ret (call-with-result thunk)))
(geiser-format geiser-log-file "geiser:eval return: ~s~%" ret)
+ (flush-when-port geiser-log-file)
ret))))