]> rhodes.io Git - swankr.git/commitdiff
Christophe Weblog Wiki Code Publications Music
implement swank:interactive-eval and swank:eval-and-grab-output
authorChristophe Rhodes <csr21@cantab.net>
Wed, 25 Aug 2010 14:57:56 +0000 (15:57 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Wed, 25 Aug 2010 14:57:56 +0000 (15:57 +0100)
This allows C-c : and C-u C-c : to work, modulo the printing of an
unnecessary [1].  The evaluation semantics of R are not what a Lisper might
expect; printToString(eval(parse(...))) does not necessarily perform the
evaluation before altering the output stream with sink() -- so capturing
all sorts of incidental output if something goes wrong.

This commit brought to you using C-c C-c.

swank.R

diff --git a/swank.R b/swank.R
index 05b1c784f6aca534b4361349ba05adb9cc732529..18269449e914970f099c240fc916ead34f11c159 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -316,3 +316,29 @@ printToString <- function(val) {
                abort="abort compilation")
   list(quote(`:compilation-result`), list(), TRUE, times[3])
 }
                abort="abort compilation")
   list(quote(`:compilation-result`), list(), TRUE, times[3])
 }
+
+`swank:interactive-eval` <-  function(io, sldbState, string) {
+  retry <- TRUE
+  value <- ""
+  while(retry) {
+    retry <- FALSE
+    withRestarts(value <- eval(parse(text=string), envir = globalenv()),
+                 retry=list(description="retry SLIME interactive evaluation request", handler=function() retry <<- TRUE))
+  }
+  printToString(value)
+}
+
+`swank:eval-and-grab-output` <- function(io, sldbState, string) {
+  retry <- TRUE
+  value <- ""
+  output <- NULL
+  f <- fifo("")
+  tryCatch({
+    sink(f)
+    while(retry) {
+      retry <- FALSE
+      withRestarts(value <- eval(parse(text=string), envir = globalenv()),
+                   retry=list(description="retry SLIME interactive evaluation request", handler=function() retry <<- TRUE))}},
+           finally={sink(); output <- readLines(f); close(f)})
+  list(output, printToString(value))
+}