From 81638f28910ac61997a3efeb60d8f64594953d89 Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Wed, 28 Nov 2012 11:54:19 +0900 Subject: [PATCH] add lazyload-eval --- emacs.el | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/emacs.el b/emacs.el index 96e8043..72704e2 100644 --- a/emacs.el +++ b/emacs.el @@ -69,14 +69,32 @@ otherwise the path where the library installed." (locate-library lib)) locate-p))) -;; (defmacro f-autoload (feature functions &rest form) -;; `(,@(mapcar (lambda (f) -;; `(autoload ,f ,(symbol-name feature))) -;; functions) -;; (eval-after-load ,feature -;; ,@form))) - -;; (f-autoload autosave (a b) (ddd) (ccc)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; autoload + +(defmacro lazyload-eval (feature functions &rest form) + "Define FUNCTIONS to autoload from FEATURE. +FEATURE is a symbol. FUNCTIONS is a list of symbols. +FORM is passed to `eval-after-load'. +When this macro is evaluated, this returns the path to library if feature +found, otherwise returns nil." + `(progn + ,@(mapcar (lambda (f) + `(autoload (quote ,f) + ,(symbol-name (eval feature)) + "" + t)) + (eval functions)) + (eval-after-load ,feature + '(progn + ,@form)) + (locate-library ,(symbol-name (eval feature))))) + +;; (macroexpand '(f-autoload 'autosave '(a-f b-f) (message "1") (message "2"))) +(when (lazyload-eval 'tetris + '(tetris) + (message "tetris loaded!")) + (message "tetris found!")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; start and quit