aboutsummaryrefslogtreecommitdiffstats
path: root/doc/misc/cl.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/misc/cl.texi')
-rw-r--r--doc/misc/cl.texi48
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
1292accordingly for the duration of the body of the @code{cl-flet}; then 1292accordingly for the duration of the body of the @code{cl-flet}; then
1293the old function definition, or lack thereof, is restored. 1293the old function definition, or lack thereof, is restored.
1294 1294
1295You can use @code{cl-flet} to disable or modify the behavior of a 1295You can use @code{cl-flet} to disable or modify the behavior of
1296function in a temporary fashion. (Compare this with the idea 1296functions (including Emacs primitives) in a temporary, localized fashion.
1297of 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}.)
1299This will even work on Emacs primitives, although note that some calls
1300to primitive functions internal to Emacs are made without going
1301through 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
1309This code attempts to replace the built-in function @code{message} 1300The bindings are lexical in scope. This means that all references to
1310with a function that simply saves the messages in a list rather 1301the named functions must appear physically within the body of the
1311than displaying them. The original definition of @code{message} 1302@code{cl-flet} form.
1312will be restored after @code{do-something} exits. This code will
1313work fine on messages generated by other Lisp code, but messages
1314generated directly inside Emacs will not be caught since they make
1315direct C-language calls to the message routines rather than going
1316through the Lisp @code{message} function.
1317 1303
1318Functions defined by @code{cl-flet} may use the full Common Lisp 1304Functions defined by @code{cl-flet} may use the full Common Lisp
1319argument notation supported by @code{cl-defun}; also, the function 1305argument 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
1323Note that the @file{cl.el} version of this macro behaves slightly 1309Note that the @file{cl.el} version of this macro behaves slightly
1324differently. @xref{Obsolete Macros}. 1310differently. In particular, its binding is dynamic rather than
1311lexical. @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
4863that @code{flet} affects indirect calls to a function as well as calls 4850that @code{flet} affects indirect calls to a function as well as calls
4864directly inside the @code{flet} form itself. 4851directly inside the @code{flet} form itself.
4865 4852
4853This will even work on Emacs primitives, although note that some calls
4854to primitive functions internal to Emacs are made without going
4855through 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
4863This code attempts to replace the built-in function @code{message}
4864with a function that simply saves the messages in a list rather
4865than displaying them. The original definition of @code{message}
4866will be restored after @code{do-something} exits. This code will
4867work fine on messages generated by other Lisp code, but messages
4868generated directly inside Emacs will not be caught since they make
4869direct C-language calls to the message routines rather than going
4870through the Lisp @code{message} function.
4871
4866@c Bug#411. 4872@c Bug#411.
4867Note that many primitives (e.g.@: @code{+}) have special byte-compile 4873Note that many primitives (e.g.@: @code{+}) have special byte-compile
4868handling. Attempts to redefine such functions using @code{flet} will 4874handling. Attempts to redefine such functions using @code{flet} will