Created
November 28, 2012 06:20
-
-
Save 10sr/4159369 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defmacro lazy-load-eval (feature &optional functions &rest body) | |
| "Define each FUNCTIONS to autoload from FEATURE. | |
| FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil, | |
| the function same as FEATURE is defined as autoloaded function. BODY is passed | |
| to `eval-after-load'. | |
| When this macro is evaluated, this returns the path to library if FEATURE | |
| found, otherwise returns nil." | |
| (let* ((libname (symbol-name (eval feature))) | |
| (libpath (locate-library libname))) | |
| (and libpath | |
| `(progn | |
| ,@(mapcar (lambda (f) | |
| (or (fboundp f) | |
| `(autoload (quote ,f) | |
| ,libname | |
| ,(concat "Autoloaded function defined in \"" | |
| libpath | |
| "\".") | |
| t))) | |
| (or (eval functions) | |
| `(,(eval feature)))) | |
| (eval-after-load ,feature | |
| (quote (progn | |
| ,@body))) | |
| ,libpath)))) | |
| (put 'lazy-load-eval 'lisp-indent-function 2) | |
| (when (lazy-load-eval 'tetris nil | |
| (message "Tetris loaded!")) | |
| (message "Tetris found!")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment