[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Temporary changing the behavior of a function
From: |
Michael Heerdegen |
Subject: |
Re: Temporary changing the behavior of a function |
Date: |
Fri, 06 Nov 2015 19:06:54 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Marcin Borkowski <mbork@mbork.pl> writes:
> so there is this function `foo', which calls the function `bar'. The
> function `bar' is responsible for asking the user for some value and
> passing that value to the guts of `foo'.
>
> 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?
Apart from what already had been suggested, there are two more dirty
alternatives:
- Use `cl-letf' to create dynamical bindings on the place
(symbol-function 'SYMBOL), instead of using `cl-flet'. A common trick
in such situations.
- If `bar' asks always the same questions, you can push your "answers"
to `unread-command-events'. Just a workaround, but can save you from
advising at all.
Michael.