From 4da3085437b358a5c9b21a91ad01732c85568416 Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Sat, 10 Sep 2011 09:23:25 +0100 Subject: [PATCH] use withVisible() in appropriate places Makes C-c C-r substantially less painful, and also produces slightly fewer surprises at the REPL. (resolves #5) --- BUGS.org | 2 +- swank.R | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/BUGS.org b/BUGS.org index a24bd08..f44532b 100644 --- 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 11210e2..cf64daa 100644 --- 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) { -- 2.39.5