By default, advice does not take effect when you define it--only when
you activate advice for the function that was advised. You can
request the activation of advice for a function when you define the
advice, by specifying the activate
flag in the defadvice
.
But normally you activate the advice for a function by calling the
function ad-activate
or one of the other activation commands
listed below.
Separating the activation of advice from the act of defining it permits you to add several pieces of advice to one function efficiently, without redefining the function over and over as each advice is added. More importantly, it permits defining advice for a function before that function is actually defined.
When a function's advice is first activated, the function's original definition is saved, and all enabled pieces of advice for that function are combined with the original definition to make a new definition. (Pieces of advice that are currently disabled are not used; see section Enabling and Disabling Advice.) This definition is installed, and optionally byte-compiled as well, depending on conditions described below.
In all of the commands to activate advice, if compile is t
,
the command also compiles the combined definition which implements the
advice.
To activate advice for a function whose advice is already active is not a no-op. It is a useful operation which puts into effect any changes in that function's advice since the previous activation of advice for that function.
Reactivating a function's advice is useful for putting into effect all the changes that have been made in its advice (including enabling and disabling specific pieces of advice; see section Enabling and Disabling Advice) since the last time it was activated.
If the advised definition was constructed during "preactivation"
(see section Preactivation), then that definition must already be compiled,
because it was constructed during byte-compilation of the file that
contained the defadvice
with the preactivate
flag.
Go to the first, previous, next, last section, table of contents.