diff options
Diffstat (limited to 'doc/misc/cl.texi')
| -rw-r--r-- | doc/misc/cl.texi | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index a50be1027f3..beefa3e9c40 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -1292,28 +1292,14 @@ it were a @code{cl-defun} form. The function @var{name} is defined | |||
| 1292 | accordingly for the duration of the body of the @code{cl-flet}; then | 1292 | accordingly for the duration of the body of the @code{cl-flet}; then |
| 1293 | the old function definition, or lack thereof, is restored. | 1293 | the old function definition, or lack thereof, is restored. |
| 1294 | 1294 | ||
| 1295 | You can use @code{cl-flet} to disable or modify the behavior of a | 1295 | You can use @code{cl-flet} to disable or modify the behavior of |
| 1296 | function in a temporary fashion. (Compare this with the idea | 1296 | functions (including Emacs primitives) in a temporary, localized fashion. |
| 1297 | of advising functions. | 1297 | (Compare this with the idea of advising functions. |
| 1298 | @xref{Advising Functions,,,elisp,GNU Emacs Lisp Reference Manual}.) | 1298 | @xref{Advising Functions,,,elisp,GNU Emacs Lisp Reference Manual}.) |
| 1299 | This will even work on Emacs primitives, although note that some calls | ||
| 1300 | to primitive functions internal to Emacs are made without going | ||
| 1301 | through the symbol's function cell, and so will not be affected by | ||
| 1302 | @code{cl-flet}. For example, | ||
| 1303 | |||
| 1304 | @example | ||
| 1305 | (cl-flet ((message (&rest args) (push args saved-msgs))) | ||
| 1306 | (do-something)) | ||
| 1307 | @end example | ||
| 1308 | 1299 | ||
| 1309 | This code attempts to replace the built-in function @code{message} | 1300 | The bindings are lexical in scope. This means that all references to |
| 1310 | with a function that simply saves the messages in a list rather | 1301 | the named functions must appear physically within the body of the |
| 1311 | than displaying them. The original definition of @code{message} | 1302 | @code{cl-flet} form. |
| 1312 | will be restored after @code{do-something} exits. This code will | ||
| 1313 | work fine on messages generated by other Lisp code, but messages | ||
| 1314 | generated directly inside Emacs will not be caught since they make | ||
| 1315 | direct C-language calls to the message routines rather than going | ||
| 1316 | through the Lisp @code{message} function. | ||
| 1317 | 1303 | ||
| 1318 | Functions defined by @code{cl-flet} may use the full Common Lisp | 1304 | Functions defined by @code{cl-flet} may use the full Common Lisp |
| 1319 | argument notation supported by @code{cl-defun}; also, the function | 1305 | argument notation supported by @code{cl-defun}; also, the function |
| @@ -1321,7 +1307,8 @@ body is enclosed in an implicit block as if by @code{cl-defun}. | |||
| 1321 | @xref{Program Structure}. | 1307 | @xref{Program Structure}. |
| 1322 | 1308 | ||
| 1323 | Note that the @file{cl.el} version of this macro behaves slightly | 1309 | Note that the @file{cl.el} version of this macro behaves slightly |
| 1324 | differently. @xref{Obsolete Macros}. | 1310 | differently. In particular, its binding is dynamic rather than |
| 1311 | lexical. @xref{Obsolete Macros}. | ||
| 1325 | @end defmac | 1312 | @end defmac |
| 1326 | 1313 | ||
| 1327 | @defmac cl-labels (bindings@dots{}) forms@dots{} | 1314 | @defmac cl-labels (bindings@dots{}) forms@dots{} |
| @@ -4863,6 +4850,25 @@ time before Emacs had lexical binding). The result is | |||
| 4863 | that @code{flet} affects indirect calls to a function as well as calls | 4850 | that @code{flet} affects indirect calls to a function as well as calls |
| 4864 | directly inside the @code{flet} form itself. | 4851 | directly inside the @code{flet} form itself. |
| 4865 | 4852 | ||
| 4853 | This will even work on Emacs primitives, although note that some calls | ||
| 4854 | to primitive functions internal to Emacs are made without going | ||
| 4855 | through the symbol's function cell, and so will not be affected by | ||
| 4856 | @code{flet}. For example, | ||
| 4857 | |||
| 4858 | @example | ||
| 4859 | (flet ((message (&rest args) (push args saved-msgs))) | ||
| 4860 | (do-something)) | ||
| 4861 | @end example | ||
| 4862 | |||
| 4863 | This code attempts to replace the built-in function @code{message} | ||
| 4864 | with a function that simply saves the messages in a list rather | ||
| 4865 | than displaying them. The original definition of @code{message} | ||
| 4866 | will be restored after @code{do-something} exits. This code will | ||
| 4867 | work fine on messages generated by other Lisp code, but messages | ||
| 4868 | generated directly inside Emacs will not be caught since they make | ||
| 4869 | direct C-language calls to the message routines rather than going | ||
| 4870 | through the Lisp @code{message} function. | ||
| 4871 | |||
| 4866 | @c Bug#411. | 4872 | @c Bug#411. |
| 4867 | Note that many primitives (e.g.@: @code{+}) have special byte-compile | 4873 | Note that many primitives (e.g.@: @code{+}) have special byte-compile |
| 4868 | handling. Attempts to redefine such functions using @code{flet} will | 4874 | handling. Attempts to redefine such functions using @code{flet} will |