diff --git a/core/core-lib.el b/core/core-lib.el index 95e8f618c..a35393d1f 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -424,5 +424,23 @@ DOCSTRING and BODY are as in `defun'. (dolist (target (cdr targets)) (advice-add target (car targets) #',symbol)))))) +(defmacro undefadvice! (symbol _arglist &optional docstring &rest body) + "Undefine an advice called SYMBOL. + +This has the same signature as `defadvice!' an exists as an easy undefiner when +testing advice (when combined with `rotate-text'). + +\(fn SYMBOL ARGLIST &optional DOCSTRING &rest [WHERE PLACES...] BODY\)" + (declare (doc-string 3) (indent defun)) + (let (where-alist) + (unless (stringp docstring) + (push docstring body)) + (while (keywordp (car body)) + (push `(cons ,(pop body) (doom-enlist ,(pop body))) + where-alist)) + `(dolist (targets (list ,@(nreverse where-alist))) + (dolist (target (cdr targets)) + (advice-remove target #',symbol))))) + (provide 'core-lib) ;;; core-lib.el ends here diff --git a/modules/lang/emacs-lisp/config.el b/modules/lang/emacs-lisp/config.el index a4224cf09..2623a04ab 100644 --- a/modules/lang/emacs-lisp/config.el +++ b/modules/lang/emacs-lisp/config.el @@ -31,6 +31,7 @@ This marks a foldable marker for `outline-minor-mode' in elisp buffers.") ("let" "let*") ("when" "unless") ("advice-add" "advice-remove") + ("defadvice!" "undefadvice!") ("add-hook" "remove-hook") ("add-hook!" "remove-hook!") ("it" "xit")