X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/blobdiff_plain/17c7c784e0632dff2f93a69a837585fd6f31f4a1..2bc73f786f7dc35ecff3e1484a6376aae1de4962:/src/utilities.lisp diff --git a/src/utilities.lisp b/src/utilities.lisp index 0415a90..0f6a54b 100644 --- a/src/utilities.lisp +++ b/src/utilities.lisp @@ -972,6 +972,30 @@ (defun designated-condition (default-type datum arguments (t (error "Unexpected condition designator datum ~S" datum)))) +(export 'simple-control-error) +(define-condition simple-control-error (control-error simple-error) + ()) + +(export 'invoke-associated-restart) +(defun invoke-associated-restart (restart condition &rest arguments) + "Invoke the active RESTART associated with CONDITION, with the ARGUMENTS. + + Find an active restart designated by RESTART; if CONDITION is not nil, + then restrict the search to restarts associated with CONDITION, and + restarts not associated with any condition. If no such restart is found + then signal an error of type `control-error'; otherwise invoke the restart + with the given ARGUMENTS." + (apply #'invoke-restart + (or (find-restart restart condition) + (error 'simple-control-error + :format-control "~:[Restart ~S is not active~;~ + No active `~(~A~)' restart~]~ + ~@[ for condition ~S~]" + :format-arguments (list (symbolp restart) + restart + condition))) + arguments)) + ;;;-------------------------------------------------------------------------- ;;; CLOS hacking.