Christophe Weblog Wiki Code Publications Music
implement swank:find-definitions-for-emacs
authorChristophe Rhodes <csr21@cantab.net>
Wed, 1 Sep 2010 10:11:52 +0000 (11:11 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Wed, 1 Sep 2010 10:11:52 +0000 (11:11 +0100)
A simple implementation, only looking for a single function
definition (no methods, whether S3 or S4, or indeed anything else).
Enough to support M-., though.

swank.R

diff --git a/swank.R b/swank.R
index 13164853c32efb8a4c0c4086229a7431c6d99516..1dc95b48800c305489292bc95f4cdb92f381e16e 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -418,3 +418,28 @@ computeRestartsForEmacs <- function (sldbState) {
            finally={sink(); output <- readLines(f); close(f)})
   list(output, printToString(value))
 }
            finally={sink(); output <- readLines(f); close(f)})
   list(output, printToString(value))
 }
+
+`swank:find-definitions-for-emacs` <- function(slimeConnection, sldbState, string) {
+  if(exists(string, envir = globalenv())) {
+    thing <- get(string, envir = globalenv())
+    if(inherits(thing, "function")) {
+      body <- body(thing)
+      srcref <- attr(body, "srcref")
+      srcfile <- attr(body, "srcfile")
+      if(is.null(srcfile)) {
+        list()
+      } else {
+        filename <- get("filename", srcfile)
+        list(list(sprintf("function %s", string),
+                  list(quote(`:location`),
+                       list(quote(`:file`), sprintf("%s/%s", srcfile$wd, srcfile$filename)),
+                       list(quote(`:line`), srcref[[2]][[1]], srcref[[2]][[2]]-1),
+                       list())))
+      }
+    } else {
+      list()
+    }
+  } else {
+    list()
+  }
+}