-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspa_emacs_init.el
73 lines (57 loc) · 2.89 KB
/
spa_emacs_init.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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package Repositories ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'package)
(setq package-archives
'(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "http://stable.melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")))
(package-initialize)
;;;;;;;;;;;;;;;;;
;; use-package ;;
;;;;;;;;;;;;;;;;;
(package-refresh-contents)
(dolist (package '(use-package diminish bind-key))
(unless (package-installed-p package)
(package-install package)))
;; Enable use-package
(eval-when-compile
(require 'use-package)
(setq use-package-compute-statistics t))
(require 'diminish) ;; if you use :diminish
(require 'bind-key) ;; if you use any :bind variant
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Benchmarking Emacs Init ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package benchmark-init
:ensure t
:pin melpa-stable
:config
;; To disable collection of benchmark data after init is done.
(add-hook 'after-init-hook 'benchmark-init/deactivate))
;; Custom function to get full path relative to caller's location
(defun xah-get-fullpath (@file-relative-path)
"Return the full path of *file-relative-path, relative to caller's file location.
Example: If you have this line
(xah-get-fullpath \"../xyz.el\")
in the file at
/home/mary/emacs/emacs_lib.el
then the return value is
/home/mary/xyz.el
Regardless how or where emacs_lib.el is called.
This function solves 2 problems.
① If you have file A, that calls the `load' on a file at B, and B calls `load' on file C using a relative path, then Emacs will complain about unable to find C. Because, emacs does not switch current directory with `load'.
To solve this problem, when your code only knows the relative path of another file C, you can use the variable `load-file-name' to get the current file's full path, then use that with the relative path to get a full path of the file you are interested.
② To know the current file's full path, emacs has 2 ways: `load-file-name' and `buffer-file-name'. If the file is loaded by `load', then `load-file-name' works but `buffer-file-name' doesn't. If the file is called by `eval-buffer', then `load-file-name' is nil. You want to be able to get the current file's full path regardless the file is run by `load' or interactively by `eval-buffer'."
(concat (file-name-directory (or load-file-name buffer-file-name)) @file-relative-path)
)
(defconst dot-emacs-path (xah-get-fullpath "."))
;; Load plain Emacs settings
(load (xah-get-fullpath "spa_vanilla_settings"))
;; Load add-on packages
(load (xah-get-fullpath "spa_packages"))
;; Load Custom Functions
(load (xah-get-fullpath "spa_functions"))
;; Load keybindings
(load (xah-get-fullpath "spa_keybindings"))