From de8519735fa924b327c5720d9e8efc2dadc834c4 Mon Sep 17 00:00:00 2001 From: Christophe Rhodes Date: Tue, 7 Sep 2010 08:38:19 +0100 Subject: [PATCH] implement withRetryRestart Use it in swank:interactive-eval and swank:eval-and-grab-output --- swank.R | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) 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)) } -- 2.39.5