--- /dev/null
+presentationCounter <- 0
+
+savePresentedObject <- function(slimeConnection, value) {
+ if(!exists("idToObject", envir=slimeConnection)) {
+ assign("idToObject", new.env(), envir=slimeConnection)
+ }
+ presentationCounter <<- presentationCounter + 1
+ assign(as.character(presentationCounter), value, envir=slimeConnection$idToObject)
+ presentationCounter
+}
+
+presentReplResult <- function(slimeConnection, value) {
+ id <- savePresentedObject(slimeConnection, value)
+ sendToEmacs(slimeConnection,
+ list(quote(`:presentation-start`), id, quote(`:repl-result`)))
+ sendReplResult(slimeConnection, value)
+ sendToEmacs(slimeConnection,
+ list(quote(`:presentation-end`), id, quote(`:repl-result`)))
+ sendToEmacs(slimeConnection,
+ list(quote(`:write-string`), "\n", quote(`:repl-result`)))
+}
+
+sendReplResultFunction <- presentReplResult
+
+`cl:nth-value` <- function(slimeConnection, sldbState, n, values) {
+ values[[n+1]]
+}
+
+`swank:lookup-presented-object` <- function(slimeConnection, sldbState, id) {
+ str(ls(slimeConnection))
+ if(exists(as.character(id), envir=slimeConnection$idToObject)) {
+ value <- get(as.character(id), envir=slimeConnection$idToObject)
+ list(value, TRUE)
+ } else {
+ list(FALSE, FALSE)
+ }
+}
+
+`swank:lookup-presented-object-or-lose` <- function(slimeConnection, sldbState, id) {
+ stuff <- `swank:lookup-presented-object`(slimeConnection, sldbState, id)
+ if(stuff[[2]]) {
+ stuff[[1]]
+ } else {
+ stop(sprintf("attempt to access unrecorded object (id %d)", id))
+ }
+}
+
list("R", "R")
}
+sendReplResult <- function(slimeConnection, value) {
+ string <- printToString(value)
+ sendToEmacs(slimeConnection,
+ list(quote(`:write-string`),
+ paste(string, collapse="\n"),
+ quote(`:repl-result`)))
+}
+
+sendReplResultFunction <- sendReplResult
+
`swank:listener-eval` <- function(slimeConnection, sldbState, string) {
- val <- eval(parse(text=string), envir = globalenv())
- string <- printToString(val)
- sendToEmacs(slimeConnection, list(quote(`:write-string`), paste(string, collapse="\n"), quote(`:repl-result`)))
+ string <- gsub("#\\.\\(swank:lookup-presented-object-or-lose([^)]*)\\)", ".(`swank:lookup-presented-object-or-lose`(slimeConnection, sldbState,\\1))", string)
+ expr <- parse(text=string)[[1]]
+ lookedup <- do.call("bquote", list(expr))
+ value <- eval(lookedup, envir = globalenv())
+ sendReplResultFunction(slimeConnection, value)
list()
}