How to have advice not execute the function when conditions are met?

258 views Asked by At

How do you prevent the advised function from running when the advice returns nil?

(defadvice beginning-of-line (before test activate)
 nil)

-> Not running beginning-of-line at all.

EDIT: Just to take away your worries, I do not intend to use it on beginning-of-line.

1

There are 1 answers

9
Lindydancer On BEST ANSWER

You can use an around advice, as is:

(defadvice foo (around test activate)
  (if my-test
      ad-do-it))

The construct ad-do-it corresponds to running the original function.