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 18:59:14 +0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Stefan Monnier (2014-01-27 17:40 +0400) wrote:

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

Thank you very much for the detailed description.  Now I understand the
point and am going to follow your advice about using advices.



reply via email to

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