X-Git-Url: http://christophe.rhodes.io/gitweb/?p=swankr.git;a=blobdiff_plain;f=swank.R;h=cf64daaaa81b8ad7341284a67dd67423058c922f;hp=34998b652e189799bc6bf70461099f50bc5d68eb;hb=4da3085437b358a5c9b21a91ad01732c85568416;hpb=392b428c4b15258e6624b24b5838ebba7d4e23aa diff --git a/swank.R b/swank.R index 34998b6..cf64daa 100644 --- a/swank.R +++ b/swank.R @@ -13,15 +13,26 @@ ### latest version of the GNU General Public Licence is available at ### . +### KLUDGE: this assumes that we're being sourced with chdir=TRUE. +### (If not, `swank:swank-require` will work under the circumstances +### that it used to work anyway -- i.e. the working directory is the +### swankr directory) +swankrPath <- getwd() + swank <- function(port=4005) { acceptConnections(port, FALSE) } startSwank <- function(portFile) { - acceptConnections(FALSE, portFile) + acceptConnections(4005, portFile) } acceptConnections <- function(port, portFile) { + if(portFile != FALSE) { + f <- file(portFile, open="w+") + cat(port, file=f) + close(f) + } s <- socketConnection(host="localhost", server=TRUE, port=port, open="r+b") on.exit(close(s)) serve(s) @@ -283,7 +294,7 @@ printToString <- function(val) { `swank:swank-require` <- function (slimeConnection, sldbState, contribs) { for(contrib in contribs) { - filename <- sprintf("%s.R", as.character(contrib)) + filename <- sprintf("%s/%s.R", swankrPath, as.character(contrib)) if(file.exists(filename)) { source(filename) } @@ -316,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() } @@ -481,17 +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", + 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) {