From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alex Kost Newsgroups: gmane.emacs.help Subject: Re: How to shadow a function temporarily? (flet and cl-flet) Date: Mon, 27 Jan 2014 09:57:21 +0400 Message-ID: <87iot6rmpq.fsf@gmail.com> References: <87k3dm4yv4.fsf@gmail.com> <8761p64kcj.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1390802265 20911 80.91.229.3 (27 Jan 2014 05:57:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Jan 2014 05:57:45 +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 06:57:52 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 1W7fCi-0006ot-Bn for geh-help-gnu-emacs@m.gmane.org; Mon, 27 Jan 2014 06:57:52 +0100 Original-Received: from localhost ([::1]:57874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7fCi-0005D9-2J for geh-help-gnu-emacs@m.gmane.org; Mon, 27 Jan 2014 00:57:52 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7fCQ-0005Ct-4r for help-gnu-emacs@gnu.org; Mon, 27 Jan 2014 00:57:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7fCH-0004Vc-Om for help-gnu-emacs@gnu.org; Mon, 27 Jan 2014 00:57:34 -0500 Original-Received: from mail-lb0-x234.google.com ([2a00:1450:4010:c04::234]:33691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7fCH-0004VY-Fc for help-gnu-emacs@gnu.org; Mon, 27 Jan 2014 00:57:25 -0500 Original-Received: by mail-lb0-f180.google.com with SMTP id n15so4068212lbi.39 for ; Sun, 26 Jan 2014 21:57:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version:content-type; bh=DbEF9B/XNn3kwXZlEL8f3Q5LzVJPgxpiGGfF+EncvXk=; b=M+3E+XWO5C1LtcY56YE9WVST2HKwjFB/clokGNPRGTX2+fcrqktXNWkVbwAoGntCBH HrtXkReNZ83xwOSqXmqPnqD4FNZTn+5aVlzwdjj5XEc+TA27NJLh8hFSKdzrIuXBVTj6 6WWvdP8KrAMLOhRgfp3c4xC7jKxvQ/1n6YopAbMIjU/iCDTU15EEsu05jHyS5fS2hRa0 NcWsIYZe/+y4/VF7UKBFHZjCXaa6tUWN1InL9jO/haszdKpmH4kPsL6tf5Jznek5BRvv lzxvnV5MyiYHNM3we/n/kz+FUtQFaNBKFPJlKAKiEXLwfRYcb02+UGMUT15Iej8zh97t r8KA== X-Received: by 10.152.9.65 with SMTP id x1mr2333853laa.6.1390802244322; Sun, 26 Jan 2014 21:57:24 -0800 (PST) Original-Received: from leviafan (128-70-204-126.broadband.corbina.ru. [128.70.204.126]) by mx.google.com with ESMTPSA id gi5sm10923749lbc.4.2014.01.26.21.57.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jan 2014 21:57:23 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Sun, 26 Jan 2014 17:08:00 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::234 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:95684 Archived-At: --=-=-= Content-Type: text/plain 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): --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline Content-Transfer-Encoding: quoted-printable (defun macol-read-color (&optional prompt convert-to-RGB allow-empty-name m= sg) "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))) --=-=-=--