forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-site-lisp.el
56 lines (42 loc) · 1.79 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
55
56
;;; Set load path
(eval-when-compile (require 'cl))
(defun sanityinc/add-subdirs-to-load-path (parent-dir)
"Adds every non-hidden subdir of PARENT-DIR to `load-path'."
(let* ((default-directory parent-dir))
(progn
(setq load-path
(append
(loop for dir in (directory-files parent-dir)
unless (string-match "^\\." dir)
collecting (expand-file-name dir))
load-path)))))
(sanityinc/add-subdirs-to-load-path
(expand-file-name "site-lisp/" user-emacs-directory))
;;; 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)
(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))))
;; Download these upstream libs
(unless (> emacs-major-version 23)
(ensure-lib-from-url
'package
"http://repo.or.cz/w/emacs.git/blob_plain/1a0a666f941c99882093d7bd08ced15033bc3f0c:/lisp/emacs-lisp/package.el"))
(provide 'init-site-lisp)