From: Christophe Rhodes Date: Fri, 20 Aug 2010 19:17:02 +0000 (+0100) Subject: implement swank:simple-completions X-Git-Url: http://christophe.rhodes.io/gitweb/?p=swankr.git;a=commitdiff_plain;h=d572642da5a5405c20f54a83e438f95e7d2556d8 implement swank:simple-completions Probably fails as soon as slime and R disagree about what are token constituents, or if an R token contains regexp metacharacters. --- diff --git a/swank.R b/swank.R index fa910b2..ddd1a0e 100644 --- a/swank.R +++ b/swank.R @@ -295,3 +295,18 @@ printToString <- function(val) { quote(`:value`), paste(printToString(eval(parse(text=name), envir=frame)), sep="", collapse="\n")) }), list()) } + +`swank:simple-completions` <- function(io, sldbState, prefix, package) { + ## fails multiply if prefix contains regexp metacharacters + matches <- apropos(sprintf("^%s", 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) { + longest <- substr(longest, 1, nchar(longest)-1) + } + list(as.list(matches), longest) + } +}