From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#12610: unable to use macro in defadvice Date: Fri, 12 Oct 2012 09:35:09 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1350048989 26780 80.91.229.3 (12 Oct 2012 13:36:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Oct 2012 13:36:29 +0000 (UTC) Cc: 12610@debbugs.gnu.org, Le Wang To: Glenn Morris Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Oct 12 15:36:35 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TMfPi-0000ZD-Vt for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 Oct 2012 15:36:31 +0200 Original-Received: from localhost ([::1]:52893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMfPc-00045q-CP for geb-bug-gnu-emacs@m.gmane.org; Fri, 12 Oct 2012 09:36:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMfPZ-00045k-Nq for bug-gnu-emacs@gnu.org; Fri, 12 Oct 2012 09:36:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TMfPQ-0000pa-9v for bug-gnu-emacs@gnu.org; Fri, 12 Oct 2012 09:36:21 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:58659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMfPQ-0000pW-6G for bug-gnu-emacs@gnu.org; Fri, 12 Oct 2012 09:36:12 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TMfQD-0006Nj-TM for bug-gnu-emacs@gnu.org; Fri, 12 Oct 2012 09:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 Oct 2012 13:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12610 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 12610-submit@debbugs.gnu.org id=B12610.135004897324476 (code B ref 12610); Fri, 12 Oct 2012 13:37:01 +0000 Original-Received: (at 12610) by debbugs.gnu.org; 12 Oct 2012 13:36:13 +0000 Original-Received: from localhost ([127.0.0.1]:40677 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TMfPQ-0006Mi-9s for submit@debbugs.gnu.org; Fri, 12 Oct 2012 09:36:13 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:6231) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TMfPK-0006MB-JZ for 12610@debbugs.gnu.org; Fri, 12 Oct 2012 09:36:09 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8aAG6Zu09FxLQG/2dsb2JhbABEgi6uGoNJgQiCFgEFViMQCw4mEhQYDSSIIboJkEQDozOBWIMF X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="201255076" Original-Received: from 69-196-180-6.dsl.teksavvy.com (HELO pastel.home) ([69.196.180.6]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 12 Oct 2012 09:35:10 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 0066759519; Fri, 12 Oct 2012 09:35:09 -0400 (EDT) In-Reply-To: (Glenn Morris's message of "Thu, 11 Oct 2012 22:05:43 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:65517 Archived-At: > - `(advice lambda ,arglist ,@body))) > + `(advice lambda ,arglist ,@(macroexpand-all body)))) I'd rather not do such things manually. Instead, we should expose the code as code rather than hide it as data, so that macro-expansion can take place without calling it explicitly and so the byte-compiler gets to see the code, optimize it and emit warnings where needed. I.e. I think the patch should start more along the lines of the one below (100% guaranteed untested). Stefan === modified file 'lisp/emacs-lisp/advice.el' --- lisp/emacs-lisp/advice.el 2012-09-14 13:44:31 +0000 +++ lisp/emacs-lisp/advice.el 2012-10-12 13:25:22 +0000 @@ -3655,13 +3655,13 @@ (t (error "defadvice: Invalid or ambiguous flag: %s" flag)))))) args)) - (advice (ad-make-advice - name (memq 'protect flags) - (not (memq 'disable flags)) - `(advice lambda ,arglist ,@body))) + (advice `(ad-make-advice + ',name ',(memq 'protect flags) + ',(not (memq 'disable flags)) + (cons 'advice (lambda ,arglist ,@body)))) (preactivation (if (memq 'preactivate flags) (ad-preactivate-advice - function advice class position)))) + function (eval advice) class position)))) ;; Now for the things to be done at evaluation time: (if (memq 'freeze flags) ;; jwz's idea: Freeze the advised definition into a dumpable @@ -3669,7 +3669,7 @@ (ad-make-freeze-definition function advice class position) ;; the normal case: `(progn - (ad-add-advice ',function ',advice ',class ',position) + (ad-add-advice ',function ,advice ',class ',position) ,@(if preactivation `((ad-set-cache ',function