summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2009-02-08 14:16:05 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2009-02-08 14:16:05 +0100
commite16e29baa9d444be4fd5e60f93c124c666c60b80 (patch)
tree77f8bd13c48ce8ddb69bb1f04d4af3ba19b46fb2
parent3670817dcc482c75105da7965e7306044171b0d9 (diff)
downloadgeiser-chez-e16e29baa9d444be4fd5e60f93c124c666c60b80.tar.gz
geiser-chez-e16e29baa9d444be4fd5e60f93c124c666c60b80.tar.bz2
Capturing output of scheme evaluations
-rw-r--r--elisp/geiser-eval.el1
-rw-r--r--scheme/geiser/eval.scm12
2 files changed, 9 insertions, 4 deletions
diff --git a/elisp/geiser-eval.el b/elisp/geiser-eval.el
index 5369a1f..68ef1ca 100644
--- a/elisp/geiser-eval.el
+++ b/elisp/geiser-eval.el
@@ -108,6 +108,7 @@
(defsubst geiser-eval--retort-p (ret)
(and (listp ret) (or (assoc 'error ret) (assoc 'result ret))))
(defsubst geiser-eval--retort-result (ret) (cdr (assoc 'result ret)))
+(defsubst geiser-eval--retort-output (ret) (cdr (assoc 'output ret)))
(defsubst geiser-eval--retort-error (ret) (cdr (assoc 'error ret)))
(defsubst geiser-eval--error-key (err) (cdr (assoc 'key err)))
diff --git a/scheme/geiser/eval.scm b/scheme/geiser/eval.scm
index 81b2647..450221a 100644
--- a/scheme/geiser/eval.scm
+++ b/scheme/geiser/eval.scm
@@ -31,16 +31,20 @@
(define (eval-in form module-name)
"Evals FORM in the module designated by MODULE-NAME.
If MODULE-NAME is #f or resolution fails, the current module is used instead.
-The result is a list of the form ((RESULT . <form-value>))
+The result is a list of the form ((RESULT . <form-value>) (OUTPUT . <string>))
if no evaluation error happens, or ((ERROR (KEY . <error-key>) <error-arg>...))
in case of errors. Each error arg is a cons (NAME . VALUE), where NAME includes
SUBR, MSG and REST."
(let ((module (or (and module-name (resolve-module module-name))
(current-module))))
(catch #t
- (lambda () (list (cons 'result (eval form module))))
- (lambda (key . args)
- (list (cons 'error (apply parse-error (cons key args))))))))
+ (lambda ()
+ (let* ((result #f)
+ (output (with-output-to-string
+ (lambda () (set! result (eval form module))))))
+ (list (cons 'result result) (cons 'output output))))
+ (lambda (key . args)
+ (list (cons 'error (apply parse-error (cons key args))))))))
(define (parse-error key . args)
(let* ((len (length args))