| | 1396 | (defun load-history-regexp (file) |
|---|
| | 1397 | "Form a regexp to find FILE in load-history. |
|---|
| | 1398 | FILE, 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. |
|---|
| | 1413 | Return 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 | |
|---|
| 1400 | | It does nothing if FORM is already on the list for FILE. |
|---|
| 1401 | | FILE must match exactly. Normally FILE is the name of a library, |
|---|
| 1402 | | with no directory or extension specified, since that is how `load' |
|---|
| 1403 | | is normally called. |
|---|
| 1404 | | FILE can also be a feature (i.e. a symbol), in which case FORM is |
|---|
| 1405 | | evaluated whenever that feature is `provide'd." |
|---|
| 1406 | | (let ((elt (assoc file after-load-alist))) |
|---|
| 1407 | | ;; Make sure there is an element for FILE. |
|---|
| 1408 | | (unless elt (setq elt (list file)) (push elt after-load-alist)) |
|---|
| 1409 | | ;; Add FORM to the element if it isn't there. |
|---|
| | 1427 | |
|---|
| | 1428 | If a matching file is loaded again, FORM will be evaluated again. |
|---|
| | 1429 | |
|---|
| | 1430 | If FILE is a string, it may be either an absolute or a relative file |
|---|
| | 1431 | name, and may have an extension \(e.g. \".el\") or may lack one, and |
|---|
| | 1432 | additionally may or may not have an extension denoting a compressed |
|---|
| | 1433 | format \(e.g. \".gz\"). |
|---|
| | 1434 | |
|---|
| | 1435 | When FILE is absolute, it is first converted to a true name by chasing |
|---|
| | 1436 | out symbolic links. Only a file of this name \(see next paragraph for |
|---|
| | 1437 | extensions) will trigger the evaluation of FORM. When FILE is relative, |
|---|
| | 1438 | a file whose absolute true name ends in FILE will trigger evaluation. |
|---|
| | 1439 | |
|---|
| | 1440 | When FILE lacks an extension, a file name with any extension will trigger |
|---|
| | 1441 | evaluation. Otherwise, its extension must match FILE's. A further |
|---|
| | 1442 | extension for a compressed format \(e.g. \".gz\") on FILE will not affect |
|---|
| | 1443 | this name matching. |
|---|
| | 1444 | |
|---|
| | 1445 | Alternatively, FILE can be a feature (i.e. a symbol), in which case FORM |
|---|
| | 1446 | is evaluated whenever that feature is `provide'd. |
|---|
| | 1447 | |
|---|
| | 1448 | Usually FILE is just a library name like \"font-lock\" or a feature name |
|---|
| | 1449 | like 'font-lock. |
|---|
| | 1450 | |
|---|
| | 1451 | This 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. |
|---|
| 1411 | | (nconc elt (list form)) |
|---|
| 1412 | | ;; If the file has been loaded already, run FORM right away. |
|---|
| 1413 | | (if (if (symbolp file) |
|---|
| 1414 | | (featurep file) |
|---|
| 1415 | | ;; Make sure `load-history' contains the files dumped with |
|---|
| 1416 | | ;; Emacs for the case that FILE is one of them. |
|---|
| 1417 | | ;; (load-symbol-file-load-history) |
|---|
| 1418 | | (when (locate-library file) |
|---|
| 1419 | | (assoc (locate-library file) load-history))) |
|---|
| 1420 | | (eval form)))) |
|---|
| 1421 | | form) |
|---|
| | 1462 | (nconc elt (list form))) |
|---|
| | 1463 | |
|---|
| | 1464 | ;; Is there an already loaded file whose name (or `provide' name) |
|---|
| | 1465 | ;; matches FILE? |
|---|
| | 1466 | (if (if (stringp file) |
|---|
| | 1467 | (load-history-filename-element regexp-or-feature) |
|---|
| | 1468 | (featurep file)) |
|---|
| | 1469 | (eval form)))) |
|---|
| | 1470 | |
|---|
| | 1471 | (defun do-after-load-evaluation (abs-file) |
|---|
| | 1472 | "Evaluate all `eval-after-load' forms, if any, for ABS-FILE. |
|---|
| | 1473 | ABS-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)))))) |
|---|