Christophe Weblog Wiki Code Publications Music
implement swank-c-p-c
[swankr.git] / swank-c-p-c.R
diff --git a/swank-c-p-c.R b/swank-c-p-c.R
new file mode 100644 (file)
index 0000000..8d33184
--- /dev/null
@@ -0,0 +1,15 @@
+`swank:completions` <- function(slimeConnection, sldbState, prefix, package) {
+  bits <- strsplit(prefix, "(?=[A-Z._])", perl=TRUE)[[1]];
+  lrx <- literal2rx(bits)
+  ## FIXME: this includes slightly too much .*, because the strsplit
+  ## seems to split before /and/ after the match.
+  rx <- paste(lrx, collapse=".*")
+  matches <- apropos(sprintf("^%s", rx), ignore.case=FALSE)
+  nmatches <- length(matches)
+  if((nmatches == 0) && ((dollar <- regexpr("$", prefix, fixed=TRUE)) > -1)) {
+    
+    symbolFieldsCompletion(globalenv(), prefix, prefix)
+  } else {
+    returnMatches(matches)
+  }
+}