unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Defadvice use
Date: Mon, 18 Apr 2005 13:52:48 -0400	[thread overview]
Message-ID: <87acnw0yek.fsf-monnier+gnu.emacs.help@gnu.org> (raw)
In-Reply-To: yg7hdi4gs5r.fsf@fermat.math.uvsq.fr

> 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

  parent reply	other threads:[~2005-04-18 17:52 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-18 12:56 Defadvice use Matthias
2005-04-18 17:11 ` rgb
2005-04-18 17:25   ` Johan Bockgård
2005-04-18 19:05     ` rgb
2005-04-18 19:43       ` Stefan Monnier
2005-04-19  0:15         ` rgb
2005-04-19  0:28           ` Stefan Monnier
2005-04-19  3:48             ` Mis-features of let (was Defadvice use) rgb
2005-04-19  4:31               ` Mis-features of let Stefan Monnier
2005-04-19  6:38                 ` rgb
2005-04-19 12:21                   ` Stefan Monnier
2005-04-19 20:31                     ` rgb
2005-04-19 21:45                       ` David Kastrup
2005-04-19 12:55                   ` Barry Margolin
2005-04-19 20:31                     ` rgb
2005-04-20  4:12                       ` Barry Margolin
2005-04-19 21:10                     ` rgb
2005-04-19 21:57                       ` Kevin Rodgers
2005-04-19 22:00                       ` David Kastrup
2005-04-20  1:04                         ` rgb
2005-04-20 10:04                           ` David Kastrup
2005-04-20 11:57                             ` Stefan Monnier
2005-04-20 14:41                           ` Thien-Thi Nguyen
2005-04-19  9:41               ` Thien-Thi Nguyen
2005-04-19  5:07           ` Defadvice use Barry Margolin
2005-04-18 17:52 ` Stefan Monnier [this message]
2005-04-18 21:07   ` Matthias
2005-04-18 23:20     ` Stefan Monnier
2005-04-18 20:28 ` Kevin Rodgers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87acnw0yek.fsf-monnier+gnu.emacs.help@gnu.org \
    --to=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).