help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to shadow a function temporarily? (flet and cl-flet)


From: Alex Kost
Subject: Re: How to shadow a function temporarily? (flet and cl-flet)
Date: Mon, 27 Jan 2014 09:57:21 +0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Stefan Monnier (2014-01-27 02:08 +0400) wrote:

> IIUC foreground-color-at-point and background-color-at-point don't
> suffer from the same problem as + when byte-compiled, so the above
> should work.
>
> But I'd recommend you use advice, which is cleaner (e.g. C-h f will
> make it clear that something's messing with the function):
>
>    (defvar use-my-color-improvement nil)
>
>    (defadvice foreground-color-at-point (around my-improvement activate)
>      (if use-my-color-improvement
>          (setq ad-return-value (my-foreground-color-at-point))
>        ad-do-it))
>
>    (defadvice background-color-at-point (around my-improvement activate)
>      (if use-my-color-improvement
>          (setq ad-return-value (my-background-color-at-point))
>        ad-do-it))
>
>    ...
>    ...(let ((use-my-color-improvement t))
>         (read-color prompt convert-to-RGB allow-empty-name msg))
>    ...
>
> If that's for code within Emacs rather than a separate package, you'll
> want to use the new advice-add instead of defadvice, of course.

Thank you for the suggestion, but is it a normal practice to use advices
for packages?  I use several advices in my own emacs config, but as a
user of an emacs package, I don't want to see that it advises some
functions.

I prefer the following (thanks to Barry Margolin):

Attachment: binb61jfWhVDj.bin
Description: application/emacs-lisp


reply via email to

[Prev in Thread] Current Thread [Next in Thread]