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: Sun, 26 Jan 2014 17:08:00 -0500 Message-ID: References: <87k3dm4yv4.fsf@gmail.com> <8761p64kcj.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1390774112 11888 80.91.229.3 (26 Jan 2014 22:08:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 26 Jan 2014 22:08:32 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jan 26 23:08:38 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 1W7Xsb-00029e-OI for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Jan 2014 23:08:37 +0100 Original-Received: from localhost ([::1]:56486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7Xsb-0004GC-AS for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Jan 2014 17:08:37 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7XsK-0004Fr-Tj for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 17:08:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7XsD-0002N0-EC for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 17:08:20 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:36182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7XsD-0002M1-7n for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 17:08:13 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1W7XsB-000202-0g for help-gnu-emacs@gnu.org; Sun, 26 Jan 2014 23:08:11 +0100 Original-Received: from 184.175.8.124 ([184.175.8.124]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 26 Jan 2014 23:08:11 +0100 Original-Received: from monnier by 184.175.8.124 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 26 Jan 2014 23:08:11 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 38 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 184.175.8.124 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:R1C0pBVJfO0B90TLvkqV8/2uFrE= 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:95681 Archived-At: > (defun my-read-color (&optional prompt convert-to-RGB allow-empty-name msg) > (interactive "i\np\ni\np") > (flet ((foreground-color-at-point () (my-foreground-color-at-point)) > (background-color-at-point () (my-background-color-at-point))) > (read-color prompt convert-to-RGB allow-empty-name msg))) > Now i don't see another solution except of using the code of > `read-color' in `my-read-color'. 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. Stefan