[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

17. Advising Emacs Lisp Functions

The advice feature lets you add to the existing definition of a function, by advising the function. This is a cleaner method for a library to customize functions defined within Emacs—cleaner than redefining the whole function.

Each function can have multiple pieces of advice, separately defined. Each defined piece of advice can be enabled or disabled explicitly. All the enabled pieces of advice for any given function actually take effect when you activate advice for that function, or when you define or redefine the function. Note that enabling a piece of advice and activating advice for a function are not the same thing.

Usage Note: Advice is useful for altering the behavior of existing calls to an existing function. If you want the new behavior for new calls, or for key bindings, you should define a new function (or a new command) which uses the existing function.

Usage note: Advising a function can cause confusion in debugging, since people who debug calls to the original function may not notice that it has been modified with advice. Therefore, if you have the possibility to change the code of that function (or ask someone to do so) to run a hook, please solve the problem that way. Advice should be reserved for the cases where you cannot get the function changed.

In particular, this means that a file in Emacs should not put advice on a function in Emacs. There are currently a few exceptions to this convention, but we aim to correct them.


[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.