From: Stefan Monnier Date: Sat, 4 May 2013 19:49:23 +0000 (-0400) Subject: * doc/misc/cl.texi (Obsolete Macros): Describe replacements for `flet'. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2026^2~312 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0a6313f7e3062a1c4ed2b32b68122484e847dc0f;p=emacs.git * doc/misc/cl.texi (Obsolete Macros): Describe replacements for `flet'. Fixes: debbugs:14293 --- diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 5e9840a86b7..74b08c04714 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog @@ -1,3 +1,8 @@ +2013-05-04 Stefan Monnier + + * cl.texi (Obsolete Macros): Describe replacements for `flet' + (bug#14293). + 2013-04-16 Michael Albinus * tramp.texi (Frequently Asked Questions): Precise, how to define diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 83df411cb23..90f8a258d23 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi @@ -4850,10 +4850,27 @@ generated directly inside Emacs will not be caught since they make direct C-language calls to the message routines rather than going through the Lisp @code{message} function. +For those cases where the dynamic scoping of @code{flet} is desired, +@code{cl-flet} is clearly not a substitute. The most direct replacement would +be instead to use @code{cl-letf} to temporarily rebind @code{(symbol-function +'@var{fun})}. But in most cases, a better substitute is to use an advice, such +as: + +@example +(defvar my-fun-advice-enable nil) +(add-advice '@var{fun} :around + (lambda (orig &rest args) + (if my-fun-advice-enable (do-something) + (apply orig args)))) +@end example + +so that you can then replace the @code{flet} with a simple dynamically scoped +binding of @code{my-fun-advice-enable}. + @c Bug#411. -Note that many primitives (e.g., @code{+}) have special byte-compile -handling. Attempts to redefine such functions using @code{flet} will -fail if byte-compiled. +Note that many primitives (e.g., @code{+}) have special byte-compile handling. +Attempts to redefine such functions using @code{flet}, @code{cl-letf}, or an +advice will fail when byte-compiled. @c Or cl-flet. @c In such cases, use @code{labels} instead. @end defmac