From d572642da5a5405c20f54a83e438f95e7d2556d8 Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Fri, 20 Aug 2010 20:17:02 +0100 Subject: [PATCH] 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. --- swank.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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) + } +} -- 2.39.5