X-Git-Url: http://christophe.rhodes.io/gitweb/?p=swankr.git;a=blobdiff_plain;f=swank.R;h=ce757b3995574feaacd94ed83dbdd5fbe03ea27b;hp=b5c79c78204695667f421bbceb3b3e83664971c1;hb=3ca13eb5110013cf2348b3a840eff3bc4ff0ec69;hpb=dc22b346c159268666cdf0ccdafd740222ef861a diff --git a/swank.R b/swank.R index b5c79c7..ce757b3 100644 --- a/swank.R +++ b/swank.R @@ -425,19 +425,27 @@ computeRestartsForEmacs <- function (sldbState) { objs <- ls(envir=frame) list(lapply(objs, function(name) { list(quote(`:name`), name, quote(`:id`), 0, - quote(`:value`), printToString(eval(parse(text=name), envir=frame))) }), + quote(`:value`), + tryCatch({ + printToString(eval(parse(text=name), envir=frame)) + }, error=function(c) { + sprintf("error printing object") + }))}), list()) } `swank:simple-completions` <- function(slimeConnection, sldbState, prefix, package) { - ## fails multiply if prefix contains regexp metacharacters - matches <- apropos(sprintf("^%s", prefix), ignore.case=FALSE) + literal2rx <- function(string) { + ## list of ERE metacharacters from ?regexp + gsub("([.\\|()[{^$*+?])", "\\\\\\1", string) + } + matches <- apropos(sprintf("^%s", literal2rx(prefix)), ignore.case=FALSE) nmatches <- length(matches) if(nmatches == 0) { list(list(), "") } else { longest <- matches[order(nchar(matches))][1] - while(length(grep(sprintf("^%s", longest), matches)) < nmatches) { + while(length(grep(sprintf("^%s", literal2rx(longest)), matches)) < nmatches) { longest <- substr(longest, 1, nchar(longest)-1) } list(as.list(matches), longest) @@ -511,7 +519,7 @@ withRetryRestart <- function(description, expr) { envir=globalenv()))) }) output <- paste(output, sep="", collapse="\n") if(tmp$visible) { - list(output, prin1ToString(value)) + list(output, prin1ToString(tmp$value)) } else { list(output, "# invisible value") } @@ -521,7 +529,7 @@ withRetryRestart <- function(description, expr) { withRetryRestart("retry SLIME interactive evaluation request", tmp <- withVisible(eval(parse(text=string), envir=globalenv()))) if(tmp$visible) { - prin1ToString(value) + prin1ToString(tmp$value) } else { "# invisible value" }