From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: How to shadow a function temporarily? (flet and cl-flet) Date: Mon, 27 Jan 2014 08:40:42 -0500 Message-ID: References: <87k3dm4yv4.fsf@gmail.com> <8761p64kcj.fsf@gmail.com> <87iot6rmpq.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1390830078 11085 80.91.229.3 (27 Jan 2014 13:41:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Jan 2014 13:41:18 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jan 27 14:41:25 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W7mRJ-0006KE-Bt for geh-help-gnu-emacs@m.gmane.org; Mon, 27 Jan 2014 14:41:25 +0100 Original-Received: from localhost ([::1]:59604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7mRJ-0002qn-0D for geh-help-gnu-emacs@m.gmane.org; Mon, 27 Jan 2014 08:41:25 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7mQz-0002pv-07 for help-gnu-emacs@gnu.org; Mon, 27 Jan 2014 08:41:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7mQr-0002Ye-CC for help-gnu-emacs@gnu.org; Mon, 27 Jan 2014 08:41:04 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:36723) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7mQr-0002YH-57 for help-gnu-emacs@gnu.org; Mon, 27 Jan 2014 08:40:57 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1W7mQo-00063Z-SY for help-gnu-emacs@gnu.org; Mon, 27 Jan 2014 14:40:54 +0100 Original-Received: from 206-248-131-181.dsl.teksavvy.com ([206.248.131.181]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 27 Jan 2014 14:40:54 +0100 Original-Received: from monnier by 206-248-131-181.dsl.teksavvy.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 27 Jan 2014 14:40:54 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 37 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 206-248-131-181.dsl.teksavvy.com User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:9F192dfDwv38g0d+xBH2FBGROgk= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:95693 Archived-At: > 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