From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: Temporary changing the behavior of a function Date: Fri, 06 Nov 2015 17:06:37 +0100 Message-ID: <874mgz9koi.fsf@mbork.pl> References: <87lhaba0kh.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1446826036 12092 80.91.229.3 (6 Nov 2015 16:07:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Nov 2015 16:07:16 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 06 17:07:07 2015 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 1ZujXe-0004o1-So for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2015 17:07:07 +0100 Original-Received: from localhost ([::1]:39688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZujXe-00036P-Ar for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2015 11:07:06 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZujXN-00035C-Q7 for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 11:06:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZujXJ-0006aw-MU for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 11:06:49 -0500 Original-Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:36027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZujXJ-0006a3-GA for help-gnu-emacs@gnu.org; Fri, 06 Nov 2015 11:06:45 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id E15618F2008; Fri, 6 Nov 2015 17:06:44 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id W9-tX8NTYWwB; Fri, 6 Nov 2015 17:06:38 +0100 (CET) Original-Received: from localhost (unknown [109.232.24.28]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 1C1628F2004; Fri, 6 Nov 2015 17:06:38 +0100 (CET) User-agent: mu4e 0.9.15; emacs 25.0.50.1 In-reply-to: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:5e00:2:52::8 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:107974 Archived-At: On 2015-11-06, at 14:03, Stefan Monnier wrote: >> Now I want to call `foo' in the Mafia-mode;-), i.e., it should ask no >> further questions. What do I do? AFAIU, `cl-flet' won't help, since it >> is lexical. The best I can think of is to temporarily advice `bar' with >> :override - but then, instead of a `let'-like, local construct, I have >> to explicitly add and then remove the advice, right? > > (defvar my-bar-is-silent nil) > (defun my-bar-silencer (orig &rest args) > (if my-bar-is-silent (apply orig args))) > (advice-add 'bar :around #'my-bar-silencer) > > and then > > ... (let ((my-bar-is-silent t)) > (foo ...)) Thanks! Of course, I can see some performance penalty, but since it is an interactive command, this doesn't bother me at all. > -- Stefan Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University