From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: eval-after-load as a macro (and eval-next-after-load) Date: Fri, 04 Apr 2003 15:30:14 -0500 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200304042030.h34KUEQL008262@rum.cs.yale.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1049488365 18626 80.91.224.249 (4 Apr 2003 20:32:45 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 4 Apr 2003 20:32:45 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri Apr 04 22:32:34 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 191XrW-0004oh-00 for ; Fri, 04 Apr 2003 22:32:34 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 191Xtj-00053t-00 for ; Fri, 04 Apr 2003 22:34:51 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 191XrL-0006QB-02 for emacs-devel@quimby.gnus.org; Fri, 04 Apr 2003 15:32:23 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 191Xqy-0006Pc-00 for emacs-devel@gnu.org; Fri, 04 Apr 2003 15:32:00 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 191Xqx-0006Op-00 for emacs-devel@gnu.org; Fri, 04 Apr 2003 15:31:59 -0500 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.10.13) id 191XpH-0005gt-00 for emacs-devel@gnu.org; Fri, 04 Apr 2003 15:30:15 -0500 Original-Received: from rum.cs.yale.edu (localhost [127.0.0.1]) by rum.cs.yale.edu (8.12.8/8.12.8) with ESMTP id h34KUEx6008264 for ; Fri, 4 Apr 2003 15:30:14 -0500 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.12.8/8.12.8/Submit) id h34KUEQL008262; Fri, 4 Apr 2003 15:30:14 -0500 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: emacs-devel@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:12902 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:12902 eval-after-load is currently a function and is thus pretty much always used as follows: (eval-after-load "foobar" '(some code)) Now, how about turning it into a macro so we can just write: (eval-after-load "foobar" (some code)) Of course, such a change would introduce an incompatibility, but it turns out that I think it's rather minor. We can detect the case where the argument is of the form (quote ...) and treat it as it was before. That takes care of 98% of the case. Of the remaining 2% of the cases, the current Emacs sources have two cases: - the macro would break things. This only happens once in Emacs, more specifically in (defun eval-next-after-load (file) "Read the following input sexp, and run it whenever FILE is loaded. This makes or adds to an entry on `after-load-alist'. FILE should be the name of a library, with no directory name." (eval-after-load file (read))) that's the only place I could find where the expression passed to eval-after-load is not a constant. Note that eval-next-after-load is never used in Emacs and that a google search only turned up XEmacs code that adds compatibility support for Emacs' eval-after-load and eval-next-after-load: no uses. - The macro would fix things because the author didn't realize what was going on and wrote (eval-after-load "foo" (some code)) without the quote. Such a bug was recently fixed in crisp.el but there's still a few occurrences in viper.el (luckily those occurences don't matter because they only contain defadvice which works either way anyway). So I suggest we make eval-next-after-load obsolete and turn eval-after-load into a macro that emulates the function behavior in the special case that the second arg is a quoted expression. See sample patch below, Stefan --- subr.el 3 Apr 2003 23:13:38 -0000 1.347 +++ subr.el 4 Apr 2003 20:21:49 -0000 @@ -951,7 +977,7 @@ ;;;; Specifying things to do after certain files are loaded. -(defun eval-after-load (file form) +(defun eval-after-load-internal (file form) "Arrange that, if FILE is ever loaded, FORM will be run at that time. This makes or adds to an entry on `after-load-alist'. If FILE is already loaded, evaluate FORM right now. @@ -977,11 +1003,29 @@ (eval form)))) form) +(defmacro eval-after-load (file &rest code) + "Arrange that, if FILE is ever loaded, CODE will be run at that time. +This makes or adds to an entry on `after-load-alist'. +If FILE is already loaded, evaluate FORM right now. +It does nothing if CODE is already on the list for FILE. +FILE must match exactly. Normally FILE is the name of a library, +with no directory or extension specified, since that is how `load' +is normally called. +FILE can also be a feature (i.e. a symbol), in which case FORM is +evaluated whenever that feature is `provide'd." + (declare (indent 1) (debug t)) + (when (consp code) + (if (and (null (cdr code)) + (memq (car-safe (car code)) '(quote \`))) + `(eval-after-load-internal ,file ,(car code)) + `(eval-after-load-internal ,file '(progn ,@code))))) + (defun eval-next-after-load (file) "Read the following input sexp, and run it whenever FILE is loaded. This makes or adds to an entry on `after-load-alist'. FILE should be the name of a library, with no directory name." - (eval-after-load file (read))) + (eval `(eval-after-load file ,(read)))) +(make-obsolete 'eval-next-after-load 'eval-after-load "21.4") ;;; make-network-process wrappers