From: Christophe Rhodes Date: Tue, 7 Sep 2010 07:38:19 +0000 (+0100) Subject: implement withRetryRestart X-Git-Url: http://christophe.rhodes.io/gitweb/?a=commitdiff_plain;h=de8519735fa924b327c5720d9e8efc2dadc834c4;p=swankr.git implement withRetryRestart Use it in swank:interactive-eval and swank:eval-and-grab-output --- diff --git a/swank.R b/swank.R index a826c7a..22dd532 100644 --- 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)) }