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: Stefan Monnier
Subject: Re: How to shadow a function temporarily? (flet and cl-flet)
Date: Mon, 27 Jan 2014 08:40:42 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> 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.

Why would you not want to see it?

> (defun macol-read-color (&optional prompt convert-to-RGB allow-empty-name msg)
>   "Read a color name or RGB triplet.
> Same as `read-color', but use `macol-foreground-color-at-point'
> and `macol-background-color-at-point' instead of
> `foreground-color-at-point' and `background-color-at-point'."
>   (interactive "i\np\ni\np")
>   (cl-letf (((symbol-function 'foreground-color-at-point)
>              (symbol-function 'macol-foreground-color-at-point))
>             ((symbol-function 'background-color-at-point)
>              (symbol-function 'macol-background-color-at-point)))
>     (read-color prompt convert-to-RGB allow-empty-name msg)))

Now, if someone sees a problem in the behavior of
background-color-at-point, he may try to Edebug
background-color-at-point and won't understand why it's not called (or
why it *is* called but the value it returns is the value that the caller
receives, or ...).

Or someone else may start writing code relying on that new behavior
without realizing that it won't work in an Emacs that hasn't loaded this
"macol" package.

Of course, all that can happen as well with my `advice', but at least
the function's docstring will give you a hint.  You can also more easily
deactivate this behavior either by re-binding use-my-color-improvement
to nil while `read-color' is in progress, or by deactivating this
particular advice.


        Stefan




reply via email to

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