forked from NdYAG/dotemacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude.el
70 lines (63 loc) · 2.04 KB
/
include.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
;;----------------------------------------
;; include.el (el files loader)
;;
;; Copyright (c) 2013 Simon Day
;;
;; Author: Simon Day <[email protected]>
;; URL: http://daix.me
;;----------------------------------------
(require 'cl)
(defun full-user-path (p)
(concat user-emacs-directory p))
(defun include-load (lib)
(let ((path (file-name-sans-extension (locate-library lib)))
(el)
(elc))
(setq el (concat path ".el"))
(setq elc (concat path ".elc"))
(unless (and (file-exists-p elc)
(file-newer-than-file-p elc el))
(if (file-exists-p elc) (delete-file elc))
(byte-compile-file el))
(load path)))
;;;###autoload
(defun include (dir &optional files)
"load every file in the directory specified by first argument.
if second argument is given, only files in the `files` list will be loaded"
(when (file-directory-p (full-user-path dir))
(if files
(setq files (mapcar '(lambda (f) (concat f ".el")) files))
(setq files (directory-files (full-user-path dir))))
(dolist (file files)
(when (string-match "el$" file)
(include-load (concat dir (file-name-sans-extension file)))))))
;;;###autoload
(defun include-packages (&rest packages)
"automatically check required packages, and install the missed"
(message "%s" "Checking packages...")
(setq missed (remove-if 'package-installed-p packages))
(message
"%s"
(format "Packages %s missed."
(mapconcat (lambda (p) (format "%s" p)) missed ",")))
(when (> (length missed) 0)
(package-refresh-contents)
(mapcar
(lambda(p)
(message "Installing package %s" p)
(package-install p))
missed)
(package-initialize)))
;; deprecated
;;;###autoload
(defun include-path (p)
"add path and its sub-directories to `load-path` list"
(setq p (full-user-path p))
(add-to-list 'load-path p)
(dolist (f (directory-files p))
(let ((name (concat p "/" f)))
(when (and (file-directory-p name)
(not (equal f ".."))
(not (equal f ".")))
(add-to-list 'load-path name)))))
(provide 'include)