1 ;;; init-site-lisp.el --- Support elisp manually installed in the site-lisp dir -*- lexical-binding: t -*-
9 (defun sanityinc/add-subdirs-to-load-path
(parent-dir)
10 "Add every non-hidden subdir of PARENT-DIR to `load-path'."
11 (let ((default-directory parent-dir
))
16 (directory-files (expand-file-name parent-dir
) t
"^[^\\.]"))
19 ;; Add both site-lisp and its immediate subdirs to `load-path'
20 (let ((site-lisp-dir (expand-file-name "site-lisp/" user-emacs-directory
)))
21 (push site-lisp-dir load-path
)
22 (sanityinc/add-subdirs-to-load-path site-lisp-dir
))
24 ;;; Utilities for grabbing upstream libs
26 (defun site-lisp-dir-for (name)
27 (expand-file-name (format "site-lisp/%s" name
) user-emacs-directory
))
29 (defun site-lisp-library-el-path (name)
30 (expand-file-name (format "%s.el" name
) (site-lisp-dir-for name
)))
32 (defun download-site-lisp-module (name url
)
33 (let ((dir (site-lisp-dir-for name
)))
34 (message "Downloading %s from %s" name url
)
35 (unless (file-directory-p dir
)
36 (make-directory dir t
))
37 (add-to-list 'load-path dir
)
38 (let ((el-file (site-lisp-library-el-path name
)))
39 (url-copy-file url el-file t nil
)
42 (defun ensure-lib-from-url (name url
)
43 (unless (site-lisp-library-loadable-p name
)
44 (byte-compile-file (download-site-lisp-module name url
))))
46 (defun site-lisp-library-loadable-p (name)
47 "Return whether or not the library `name' can be loaded from a
48 source file under ~/.emacs.d/site-lisp/name/"
49 (let ((f (locate-library (symbol-name name
))))
50 (and f
(string-prefix-p (file-name-as-directory (site-lisp-dir-for name
)) f
))))
53 (provide 'init-site-lisp
)
54 ;;; init-site-lisp.el ends here