]> rhodes.io Git - swankr.git/commitdiff
Christophe Weblog Wiki Code Publications Music
use withVisible() in appropriate places
authorChristophe Rhodes <csr21@cantab.net>
Sat, 10 Sep 2011 08:23:25 +0000 (09:23 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Sat, 10 Sep 2011 08:23:25 +0000 (09:23 +0100)
Makes C-c C-r substantially less painful, and also produces slightly
fewer surprises at the REPL.  (resolves #5)

BUGS.org
swank.R

index a24bd08d14420f0df8d023bb39de54e10c8b5dc0..f44532b6e357371f6ab82eb2fea7ef7a84c00495 100644 (file)
--- a/BUGS.org
+++ b/BUGS.org
@@ -18,7 +18,7 @@
 * OPEN #4 multibyte characters corrupt slime connection              :NORMAL:
   Not in all circumstances (e.g. ="£"= is OK) but =1:£= fails in
   slime-net-read-or-lose.
-* OPEN #5 respect visibility of evaluated results                  :WISHLIST:
+* RESOLVED #5 respect visibility of evaluated results              :WISHLIST:
   I think we can do this by calling =.Internal(eval.with.vis(...))=
   instead of just regular =eval()=
 * OPEN #6 occasional invalid sink() errors                           :NORMAL:
diff --git a/swank.R b/swank.R
index 11210e28d415f6f102899b4e9b672d0b352453c4..cf64daaaa81b8ad7341284a67dd67423058c922f 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -327,8 +327,10 @@ sendReplResultFunction <- sendReplResult
   expr <- parse(text=string)[[1]]
   ## O maybe this is even uglier
   lookedup <- do.call("bquote", list(expr))
-  value <- eval(lookedup, envir = globalenv())
-  sendReplResultFunction(slimeConnection, value)
+  tmp <- withVisible(eval(lookedup, envir = globalenv()))
+  if(tmp$visible) {
+    sendReplResultFunction(slimeConnection, tmp$value)
+  }
   list()
 }
 
@@ -492,23 +494,35 @@ withRetryRestart <- function(description, expr) {
 
 `swank:interactive-eval` <-  function(slimeConnection, sldbState, string) {
   withRetryRestart("retry SLIME interactive evaluation request",
-                   value <- eval(parse(text=string), envir=globalenv()))
-  prin1ToString(value)
+                   tmp <- withVisible(eval(parse(text=string), envir=globalenv())))
+  if(tmp$visible) {
+    prin1ToString(tmp$value)
+  } else {
+    "# invisible value"
+  }
 }
 
 `swank:eval-and-grab-output` <- function(slimeConnection, sldbState, string) {
   withRetryRestart("retry SLIME interactive evaluation request",
                    { output <-
-                       capture.output(value <- eval(parse(text=string),
-                                                    envir=globalenv())) })
+                       capture.output(tmp <- withVisible(eval(parse(text=string),
+                                                              envir=globalenv()))) })
   output <- paste(output, sep="", collapse="\n")
-  list(output, prin1ToString(value))
+  if(tmp$visible) {
+    list(output, prin1ToString(value))
+  } else {
+    list(output, "# invisible value")
+  }
 }
 
 `swank:interactive-eval-region` <- function(slimeConnection, sldbState, string) {
   withRetryRestart("retry SLIME interactive evaluation request",
-                   value <- eval(parse(text=string), envir=globalenv()))
-  prin1ToString(value)
+                   tmp <- withVisible(eval(parse(text=string), envir=globalenv())))
+  if(tmp$visible) {
+    prin1ToString(value)
+  } else {
+    "# invisible value"
+  }
 }
 
 `swank:find-definitions-for-emacs` <- function(slimeConnection, sldbState, string) {