Two solutions:
- Use
ad-add-advice
instead ofdefadvice
. - If you're using Emacs trunk, you can use the new
advice-add
.
Using advice-add
would look like the following code:
(defun my-check-commented-parens (orig-fun &rest args)
(if (not (and (called-interactively-p 'any)
(use-region-p)))
(apply orig-fun args)
(my-check-parens-and-warn-if-mismatch "You commented out a region and introduced a mismatched paren")
(apply orig-fun args)
(my-check-parens-and-warn-if-mismatch "You uncommented out a region and introduced a mismatched paren")))
(dolist (command '(paredit-comment-dwim comment-dwim))
(advice-add command :around #'my-check-commented-parens))