Christophe Weblog Wiki Code Publications Music
give us a chance with utf-8
[swankr.git] / swank.R
diff --git a/swank.R b/swank.R
index 0b48ed34e1dd29f2e0f5a96bb98594fdeb227db6..dea28cf99f2f72cec6ccadc13d1266b88b571c78 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -62,7 +62,7 @@ dispatch <- function(slimeConnection, event, sldbState=NULL) {
 sendToEmacs <- function(slimeConnection, obj) {
   io <- slimeConnection$io
   payload <- writeSexpToString(obj)
-  writeChar(sprintf("%06x", nchar(payload)), io, eos=NULL)
+  writeChar(sprintf("%06x", nchar(payload, type="bytes")), io, eos=NULL)
   writeChar(payload, io, eos=NULL)
   flush(io)
 }
@@ -287,6 +287,7 @@ printToString <- function(val) {
 `swank:connection-info` <- function (slimeConnection, sldbState) {
   list(quote(`:pid`), Sys.getpid(),
        quote(`:package`), list(quote(`:name`), "R", quote(`:prompt`), "R> "),
+       quote(`:encoding`), list(quote(`:coding-systems`), list("utf-8-unix")),
        quote(`:lisp-implementation`), list(quote(`:type`), "R",
                                            quote(`:name`), "R",
                                            quote(`:version`), paste(R.version$major, R.version$minor, sep=".")))
@@ -423,6 +424,9 @@ computeRestartsForEmacs <- function (sldbState) {
 `swank:frame-locals-and-catch-tags` <- function(slimeConnection, sldbState, index) {
   frame <- sldbState$frames[[1+index]]
   objs <- ls(envir=frame)
+  if(identical(frame, globalenv())) {
+    objs <- c()
+  }
   list(lapply(objs, function(name) { list(quote(`:name`), name,
                                           quote(`:id`), 0,
                                           quote(`:value`),
@@ -519,7 +523,7 @@ withRetryRestart <- function(description, expr) {
                                                               envir=globalenv()))) })
   output <- paste(output, sep="", collapse="\n")
   if(tmp$visible) {
-    list(output, prin1ToString(value))
+    list(output, prin1ToString(tmp$value))
   } else {
     list(output, "# invisible value")
   }
@@ -529,7 +533,7 @@ withRetryRestart <- function(description, expr) {
   withRetryRestart("retry SLIME interactive evaluation request",
                    tmp <- withVisible(eval(parse(text=string), envir=globalenv())))
   if(tmp$visible) {
-    prin1ToString(value)
+    prin1ToString(tmp$value)
   } else {
     "# invisible value"
   }