Christophe Weblog Wiki Code Publications Music
implement swank:simple-completions
[swankr.git] / swank.R
diff --git a/swank.R b/swank.R
index f3a85ccc6a8b0d770b9273180bb179e717fc736d..ddd1a0e5b64df12104370a3851e55cf3e9981379 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -262,6 +262,10 @@ printToString <- function(val) {
   "No Arglist Information"
 }
 
+`swank:operator-arglist` <- function(io, sldbState, op, package) {
+  list()
+}
+
 `swank:throw-to-toplevel` <- function(io, sldbState) {
   condition <- simpleCondition("Throw to toplevel")
   class(condition) <- c("swankTopLevel", class(condition))
@@ -291,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)
+  }
+}