Christophe Weblog Wiki Code Publications Music
implement swank:compile-string-for-emacs
[swankr.git] / swank.R
diff --git a/swank.R b/swank.R
index fa910b2abd5d3d918cbaa729ed291df2479e76da..1c1633d77ad8c7aa7fa8a709eb3a3bcd02e57e10 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -295,3 +295,26 @@ 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)
+  }
+}
+
+`swank:compile-string-for-emacs` <- function(io, sldbState, string, buffer, position, filename, policy) {
+  # FIXME: I think in parse() here we can use srcref to associate
+  # buffer/filename/position to the objects.  Or something.
+  withRestarts({ times <- system.time(eval(parse(text=string), envir = globalenv())) },
+               abort="abort compilation")
+  list(quote(`:compilation-result`), list(), TRUE, times[3])
+}