From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: PJ Weisberg Newsgroups: gmane.emacs.help Subject: Re: flet + advised functions Date: Tue, 8 Mar 2011 11:38:47 -0800 Message-ID: References: <87sjuyhzvm.fsf@fh-trier.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1299613200 32438 80.91.229.12 (8 Mar 2011 19:40:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Mar 2011 19:40:00 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Andreas Politz Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 08 20:39:54 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Px2l7-0001PT-TC for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Mar 2011 20:39:54 +0100 Original-Received: from localhost ([127.0.0.1]:49158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Px2l7-0005Gr-01 for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Mar 2011 14:39:53 -0500 Original-Received: from [140.186.70.92] (port=44094 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Px2kd-0005GG-6i for help-gnu-emacs@gnu.org; Tue, 08 Mar 2011 14:39:24 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Px2kb-0006TB-IA for help-gnu-emacs@gnu.org; Tue, 08 Mar 2011 14:39:23 -0500 Original-Received: from p3plsmtpa01-06.prod.phx3.secureserver.net ([72.167.82.86]:56989) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Px2kb-0006Se-By for help-gnu-emacs@gnu.org; Tue, 08 Mar 2011 14:39:21 -0500 Original-Received: (qmail 21726 invoked from network); 8 Mar 2011 19:39:19 -0000 Original-Received: from unknown (209.85.161.41) by p3plsmtpa01-06.prod.phx3.secureserver.net (72.167.82.86) with ESMTP; 08 Mar 2011 19:39:19 -0000 Original-Received: by fxm5 with SMTP id 5so6436701fxm.0 for ; Tue, 08 Mar 2011 11:39:17 -0800 (PST) Original-Received: by 10.223.96.137 with SMTP id h9mr2220546fan.141.1299613127923; Tue, 08 Mar 2011 11:38:47 -0800 (PST) Original-Received: by 10.223.81.66 with HTTP; Tue, 8 Mar 2011 11:38:47 -0800 (PST) In-Reply-To: <87sjuyhzvm.fsf@fh-trier.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 72.167.82.86 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:79892 Archived-At: On Mon, Mar 7, 2011 at 10:47 PM, Andreas Politz wrote= : > > I just discovered that `flet' does not work with (some form of) > advised functions, such that it doesn't restore the original > function. =A0I have found no references to this behaviour on the > net, no bug reports either. =A0The results are the same in > emacs22/24. I assume, it has been this way for a long time !? > > (progn > =A0(unintern 'foo) > =A0(defun foo () 'defun) > =A0(defadvice foo (around foo activate) > =A0 =A0ad-do-it) > =A0(setq letf-save (symbol-function > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;;'ad-Orig-foo > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 'foo > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 )) > =A0(fset 'foo (lambda nil 'flet)) > =A0(fset 'foo letf-save) > =A0(foo)) > > =3D> flet > > -ap > This belongs in a bug-report, not on the help mailing list. It looks like the problem is with symbol-function, not flet (since you never actually use flet in the example). '(unintern foo)' is also unnecessary; I'd remove it to avoid muddying the waters. (progn (defun foo () 'defun) (defadvice foo (around foo activate) ad-do-it) (setq letf-save (symbol-function 'foo )) (fset 'foo (lambda nil 'fset)) (fset 'foo letf-save) (foo)) =3D> fset (symbol-function 'foo) =3D> #[nil "\301=18\302 \211=10)\207" [ad-return-value nil ad-Orig-foo] 2 #("Advice doc string" 0 17 (ad-advice-info foo))] I see that the byte-compiled result of symbol-function doesn't contain the symbol that it's supposed to return, but an un-advised version does. (progn (defun foo () 'defun) (setq letf-save (symbol-function 'foo )) (fset 'foo (lambda nil 'fset)) (fset 'foo letf-save) (byte-compile 'foo) (symbol-function 'foo)) =3D> #[nil "\300\207" [defun] 1] -PJ