diff options
| author | Stefan Monnier | 2014-01-10 14:40:32 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2014-01-10 14:40:32 -0500 |
| commit | 122ff675df692bab3b5b6409044b0f0e66bad82f (patch) | |
| tree | 347d4d63e9037fb74c324319de223b23cf00d399 /doc | |
| parent | cd6d07ece2278b315852e20f07cfea05bd5bd29b (diff) | |
| download | emacs-122ff675df692bab3b5b6409044b0f0e66bad82f.tar.gz emacs-122ff675df692bab3b5b6409044b0f0e66bad82f.zip | |
* doc/lispref/functions.texi (Advising Functions): New section.
* doc/lispref/modes.texi (Running Hooks): Don't document with-wrapper-hook and
run-hook-wrapped any more.
(Hooks): Link to the new Advising Functions node.
* doc/lispref/elisp.texi (Top): Don't include advice.texi.
* doc/lispref/advice.texi: Remove.
* doc/lispref/makefile.w32-in (srcs):
* doc/lispref/Makefile.in (srcs): Adjust accordingly.
* doc/misc/cl.texi (Function Bindings): Fix incorrect description of cl-let.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/ChangeLog | 11 | ||||
| -rw-r--r-- | doc/lispref/Makefile.in | 1 | ||||
| -rw-r--r-- | doc/lispref/advice.texi | 749 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 15 | ||||
| -rw-r--r-- | doc/lispref/functions.texi | 274 | ||||
| -rw-r--r-- | doc/lispref/makefile.w32-in | 1 | ||||
| -rw-r--r-- | doc/lispref/modes.texi | 51 | ||||
| -rw-r--r-- | doc/misc/ChangeLog | 88 | ||||
| -rw-r--r-- | doc/misc/cl.texi | 9 |
9 files changed, 333 insertions, 866 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 2963ffc9a60..38427e56b9b 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2014-01-10 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * functions.texi (Advising Functions): New section. | ||
| 4 | * modes.texi (Running Hooks): Don't document with-wrapper-hook and | ||
| 5 | run-hook-wrapped any more. | ||
| 6 | (Hooks): Link to the new Advising Functions node. | ||
| 7 | * elisp.texi (Top): Don't include advice.texi. | ||
| 8 | * advice.texi: Remove. | ||
| 9 | * makefile.w32-in (srcs): | ||
| 10 | * Makefile.in (srcs): Adjust accordingly. | ||
| 11 | |||
| 1 | 2014-01-09 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de> | 12 | 2014-01-09 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de> |
| 2 | 13 | ||
| 3 | * text.texi (Parsing HTML/XML): Document `shr-insert-document'. | 14 | * text.texi (Parsing HTML/XML): Document `shr-insert-document'. |
diff --git a/doc/lispref/Makefile.in b/doc/lispref/Makefile.in index 6f3320d029c..bb8d4f82884 100644 --- a/doc/lispref/Makefile.in +++ b/doc/lispref/Makefile.in | |||
| @@ -76,7 +76,6 @@ srcs = \ | |||
| 76 | $(srcdir)/elisp.texi \ | 76 | $(srcdir)/elisp.texi \ |
| 77 | $(emacsdir)/emacsver.texi \ | 77 | $(emacsdir)/emacsver.texi \ |
| 78 | $(srcdir)/abbrevs.texi \ | 78 | $(srcdir)/abbrevs.texi \ |
| 79 | $(srcdir)/advice.texi \ | ||
| 80 | $(srcdir)/anti.texi \ | 79 | $(srcdir)/anti.texi \ |
| 81 | $(srcdir)/backups.texi \ | 80 | $(srcdir)/backups.texi \ |
| 82 | $(srcdir)/buffers.texi \ | 81 | $(srcdir)/buffers.texi \ |
diff --git a/doc/lispref/advice.texi b/doc/lispref/advice.texi deleted file mode 100644 index c55f93d445f..00000000000 --- a/doc/lispref/advice.texi +++ /dev/null | |||
| @@ -1,749 +0,0 @@ | |||
| 1 | @c -*-texinfo-*- | ||
| 2 | @c This is part of the GNU Emacs Lisp Reference Manual. | ||
| 3 | @c Copyright (C) 1998-1999, 2001-2014 Free Software Foundation, Inc. | ||
| 4 | @c See the file elisp.texi for copying conditions. | ||
| 5 | @node Advising Functions | ||
| 6 | @chapter Advising Emacs Lisp Functions | ||
| 7 | @cindex advising functions | ||
| 8 | |||
| 9 | @cindex piece of advice | ||
| 10 | The @dfn{advice} feature lets you add to the existing definition of | ||
| 11 | a function, by @dfn{advising the function}. A function can have | ||
| 12 | multiple @dfn{pieces of advice}, each of which can be separately | ||
| 13 | defined, and separately enabled or disabled (@pxref{Activation of | ||
| 14 | Advice}). Each piece of advice can alter almost anything about the | ||
| 15 | function, including its argument list, what the function does when it | ||
| 16 | runs, and the value it returns. | ||
| 17 | |||
| 18 | Advice can be useful for altering the behavior of an existing | ||
| 19 | function without having to redefine the whole function. However, it | ||
| 20 | can be a source of bugs, since existing callers to the function may | ||
| 21 | assume the old behavior, and work incorrectly when the behavior is | ||
| 22 | changed by advice. Advice can also cause confusion in debugging, if | ||
| 23 | the person doing the debugging does not notice or remember that the | ||
| 24 | function has been modified by advice. | ||
| 25 | |||
| 26 | For these reasons, advice should be reserved for the cases where you | ||
| 27 | cannot modify a function's behavior in any other way. If it is | ||
| 28 | possible to do the same thing via a hook, that is preferable | ||
| 29 | (@pxref{Hooks}). If you simply want to change what a particular key | ||
| 30 | does, it may be better to write a new command, and remap the old | ||
| 31 | command's key bindings to the new one (@pxref{Remapping Commands}). | ||
| 32 | In particular, Emacs's own source files should not put advice on | ||
| 33 | functions in Emacs. (There are currently a few exceptions to this | ||
| 34 | convention, but we aim to correct them.) | ||
| 35 | |||
| 36 | Macros can also be advised, in much the same way as functions. | ||
| 37 | However, special forms (@pxref{Special Forms}) cannot be advised. | ||
| 38 | |||
| 39 | It is possible to advise a primitive (@pxref{What Is a Function}), | ||
| 40 | but one should typically @emph{not} do so, for two reasons. Firstly, | ||
| 41 | some primitives are used by the advice mechanism, and advising them | ||
| 42 | could cause an infinite recursion. Secondly, many primitives are | ||
| 43 | called directly from C, and such calls ignore advice; hence, one ends | ||
| 44 | up in a confusing situation where some calls (occurring from Lisp | ||
| 45 | code) obey the advice and other calls (from C code) do not. | ||
| 46 | |||
| 47 | @menu | ||
| 48 | * Simple Advice:: A simple example to explain the basics of advice. | ||
| 49 | * Defining Advice:: Detailed description of @code{defadvice}. | ||
| 50 | * Around-Advice:: Wrapping advice around a function's definition. | ||
| 51 | * Computed Advice:: ...is to @code{defadvice} as @code{fset} is to @code{defun}. | ||
| 52 | * Activation of Advice:: Advice doesn't do anything until you activate it. | ||
| 53 | * Enabling Advice:: You can enable or disable each piece of advice. | ||
| 54 | * Preactivation:: Preactivation is a way of speeding up the | ||
| 55 | loading of compiled advice. | ||
| 56 | * Argument Access in Advice:: How advice can access the function's arguments. | ||
| 57 | * Combined Definition:: How advice is implemented. | ||
| 58 | @end menu | ||
| 59 | |||
| 60 | @node Simple Advice | ||
| 61 | @section A Simple Advice Example | ||
| 62 | |||
| 63 | The command @code{next-line} moves point down vertically one or more | ||
| 64 | lines; it is the standard binding of @kbd{C-n}. When used on the last | ||
| 65 | line of the buffer, this command inserts a newline to create a line to | ||
| 66 | move to if @code{next-line-add-newlines} is non-@code{nil} (its default | ||
| 67 | is @code{nil}.) | ||
| 68 | |||
| 69 | Suppose you wanted to add a similar feature to @code{previous-line}, | ||
| 70 | which would insert a new line at the beginning of the buffer for the | ||
| 71 | command to move to (when @code{next-line-add-newlines} is | ||
| 72 | non-@code{nil}). How could you do this? | ||
| 73 | |||
| 74 | You could do it by redefining the whole function, but that is not | ||
| 75 | modular. The advice feature provides a cleaner alternative: you can | ||
| 76 | effectively add your code to the existing function definition, without | ||
| 77 | actually changing or even seeing that definition. Here is how to do | ||
| 78 | this: | ||
| 79 | |||
| 80 | @example | ||
| 81 | (defadvice previous-line (before next-line-at-end | ||
| 82 | (&optional arg try-vscroll)) | ||
| 83 | "Insert an empty line when moving up from the top line." | ||
| 84 | (if (and next-line-add-newlines (= arg 1) | ||
| 85 | (save-excursion (beginning-of-line) (bobp))) | ||
| 86 | (progn | ||
| 87 | (beginning-of-line) | ||
| 88 | (newline)))) | ||
| 89 | @end example | ||
| 90 | |||
| 91 | This expression defines a @dfn{piece of advice} for the function | ||
| 92 | @code{previous-line}. This piece of advice is named | ||
| 93 | @code{next-line-at-end}, and the symbol @code{before} says that it is | ||
| 94 | @dfn{before-advice} which should run before the regular definition of | ||
| 95 | @code{previous-line}. @code{(&optional arg try-vscroll)} specifies | ||
| 96 | how the advice code can refer to the function's arguments. | ||
| 97 | |||
| 98 | When this piece of advice runs, it creates an additional line, in the | ||
| 99 | situation where that is appropriate, but does not move point to that | ||
| 100 | line. This is the correct way to write the advice, because the normal | ||
| 101 | definition will run afterward and will move back to the newly inserted | ||
| 102 | line. | ||
| 103 | |||
| 104 | Defining the advice doesn't immediately change the function | ||
| 105 | @code{previous-line}. That happens when you @dfn{activate} the advice, | ||
| 106 | like this: | ||
| 107 | |||
| 108 | @example | ||
| 109 | (ad-activate 'previous-line) | ||
| 110 | @end example | ||
| 111 | |||
| 112 | @noindent | ||
| 113 | This is what actually begins to use the advice that has been defined so | ||
| 114 | far for the function @code{previous-line}. Henceforth, whenever that | ||
| 115 | function is run, whether invoked by the user with @kbd{C-p} or | ||
| 116 | @kbd{M-x}, or called from Lisp, it runs the advice first, and its | ||
| 117 | regular definition second. | ||
| 118 | |||
| 119 | This example illustrates before-advice, which is one @dfn{class} of | ||
| 120 | advice: it runs before the function's base definition. There are two | ||
| 121 | other advice classes: @dfn{after-advice}, which runs after the base | ||
| 122 | definition, and @dfn{around-advice}, which lets you specify an | ||
| 123 | expression to wrap around the invocation of the base definition. | ||
| 124 | |||
| 125 | @node Defining Advice | ||
| 126 | @section Defining Advice | ||
| 127 | @cindex defining advice | ||
| 128 | @cindex advice, defining | ||
| 129 | |||
| 130 | To define a piece of advice, use the macro @code{defadvice}. A call | ||
| 131 | to @code{defadvice} has the following syntax, which is based on the | ||
| 132 | syntax of @code{defun} and @code{defmacro}, but adds more: | ||
| 133 | |||
| 134 | @findex defadvice | ||
| 135 | @example | ||
| 136 | (defadvice @var{function} (@var{class} @var{name} | ||
| 137 | @r{[}@var{position}@r{]} @r{[}@var{arglist}@r{]} | ||
| 138 | @var{flags}...) | ||
| 139 | @r{[}@var{documentation-string}@r{]} | ||
| 140 | @r{[}@var{interactive-form}@r{]} | ||
| 141 | @var{body-forms}...) | ||
| 142 | @end example | ||
| 143 | |||
| 144 | @noindent | ||
| 145 | Here, @var{function} is the name of the function (or macro) to be | ||
| 146 | advised. From now on, we will write just ``function'' when describing | ||
| 147 | the entity being advised, but this always includes macros. | ||
| 148 | |||
| 149 | In place of the argument list in an ordinary definition, an advice | ||
| 150 | definition calls for several different pieces of information. | ||
| 151 | |||
| 152 | @cindex class of advice | ||
| 153 | @cindex before-advice | ||
| 154 | @cindex after-advice | ||
| 155 | @cindex around-advice | ||
| 156 | @var{class} specifies the @dfn{class} of the advice---one of @code{before}, | ||
| 157 | @code{after}, or @code{around}. Before-advice runs before the function | ||
| 158 | itself; after-advice runs after the function itself; around-advice is | ||
| 159 | wrapped around the execution of the function itself. After-advice and | ||
| 160 | around-advice can override the return value by setting | ||
| 161 | @code{ad-return-value}. | ||
| 162 | |||
| 163 | @defvar ad-return-value | ||
| 164 | While advice is executing, after the function's original definition has | ||
| 165 | been executed, this variable holds its return value, which will | ||
| 166 | ultimately be returned to the caller after finishing all the advice. | ||
| 167 | After-advice and around-advice can arrange to return some other value | ||
| 168 | by storing it in this variable. | ||
| 169 | @end defvar | ||
| 170 | |||
| 171 | The argument @var{name} is the name of the advice, a non-@code{nil} | ||
| 172 | symbol. The advice name uniquely identifies one piece of advice, within all | ||
| 173 | the pieces of advice in a particular class for a particular | ||
| 174 | @var{function}. The name allows you to refer to the piece of | ||
| 175 | advice---to redefine it, or to enable or disable it. | ||
| 176 | |||
| 177 | The optional @var{position} specifies where, in the current list of | ||
| 178 | advice of the specified @var{class}, this new advice should be placed. | ||
| 179 | It should be either @code{first}, @code{last} or a number that specifies | ||
| 180 | a zero-based position (@code{first} is equivalent to 0). If no position | ||
| 181 | is specified, the default is @code{first}. Position values outside the | ||
| 182 | range of existing positions in this class are mapped to the beginning or | ||
| 183 | the end of the range, whichever is closer. The @var{position} value is | ||
| 184 | ignored when redefining an existing piece of advice. | ||
| 185 | |||
| 186 | The optional @var{arglist} can be used to define the argument list for | ||
| 187 | the sake of advice. This becomes the argument list of the combined | ||
| 188 | definition that is generated in order to run the advice (@pxref{Combined | ||
| 189 | Definition}). Therefore, the advice expressions can use the argument | ||
| 190 | variables in this list to access argument values. | ||
| 191 | |||
| 192 | The argument list used in advice need not be the same as the argument | ||
| 193 | list used in the original function, but must be compatible with it, so | ||
| 194 | that it can handle the ways the function is actually called. If two | ||
| 195 | pieces of advice for a function both specify an argument list, they must | ||
| 196 | specify the same argument list. | ||
| 197 | |||
| 198 | @xref{Argument Access in Advice}, for more information about argument | ||
| 199 | lists and advice, and a more flexible way for advice to access the | ||
| 200 | arguments. | ||
| 201 | |||
| 202 | The remaining elements, @var{flags}, are symbols that specify further | ||
| 203 | information about how to use this piece of advice. Here are the valid | ||
| 204 | symbols and their meanings: | ||
| 205 | |||
| 206 | @table @code | ||
| 207 | @item activate | ||
| 208 | Activate the advice for @var{function} now. Changes in a function's | ||
| 209 | advice always take effect the next time you activate advice for the | ||
| 210 | function; this flag says to do so, for @var{function}, immediately after | ||
| 211 | defining this piece of advice. | ||
| 212 | |||
| 213 | @cindex forward advice | ||
| 214 | This flag has no immediate effect if @var{function} itself is not defined yet (a | ||
| 215 | situation known as @dfn{forward advice}), because it is impossible to | ||
| 216 | activate an undefined function's advice. However, defining | ||
| 217 | @var{function} will automatically activate its advice. | ||
| 218 | |||
| 219 | @item protect | ||
| 220 | Protect this piece of advice against non-local exits and errors in | ||
| 221 | preceding code and advice. Protecting advice places it as a cleanup in | ||
| 222 | an @code{unwind-protect} form, so that it will execute even if the | ||
| 223 | previous code gets an error or uses @code{throw}. @xref{Cleanups}. | ||
| 224 | |||
| 225 | @item compile | ||
| 226 | Compile the combined definition that is used to run the advice. This | ||
| 227 | flag is ignored unless @code{activate} is also specified. | ||
| 228 | @xref{Combined Definition}. | ||
| 229 | |||
| 230 | @item disable | ||
| 231 | Initially disable this piece of advice, so that it will not be used | ||
| 232 | unless subsequently explicitly enabled. @xref{Enabling Advice}. | ||
| 233 | |||
| 234 | @item preactivate | ||
| 235 | Activate advice for @var{function} when this @code{defadvice} is | ||
| 236 | compiled or macroexpanded. This generates a compiled advised definition | ||
| 237 | according to the current advice state, which will be used during | ||
| 238 | activation if appropriate. @xref{Preactivation}. | ||
| 239 | |||
| 240 | This is useful only if this @code{defadvice} is byte-compiled. | ||
| 241 | @end table | ||
| 242 | |||
| 243 | The optional @var{documentation-string} serves to document this piece of | ||
| 244 | advice. When advice is active for @var{function}, the documentation for | ||
| 245 | @var{function} (as returned by @code{documentation}) combines the | ||
| 246 | documentation strings of all the advice for @var{function} with the | ||
| 247 | documentation string of its original function definition. | ||
| 248 | |||
| 249 | The optional @var{interactive-form} form can be supplied to change the | ||
| 250 | interactive behavior of the original function. If more than one piece | ||
| 251 | of advice has an @var{interactive-form}, then the first one (the one | ||
| 252 | with the smallest position) found among all the advice takes precedence. | ||
| 253 | |||
| 254 | The possibly empty list of @var{body-forms} specifies the body of the | ||
| 255 | advice. The body of an advice can access or change the arguments, the | ||
| 256 | return value, the binding environment, and perform any other kind of | ||
| 257 | side effect. | ||
| 258 | |||
| 259 | @strong{Warning:} When you advise a macro, keep in mind that macros are | ||
| 260 | expanded when a program is compiled, not when a compiled program is run. | ||
| 261 | All subroutines used by the advice need to be available when the byte | ||
| 262 | compiler expands the macro. | ||
| 263 | |||
| 264 | @deffn Command ad-unadvise function | ||
| 265 | This command deletes all pieces of advice from @var{function}. | ||
| 266 | @end deffn | ||
| 267 | |||
| 268 | @deffn Command ad-unadvise-all | ||
| 269 | This command deletes all pieces of advice from all functions. | ||
| 270 | @end deffn | ||
| 271 | |||
| 272 | @node Around-Advice | ||
| 273 | @section Around-Advice | ||
| 274 | |||
| 275 | Around-advice lets you ``wrap'' a Lisp expression ``around'' the | ||
| 276 | original function definition. You specify where the original function | ||
| 277 | definition should go by means of the special symbol @code{ad-do-it}. | ||
| 278 | Where this symbol occurs inside the around-advice body, it is replaced | ||
| 279 | with a @code{progn} containing the forms of the surrounded code. Here | ||
| 280 | is an example: | ||
| 281 | |||
| 282 | @example | ||
| 283 | (defadvice foo (around foo-around) | ||
| 284 | "Ignore case in `foo'." | ||
| 285 | (let ((case-fold-search t)) | ||
| 286 | ad-do-it)) | ||
| 287 | @end example | ||
| 288 | |||
| 289 | @noindent | ||
| 290 | Its effect is to make sure that case is ignored in | ||
| 291 | searches when the original definition of @code{foo} is run. | ||
| 292 | |||
| 293 | @defvar ad-do-it | ||
| 294 | This is not really a variable, rather a place-holder that looks like a | ||
| 295 | variable. You use it in around-advice to specify the place to run the | ||
| 296 | function's original definition and other ``earlier'' around-advice. | ||
| 297 | @end defvar | ||
| 298 | |||
| 299 | If the around-advice does not use @code{ad-do-it}, then it does not run | ||
| 300 | the original function definition. This provides a way to override the | ||
| 301 | original definition completely. (It also overrides lower-positioned | ||
| 302 | pieces of around-advice). | ||
| 303 | |||
| 304 | If the around-advice uses @code{ad-do-it} more than once, the original | ||
| 305 | definition is run at each place. In this way, around-advice can execute | ||
| 306 | the original definition (and lower-positioned pieces of around-advice) | ||
| 307 | several times. Another way to do that is by using @code{ad-do-it} | ||
| 308 | inside of a loop. | ||
| 309 | |||
| 310 | @node Computed Advice | ||
| 311 | @section Computed Advice | ||
| 312 | |||
| 313 | The macro @code{defadvice} resembles @code{defun} in that the code for | ||
| 314 | the advice, and all other information about it, are explicitly stated in | ||
| 315 | the source code. You can also create advice whose details are computed, | ||
| 316 | using the function @code{ad-add-advice}. | ||
| 317 | |||
| 318 | @defun ad-add-advice function advice class position | ||
| 319 | Calling @code{ad-add-advice} adds @var{advice} as a piece of advice to | ||
| 320 | @var{function} in class @var{class}. The argument @var{advice} has | ||
| 321 | this form: | ||
| 322 | |||
| 323 | @example | ||
| 324 | (@var{name} @var{protected} @var{enabled} @var{definition}) | ||
| 325 | @end example | ||
| 326 | |||
| 327 | @noindent | ||
| 328 | Here, @var{protected} and @var{enabled} are flags; if @var{protected} | ||
| 329 | is non-@code{nil}, the advice is protected against non-local exits | ||
| 330 | (@pxref{Defining Advice}), and if @var{enabled} is @code{nil} the | ||
| 331 | advice is initially disabled (@pxref{Enabling Advice}). | ||
| 332 | @var{definition} should have the form | ||
| 333 | |||
| 334 | @example | ||
| 335 | (advice . @var{lambda}) | ||
| 336 | @end example | ||
| 337 | |||
| 338 | @noindent | ||
| 339 | where @var{lambda} is a lambda expression; this lambda expression is | ||
| 340 | called in order to perform the advice. @xref{Lambda Expressions}. | ||
| 341 | |||
| 342 | If the @var{function} argument to @code{ad-add-advice} already has one | ||
| 343 | or more pieces of advice in the specified @var{class}, then | ||
| 344 | @var{position} specifies where in the list to put the new piece of | ||
| 345 | advice. The value of @var{position} can either be @code{first}, | ||
| 346 | @code{last}, or a number (counting from 0 at the beginning of the | ||
| 347 | list). Numbers outside the range are mapped to the beginning or the | ||
| 348 | end of the range, whichever is closer. The @var{position} value is | ||
| 349 | ignored when redefining an existing piece of advice. | ||
| 350 | |||
| 351 | If @var{function} already has a piece of @var{advice} with the same | ||
| 352 | name, then the position argument is ignored and the old advice is | ||
| 353 | replaced with the new one. | ||
| 354 | @end defun | ||
| 355 | |||
| 356 | @node Activation of Advice | ||
| 357 | @section Activation of Advice | ||
| 358 | @cindex activating advice | ||
| 359 | @cindex advice, activating | ||
| 360 | |||
| 361 | By default, advice does not take effect when you define it---only when | ||
| 362 | you @dfn{activate} advice for the function. However, the advice will | ||
| 363 | be activated automatically if you define or redefine the function | ||
| 364 | later. You can request the activation of advice for a function when | ||
| 365 | you define the advice, by specifying the @code{activate} flag in the | ||
| 366 | @code{defadvice}; or you can activate the advice separately by calling | ||
| 367 | the function @code{ad-activate} or one of the other activation | ||
| 368 | commands listed below. | ||
| 369 | |||
| 370 | Separating the activation of advice from the act of defining it permits | ||
| 371 | you to add several pieces of advice to one function efficiently, without | ||
| 372 | redefining the function over and over as each advice is added. More | ||
| 373 | importantly, it permits defining advice for a function before that | ||
| 374 | function is actually defined. | ||
| 375 | |||
| 376 | When a function's advice is first activated, the function's original | ||
| 377 | definition is saved, and all enabled pieces of advice for that function | ||
| 378 | are combined with the original definition to make a new definition. | ||
| 379 | (Pieces of advice that are currently disabled are not used; see | ||
| 380 | @ref{Enabling Advice}.) This definition is installed, and optionally | ||
| 381 | byte-compiled as well, depending on conditions described below. | ||
| 382 | |||
| 383 | In all of the commands to activate advice, if @var{compile} is | ||
| 384 | @code{t} (or anything but @code{nil} or a negative number), the | ||
| 385 | command also compiles the combined definition which implements the | ||
| 386 | advice. If it is @code{nil} or a negative number, what happens | ||
| 387 | depends on @code{ad-default-compilation-action} as described below. | ||
| 388 | |||
| 389 | @deffn Command ad-activate function &optional compile | ||
| 390 | This command activates all the advice defined for @var{function}. | ||
| 391 | @end deffn | ||
| 392 | |||
| 393 | Activating advice does nothing if @var{function}'s advice is already | ||
| 394 | active. But if there is new advice, added since the previous time you | ||
| 395 | activated advice for @var{function}, it activates the new advice. | ||
| 396 | |||
| 397 | @deffn Command ad-deactivate function | ||
| 398 | This command deactivates the advice for @var{function}. | ||
| 399 | @cindex deactivating advice | ||
| 400 | @c @cindex advice, deactivating "advice, activating" is just above | ||
| 401 | @end deffn | ||
| 402 | |||
| 403 | @deffn Command ad-update function &optional compile | ||
| 404 | This command activates the advice for @var{function} | ||
| 405 | if its advice is already activated. This is useful | ||
| 406 | if you change the advice. | ||
| 407 | @end deffn | ||
| 408 | |||
| 409 | @deffn Command ad-activate-all &optional compile | ||
| 410 | This command activates the advice for all functions. | ||
| 411 | @end deffn | ||
| 412 | |||
| 413 | @deffn Command ad-deactivate-all | ||
| 414 | This command deactivates the advice for all functions. | ||
| 415 | @end deffn | ||
| 416 | |||
| 417 | @deffn Command ad-update-all &optional compile | ||
| 418 | This command activates the advice for all functions | ||
| 419 | whose advice is already activated. This is useful | ||
| 420 | if you change the advice of some functions. | ||
| 421 | @end deffn | ||
| 422 | |||
| 423 | @deffn Command ad-activate-regexp regexp &optional compile | ||
| 424 | This command activates all pieces of advice whose names match | ||
| 425 | @var{regexp}. More precisely, it activates all advice for any function | ||
| 426 | which has at least one piece of advice that matches @var{regexp}. | ||
| 427 | @end deffn | ||
| 428 | |||
| 429 | @deffn Command ad-deactivate-regexp regexp | ||
| 430 | This command deactivates all pieces of advice whose names match | ||
| 431 | @var{regexp}. More precisely, it deactivates all advice for any | ||
| 432 | function which has at least one piece of advice that matches | ||
| 433 | @var{regexp}. | ||
| 434 | @end deffn | ||
| 435 | |||
| 436 | @deffn Command ad-update-regexp regexp &optional compile | ||
| 437 | This command activates pieces of advice whose names match @var{regexp}, | ||
| 438 | but only those for functions whose advice is already activated. | ||
| 439 | @cindex reactivating advice | ||
| 440 | |||
| 441 | Reactivating a function's advice is useful for putting into effect all | ||
| 442 | the changes that have been made in its advice (including enabling and | ||
| 443 | disabling specific pieces of advice; @pxref{Enabling Advice}) since the | ||
| 444 | last time it was activated. | ||
| 445 | @end deffn | ||
| 446 | |||
| 447 | @deffn Command ad-start-advice | ||
| 448 | Turn on automatic advice activation when a function is defined or | ||
| 449 | redefined. This is the default mode. | ||
| 450 | @end deffn | ||
| 451 | |||
| 452 | @deffn Command ad-stop-advice | ||
| 453 | Turn off automatic advice activation when a function is defined or | ||
| 454 | redefined. | ||
| 455 | @end deffn | ||
| 456 | |||
| 457 | @defopt ad-default-compilation-action | ||
| 458 | This variable controls whether to compile the combined definition | ||
| 459 | that results from activating advice for a function. | ||
| 460 | |||
| 461 | A value of @code{always} specifies to compile unconditionally. | ||
| 462 | A value of @code{never} specifies never compile the advice. | ||
| 463 | |||
| 464 | A value of @code{maybe} specifies to compile if the byte compiler is | ||
| 465 | already loaded. A value of @code{like-original} specifies to compile | ||
| 466 | the advice if the original definition of the advised function is | ||
| 467 | compiled or a built-in function. | ||
| 468 | |||
| 469 | This variable takes effect only if the @var{compile} argument of | ||
| 470 | @code{ad-activate} (or any of the above functions) did not force | ||
| 471 | compilation. | ||
| 472 | @end defopt | ||
| 473 | |||
| 474 | If the advised definition was constructed during ``preactivation'' | ||
| 475 | (@pxref{Preactivation}), then that definition must already be compiled, | ||
| 476 | because it was constructed during byte-compilation of the file that | ||
| 477 | contained the @code{defadvice} with the @code{preactivate} flag. | ||
| 478 | |||
| 479 | @node Enabling Advice | ||
| 480 | @section Enabling and Disabling Advice | ||
| 481 | @cindex enabling advice | ||
| 482 | @cindex advice, enabling and disabling | ||
| 483 | @cindex disabling advice | ||
| 484 | |||
| 485 | Each piece of advice has a flag that says whether it is enabled or | ||
| 486 | not. By enabling or disabling a piece of advice, you can turn it on | ||
| 487 | and off without having to undefine and redefine it. For example, here is | ||
| 488 | how to disable a particular piece of advice named @code{my-advice} for | ||
| 489 | the function @code{foo}: | ||
| 490 | |||
| 491 | @example | ||
| 492 | (ad-disable-advice 'foo 'before 'my-advice) | ||
| 493 | @end example | ||
| 494 | |||
| 495 | This function by itself only changes the enable flag for a piece of | ||
| 496 | advice. To make the change take effect in the advised definition, you | ||
| 497 | must activate the advice for @code{foo} again: | ||
| 498 | |||
| 499 | @example | ||
| 500 | (ad-activate 'foo) | ||
| 501 | @end example | ||
| 502 | |||
| 503 | @deffn Command ad-disable-advice function class name | ||
| 504 | This command disables the piece of advice named @var{name} in class | ||
| 505 | @var{class} on @var{function}. | ||
| 506 | @end deffn | ||
| 507 | |||
| 508 | @deffn Command ad-enable-advice function class name | ||
| 509 | This command enables the piece of advice named @var{name} in class | ||
| 510 | @var{class} on @var{function}. | ||
| 511 | @end deffn | ||
| 512 | |||
| 513 | You can also disable many pieces of advice at once, for various | ||
| 514 | functions, using a regular expression. As always, the changes take real | ||
| 515 | effect only when you next reactivate advice for the functions in | ||
| 516 | question. | ||
| 517 | |||
| 518 | @deffn Command ad-disable-regexp regexp | ||
| 519 | This command disables all pieces of advice whose names match | ||
| 520 | @var{regexp}, in all classes, on all functions. | ||
| 521 | @end deffn | ||
| 522 | |||
| 523 | @deffn Command ad-enable-regexp regexp | ||
| 524 | This command enables all pieces of advice whose names match | ||
| 525 | @var{regexp}, in all classes, on all functions. | ||
| 526 | @end deffn | ||
| 527 | |||
| 528 | @node Preactivation | ||
| 529 | @section Preactivation | ||
| 530 | @cindex preactivating advice | ||
| 531 | @cindex advice, preactivating | ||
| 532 | |||
| 533 | Constructing a combined definition to execute advice is moderately | ||
| 534 | expensive. When a library advises many functions, this can make loading | ||
| 535 | the library slow. In that case, you can use @dfn{preactivation} to | ||
| 536 | construct suitable combined definitions in advance. | ||
| 537 | |||
| 538 | To use preactivation, specify the @code{preactivate} flag when you | ||
| 539 | define the advice with @code{defadvice}. This @code{defadvice} call | ||
| 540 | creates a combined definition which embodies this piece of advice | ||
| 541 | (whether enabled or not) plus any other currently enabled advice for the | ||
| 542 | same function, and the function's own definition. If the | ||
| 543 | @code{defadvice} is compiled, that compiles the combined definition | ||
| 544 | also. | ||
| 545 | |||
| 546 | When the function's advice is subsequently activated, if the enabled | ||
| 547 | advice for the function matches what was used to make this combined | ||
| 548 | definition, then the existing combined definition is used, thus avoiding | ||
| 549 | the need to construct one. Thus, preactivation never causes wrong | ||
| 550 | results---but it may fail to do any good, if the enabled advice at the | ||
| 551 | time of activation doesn't match what was used for preactivation. | ||
| 552 | |||
| 553 | Here are some symptoms that can indicate that a preactivation did not | ||
| 554 | work properly, because of a mismatch. | ||
| 555 | |||
| 556 | @itemize @bullet | ||
| 557 | @item | ||
| 558 | Activation of the advised | ||
| 559 | function takes longer than usual. | ||
| 560 | @item | ||
| 561 | The byte compiler gets | ||
| 562 | loaded while an advised function gets activated. | ||
| 563 | @item | ||
| 564 | @code{byte-compile} is included in the value of @code{features} even | ||
| 565 | though you did not ever explicitly use the byte compiler. | ||
| 566 | @end itemize | ||
| 567 | |||
| 568 | Compiled preactivated advice works properly even if the function itself | ||
| 569 | is not defined until later; however, the function needs to be defined | ||
| 570 | when you @emph{compile} the preactivated advice. | ||
| 571 | |||
| 572 | There is no elegant way to find out why preactivated advice is not being | ||
| 573 | used. What you can do is to trace the function | ||
| 574 | @code{ad-cache-id-verification-code} (with the function | ||
| 575 | @code{trace-function-background}) before the advised function's advice | ||
| 576 | is activated. After activation, check the value returned by | ||
| 577 | @code{ad-cache-id-verification-code} for that function: @code{verified} | ||
| 578 | means that the preactivated advice was used, while other values give | ||
| 579 | some information about why they were considered inappropriate. | ||
| 580 | |||
| 581 | @strong{Warning:} There is one known case that can make preactivation | ||
| 582 | fail, in that a preconstructed combined definition is used even though | ||
| 583 | it fails to match the current state of advice. This can happen when two | ||
| 584 | packages define different pieces of advice with the same name, in the | ||
| 585 | same class, for the same function. But you should avoid that anyway. | ||
| 586 | |||
| 587 | @node Argument Access in Advice | ||
| 588 | @section Argument Access in Advice | ||
| 589 | |||
| 590 | The simplest way to access the arguments of an advised function in the | ||
| 591 | body of a piece of advice is to use the same names that the function | ||
| 592 | definition uses. To do this, you need to know the names of the argument | ||
| 593 | variables of the original function. | ||
| 594 | |||
| 595 | While this simple method is sufficient in many cases, it has a | ||
| 596 | disadvantage: it is not robust, because it hard-codes the argument names | ||
| 597 | into the advice. If the definition of the original function changes, | ||
| 598 | the advice might break. | ||
| 599 | |||
| 600 | Another method is to specify an argument list in the advice itself. | ||
| 601 | This avoids the need to know the original function definition's argument | ||
| 602 | names, but it has a limitation: all the advice on any particular | ||
| 603 | function must use the same argument list, because the argument list | ||
| 604 | actually used for all the advice comes from the first piece of advice | ||
| 605 | for that function. | ||
| 606 | |||
| 607 | A more robust method is to use macros that are translated into the | ||
| 608 | proper access forms at activation time, i.e., when constructing the | ||
| 609 | advised definition. Access macros access actual arguments by their | ||
| 610 | (zero-based) position, regardless of how these actual arguments get | ||
| 611 | distributed onto the argument variables of a function. This is robust | ||
| 612 | because in Emacs Lisp the meaning of an argument is strictly | ||
| 613 | determined by its position in the argument list. | ||
| 614 | |||
| 615 | @defmac ad-get-arg position | ||
| 616 | This returns the actual argument that was supplied at @var{position}. | ||
| 617 | @end defmac | ||
| 618 | |||
| 619 | @defmac ad-get-args position | ||
| 620 | This returns the list of actual arguments supplied starting at | ||
| 621 | @var{position}. | ||
| 622 | @end defmac | ||
| 623 | |||
| 624 | @defmac ad-set-arg position value | ||
| 625 | This sets the value of the actual argument at @var{position} to | ||
| 626 | @var{value} | ||
| 627 | @end defmac | ||
| 628 | |||
| 629 | @defmac ad-set-args position value-list | ||
| 630 | This sets the list of actual arguments starting at @var{position} to | ||
| 631 | @var{value-list}. | ||
| 632 | @end defmac | ||
| 633 | |||
| 634 | Now an example. Suppose the function @code{foo} is defined as | ||
| 635 | |||
| 636 | @example | ||
| 637 | (defun foo (x y &optional z &rest r) ...) | ||
| 638 | @end example | ||
| 639 | |||
| 640 | @noindent | ||
| 641 | and is then called with | ||
| 642 | |||
| 643 | @example | ||
| 644 | (foo 0 1 2 3 4 5 6) | ||
| 645 | @end example | ||
| 646 | |||
| 647 | @noindent | ||
| 648 | which means that @var{x} is 0, @var{y} is 1, @var{z} is 2 and @var{r} is | ||
| 649 | @code{(3 4 5 6)} within the body of @code{foo}. Here is what | ||
| 650 | @code{ad-get-arg} and @code{ad-get-args} return in this case: | ||
| 651 | |||
| 652 | @example | ||
| 653 | (ad-get-arg 0) @result{} 0 | ||
| 654 | (ad-get-arg 1) @result{} 1 | ||
| 655 | (ad-get-arg 2) @result{} 2 | ||
| 656 | (ad-get-arg 3) @result{} 3 | ||
| 657 | (ad-get-args 2) @result{} (2 3 4 5 6) | ||
| 658 | (ad-get-args 4) @result{} (4 5 6) | ||
| 659 | @end example | ||
| 660 | |||
| 661 | Setting arguments also makes sense in this example: | ||
| 662 | |||
| 663 | @example | ||
| 664 | (ad-set-arg 5 "five") | ||
| 665 | @end example | ||
| 666 | |||
| 667 | @noindent | ||
| 668 | has the effect of changing the sixth argument to @code{"five"}. If this | ||
| 669 | happens in advice executed before the body of @code{foo} is run, then | ||
| 670 | @var{r} will be @code{(3 4 "five" 6)} within that body. | ||
| 671 | |||
| 672 | Here is an example of setting a tail of the argument list: | ||
| 673 | |||
| 674 | @example | ||
| 675 | (ad-set-args 0 '(5 4 3 2 1 0)) | ||
| 676 | @end example | ||
| 677 | |||
| 678 | @noindent | ||
| 679 | If this happens in advice executed before the body of @code{foo} is run, | ||
| 680 | then within that body, @var{x} will be 5, @var{y} will be 4, @var{z} | ||
| 681 | will be 3, and @var{r} will be @code{(2 1 0)} inside the body of | ||
| 682 | @code{foo}. | ||
| 683 | |||
| 684 | These argument constructs are not really implemented as Lisp macros. | ||
| 685 | Instead they are implemented specially by the advice mechanism. | ||
| 686 | |||
| 687 | @node Combined Definition | ||
| 688 | @section The Combined Definition | ||
| 689 | |||
| 690 | Suppose that a function has @var{n} pieces of before-advice | ||
| 691 | (numbered from 0 through @var{n}@minus{}1), @var{m} pieces of | ||
| 692 | around-advice and @var{k} pieces of after-advice. Assuming no piece | ||
| 693 | of advice is protected, the combined definition produced to implement | ||
| 694 | the advice for a function looks like this: | ||
| 695 | |||
| 696 | @example | ||
| 697 | (lambda @var{arglist} | ||
| 698 | @r{[} @r{[}@var{advised-docstring}@r{]} @r{[}(interactive ...)@r{]} @r{]} | ||
| 699 | (let (ad-return-value) | ||
| 700 | @r{before-0-body-form}... | ||
| 701 | .... | ||
| 702 | @r{before-@var{n}@minus{}1-body-form}... | ||
| 703 | @r{around-0-body-form}... | ||
| 704 | @r{around-1-body-form}... | ||
| 705 | .... | ||
| 706 | @r{around-@var{m}@minus{}1-body-form}... | ||
| 707 | (setq ad-return-value | ||
| 708 | @r{apply original definition to @var{arglist}}) | ||
| 709 | @r{end-of-around-@var{m}@minus{}1-body-form}... | ||
| 710 | .... | ||
| 711 | @r{end-of-around-1-body-form}... | ||
| 712 | @r{end-of-around-0-body-form}... | ||
| 713 | @r{after-0-body-form}... | ||
| 714 | .... | ||
| 715 | @r{after-@var{k}@minus{}1-body-form}... | ||
| 716 | ad-return-value)) | ||
| 717 | @end example | ||
| 718 | |||
| 719 | Macros are redefined as macros, which means adding @code{macro} to | ||
| 720 | the beginning of the combined definition. | ||
| 721 | |||
| 722 | The interactive form is present if the original function or some piece | ||
| 723 | of advice specifies one. When an interactive primitive function is | ||
| 724 | advised, advice uses a special method: it calls the primitive with | ||
| 725 | @code{call-interactively} so that it will read its own arguments. | ||
| 726 | In this case, the advice cannot access the arguments. | ||
| 727 | |||
| 728 | The body forms of the various advice in each class are assembled | ||
| 729 | according to their specified order. The forms of around-advice @var{l} | ||
| 730 | are included in one of the forms of around-advice @var{l} @minus{} 1. | ||
| 731 | |||
| 732 | The innermost part of the around advice onion is | ||
| 733 | |||
| 734 | @display | ||
| 735 | apply original definition to @var{arglist} | ||
| 736 | @end display | ||
| 737 | |||
| 738 | @noindent | ||
| 739 | whose form depends on the type of the original function. The variable | ||
| 740 | @code{ad-return-value} is set to whatever this returns. The variable is | ||
| 741 | visible to all pieces of advice, which can access and modify it before | ||
| 742 | it is actually returned from the advised function. | ||
| 743 | |||
| 744 | The semantic structure of advised functions that contain protected | ||
| 745 | pieces of advice is the same. The only difference is that | ||
| 746 | @code{unwind-protect} forms ensure that the protected advice gets | ||
| 747 | executed even if some previous piece of advice had an error or a | ||
| 748 | non-local exit. If any around-advice is protected, then the whole | ||
| 749 | around-advice onion is protected as a result. | ||
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index 9681c3c42a3..0b2154cdb5e 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -194,7 +194,6 @@ To view this manual in other formats, click | |||
| 194 | 194 | ||
| 195 | * Loading:: Reading files of Lisp code into Lisp. | 195 | * Loading:: Reading files of Lisp code into Lisp. |
| 196 | * Byte Compilation:: Compilation makes programs run faster. | 196 | * Byte Compilation:: Compilation makes programs run faster. |
| 197 | * Advising Functions:: Adding to the definition of a function. | ||
| 198 | * Debugging:: Tools and tips for debugging Lisp programs. | 197 | * Debugging:: Tools and tips for debugging Lisp programs. |
| 199 | 198 | ||
| 200 | * Read and Print:: Converting Lisp objects to text and back. | 199 | * Read and Print:: Converting Lisp objects to text and back. |
| @@ -614,19 +613,6 @@ Byte Compilation | |||
| 614 | * Byte-Code Objects:: The data type used for byte-compiled functions. | 613 | * Byte-Code Objects:: The data type used for byte-compiled functions. |
| 615 | * Disassembly:: Disassembling byte-code; how to read byte-code. | 614 | * Disassembly:: Disassembling byte-code; how to read byte-code. |
| 616 | 615 | ||
| 617 | Advising Emacs Lisp Functions | ||
| 618 | |||
| 619 | * Simple Advice:: A simple example to explain the basics of advice. | ||
| 620 | * Defining Advice:: Detailed description of @code{defadvice}. | ||
| 621 | * Around-Advice:: Wrapping advice around a function's definition. | ||
| 622 | * Computed Advice:: ...is to @code{defadvice} as @code{fset} is to @code{defun}. | ||
| 623 | * Activation of Advice:: Advice doesn't do anything until you activate it. | ||
| 624 | * Enabling Advice:: You can enable or disable each piece of advice. | ||
| 625 | * Preactivation:: Preactivation is a way of speeding up the | ||
| 626 | loading of compiled advice. | ||
| 627 | * Argument Access in Advice:: How advice can access the function's arguments. | ||
| 628 | * Combined Definition:: How advice is implemented. | ||
| 629 | |||
| 630 | Debugging Lisp Programs | 616 | Debugging Lisp Programs |
| 631 | 617 | ||
| 632 | * Debugger:: A debugger for the Emacs Lisp evaluator. | 618 | * Debugger:: A debugger for the Emacs Lisp evaluator. |
| @@ -1561,7 +1547,6 @@ Object Internals | |||
| 1561 | @include customize.texi | 1547 | @include customize.texi |
| 1562 | @include loading.texi | 1548 | @include loading.texi |
| 1563 | @include compile.texi | 1549 | @include compile.texi |
| 1564 | @include advice.texi | ||
| 1565 | 1550 | ||
| 1566 | @c This includes edebug.texi. | 1551 | @c This includes edebug.texi. |
| 1567 | @include debugging.texi | 1552 | @include debugging.texi |
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index d203f1c824f..d86430a5ac0 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi | |||
| @@ -21,6 +21,7 @@ define them. | |||
| 21 | * Function Cells:: Accessing or setting the function definition | 21 | * Function Cells:: Accessing or setting the function definition |
| 22 | of a symbol. | 22 | of a symbol. |
| 23 | * Closures:: Functions that enclose a lexical environment. | 23 | * Closures:: Functions that enclose a lexical environment. |
| 24 | * Advising Functions:: Adding to the definition of a function. | ||
| 24 | * Obsolete Functions:: Declaring functions obsolete. | 25 | * Obsolete Functions:: Declaring functions obsolete. |
| 25 | * Inline Functions:: Functions that the compiler will expand inline. | 26 | * Inline Functions:: Functions that the compiler will expand inline. |
| 26 | * Declare Form:: Adding additional information about a function. | 27 | * Declare Form:: Adding additional information about a function. |
| @@ -1077,12 +1078,10 @@ This function stores @var{definition} in the function cell of | |||
| 1077 | this is not checked. The argument @var{symbol} is an ordinary evaluated | 1078 | this is not checked. The argument @var{symbol} is an ordinary evaluated |
| 1078 | argument. | 1079 | argument. |
| 1079 | 1080 | ||
| 1080 | The primary use of this function is as a subroutine by constructs that | 1081 | The primary use of this function is as a subroutine by constructs that define |
| 1081 | define or alter functions, like @code{defadvice} (@pxref{Advising | 1082 | or alter functions, like @code{defun} or @code{advice-add} (@pxref{Advising |
| 1082 | Functions}). (If @code{defun} were not a primitive, it could be | 1083 | Functions}). You can also use it to give a symbol a function definition that |
| 1083 | written as a Lisp macro using @code{fset}.) You can also use it to | 1084 | is not a function, e.g., a keyboard macro (@pxref{Keyboard Macros}): |
| 1084 | give a symbol a function definition that is not a list, e.g., a | ||
| 1085 | keyboard macro (@pxref{Keyboard Macros}): | ||
| 1086 | 1085 | ||
| 1087 | @example | 1086 | @example |
| 1088 | ;; @r{Define a named keyboard macro.} | 1087 | ;; @r{Define a named keyboard macro.} |
| @@ -1133,6 +1132,269 @@ However, the fact that the internal structure of a closure is | |||
| 1133 | implementation detail. For this reason, we recommend against directly | 1132 | implementation detail. For this reason, we recommend against directly |
| 1134 | examining or altering the structure of closure objects. | 1133 | examining or altering the structure of closure objects. |
| 1135 | 1134 | ||
| 1135 | @node Advising Functions | ||
| 1136 | @section Advising Emacs Lisp Functions | ||
| 1137 | @cindex advising functions | ||
| 1138 | @cindex piece of advice | ||
| 1139 | |||
| 1140 | Any variable or object field which holds a function can be modified with the | ||
| 1141 | appropriate setter function, such as @code{set-process-filter}, @code{fset}, or | ||
| 1142 | @code{setq}, but those can be too blunt, completely throwing away the | ||
| 1143 | previous value. | ||
| 1144 | |||
| 1145 | In order to modify such hooks in a more controlled way, Emacs provides the | ||
| 1146 | macros @code{add-function} and @code{remove-function}, which let you modify the | ||
| 1147 | existing function value by composing it with another function. | ||
| 1148 | |||
| 1149 | For example, in order to trace the calls to a process filter, you can use: | ||
| 1150 | |||
| 1151 | @example | ||
| 1152 | (add-function :before (process-filter proc) #'my-tracing-function) | ||
| 1153 | @end example | ||
| 1154 | |||
| 1155 | This will cause the process's output to be passed first to | ||
| 1156 | @code{my-tracing-function} and then to the original process filter. | ||
| 1157 | When you're done with it, you can revert to the untraced behavior with: | ||
| 1158 | |||
| 1159 | @example | ||
| 1160 | (remove-function (process-filter proc) #'my-tracing-function) | ||
| 1161 | @end example | ||
| 1162 | |||
| 1163 | The argument @code{:before} specifies how the two functions are composed, since | ||
| 1164 | there are many different ways to do it. The added function is also called an | ||
| 1165 | @emph{advice}. | ||
| 1166 | |||
| 1167 | The function cell of a symbol can be manipulated similarly, but since it can | ||
| 1168 | contain other things than a plain function, you have to use @var{advice-add} | ||
| 1169 | and @var{advice-remove} instead, which | ||
| 1170 | @c use @var{add-function} and @var{remove-function} internally, but | ||
| 1171 | know how to handle cases such as when the function cell holds a macro rather | ||
| 1172 | than function, or when the function is autoloaded so the advice's activation | ||
| 1173 | needs to be postponed. | ||
| 1174 | |||
| 1175 | @menu | ||
| 1176 | * Advising Primitives:: Primitives to Manipulate Advices | ||
| 1177 | * Advising Named Functions:: Advising Named Functions | ||
| 1178 | @end menu | ||
| 1179 | |||
| 1180 | @node Advising Primitives | ||
| 1181 | @subsection Primitives to manipulate advice | ||
| 1182 | |||
| 1183 | @defmac add-function where place function &optional props | ||
| 1184 | This macro is the handy way to add the advice @var{function} to the function | ||
| 1185 | stored in @var{place} (@pxref{Generalized Variables}). | ||
| 1186 | |||
| 1187 | @var{where} determines how @var{function} is composed with the | ||
| 1188 | existing function. It can be one of the following: | ||
| 1189 | |||
| 1190 | @table @code | ||
| 1191 | @item :before | ||
| 1192 | Call @var{function} before the old function. Both functions receive the | ||
| 1193 | same arguments, and the return value of the composition is the return value of | ||
| 1194 | the old function. More specifically, the composition of the two functions | ||
| 1195 | behaves like: | ||
| 1196 | @example | ||
| 1197 | (lambda (&rest r) (apply @var{function} r) (apply @var{oldfun} r)) | ||
| 1198 | @end example | ||
| 1199 | This is similar to @code{(add-hook @var{hook} @var{function})}, except that it | ||
| 1200 | applies to single-function hooks rather than normal hooks. | ||
| 1201 | |||
| 1202 | @item :after | ||
| 1203 | Call @var{function} after the old function. Both functions receive the | ||
| 1204 | same arguments, and the return value of the composition is the return value of | ||
| 1205 | the old function. More specifically, the composition of the two functions | ||
| 1206 | behaves like: | ||
| 1207 | @example | ||
| 1208 | (lambda (&rest r) (prog1 (apply @var{oldfun} r) (apply @var{function} r))) | ||
| 1209 | @end example | ||
| 1210 | This is similar to @code{(add-hook @var{hook} @var{function} nil 'append)}, | ||
| 1211 | except that it applies to single-function hooks rather than normal hooks. | ||
| 1212 | |||
| 1213 | @item :override | ||
| 1214 | This completely replaces the old function with the new one. The old function | ||
| 1215 | can of course be recovered if you later call @code{remove-function}. | ||
| 1216 | |||
| 1217 | @item :around | ||
| 1218 | Call @var{function} instead of the old function, but provide the old function | ||
| 1219 | as an extra argument to @var{function}. This is the most flexible composition. | ||
| 1220 | For example, it lets you call the old function with different arguments, or | ||
| 1221 | within a let-binding, or you can sometimes delegate the work to the old | ||
| 1222 | function and sometimes override it completely. More specifically, the | ||
| 1223 | composition of the two functions behaves like: | ||
| 1224 | @example | ||
| 1225 | (lambda (&rest r) (apply @var{function} @var{oldfun} r)) | ||
| 1226 | @end example | ||
| 1227 | |||
| 1228 | @item :before-while | ||
| 1229 | Call @var{function} before the old function and don't call the old | ||
| 1230 | function if @var{function} returns @code{nil}. Both functions receive the | ||
| 1231 | same arguments, and the return value of the composition is the return value of | ||
| 1232 | the old function. More specifically, the composition of the two functions | ||
| 1233 | behaves like: | ||
| 1234 | @example | ||
| 1235 | (lambda (&rest r) (and (apply @var{function} r) (apply @var{oldfun} r))) | ||
| 1236 | @end example | ||
| 1237 | This is reminiscent of @code{(add-hook @var{hook} @var{function})}, when | ||
| 1238 | @var{hook} is run via @code{run-hook-with-args-until-failure}. | ||
| 1239 | |||
| 1240 | @item :before-until | ||
| 1241 | Call @var{function} before the old function and only call the old function if | ||
| 1242 | @var{function} returns @code{nil}. More specifically, the composition of the | ||
| 1243 | two functions behaves like: | ||
| 1244 | @example | ||
| 1245 | (lambda (&rest r) (or (apply @var{function} r) (apply @var{oldfun} r))) | ||
| 1246 | @end example | ||
| 1247 | This is reminiscent of @code{(add-hook @var{hook} @var{function})}, when | ||
| 1248 | @var{hook} is run via @code{run-hook-with-args-until-success}. | ||
| 1249 | |||
| 1250 | @item :after-while | ||
| 1251 | Call @var{function} after the old function and only if the old function | ||
| 1252 | returned non-@code{nil}. Both functions receive the same arguments, and the | ||
| 1253 | return value of the composition is the return value of @var{function}. | ||
| 1254 | More specifically, the composition of the two functions behaves like: | ||
| 1255 | @example | ||
| 1256 | (lambda (&rest r) (and (apply @var{oldfun} r) (apply @var{function} r))) | ||
| 1257 | @end example | ||
| 1258 | This is reminiscent of @code{(add-hook @var{hook} @var{function} nil 'append)}, | ||
| 1259 | when @var{hook} is run via @code{run-hook-with-args-until-failure}. | ||
| 1260 | |||
| 1261 | @item :after-until | ||
| 1262 | Call @var{function} after the old function and only if the old function | ||
| 1263 | returned @code{nil}. More specifically, the composition of the two functions | ||
| 1264 | behaves like: | ||
| 1265 | @example | ||
| 1266 | (lambda (&rest r) (or (apply @var{oldfun} r) (apply @var{function} r))) | ||
| 1267 | @end example | ||
| 1268 | This is reminiscent of @code{(add-hook @var{hook} @var{function} nil 'append)}, | ||
| 1269 | when @var{hook} is run via @code{run-hook-with-args-until-success}. | ||
| 1270 | |||
| 1271 | @item :filter-args | ||
| 1272 | Call @var{function} first and use the result (which should be a list) as the | ||
| 1273 | new arguments to pass to the old function. More specifically, the composition | ||
| 1274 | of the two functions behaves like: | ||
| 1275 | @example | ||
| 1276 | (lambda (&rest r) (apply @var{oldfun} (funcall @var{function} r))) | ||
| 1277 | @end example | ||
| 1278 | |||
| 1279 | @item :filter-return | ||
| 1280 | Call the old function first and pass the result to @var{function}. | ||
| 1281 | More specifically, the composition of the two functions behaves like: | ||
| 1282 | @example | ||
| 1283 | (lambda (&rest r) (funcall @var{function} (apply @var{oldfun} r))) | ||
| 1284 | @end example | ||
| 1285 | @end table | ||
| 1286 | |||
| 1287 | When modifying a variable (whose name will usually end with @code{-function}), | ||
| 1288 | you can choose whether @var{function} is used globally or only in the current | ||
| 1289 | buffer: if @var{place} is just a symbol, then @var{function} is added to the | ||
| 1290 | global value of @var{place}. Whereas if @var{place} is of the form | ||
| 1291 | @code{(local @var{symbol})}, where @var{symbol} is an expression which returns | ||
| 1292 | the variable name, then @var{function} will only be added in the | ||
| 1293 | current buffer. | ||
| 1294 | |||
| 1295 | Every function added with @code{add-function} can be accompanied by an | ||
| 1296 | association list of properties @var{props}. Currently only two of those | ||
| 1297 | properties have a special meaning: | ||
| 1298 | |||
| 1299 | @table @code | ||
| 1300 | @item name | ||
| 1301 | This gives a name to the advice, which @code{remove-function} can use to | ||
| 1302 | identify which function to remove. Typically used when @var{function} is an | ||
| 1303 | anonymous function. | ||
| 1304 | |||
| 1305 | @item depth | ||
| 1306 | This specifies where to place the advice, in case several advices are present. | ||
| 1307 | By default, the depth is 0. A depth of 100 indicates that this advice should | ||
| 1308 | be kept as deep as possible, whereas a depth of -100 indicates that it | ||
| 1309 | should stay as the outermost advice. When two advices specify the same depth, | ||
| 1310 | the most recently added advice will be outermost. | ||
| 1311 | @end table | ||
| 1312 | @end defmac | ||
| 1313 | |||
| 1314 | @defmac remove-function place function | ||
| 1315 | This macro removes @var{function} from the function stored in | ||
| 1316 | @var{place}. This only works if @var{function} was added to @var{place} | ||
| 1317 | using @code{add-function}. | ||
| 1318 | |||
| 1319 | @var{function} is compared with functions added to @var{place} using | ||
| 1320 | @code{equal}, to try and make it work also with lambda expressions. It is | ||
| 1321 | additionally compared also with the @code{name} property of the functions added | ||
| 1322 | to @var{place}, which can be more reliable than comparing lambda expressions | ||
| 1323 | using @code{equal}. | ||
| 1324 | @end defmac | ||
| 1325 | |||
| 1326 | @defun advice-function-member-p advice function-def | ||
| 1327 | Return non-@code{nil} if @var{advice} is already in @var{function-def}. | ||
| 1328 | Like for @code{remove-function} above, instead of @var{advice} being the actual | ||
| 1329 | function, it can also be the @code{name} of the piece of advice. | ||
| 1330 | @end defun | ||
| 1331 | |||
| 1332 | @defun advice-function-mapc f function-def | ||
| 1333 | Call the function @var{f} for every advice that was added to | ||
| 1334 | @var{function-def}. @var{f} is called with two arguments: the advice function | ||
| 1335 | and its properties. | ||
| 1336 | @end defun | ||
| 1337 | |||
| 1338 | @node Advising Named Functions | ||
| 1339 | @subsection Advising Named Functions | ||
| 1340 | |||
| 1341 | A common use of advice is for named functions and macros. | ||
| 1342 | Since @var{add-function} does not know how to deal with macros and autoloaded | ||
| 1343 | functions, Emacs provides a separate set of functions to manipulate pieces of | ||
| 1344 | advice applied to named functions. | ||
| 1345 | |||
| 1346 | Advice can be useful for altering the behavior of an existing | ||
| 1347 | function without having to redefine the whole function. However, it | ||
| 1348 | can be a source of bugs, since existing callers to the function may | ||
| 1349 | assume the old behavior, and work incorrectly when the behavior is | ||
| 1350 | changed by advice. Advice can also cause confusion in debugging, if | ||
| 1351 | the person doing the debugging does not notice or remember that the | ||
| 1352 | function has been modified by advice. | ||
| 1353 | |||
| 1354 | For these reasons, advice should be reserved for the cases where you | ||
| 1355 | cannot modify a function's behavior in any other way. If it is | ||
| 1356 | possible to do the same thing via a hook, that is preferable | ||
| 1357 | (@pxref{Hooks}). If you simply want to change what a particular key | ||
| 1358 | does, it may be better to write a new command, and remap the old | ||
| 1359 | command's key bindings to the new one (@pxref{Remapping Commands}). | ||
| 1360 | In particular, Emacs's own source files should not put advice on | ||
| 1361 | functions in Emacs. (There are currently a few exceptions to this | ||
| 1362 | convention, but we aim to correct them.) | ||
| 1363 | |||
| 1364 | Macros can also be advised, in much the same way as functions. | ||
| 1365 | However, special forms (@pxref{Special Forms}) cannot be advised. | ||
| 1366 | |||
| 1367 | It is possible to advise a primitive (@pxref{What Is a Function}), | ||
| 1368 | but one should typically @emph{not} do so, for two reasons. Firstly, | ||
| 1369 | some primitives are used by the advice mechanism, and advising them | ||
| 1370 | could cause an infinite recursion. Secondly, many primitives are | ||
| 1371 | called directly from C, and such calls ignore advice; hence, one ends | ||
| 1372 | up in a confusing situation where some calls (occurring from Lisp | ||
| 1373 | code) obey the advice and other calls (from C code) do not. | ||
| 1374 | |||
| 1375 | @defun advice-add symbol where function &optional props | ||
| 1376 | Add the advice @var{function} to the named function @var{symbol}. | ||
| 1377 | @var{where} and @var{props} have the same meaning as for @code{add-function} | ||
| 1378 | (@pxref{Advising Primitives}). | ||
| 1379 | @end defun | ||
| 1380 | |||
| 1381 | @defun advice-remove symbol function | ||
| 1382 | Remove the advice @var{function} from the named function @var{symbol}. | ||
| 1383 | @var{function} can also be the @code{name} of an advice. | ||
| 1384 | @end defun | ||
| 1385 | |||
| 1386 | @defun advice-member-p function symbol | ||
| 1387 | Return non-@code{nil} if the advice @var{function} is already in the named | ||
| 1388 | function @var{symbol}. @var{function} can also be the @code{name} of | ||
| 1389 | an advice. | ||
| 1390 | @end defun | ||
| 1391 | |||
| 1392 | @defun advice-mapc function symbol | ||
| 1393 | Call @var{function} for every advice that was added to the named function | ||
| 1394 | @var{symbol}. @var{function} is called with two arguments: the advice function | ||
| 1395 | and its properties. | ||
| 1396 | @end defun | ||
| 1397 | |||
| 1136 | @node Obsolete Functions | 1398 | @node Obsolete Functions |
| 1137 | @section Declaring Functions Obsolete | 1399 | @section Declaring Functions Obsolete |
| 1138 | @cindex obsolete functions | 1400 | @cindex obsolete functions |
diff --git a/doc/lispref/makefile.w32-in b/doc/lispref/makefile.w32-in index a56edd9f498..01fe14944fd 100644 --- a/doc/lispref/makefile.w32-in +++ b/doc/lispref/makefile.w32-in | |||
| @@ -49,7 +49,6 @@ texinputdir = $(srcdir)\..\..\nt\envadd.bat \ | |||
| 49 | srcs = \ | 49 | srcs = \ |
| 50 | $(emacsdir)/emacsver.texi \ | 50 | $(emacsdir)/emacsver.texi \ |
| 51 | $(srcdir)/abbrevs.texi \ | 51 | $(srcdir)/abbrevs.texi \ |
| 52 | $(srcdir)/advice.texi \ | ||
| 53 | $(srcdir)/anti.texi \ | 52 | $(srcdir)/anti.texi \ |
| 54 | $(srcdir)/backups.texi \ | 53 | $(srcdir)/backups.texi \ |
| 55 | $(srcdir)/buffers.texi \ | 54 | $(srcdir)/buffers.texi \ |
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index 50bbe2914ee..df0dd1a58e0 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi | |||
| @@ -69,11 +69,13 @@ functions are called with arguments, or their return values are used | |||
| 69 | in some way. The hook's documentation says how the functions are | 69 | in some way. The hook's documentation says how the functions are |
| 70 | called. You can use @code{add-hook} to add a function to an abnormal | 70 | called. You can use @code{add-hook} to add a function to an abnormal |
| 71 | hook, but you must write the function to follow the hook's calling | 71 | hook, but you must write the function to follow the hook's calling |
| 72 | convention. | 72 | convention. By convention, abnormal hook names end in @samp{-functions}. |
| 73 | 73 | ||
| 74 | By convention, abnormal hook names end in @samp{-functions}. If the | 74 | @cindex single-function hook |
| 75 | variable's name ends in @samp{-function}, then its value is just a single | 75 | If the variable's name ends in @samp{-function}, then its value is |
| 76 | function, not a list of functions. | 76 | just a single function, not a list of functions. @code{add-hook} cannot be |
| 77 | used to modify such a @emph{single function hook}, and you have to use | ||
| 78 | @code{add-function} instead (@pxref{Advising Functions}). | ||
| 77 | 79 | ||
| 78 | @menu | 80 | @menu |
| 79 | * Running Hooks:: How to run a hook. | 81 | * Running Hooks:: How to run a hook. |
| @@ -129,47 +131,6 @@ non-@code{nil} value, it returns that value; otherwise it returns | |||
| 129 | @code{nil}. | 131 | @code{nil}. |
| 130 | @end defun | 132 | @end defun |
| 131 | 133 | ||
| 132 | @defmac with-wrapper-hook hook args &rest body | ||
| 133 | This macro runs the abnormal hook @code{hook} as a series of nested | ||
| 134 | ``wrapper functions'' around the @var{body} forms. The effect is | ||
| 135 | similar to nested @code{around} advices (@pxref{Around-Advice}). | ||
| 136 | |||
| 137 | Each hook function should accept an argument list consisting of a function | ||
| 138 | @var{fun}, followed by the additional arguments listed in @var{args}. | ||
| 139 | The first hook function is passed a function @var{fun} that, if it is | ||
| 140 | called with arguments @var{args}, performs @var{body} (i.e., the default | ||
| 141 | operation). The @var{fun} passed to each successive hook function is | ||
| 142 | constructed from all the preceding hook functions (and @var{body}); if | ||
| 143 | this @var{fun} is called with arguments @var{args}, it does what the | ||
| 144 | @code{with-wrapper-hook} call would if the preceding hook functions were | ||
| 145 | the only ones in @var{hook}. | ||
| 146 | |||
| 147 | Each hook function may call its @var{fun} argument as many times as it | ||
| 148 | wishes, including never. In that case, such a hook function acts to | ||
| 149 | replace the default definition altogether, and any preceding hook | ||
| 150 | functions. Of course, a subsequent hook function may do the same thing. | ||
| 151 | |||
| 152 | Each hook function definition is used to construct the @var{fun} passed | ||
| 153 | to the next hook function in @var{hook}, if any. The last or | ||
| 154 | ``outermost'' @var{fun} is called once to produce the overall effect. | ||
| 155 | |||
| 156 | When might you want to use a wrapper hook? The function | ||
| 157 | @code{filter-buffer-substring} illustrates a common case. There is a | ||
| 158 | basic functionality, performed by @var{body}---in this case, to extract | ||
| 159 | a buffer-substring. Then any number of hook functions can act in | ||
| 160 | sequence to modify that string, before returning the final result. | ||
| 161 | A wrapper-hook also allows for a hook function to completely replace the | ||
| 162 | default definition (by not calling @var{fun}). | ||
| 163 | @end defmac | ||
| 164 | |||
| 165 | @defun run-hook-wrapped hook wrap-function &rest args | ||
| 166 | This function is similar to @code{run-hook-with-args-until-success}. | ||
| 167 | Like that function, it runs the functions on the abnormal hook | ||
| 168 | @code{hook}, stopping at the first one that returns non-@code{nil}. | ||
| 169 | Instead of calling the hook functions directly, though, it actually | ||
| 170 | calls @code{wrap-function} with arguments @code{fun} and @code{args}. | ||
| 171 | @end defun | ||
| 172 | |||
| 173 | @node Setting Hooks | 134 | @node Setting Hooks |
| 174 | @subsection Setting Hooks | 135 | @subsection Setting Hooks |
| 175 | 136 | ||
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 41e7e3d768f..65a2da7d542 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2014-01-10 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * cl.texi (Function Bindings): Fix incorrect description of cl-let. | ||
| 4 | |||
| 1 | 2014-01-09 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de> | 5 | 2014-01-09 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de> |
| 2 | 6 | ||
| 3 | * Makefile.in: Add eww.texi. | 7 | * Makefile.in: Add eww.texi. |
| @@ -18,8 +22,8 @@ | |||
| 18 | (Advanced configuration) | 22 | (Advanced configuration) |
| 19 | (Header arguments in Org mode properties): Spelling fixes. | 23 | (Header arguments in Org mode properties): Spelling fixes. |
| 20 | (Special blocks): Add #+BEGIN_ABSTRACT as another example. | 24 | (Special blocks): Add #+BEGIN_ABSTRACT as another example. |
| 21 | (@LaTeX{} specific attributes): New index entries. Use | 25 | (@LaTeX{} specific attributes): New index entries. |
| 22 | #+BEGIN_ABSTRACT in the example. | 26 | Use #+BEGIN_ABSTRACT in the example. |
| 23 | 27 | ||
| 24 | 2013-01-07 Nicolas Goaziou <n.goaziou@gmail.com> | 28 | 2013-01-07 Nicolas Goaziou <n.goaziou@gmail.com> |
| 25 | 29 | ||
| @@ -80,7 +84,7 @@ | |||
| 80 | 84 | ||
| 81 | 2014-01-02 Aidan Gauland <aidalgol@amuri.net> | 85 | 2014-01-02 Aidan Gauland <aidalgol@amuri.net> |
| 82 | 86 | ||
| 83 | * eshell.texi (Command Basics): Removed `Command basics' chapter. | 87 | * eshell.texi (Command Basics): Remove `Command basics' chapter. |
| 84 | 88 | ||
| 85 | 2014-01-02 Aidan Gauland <aidalgol@amuri.net> | 89 | 2014-01-02 Aidan Gauland <aidalgol@amuri.net> |
| 86 | 90 | ||
| @@ -200,8 +204,8 @@ | |||
| 200 | * org.texi (Orgstruct mode): Fix suggested setting of | 204 | * org.texi (Orgstruct mode): Fix suggested setting of |
| 201 | `orgstruct-heading-prefix-regexp'. | 205 | `orgstruct-heading-prefix-regexp'. |
| 202 | 206 | ||
| 203 | * org.texi (Export settings): Document | 207 | * org.texi (Export settings): |
| 204 | `org-export-allow-bind-keywords'. | 208 | Document `org-export-allow-bind-keywords'. |
| 205 | 209 | ||
| 206 | * org.texi (History and Acknowledgments): Small rephrasing. | 210 | * org.texi (History and Acknowledgments): Small rephrasing. |
| 207 | 211 | ||
| @@ -209,8 +213,8 @@ | |||
| 209 | in a year datetree. | 213 | in a year datetree. |
| 210 | 214 | ||
| 211 | * org.texi (Beamer export, @LaTeX{} and PDF export) | 215 | * org.texi (Beamer export, @LaTeX{} and PDF export) |
| 212 | (Header and sectioning, @LaTeX{} specific attributes): Enhance | 216 | (Header and sectioning, @LaTeX{} specific attributes): |
| 213 | style. | 217 | Enhance style. |
| 214 | 218 | ||
| 215 | * org.texi (Agenda commands): Add a footnote about dragging agenda | 219 | * org.texi (Agenda commands): Add a footnote about dragging agenda |
| 216 | lines: it does not persist and it does not change the .org files. | 220 | lines: it does not persist and it does not change the .org files. |
| @@ -229,15 +233,15 @@ | |||
| 229 | 233 | ||
| 230 | * org.texi (Other built-in back-ends): New section. | 234 | * org.texi (Other built-in back-ends): New section. |
| 231 | 235 | ||
| 232 | * org.texi (Editing source code): Document | 236 | * org.texi (Editing source code): |
| 233 | `org-edit-src-auto-save-idle-delay' and | 237 | Document `org-edit-src-auto-save-idle-delay' and |
| 234 | `org-edit-src-turn-on-auto-save'. | 238 | `org-edit-src-turn-on-auto-save'. |
| 235 | 239 | ||
| 236 | * org.texi (External links): Document contributed link types | 240 | * org.texi (External links): Document contributed link types |
| 237 | separately. | 241 | separately. |
| 238 | 242 | ||
| 239 | * org.texi (Closing items): Document | 243 | * org.texi (Closing items): |
| 240 | `org-closed-keep-when-no-todo'. | 244 | Document `org-closed-keep-when-no-todo'. |
| 241 | 245 | ||
| 242 | * org.texi (Export back-ends): Rename from "Export formats". | 246 | * org.texi (Export back-ends): Rename from "Export formats". |
| 243 | (The Export Dispatcher): Remove reference to | 247 | (The Export Dispatcher): Remove reference to |
| @@ -273,8 +277,8 @@ | |||
| 273 | (Agenda commands): Move details about filtering commands to | 277 | (Agenda commands): Move details about filtering commands to |
| 274 | the new section, only include a summary here. | 278 | the new section, only include a summary here. |
| 275 | (Customizing tables in ODT export) | 279 | (Customizing tables in ODT export) |
| 276 | (System-wide header arguments, Conflicts, Dynamic blocks): Use | 280 | (System-wide header arguments, Conflicts, Dynamic blocks): |
| 277 | spaces for indentation. | 281 | Use spaces for indentation. |
| 278 | 282 | ||
| 279 | * org.texi (Emphasis and monospace): Mention `org-emphasis-alist'. | 283 | * org.texi (Emphasis and monospace): Mention `org-emphasis-alist'. |
| 280 | 284 | ||
| @@ -331,8 +335,8 @@ | |||
| 331 | (In-buffer settings): Update to reflect changes from the new | 335 | (In-buffer settings): Update to reflect changes from the new |
| 332 | export engine. | 336 | export engine. |
| 333 | 337 | ||
| 334 | * org.texi (Matching tags and properties): More examples. Explain | 338 | * org.texi (Matching tags and properties): More examples. |
| 335 | group tags expansion as regular expressions. | 339 | Explain group tags expansion as regular expressions. |
| 336 | 340 | ||
| 337 | * org.texi (Tag groups): New section. | 341 | * org.texi (Tag groups): New section. |
| 338 | 342 | ||
| @@ -357,8 +361,8 @@ | |||
| 357 | 361 | ||
| 358 | * org.texi (Org syntax): New section. | 362 | * org.texi (Org syntax): New section. |
| 359 | 363 | ||
| 360 | * org.texi (Orgstruct mode): Document | 364 | * org.texi (Orgstruct mode): |
| 361 | `orgstruct-heading-prefix-regexp'. | 365 | Document `orgstruct-heading-prefix-regexp'. |
| 362 | 366 | ||
| 363 | * org.texi (Speeding up your agendas): New section. | 367 | * org.texi (Speeding up your agendas): New section. |
| 364 | 368 | ||
| @@ -382,8 +386,8 @@ | |||
| 382 | * org.texi: Update the list contributions. | 386 | * org.texi: Update the list contributions. |
| 383 | 387 | ||
| 384 | * org.texi (Agenda commands): Exporting the agenda to an .org file | 388 | * org.texi (Agenda commands): Exporting the agenda to an .org file |
| 385 | will not copy the subtrees and the inherited tags. Document | 389 | will not copy the subtrees and the inherited tags. |
| 386 | `org-agenda-filter-by-regexp'. | 390 | Document `org-agenda-filter-by-regexp'. |
| 387 | 391 | ||
| 388 | * org.texi (Publishing action, Complex example): Fix names of | 392 | * org.texi (Publishing action, Complex example): Fix names of |
| 389 | publishing functions. | 393 | publishing functions. |
| @@ -397,8 +401,8 @@ | |||
| 397 | * org.texi (Capture): Mention that org-remember.el is not | 401 | * org.texi (Capture): Mention that org-remember.el is not |
| 398 | supported anymore. | 402 | supported anymore. |
| 399 | 403 | ||
| 400 | * org.texi (Top, Exporting, Beamer class export): Delete | 404 | * org.texi (Top, Exporting, Beamer class export): |
| 401 | references to the TaskJuggler export. | 405 | Delete references to the TaskJuggler export. |
| 402 | (History and Acknowledgments): Mention that the TaskJuggler has | 406 | (History and Acknowledgments): Mention that the TaskJuggler has |
| 403 | been rewritten by Nicolas and now lives in the contrib/ directory | 407 | been rewritten by Nicolas and now lives in the contrib/ directory |
| 404 | of Org's distribution. Mention that Jambunathan rewrote the HTML | 408 | of Org's distribution. Mention that Jambunathan rewrote the HTML |
| @@ -415,16 +419,16 @@ | |||
| 415 | (@LaTeX{} and PDF export, Header and sectioning) | 419 | (@LaTeX{} and PDF export, Header and sectioning) |
| 416 | (Publishing options): Fix LaTeX options names. | 420 | (Publishing options): Fix LaTeX options names. |
| 417 | 421 | ||
| 418 | * org.texi (Export options, CSS support, In-buffer settings): Fix | 422 | * org.texi (Export options, CSS support, In-buffer settings): |
| 419 | references to HTML_LINK_* and HTML_STYLE keywords. | 423 | Fix references to HTML_LINK_* and HTML_STYLE keywords. |
| 420 | 424 | ||
| 421 | * org.texi (Export options, In-buffer settings): Fix references to | 425 | * org.texi (Export options, In-buffer settings): Fix references to |
| 422 | #+SELECT_TAGS and #+EXCLUDE_TAGS and remove reference to #+XSLT. | 426 | #+SELECT_TAGS and #+EXCLUDE_TAGS and remove reference to #+XSLT. |
| 423 | 427 | ||
| 424 | * org.texi (Top, Markup, Initial text, Images and tables) | 428 | * org.texi (Top, Markup, Initial text, Images and tables) |
| 425 | (@LaTeX{} fragments, @LaTeX{} fragments, Exporting) | 429 | (@LaTeX{} fragments, @LaTeX{} fragments, Exporting) |
| 426 | (Export options, JavaScript support, Beamer class export): Remove | 430 | (Export options, JavaScript support, Beamer class export): |
| 427 | references to the DocBook export, which has been deleted. | 431 | Remove references to the DocBook export, which has been deleted. |
| 428 | (History and Acknowledgments): Mention that DocBook has been | 432 | (History and Acknowledgments): Mention that DocBook has been |
| 429 | deleted, suggest to use the Texinfo exporter instead, then to | 433 | deleted, suggest to use the Texinfo exporter instead, then to |
| 430 | convert the .texi to DocBook with makeinfo. | 434 | convert the .texi to DocBook with makeinfo. |
| @@ -433,8 +437,8 @@ | |||
| 433 | * org.texi (Deadlines and scheduling): Add a variable to the | 437 | * org.texi (Deadlines and scheduling): Add a variable to the |
| 434 | index. Add documentation about delays for scheduled tasks. | 438 | index. Add documentation about delays for scheduled tasks. |
| 435 | 439 | ||
| 436 | * org.texi (Emphasis and monospace): Mention | 440 | * org.texi (Emphasis and monospace): |
| 437 | `org-fontify-emphasized-text' and | 441 | Mention `org-fontify-emphasized-text' and |
| 438 | `org-emphasis-regexp-components'. | 442 | `org-emphasis-regexp-components'. |
| 439 | 443 | ||
| 440 | * org.texi (References): Small enhancement. | 444 | * org.texi (References): Small enhancement. |
| @@ -491,7 +495,7 @@ | |||
| 491 | 495 | ||
| 492 | * org.texi (Extracting source code): Mention the prefix argument | 496 | * org.texi (Extracting source code): Mention the prefix argument |
| 493 | to org-babel-tangle. | 497 | to org-babel-tangle. |
| 494 | (noweb): Removed erroneous negative. | 498 | (noweb): Remove erroneous negative. |
| 495 | (Specific header arguments): Document new header arguments. | 499 | (Specific header arguments): Document new header arguments. |
| 496 | Documentation for new tangle-mode header argument. | 500 | Documentation for new tangle-mode header argument. |
| 497 | (Top): Documentation for new tangle-mode header argument. | 501 | (Top): Documentation for new tangle-mode header argument. |
| @@ -595,8 +599,8 @@ | |||
| 595 | * org.texi (Header and sectioning): Add a footnote about the | 599 | * org.texi (Header and sectioning): Add a footnote about the |
| 596 | different between LATEX_HEADER_EXTRA and LATEX_HEADER. | 600 | different between LATEX_HEADER_EXTRA and LATEX_HEADER. |
| 597 | 601 | ||
| 598 | * org.texi (The Export Dispatcher): Document | 602 | * org.texi (The Export Dispatcher): |
| 599 | `org-export-in-background'. | 603 | Document `org-export-in-background'. |
| 600 | 604 | ||
| 601 | * org.texi (Footnotes): Export back-ends do not use | 605 | * org.texi (Footnotes): Export back-ends do not use |
| 602 | `org-footnote-normalize' anymore. | 606 | `org-footnote-normalize' anymore. |
| @@ -618,19 +622,19 @@ | |||
| 618 | * org.texi (Include files): Remove reference to :prefix1 | 622 | * org.texi (Include files): Remove reference to :prefix1 |
| 619 | and :prefix. Give more details for :minlevel. | 623 | and :prefix. Give more details for :minlevel. |
| 620 | 624 | ||
| 621 | * org.texi (Macro replacement): Fix macro name. Update | 625 | * org.texi (Macro replacement): Fix macro name. |
| 622 | documentation about possible locations and escaping mechanism. | 626 | Update documentation about possible locations and escaping mechanism. |
| 623 | 627 | ||
| 624 | * org.texi (Table of contents): Update documentation. Document | 628 | * org.texi (Table of contents): Update documentation. |
| 625 | lists of listings and lists of tables. Add documentation for | 629 | Document lists of listings and lists of tables. Add documentation for |
| 626 | optional title and #+TOC: keyword. | 630 | optional title and #+TOC: keyword. |
| 627 | 631 | ||
| 628 | 2013-11-12 Rick Frankel <rick@rickster.com> | 632 | 2013-11-12 Rick Frankel <rick@rickster.com> |
| 629 | 633 | ||
| 630 | * org.texi (results): Add Format section, broken out of Type | 634 | * org.texi (results): Add Format section, broken out of Type |
| 631 | section to match code. | 635 | section to match code. |
| 632 | (hlines, colnames): Remove incorrect Emacs Lisp exception. Note | 636 | (hlines, colnames): Remove incorrect Emacs Lisp exception. |
| 633 | that the actual default handling (at least for python and | 637 | Note that the actual default handling (at least for python and |
| 634 | emacs-lisp) does not seem to match the description. | 638 | emacs-lisp) does not seem to match the description. |
| 635 | 639 | ||
| 636 | 2013-11-12 Sacha Chua <sacha@sachachua.com> (tiny change) | 640 | 2013-11-12 Sacha Chua <sacha@sachachua.com> (tiny change) |
| @@ -640,8 +644,8 @@ | |||
| 640 | 644 | ||
| 641 | 2013-11-12 Yasushi Shoji <yashi@atmark-techno.com> | 645 | 2013-11-12 Yasushi Shoji <yashi@atmark-techno.com> |
| 642 | 646 | ||
| 643 | * org.texi (Resolving idle time): Document | 647 | * org.texi (Resolving idle time): |
| 644 | `org-clock-x11idle-program-name'. | 648 | Document `org-clock-x11idle-program-name'. |
| 645 | 649 | ||
| 646 | 2013-10-24 Michael Albinus <michael.albinus@gmx.de> | 650 | 2013-10-24 Michael Albinus <michael.albinus@gmx.de> |
| 647 | 651 | ||
| @@ -882,8 +886,8 @@ | |||
| 882 | 886 | ||
| 883 | 2013-07-29 Michael Albinus <michael.albinus@gmx.de> | 887 | 2013-07-29 Michael Albinus <michael.albinus@gmx.de> |
| 884 | 888 | ||
| 885 | * tramp.texi (Frequently Asked Questions): Mention | 889 | * tramp.texi (Frequently Asked Questions): |
| 886 | `tramp-use-ssh-controlmaster-options'. | 890 | Mention `tramp-use-ssh-controlmaster-options'. |
| 887 | 891 | ||
| 888 | 2013-07-26 Tassilo Horn <tsdh@gnu.org> | 892 | 2013-07-26 Tassilo Horn <tsdh@gnu.org> |
| 889 | 893 | ||
| @@ -927,8 +931,8 @@ | |||
| 927 | 2013-07-08 Tassilo Horn <tsdh@gnu.org> | 931 | 2013-07-08 Tassilo Horn <tsdh@gnu.org> |
| 928 | 932 | ||
| 929 | * gnus.texi (lines): Correct description of | 933 | * gnus.texi (lines): Correct description of |
| 930 | `gnus-registry-track-extra's default value. Mention | 934 | `gnus-registry-track-extra's default value. |
| 931 | `gnus-registry-remove-extra-data'. | 935 | Mention `gnus-registry-remove-extra-data'. |
| 932 | 936 | ||
| 933 | 2013-07-06 Lars Ingebrigtsen <larsi@gnus.org> | 937 | 2013-07-06 Lars Ingebrigtsen <larsi@gnus.org> |
| 934 | 938 | ||
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 08f9610e594..0490cf639ac 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -1282,13 +1282,8 @@ cells of symbols rather than on the value cells. Each @var{binding} | |||
| 1282 | must be a list of the form @samp{(@var{name} @var{arglist} | 1282 | must be a list of the form @samp{(@var{name} @var{arglist} |
| 1283 | @var{forms}@dots{})}, which defines a function exactly as if | 1283 | @var{forms}@dots{})}, which defines a function exactly as if |
| 1284 | it were a @code{cl-defun} form. The function @var{name} is defined | 1284 | it were a @code{cl-defun} form. The function @var{name} is defined |
| 1285 | accordingly for the duration of the body of the @code{cl-flet}; then | 1285 | accordingly but only within the body of the @code{cl-flet}, hiding any external |
| 1286 | the old function definition, or lack thereof, is restored. | 1286 | definition if applicable. |
| 1287 | |||
| 1288 | You can use @code{cl-flet} to disable or modify the behavior of | ||
| 1289 | functions (including Emacs primitives) in a temporary, localized fashion. | ||
| 1290 | (Compare this with the idea of advising functions. | ||
| 1291 | @xref{Advising Functions,,,elisp,GNU Emacs Lisp Reference Manual}.) | ||
| 1292 | 1287 | ||
| 1293 | The bindings are lexical in scope. This means that all references to | 1288 | The bindings are lexical in scope. This means that all references to |
| 1294 | the named functions must appear physically within the body of the | 1289 | the named functions must appear physically within the body of the |