Christophe Weblog Wiki Code Publications Music
implement swank:simple-completions
authorChristophe Rhodes <csr21@cantab.net>
Fri, 20 Aug 2010 19:17:02 +0000 (20:17 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Fri, 20 Aug 2010 19:17:02 +0000 (20:17 +0100)
Probably fails as soon as slime and R disagree about what are token
constituents, or if an R token contains regexp metacharacters.

swank.R

diff --git a/swank.R b/swank.R
index fa910b2abd5d3d918cbaa729ed291df2479e76da..ddd1a0e5b64df12104370a3851e55cf3e9981379 100644 (file)
--- 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())
 }
                                           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)
+  }
+}