aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2006-05-24 13:22:12 +0000
committerAlan Mackenzie2006-05-24 13:22:12 +0000
commit33d74677e73926286cf179457dacebcea3306418 (patch)
tree3b684b304b42a5ede630273ecec8fe510108d46d
parenta386b0959d81786a197f2c71170ba716c71702df (diff)
downloademacs-33d74677e73926286cf179457dacebcea3306418.tar.gz
emacs-33d74677e73926286cf179457dacebcea3306418.zip
startup.el (command-line): For names of preloaded files, don't append
".elc" (now done in Fload), and call file-truename on the lisp directory. subr.el (eval-after-load): Fix the doc-string. Allow FILE to match ANY loaded file with the right name, not just those in load-path. Put a regexp matching the file name into after-load-alist, rather than the name itself. subr.el: New functions load-history-regexp, load-history-filename-element, do-after-load-evaluation. international/mule.el (load-with-code-conversion): Do the eval-after-load stuff by calling do-after-load-evaluation.
-rw-r--r--lisp/international/mule.el6
-rw-r--r--lisp/startup.el11
-rw-r--r--lisp/subr.el106
3 files changed, 92 insertions, 31 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el
index 350b6347b42..72198bb1258 100644
--- a/lisp/international/mule.el
+++ b/lisp/international/mule.el
@@ -98,9 +98,9 @@ Return t if file exists."
98 )) 98 ))
99 (let (kill-buffer-hook kill-buffer-query-functions) 99 (let (kill-buffer-hook kill-buffer-query-functions)
100 (kill-buffer buffer))) 100 (kill-buffer buffer)))
101 (let ((hook (assoc file after-load-alist))) 101 (unless purify-flag
102 (when hook 102 (do-after-load-evaluation fullname))
103 (mapcar (function eval) (cdr hook)))) 103
104 (unless (or nomessage noninteractive) 104 (unless (or nomessage noninteractive)
105 (if source 105 (if source
106 (message "Loading %s (source)...done" file) 106 (message "Loading %s (source)...done" file)
diff --git a/lisp/startup.el b/lisp/startup.el
index 3e2bff1088e..d41c812565f 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -644,18 +644,17 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
644 644
645 ;; Convert preloaded file names to absolute. 645 ;; Convert preloaded file names to absolute.
646 (let ((lisp-dir 646 (let ((lisp-dir
647 (file-name-directory 647 (file-truename
648 (locate-file "simple" load-path 648 (file-name-directory
649 (get-load-suffixes))))) 649 (locate-file "simple" load-path
650 (get-load-suffixes))))))
650 651
651 (setq load-history 652 (setq load-history
652 (mapcar (lambda (elt) 653 (mapcar (lambda (elt)
653 (if (and (stringp (car elt)) 654 (if (and (stringp (car elt))
654 (not (file-name-absolute-p (car elt)))) 655 (not (file-name-absolute-p (car elt))))
655 (cons (concat lisp-dir 656 (cons (concat lisp-dir
656 (car elt) 657 (car elt))
657 (if (string-match "[.]el$" (car elt))
658 "" ".elc"))
659 (cdr elt)) 658 (cdr elt))
660 elt)) 659 elt))
661 load-history))) 660 load-history)))
diff --git a/lisp/subr.el b/lisp/subr.el
index 956fcef64f4..54361e92eec 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1393,32 +1393,94 @@ That function's doc string says which file created it."
1393 t)) 1393 t))
1394 nil)) 1394 nil))
1395 1395
1396(defun load-history-regexp (file)
1397 "Form a regexp to find FILE in load-history.
1398FILE, a string, is described in eval-after-load's doc-string."
1399 (if (file-name-absolute-p file)
1400 (setq file (file-truename file)))
1401 (concat (if (file-name-absolute-p file) "\\`" "\\<")
1402 (regexp-quote file)
1403 (if (file-name-extension file)
1404 ""
1405 ;; Note: regexp-opt can't be used here, since we need to call
1406 ;; this before Emacs has been fully started. 2006-05-21
1407 (concat "\\(" (mapconcat 'regexp-quote load-suffixes "\\|") "\\)?"))
1408 "\\(" (mapconcat 'regexp-quote jka-compr-load-suffixes "\\|")
1409 "\\)?\\'"))
1410
1411(defun load-history-filename-element (file-regexp)
1412 "Get the first elt of load-history whose car matches FILE-REGEXP.
1413Return nil if there isn't one."
1414 (let* ((loads load-history)
1415 (load-elt (and loads (car loads))))
1416 (save-match-data
1417 (while (and loads
1418 (or (null (car load-elt))
1419 (not (string-match file-regexp (car load-elt)))))
1420 (setq loads (cdr loads)
1421 load-elt (and loads (car loads)))))
1422 load-elt))
1423
1396(defun eval-after-load (file form) 1424(defun eval-after-load (file form)
1397 "Arrange that, if FILE is ever loaded, FORM will be run at that time. 1425 "Arrange that, if FILE is ever loaded, FORM will be run at that time.
1398This makes or adds to an entry on `after-load-alist'.
1399If FILE is already loaded, evaluate FORM right now. 1426If FILE is already loaded, evaluate FORM right now.
1400It does nothing if FORM is already on the list for FILE. 1427
1401FILE must match exactly. Normally FILE is the name of a library, 1428If a matching file is loaded again, FORM will be evaluated again.
1402with no directory or extension specified, since that is how `load' 1429
1403is normally called. 1430If FILE is a string, it may be either an absolute or a relative file
1404FILE can also be a feature (i.e. a symbol), in which case FORM is 1431name, and may have an extension \(e.g. \".el\") or may lack one, and
1405evaluated whenever that feature is `provide'd." 1432additionally may or may not have an extension denoting a compressed
1406 (let ((elt (assoc file after-load-alist))) 1433format \(e.g. \".gz\").
1407 ;; Make sure there is an element for FILE. 1434
1408 (unless elt (setq elt (list file)) (push elt after-load-alist)) 1435When FILE is absolute, it is first converted to a true name by chasing
1409 ;; Add FORM to the element if it isn't there. 1436out symbolic links. Only a file of this name \(see next paragraph for
1437extensions) will trigger the evaluation of FORM. When FILE is relative,
1438a file whose absolute true name ends in FILE will trigger evaluation.
1439
1440When FILE lacks an extension, a file name with any extension will trigger
1441evaluation. Otherwise, its extension must match FILE's. A further
1442extension for a compressed format \(e.g. \".gz\") on FILE will not affect
1443this name matching.
1444
1445Alternatively, FILE can be a feature (i.e. a symbol), in which case FORM
1446is evaluated whenever that feature is `provide'd.
1447
1448Usually FILE is just a library name like \"font-lock\" or a feature name
1449like 'font-lock.
1450
1451This function makes or adds to an entry on `after-load-alist'."
1452 ;; Add this FORM into after-load-alist (regardless of whether we'll be
1453 ;; evaluating it now).
1454 (let* ((regexp-or-feature
1455 (if (stringp file) (load-history-regexp file) file))
1456 (elt (assoc regexp-or-feature after-load-alist)))
1457 (unless elt
1458 (setq elt (list regexp-or-feature))
1459 (push elt after-load-alist))
1460 ;; Add FORM to the element unless it's already there.
1410 (unless (member form (cdr elt)) 1461 (unless (member form (cdr elt))
1411 (nconc elt (list form)) 1462 (nconc elt (list form)))
1412 ;; If the file has been loaded already, run FORM right away. 1463
1413 (if (if (symbolp file) 1464 ;; Is there an already loaded file whose name (or `provide' name)
1414 (featurep file) 1465 ;; matches FILE?
1415 ;; Make sure `load-history' contains the files dumped with 1466 (if (if (stringp file)
1416 ;; Emacs for the case that FILE is one of them. 1467 (load-history-filename-element regexp-or-feature)
1417 ;; (load-symbol-file-load-history) 1468 (featurep file))
1418 (when (locate-library file) 1469 (eval form))))
1419 (assoc (locate-library file) load-history))) 1470
1420 (eval form)))) 1471(defun do-after-load-evaluation (abs-file)
1421 form) 1472 "Evaluate all `eval-after-load' forms, if any, for ABS-FILE.
1473ABS-FILE, a string, should be the absolute true name of a file just loaded."
1474 (let ((after-load-elts after-load-alist)
1475 a-l-element file-elements file-element form)
1476 (while after-load-elts
1477 (setq a-l-element (car after-load-elts)
1478 after-load-elts (cdr after-load-elts))
1479 (when (and (stringp (car a-l-element))
1480 (string-match (car a-l-element) abs-file))
1481 (while (setq a-l-element (cdr a-l-element)) ; discard the file name
1482 (setq form (car a-l-element))
1483 (eval form))))))
1422 1484
1423(defun eval-next-after-load (file) 1485(defun eval-next-after-load (file)
1424 "Read the following input sexp, and run it whenever FILE is loaded. 1486 "Read the following input sexp, and run it whenever FILE is loaded.