I sometimes want to bypass the advice I have defined on some function. Something like:
(call-without-advice #'fn ...)
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
I can't find a public interface for that. In Emacs 25.5 and Emacs 27.1 and presumably every version in between (I haven't checked older or more recent versions), for new-style advice (
nadvice.el), you can use
(advice--cd*r (symbol-function #'fn))
For old-style advice (
I've thought about this before, and there's a less-than-perfect solution:
you need to store the original definition before any
(defun f () (insert "233\n")) (setq f.backup (symbol-function 'f)) (advice-add 'f :around (lambda (fobj &rest args) (insert (format "eq?: %s\n" (eq f.backup fobj))) (apply fobj args)))
It is also convenient to store the definition in symbol-plist.
(advice-add 'advice-add :before (lambda (symbol &rest _) (unless (get symbol :shynur/original-definition) (put symbol :shynur/original-definition (symbol-function symbol))))) (defun call-without-advice (symbol &rest arguments) (apply (or (get symbol :shynur/original-definition) symbol) arguments))
looks much better now.