Let #'eval-after-load accept symbol for FILE arg
authorSteve Youngs <steve@sxemacs.org>
Sat, 18 Jun 2016 09:53:23 +0000 (19:53 +1000)
committerSteve Youngs <steve@sxemacs.org>
Sat, 18 Jun 2016 09:53:23 +0000 (19:53 +1000)
While looking into bug 183 I noticed that FSF's #'eval-after-load also
accepts a feature (i.e, a symbol) for the FILE arg.  I personally don't
think that's a wonderful idea, but I did see that a few things in
GNU/Emacs are using it (Tramp, for example).  This change adds rudimentary
support in our #'eval-after-load.  Basically, if FILE is a symbol, look up
a filename from #'feature-file, or use #'symbol-name if that fails.

The doc string was amended accordingly, and a note about the futility of
using #'eval-after-load with dumped lisp was also added.

* lisp/subr.el (eval-after-load): Also accept symbols for FILE
arg.
Add a note to doc string about the futility of using this on
dumped lisp.

Signed-off-by: Steve Youngs <steve@sxemacs.org>
lisp/subr.el

index 9d1cde1..694d7a1 100644 (file)
@@ -1686,11 +1686,22 @@ If FILE is already loaded, evaluate FORM right now.
 It does nothing if FORM 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."
-  ;; Make sure `load-history' contains the files dumped with Emacs
-  ;; for the case that FILE is one of the files dumped with Emacs.
-  (if-fboundp 'load-symbol-file-load-history
-      (load-symbol-file-load-history))
+is normally called.
+For compatibility with FSF, FILE can also be a feature, i.e, a symbol.
+
+Please be aware that if FILE is a lib that is dumped then you are not
+gaining anything by using this, you may as well simply call FORM directly
+without `eval-after-load'."
+  ;; FSFmacs allows FILE to be a symbol (provided feature). I can't
+  ;; decide if that's a good thing or not, or even how to go about it
+  ;; in a smart way.  So, for now, look it up from #'feature-file or
+  ;; use #'symbol-name failing that. --SY.
+  (when (symbolp file)
+    ;; Lets at least try to get a real filename
+    (setq file (or (ignore-errors
+                    (file-name-sans-extension
+                     (file-basename (feature-file file))))
+                  (symbol-name file))))
   ;; Make sure there is an element for FILE.
   (or (assoc file after-load-alist)
       (setq after-load-alist (cons (list file) after-load-alist)))