diff options
| author | Stefan Monnier | 2013-06-13 18:24:52 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2013-06-13 18:24:52 -0400 |
| commit | de0503df97a507a523a192e877a8d5c7439c4846 (patch) | |
| tree | 0753a678f85a7ea1a2eb46b81067e8a5d6dfc1e0 /lisp | |
| parent | bc5c8c5a6a1956122284468879862b1850dc3b5d (diff) | |
| download | emacs-de0503df97a507a523a192e877a8d5c7439c4846.tar.gz emacs-de0503df97a507a523a192e877a8d5c7439c4846.zip | |
* lisp/subr.el (with-eval-after-load): New macro.
(eval-after-load): Allow form to be a function.
take advantage of lexical-binding.
(do-after-load-evaluation): Use dolist and adjust to new format.
* lisp/simple.el (bad-packages-alist): Use dolist and with-eval-after-load.
* doc/lispref/loading.texi (Hooks for Loading): Document with-eval-after-load
instead of eval-after-load. Don't document after-load-alist.
* src/lread.c (syms_of_lread):
* src/fns.c (Fprovide): Adjust to new format of after-load-alist.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/simple.el | 11 | ||||
| -rw-r--r-- | lisp/subr.el | 74 |
3 files changed, 58 insertions, 35 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 98e0382853d..88f218d15f3 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2013-06-13 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * subr.el (with-eval-after-load): New macro. | ||
| 4 | (eval-after-load): Allow form to be a function. | ||
| 5 | take advantage of lexical-binding. | ||
| 6 | (do-after-load-evaluation): Use dolist and adjust to new format. | ||
| 7 | * simple.el (bad-packages-alist): Use dolist and with-eval-after-load. | ||
| 8 | |||
| 1 | 2013-06-13 Juri Linkov <juri@jurta.org> | 9 | 2013-06-13 Juri Linkov <juri@jurta.org> |
| 2 | 10 | ||
| 3 | * replace.el (perform-replace): Display "symbol " and other search | 11 | * replace.el (perform-replace): Display "symbol " and other search |
diff --git a/lisp/simple.el b/lisp/simple.el index 15bf8779f56..3fd94e96d33 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -7295,8 +7295,7 @@ version and use the one distributed with Emacs.")) | |||
| 7295 | "Alist of packages known to cause problems in this version of Emacs. | 7295 | "Alist of packages known to cause problems in this version of Emacs. |
| 7296 | Each element has the form (PACKAGE SYMBOL REGEXP STRING). | 7296 | Each element has the form (PACKAGE SYMBOL REGEXP STRING). |
| 7297 | PACKAGE is either a regular expression to match file names, or a | 7297 | PACKAGE is either a regular expression to match file names, or a |
| 7298 | symbol (a feature name); see the documentation of | 7298 | symbol (a feature name), like for `with-eval-after-load'. |
| 7299 | `after-load-alist', to which this variable adds functions. | ||
| 7300 | SYMBOL is either the name of a string variable, or `t'. Upon | 7299 | SYMBOL is either the name of a string variable, or `t'. Upon |
| 7301 | loading PACKAGE, if SYMBOL is t or matches REGEXP, display a | 7300 | loading PACKAGE, if SYMBOL is t or matches REGEXP, display a |
| 7302 | warning using STRING as the message.") | 7301 | warning using STRING as the message.") |
| @@ -7314,10 +7313,10 @@ warning using STRING as the message.") | |||
| 7314 | (display-warning package (nth 3 list) :warning))) | 7313 | (display-warning package (nth 3 list) :warning))) |
| 7315 | (error nil))) | 7314 | (error nil))) |
| 7316 | 7315 | ||
| 7317 | (mapc (lambda (elem) | 7316 | (dolist (elem bad-packages-alist) |
| 7318 | (eval-after-load (car elem) `(bad-package-check ',(car elem)))) | 7317 | (let ((pkg (car elem))) |
| 7319 | bad-packages-alist) | 7318 | (with-eval-after-load pkg |
| 7320 | 7319 | (bad-package-check pkg)))) | |
| 7321 | 7320 | ||
| 7322 | (provide 'simple) | 7321 | (provide 'simple) |
| 7323 | 7322 | ||
diff --git a/lisp/subr.el b/lisp/subr.el index 380b2ba66ee..05f9167c699 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -3729,6 +3729,8 @@ Return nil if there isn't one." | |||
| 3729 | (defun eval-after-load (file form) | 3729 | (defun eval-after-load (file form) |
| 3730 | "Arrange that if FILE is loaded, FORM will be run immediately afterwards. | 3730 | "Arrange that if FILE is loaded, FORM will be run immediately afterwards. |
| 3731 | If FILE is already loaded, evaluate FORM right now. | 3731 | If FILE is already loaded, evaluate FORM right now. |
| 3732 | FORM can be an Elisp expression (in which case it's passed to `eval'), | ||
| 3733 | or a function (in which case it's passed to `funcall' with no argument). | ||
| 3732 | 3734 | ||
| 3733 | If a matching file is loaded again, FORM will be evaluated again. | 3735 | If a matching file is loaded again, FORM will be evaluated again. |
| 3734 | 3736 | ||
| @@ -3756,43 +3758,58 @@ Usually FILE is just a library name like \"font-lock\" or a feature name | |||
| 3756 | like 'font-lock. | 3758 | like 'font-lock. |
| 3757 | 3759 | ||
| 3758 | This function makes or adds to an entry on `after-load-alist'." | 3760 | This function makes or adds to an entry on `after-load-alist'." |
| 3761 | (declare (compiler-macro | ||
| 3762 | (lambda (whole) | ||
| 3763 | (if (eq 'quote (car-safe form)) | ||
| 3764 | ;; Quote with lambda so the compiler can look inside. | ||
| 3765 | `(eval-after-load ,file (lambda () ,(nth 1 form))) | ||
| 3766 | whole)))) | ||
| 3759 | ;; Add this FORM into after-load-alist (regardless of whether we'll be | 3767 | ;; Add this FORM into after-load-alist (regardless of whether we'll be |
| 3760 | ;; evaluating it now). | 3768 | ;; evaluating it now). |
| 3761 | (let* ((regexp-or-feature | 3769 | (let* ((regexp-or-feature |
| 3762 | (if (stringp file) | 3770 | (if (stringp file) |
| 3763 | (setq file (purecopy (load-history-regexp file))) | 3771 | (setq file (purecopy (load-history-regexp file))) |
| 3764 | file)) | 3772 | file)) |
| 3765 | (elt (assoc regexp-or-feature after-load-alist))) | 3773 | (elt (assoc regexp-or-feature after-load-alist)) |
| 3774 | (func | ||
| 3775 | (if (functionp form) form | ||
| 3776 | ;; Try to use the "current" lexical/dynamic mode for `form'. | ||
| 3777 | (eval `(lambda () ,form) lexical-binding)))) | ||
| 3766 | (unless elt | 3778 | (unless elt |
| 3767 | (setq elt (list regexp-or-feature)) | 3779 | (setq elt (list regexp-or-feature)) |
| 3768 | (push elt after-load-alist)) | 3780 | (push elt after-load-alist)) |
| 3769 | ;; Make sure `form' is evalled in the current lexical/dynamic code. | ||
| 3770 | (setq form `(funcall ',(eval `(lambda () ,form) lexical-binding))) | ||
| 3771 | ;; Is there an already loaded file whose name (or `provide' name) | 3781 | ;; Is there an already loaded file whose name (or `provide' name) |
| 3772 | ;; matches FILE? | 3782 | ;; matches FILE? |
| 3773 | (prog1 (if (if (stringp file) | 3783 | (prog1 (if (if (stringp file) |
| 3774 | (load-history-filename-element regexp-or-feature) | 3784 | (load-history-filename-element regexp-or-feature) |
| 3775 | (featurep file)) | 3785 | (featurep file)) |
| 3776 | (eval form)) | 3786 | (funcall func)) |
| 3777 | (when (symbolp regexp-or-feature) | 3787 | (let ((delayed-func |
| 3778 | ;; For features, the after-load-alist elements get run when `provide' is | 3788 | (if (not (symbolp regexp-or-feature)) func |
| 3779 | ;; called rather than at the end of the file. So add an indirection to | 3789 | ;; For features, the after-load-alist elements get run when |
| 3780 | ;; make sure that `form' is really run "after-load" in case the provide | 3790 | ;; `provide' is called rather than at the end of the file. |
| 3781 | ;; call happens early. | 3791 | ;; So add an indirection to make sure that `func' is really run |
| 3782 | (setq form | 3792 | ;; "after-load" in case the provide call happens early. |
| 3783 | `(if load-file-name | 3793 | (lambda () |
| 3784 | (let ((fun (make-symbol "eval-after-load-helper"))) | 3794 | (if (not load-file-name) |
| 3785 | (fset fun `(lambda (file) | 3795 | ;; Not being provided from a file, run func right now. |
| 3786 | (if (not (equal file ',load-file-name)) | 3796 | (funcall func) |
| 3787 | nil | 3797 | (let ((lfn load-file-name)) |
| 3788 | (remove-hook 'after-load-functions ',fun) | 3798 | (letrec ((fun (lambda (file) |
| 3789 | ,',form))) | 3799 | (when (equal file lfn) |
| 3790 | (add-hook 'after-load-functions fun)) | 3800 | (remove-hook 'after-load-functions fun) |
| 3791 | ;; Not being provided from a file, run form right now. | 3801 | (funcall func))))) |
| 3792 | ,form))) | 3802 | (add-hook 'after-load-functions fun)))))))) |
| 3793 | ;; Add FORM to the element unless it's already there. | 3803 | ;; Add FORM to the element unless it's already there. |
| 3794 | (unless (member form (cdr elt)) | 3804 | (unless (member delayed-func (cdr elt)) |
| 3795 | (nconc elt (list form)))))) | 3805 | (nconc elt (list delayed-func))))))) |
| 3806 | |||
| 3807 | (defmacro with-eval-after-load (file &rest body) | ||
| 3808 | "Execute BODY after FILE is loaded. | ||
| 3809 | FILE is normally a feature name, but it can also be a file name, | ||
| 3810 | in case that file does not provide any feature." | ||
| 3811 | (declare (indent 1) (debug t)) | ||
| 3812 | `(eval-after-load ,file (lambda () ,@body))) | ||
| 3796 | 3813 | ||
| 3797 | (defvar after-load-functions nil | 3814 | (defvar after-load-functions nil |
| 3798 | "Special hook run after loading a file. | 3815 | "Special hook run after loading a file. |
| @@ -3804,12 +3821,11 @@ name of the file just loaded.") | |||
| 3804 | ABS-FILE, a string, should be the absolute true name of a file just loaded. | 3821 | ABS-FILE, a string, should be the absolute true name of a file just loaded. |
| 3805 | This function is called directly from the C code." | 3822 | This function is called directly from the C code." |
| 3806 | ;; Run the relevant eval-after-load forms. | 3823 | ;; Run the relevant eval-after-load forms. |
| 3807 | (mapc #'(lambda (a-l-element) | 3824 | (dolist (a-l-element after-load-alist) |
| 3808 | (when (and (stringp (car a-l-element)) | 3825 | (when (and (stringp (car a-l-element)) |
| 3809 | (string-match-p (car a-l-element) abs-file)) | 3826 | (string-match-p (car a-l-element) abs-file)) |
| 3810 | ;; discard the file name regexp | 3827 | ;; discard the file name regexp |
| 3811 | (mapc #'eval (cdr a-l-element)))) | 3828 | (mapc #'funcall (cdr a-l-element)))) |
| 3812 | after-load-alist) | ||
| 3813 | ;; Complain when the user uses obsolete files. | 3829 | ;; Complain when the user uses obsolete files. |
| 3814 | (when (string-match-p "/obsolete/[^/]*\\'" abs-file) | 3830 | (when (string-match-p "/obsolete/[^/]*\\'" abs-file) |
| 3815 | (run-with-timer 0 nil | 3831 | (run-with-timer 0 nil |