]> rhodes.io Git - swankr.git/commitdiff
Christophe Weblog Wiki Code Publications Music
implement withRetryRestart
authorChristophe Rhodes <csr21@cantab.net>
Tue, 7 Sep 2010 07:38:19 +0000 (08:38 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Tue, 7 Sep 2010 07:38:19 +0000 (08:38 +0100)
Use it in swank:interactive-eval and swank:eval-and-grab-output

swank.R

diff --git a/swank.R b/swank.R
index a826c7a7a250115a88e8dc8ace283bf7da9a035c..22dd53286c467fc02abb8a162e942fb04f10c5d8 100644 (file)
--- a/swank.R
+++ b/swank.R
@@ -401,25 +401,28 @@ computeRestartsForEmacs <- function (sldbState) {
   list(quote(`:compilation-result`), list(), TRUE, times[3])
 }
 
-`swank:interactive-eval` <-  function(slimeConnection, sldbState, string) {
+withRetryRestart <- function(description, expr) {
+  call <- substitute(expr)
   retry <- TRUE
-  value <- ""
   while(retry) {
     retry <- FALSE
-    withRestarts(value <- eval(parse(text=string), envir = globalenv()),
-                 retry=list(description="retry SLIME interactive evaluation request", handler=function() retry <<- TRUE))
+    withRestarts(eval.parent(call),
+                 retry=list(description=description,
+                   handler=function() retry <<- TRUE))
   }
+}
+
+`swank:interactive-eval` <-  function(slimeConnection, sldbState, string) {
+  withRetryRestart("retry SLIME interactive evaluation request",
+                   value <- eval(parse(text=string), envir=globalenv()))
   printToString(value)
 }
 
 `swank:eval-and-grab-output` <- function(slimeConnection, sldbState, string) {
-  retry <- TRUE
-  value <- ""
-  output <-
-    withOutputToString(while(retry) {
-      retry <- FALSE
-      withRestarts(value <- eval(parse(text=string), envir = globalenv()),
-                   retry=list(description="retry SLIME interactive evaluation request", handler=function() retry <<- TRUE))})
+  withRetryRestart("retry SLIME interactive evaluation request",
+                   { output <-
+                       withOutputToString(value <- eval(parse(text=string),
+                                                        envir=globalenv())) })
   list(output, printToString(value))
 }