X-Git-Url: http://christophe.rhodes.io/gitweb/?p=swankr.git;a=blobdiff_plain;f=swank.R;h=0b48ed34e1dd29f2e0f5a96bb98594fdeb227db6;hp=cf64daaaa81b8ad7341284a67dd67423058c922f;hb=d11a1ea1567dd40eec6d281b6d2836dd4d79b271;hpb=4da3085437b358a5c9b21a91ad01732c85568416 diff --git a/swank.R b/swank.R index cf64daa..0b48ed3 100644 --- a/swank.R +++ b/swank.R @@ -324,12 +324,14 @@ sendReplResultFunction <- sendReplResult `swank:listener-eval` <- function(slimeConnection, sldbState, string) { ## O how ugly string <- gsub("#\\.\\(swank:lookup-presented-object-or-lose([^)]*)\\)", ".(`swank:lookup-presented-object-or-lose`(slimeConnection, sldbState,\\1))", string) - expr <- parse(text=string)[[1]] - ## O maybe this is even uglier - lookedup <- do.call("bquote", list(expr)) - tmp <- withVisible(eval(lookedup, envir = globalenv())) - if(tmp$visible) { - sendReplResultFunction(slimeConnection, tmp$value) + for(expr in parse(text=string)) { + expr <- expr + ## O maybe this is even uglier + lookedup <- do.call("bquote", list(expr)) + tmp <- withVisible(eval(lookedup, envir = globalenv())) + if(tmp$visible) { + sendReplResultFunction(slimeConnection, tmp$value) + } } list() } @@ -423,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)