From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Defadvice use Date: Mon, 18 Apr 2005 13:52:48 -0400 Organization: Bell Sympatico Message-ID: <87acnw0yek.fsf-monnier+gnu.emacs.help@gnu.org> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1113847630 23648 80.91.229.2 (18 Apr 2005 18:07:10 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 18 Apr 2005 18:07:10 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Apr 18 20:07:08 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DNae1-00066i-RS for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Apr 2005 20:06:50 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DNaiB-0001lv-6H for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Apr 2005 14:11:07 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsfeed.news.ucla.edu!cyclone.bc.net!news.alt.net!wns13feed!worldnet.att.net!207.35.177.252!nf3.bellglobal.com!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:vXqwQUuwtrS+WhHzMynprfG3C8A= Original-Lines: 38 Original-NNTP-Posting-Host: 65.92.243.79 Original-X-Complaints-To: abuse@sympatico.ca Original-X-Trace: news20.bellglobal.com 1113846768 65.92.243.79 (Mon, 18 Apr 2005 13:52:48 EDT) Original-NNTP-Posting-Date: Mon, 18 Apr 2005 13:52:48 EDT Original-Xref: shelby.stanford.edu gnu.emacs.help:130216 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:25783 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:25783 > 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