Skip to content

Instantly share code, notes, and snippets.

@mpontus
Created April 24, 2015 09:43
Show Gist options
  • Save mpontus/b6d848559ddb450ffd37 to your computer and use it in GitHub Desktop.
Save mpontus/b6d848559ddb450ffd37 to your computer and use it in GitHub Desktop.
(defmacro ecukes-recurse-catch (symbols &rest body)
"Catch on entry to SYMBOLS during execution of BODY."
(letrec ((value (make-symbol "thrown-value"))
(function (lambda () (throw value nil)))
(fnsym (make-symbol "advice")) (unwind))
`(let ((,fnsym ,function))
,@(mapcar (lambda (symbol)
(prog1 `(advice-add ',symbol :override ,fnsym)
(push `(remove-advice ',symbol ,fnsym) unwind)))
(if (listp symbols) symbols (list symbols)))
(unwind-protect (catch ,value ,@body) ,unwind))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment