Next: , Previous: Defining Advice, Up: Advising Functions


17.3 Around-Advice

Around-advice lets you “wrap” a Lisp expression “around” the original function definition. You specify where the original function definition should go by means of the special symbol ad-do-it. Where this symbol occurs inside the around-advice body, it is replaced with a progn containing the forms of the surrounded code. Here is an example:

     (defadvice foo (around foo-around)
       "Ignore case in `foo'."
       (let ((case-fold-search t))
         ad-do-it))

Its effect is to make sure that case is ignored in searches when the original definition of foo is run.

— Variable: ad-do-it

This is not really a variable, but it is somewhat used like one in around-advice. It specifies the place to run the function's original definition and other “earlier” around-advice.

If the around-advice does not use ad-do-it, then it does not run the original function definition. This provides a way to override the original definition completely. (It also overrides lower-positioned pieces of around-advice).

If the around-advice uses ad-do-it more than once, the original definition is run at each place. In this way, around-advice can execute the original definition (and lower-positioned pieces of around-advice) several times. Another way to do that is by using ad-do-it inside of a loop.