-
Notifications
You must be signed in to change notification settings - Fork 1
/
init-utils.el
78 lines (62 loc) · 2.18 KB
/
init-utils.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
71
72
73
74
75
76
77
78
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utility functions used across my init files. ;;
;; ;;
;; Author: Pushpal Sidhu <[email protected]> ;;
;; Date: 20171128 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (fboundp 'with-eval-after-load)
(defalias 'after-load 'with-eval-after-load)
(defmacro after-load (feature &rest body)
"After FEATURE is loaded, evaluate BODY."
(declare (indent defun))
`(eval-after-load ,feature
'(progn ,@body))))
;; Load Global Vars ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun util/lgv ()
"Load global vars into file"
(load (expand-file-name "global-vars.el" user-emacs-directory))
(require 'global-vars)
)
(defun util/compile-directory (dir)
"Compile files in directory DIR if req'd"
(byte-recompile-directory (expand-file-name dir) 0)
)
(defun util/load-elc-directory (dir)
"Loads elc files in directory DIR"
(let ((load-it (lambda (f)
(load-file f)))
)
(mapc load-it (directory-files-recursively dir "\\.elc$"))))
(defun util/load-directory (dir)
"Loads files in directory DIR"
(let ((load-it (lambda (f)
(load-file f)))
)
(mapc load-it (directory-files-recursively dir "\\.el$"))))
(defun util/mkdir (dir)
"Checks whether directory DIR exists. If not, create it and
it's parents"
(if (not (file-exists-p dir))
(make-directory dir t)
)
)
(defun util/touch (file)
"Checks whether file FILE exists. If not, create it."
(if (not (file-exists-p file))
(write-region "" nil file)
)
)
(defun util/hook-ext-to-mode (ext md)
"Hooks an extention (EXT) to a MODE"
(progn
(setq tmp (format "\\.%s\\'" ext))
(add-to-list 'auto-mode-alist `(,tmp . ,md))
)
)
(defun util/add-multi-hook (hooks fn)
"Adds multiple hooks to a single function"
(mapc (lambda (hook)
(add-hook hook fn))
hooks)
)
(provide 'init-utils)