X-Git-Url: http://christophe.rhodes.io/gitweb/?p=swankr.git;a=blobdiff_plain;f=swank.R;h=488ad56943417d0414b9eba804fc14d63cd0a4b1;hp=13164853c32efb8a4c0c4086229a7431c6d99516;hb=df9e80e09eb7639969fbcdb57899efe72688486b;hpb=eb2756730af853555a941d7acb595c07169f3524 diff --git a/swank.R b/swank.R index 1316485..488ad56 100644 --- a/swank.R +++ b/swank.R @@ -113,6 +113,7 @@ sldbLoop <- function(slimeConnection, sldbState, id) { } readPacket <- function(io) { + socketSelect(list(io)) header <- readChunk(io, 6) len <- strtoi(header, base=16) payload <- readChunk(io, len) @@ -246,7 +247,11 @@ writeSexpToString <- function(obj) { printToString <- function(val) { f <- fifo("") - tryCatch({ sink(f); print(val); sink(); readLines(f) }, + sink(f) + tryCatch({ + tryCatch(str(val, indent.str="", list.len=5, max.level=2), + finally=sink()) + readLines(f) }, finally=close(f)) } @@ -418,3 +423,38 @@ computeRestartsForEmacs <- function (sldbState) { finally={sink(); output <- readLines(f); close(f)}) list(output, printToString(value)) } + +`swank:find-definitions-for-emacs` <- function(slimeConnection, sldbState, string) { + if(exists(string, envir = globalenv())) { + thing <- get(string, envir = globalenv()) + if(inherits(thing, "function")) { + body <- body(thing) + srcref <- attr(body, "srcref") + srcfile <- attr(body, "srcfile") + if(is.null(srcfile)) { + list() + } else { + filename <- get("filename", srcfile) + list(list(sprintf("function %s", string), + list(quote(`:location`), + list(quote(`:file`), sprintf("%s/%s", srcfile$wd, srcfile$filename)), + list(quote(`:line`), srcref[[2]][[1]], srcref[[2]][[2]]-1), + list()))) + } + } else { + list() + } + } else { + list() + } +} + +`swank:value-for-editing` <- function(slimeConnection, sldbState, string) { + paste(deparse(eval(parse(text=string), envir = globalenv()), control="all"), + collapse="\n", sep="") +} + +`swank:commit-edited-value` <- function(slimeConnection, sldbState, string, value) { + eval(parse(text=sprintf("%s <- %s", string, value)), envir = globalenv()) + TRUE +}