[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Temporary changing the behavior of a function
From: |
Marcin Borkowski |
Subject: |
Re: Temporary changing the behavior of a function |
Date: |
Fri, 06 Nov 2015 17:06:37 +0100 |
User-agent: |
mu4e 0.9.15; emacs 25.0.50.1 |
On 2015-11-06, at 14:03, Stefan Monnier <monnier@iro.umontreal.ca> 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 <dosomethinggrommit> (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