Skip to content

Instantly share code, notes, and snippets.

@cvmat
Created August 28, 2012 16:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvmat/3499459 to your computer and use it in GitHub Desktop.
Save cvmat/3499459 to your computer and use it in GitHub Desktop.
macro for autoload and eval-after-load
;;
;; Example with after-body.
;; (eval-after-autoload-if-found
;; '(cycle-buffer cycle-buffer-backward) "cycle-buffer" nil t nil
;; (setq cycle-buffer-allow-visible t)
;; (setq cycle-buffer-show-length 12)
;; (setq cycle-buffer-show-format '(" <(%s)>" . " %s")))
;;
;; Example without after-body.
;; (eval-after-autoload-if-found 'smooth-scrolling "smooth-scrolling" nil t)
;;
(defmacro eval-after-autoload-if-found (functions file &optional docstring interactive type &rest after-body)
"Set up autoload and eval-after-load for FUNCTIONS iff. FILE has found."
`(let* ((functions ,functions)
(docstring ,docstring)
(interactive ,interactive)
(type ,type)
(file ,file))
(when (locate-library file)
(mapc (lambda (func)
(autoload func file docstring interactive type))
(if (listp functions)
functions
(list functions)))
,@(when after-body
`((eval-after-load file '(progn ,@after-body))))
t)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment