help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Defadvice use


From: Stefan Monnier
Subject: Re: Defadvice use
Date: Mon, 18 Apr 2005 13:52:48 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> I'm trying to use an advice around the function; the advice providing
> a binding of the symbol `read-minibuffer' to the definition of
> `my-read-minibuffer'. Like the following:

> (defadvice la-fonction
>   (around la-fonction-extended enable compile)
>   "Documentation"
>    (let (f1)
>      (fset 'f1 read-minibuffer)
>      (fset 'read-minibuffer my-read-minibuffer)
>      ad-do-it
>      (fset 'read-minibuffer f1)))

> Any comment? Is it silly? Is there a better way? Any idea?

The last fset will not be executed if the ad-do-it signals an error (or is
interrupted with C-g, ...).  To protect against such eventualities, you want
to use unwind-protect.

An alternative is to use (require 'cl) and then

   (defadvice la-fonction
     (around la-fonction-extended enable compile)
     "Documentation"
     (flet ((read-minibuffer my-read-minibuffer))
       ad-do-it))

it does the same as what you did (except it uses unwind-protect), tho.
In general, I don't think there's a better way.  I would argue that if you
need to use such an ugly hack, you should only be morally allowed to do that
after sending a patch that will make it unnecessary in the future.

I.e. please try and send a patch that makes this hack unnecessary.
You can then use this hack, knowing that it's only a temporary workaround
until your patch is accepted and/or in widespread use.


        Stefan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]