improve erc-sasl
[Emacs.git] / lisp / init-site-lisp.el
blobc830042455033cdf21e432c245ad8b278a7fc3cd
1 ;;; init-site-lisp.el --- Support elisp manually installed in the site-lisp dir -*- lexical-binding: t -*-
2 ;;; Commentary:
3 ;;; Code:
5 ;;; Set load path
7 (require 'cl-lib)
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))
12 (setq load-path
13 (append
14 (cl-remove-if-not
15 #'file-directory-p
16 (directory-files (expand-file-name parent-dir) t "^[^\\.]"))
17 load-path))))
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)
40 el-file)))
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