forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-site-lisp.el
54 lines (42 loc) · 1.8 KB
/
init-site-lisp.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;;; init-site-lisp.el --- Support elisp manually installed in the site-lisp dir -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
;;; Set load path
(require 'cl-lib)
(defun sanityinc/add-subdirs-to-load-path (parent-dir)
"Add every non-hidden subdir of PARENT-DIR to `load-path'."
(let ((default-directory parent-dir))
(setq load-path
(append
(cl-remove-if-not
#'file-directory-p
(directory-files (expand-file-name parent-dir) t "^[^\\.]"))
load-path))))
;; Add both site-lisp and its immediate subdirs to `load-path'
(let ((site-lisp-dir (expand-file-name "site-lisp/" user-emacs-directory)))
(push site-lisp-dir load-path)
(sanityinc/add-subdirs-to-load-path site-lisp-dir))
;;; Utilities for grabbing upstream libs
(defun site-lisp-dir-for (name)
(expand-file-name (format "site-lisp/%s" name) user-emacs-directory))
(defun site-lisp-library-el-path (name)
(expand-file-name (format "%s.el" name) (site-lisp-dir-for name)))
(defun download-site-lisp-module (name url)
(let ((dir (site-lisp-dir-for name)))
(message "Downloading %s from %s" name url)
(unless (file-directory-p dir)
(make-directory dir t))
(add-to-list 'load-path dir)
(let ((el-file (site-lisp-library-el-path name)))
(url-copy-file url el-file t nil)
el-file)))
(defun ensure-lib-from-url (name url)
(unless (site-lisp-library-loadable-p name)
(byte-compile-file (download-site-lisp-module name url))))
(defun site-lisp-library-loadable-p (name)
"Return whether or not the library `name' can be loaded from a
source file under ~/.emacs.d/site-lisp/name/"
(let ((f (locate-library (symbol-name name))))
(and f (string-prefix-p (file-name-as-directory (site-lisp-dir-for name)) f))))
(provide 'init-site-lisp)
;;; init-site-lisp.el ends here