From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Elena Newsgroups: gmane.emacs.help Subject: Re: Redefining functions and variables Date: Thu, 29 Jul 2010 01:32:06 -0700 (PDT) Organization: http://groups.google.com Message-ID: <08217e84-b4a0-4dd0-afbf-abd4d762c759@w30g2000yqw.googlegroups.com> References: <68e690c9-aece-461d-afe9-ca9115ceaee5@m1g2000vbh.googlegroups.com> <76fd4dc4-a964-4629-90e2-329e1b83fd8d@h25g2000vba.googlegroups.com> <876300fnpk.fsf@fh-trier.de> <55e481e3-b894-499f-80b3-1c96b2c338ce@d37g2000yqm.googlegroups.com> <61db17c1-8c30-44a1-b96e-9eec802156fe@j8g2000yqd.googlegroups.com> <87tynjl9x3.fsf@fh-trier.de> <87hbjjibrk.fsf@kuiper.lan.informatimago.com> 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 1291852519 15545 80.91.229.12 (8 Dec 2010 23:55:19 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2010 23:55:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 00:55:15 2010 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 1PQTqt-00078x-KV for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 00:55:15 +0100 Original-Received: from localhost ([127.0.0.1]:45184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQTqt-0007YG-4x for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 18:55:15 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!w30g2000yqw.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 62 Original-NNTP-Posting-Host: 89.96.190.244 Original-X-Trace: posting.google.com 1280392326 30906 127.0.0.1 (29 Jul 2010 08:32:06 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 29 Jul 2010 08:32:06 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w30g2000yqw.googlegroups.com; posting-host=89.96.190.244; posting-account=AFCLjAoAAABJAOf_HjgEEEi3ty-lG5m2 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8,gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:180171 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:76250 Archived-At: On Jul 28, 8:37=A0pm, p...@informatimago.com (Pascal J. Bourguignon) wrote: > Andreas Politz writes: > > Elena writes: > > >> On Jul 28, 7:51=A0am, Elena wrote: > >>> > Of course this leads to an endless recursive loop, expanding your m= acro > >>> > again and again ... > > >>> Then I should have tested the macro with `macroexpand-all' instead of > >>> `macroexpand'. However, I've tried using the macro, and it seemed to > >>> work, albeit it choked on the unquoted symbol passed to `fboundp'. > > >> I think it seemed to work because the macro was interpreted, therefore > >> it was expanded only once before the failure. > > > Don't know, but defining `defun' as a macro usually deletes the origina= l > > subst (which is a special form, which is kind of like a macro). > > > (defvar defun-subst (symbol-function 'defun)) > > > (defmacro defun (name args &rest body) > > =A0 `(defun ,name ,args ,@body)) > > > (defun foo ()) > > ;; Enters the debugger because of recursion limit reached. > > > ;; Restore original defun > > (fset 'defun defun-subst) > > Another way: > > (defvar old-defun 'defun) ; the symbol! > (unintern 'defun) > > (defmacro defun (name args &rest body) > =A0 `(progn > =A0 =A0 =A0 (message "defining %S" name) > =A0 =A0 =A0 (,old-defun ,name ,args ,@body))) This is very close to what I was looking for. Thanks, Pascal. My modified macro is below. Why ',name is expanded as ... (as shown by `macroexpand-all'? (defvar old-defun 'defun) ; the symbol! (unintern 'defun) (defmacro defun (name args &rest body) `(progn ;; `load-file-name' is not null only if we are loading a file. (when (and load-file-name (fboundp ',name)) (message "Warning: %s is being redefined in %s." (symbol-name ',name) load-file-name) (,old-defun ,name ,args ,@body))))