-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.el
30 lines (26 loc) · 1003 Bytes
/
functions.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
(require 'cl)
(defun my-check-or-install-package (pkg)
(or (package-installed-p pkg)
(package-install pkg)))
(defun my-load-init (modules)
"Load initialization files"
(dolist (x modules)
(load (format "%s/init/%s" +my-emacs-config-dir+ x) t)))
(defun my-add-to-path (dir)
"Add directory 'dir' in +my-emacs-config-dir+ to 'load-path'"
(let ((name
(etypecase dir
(symbol (format "%s/%s" +my-emacs-config-dir+ dir))
(string dir))))
(when (file-exists-p name)
(add-to-list 'load-path name))))
(defmacro* my-require-and-eval ((feature &optional add-to-path package-name) &body body)
"Execute code if feature was loaded successfully"
`(progn
,(when package-name
`(my-check-or-install-package ',package-name))
,(when add-to-path
`(my-add-to-path ',add-to-path))
(if (require ',feature nil t)
(progn ,@body)
(message "my-require-and-eval: require filed for '%s'" ',feature))))