-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
195 lines (158 loc) · 6.97 KB
/
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
;;; init.el --- Load my configuration -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(require 'cl-lib)
;; every custom variable of my config have the following group
(defgroup my nil "Group for all my config files." :group 'tools)
;;; HACKS
;; don't load anything useless at the startup (like `emacs-lisp-mode' for
;; *Scratch* or `dashboard')
(setq initial-major-mode 'fundamental-mode)
;; PERF,UX: Remove "For information about GNU Emacs..." message at startup.
;; It's redundant with our dashboard and incurs a premature redraw.
(advice-add #'display-startup-echo-area-message :override #'ignore)
;; PERF: Suppress the vanilla startup screen completely. We've disabled it
;; with `inhibit-startup-screen', but it would still initialize anyway.
;; This involves some file IO and/or bitmap work (depending on the frame
;; type) that we can no-op for a free 50-100ms boost in startup time.
(advice-add #'display-startup-screen :override #'ignore)
;; Increase how much is read from processes in a single chunk (default is 4kb).
;; This is further increased elsewhere, where needed (like our LSP module).
(setq read-process-output-max (* 64 1024)) ; 64kb
;; PERF: Line numbers are pretty slow all around. The performance boost of disabling
;; them outweighs the utility of always keeping them on.
(defvar display-line-numbers-type)
(setq display-line-numbers-type nil)
;; change Emacs config directory depends on init file
;;
;; after this config you can easily run Emacs with "emacs -l init.el"
;; not only when init.el inside ~/.emacs.d
(eval-and-compile
(setq user-emacs-directory
(file-name-directory (or load-file-name
(buffer-file-name)
byte-compile-current-file))))
(declare-function my-byte-compile-local-projects-autoloads "my-config-funcs")
;;; Handle --local-projects flag
;; byte-compile local-projects and generate autoloads
(when (member "--local-projects" command-line-args)
;; generate autoloads
(loaddefs-generate (locate-user-emacs-file "lisp/local-projects")
(locate-user-emacs-file "lisp/local-projects/my-autoload.el"))
;; also I byte-compile EACH of local projects them after load
;; `my-modules'
)
;;; Local Projects
;; It is my own small "packages" which aren't so big to create real packages
(eval-and-compile
;; add some files into the `load-path' that config files can require
;; them and byte-compiler will be happy
(add-to-list 'load-path (locate-user-emacs-file "lisp/"))
(add-to-list 'load-path (locate-user-emacs-file "lisp/package-management/"))
(add-to-list 'load-path (locate-user-emacs-file "lisp/local-projects"))
(load (locate-user-emacs-file "lisp/local-projects/my-autoload") :noerror :nomessage))
;;; add to `load-path' all installed packages
;;
;; I'm use `pam' which is built over straight.
;;
;; if packages was already installed, then every package was loaded
;; from the `pam' directory, it's more faster than load packages from
;; package specific directories (what do `straight') because in 2nd
;; case `load-path' will contain about 200+(*) directories and to load
;; one package with `require' Emacs will checks all these dirs. When
;; all packages files located inside the `pam' dir Emacs checks only
;; `pam' dir (instead of 200 other dirs).
;;
;; O(n) vs O(1) to load one package (n is amount of packages)
;;
;; This optimization matters for Windows, where slow IO
;;
;; NOTE: amount of the directories in the `load-path' depends on
;; amount of the packages and their dependencies (if you use
;; straight)
(require 'pam)
(pam-activate)
;;; Handle --modules
;; generate and byte-compile my-modules.el
;;
;; NOTE: I do it after local-projects, because `my-build-config' is a
;; local project too
(declare-function my-build-config "my-build-config.el")
(when (member "--modules" command-line-args)
(require 'my-build-config)
(my-build-config))
(when (member "--bcompile" command-line-args)
(byte-compile-file (locate-user-emacs-file "init.el"))
(byte-compile-file (locate-user-emacs-file "early-init.el"))
(pam-byte-compile-pkg-autoloads))
;;; don't use init.el for custom.el which I don't use
;;
;; in the most of configurations, after it Emacs load custom.el, but I
;; fount it a bit useless. I prefer `setq' over `custom'
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
;; some useful macros
(require 'my-macros)
(declare-function my-require-times "my-bench")
(add-to-list!
'command-line-functions
;; --kill
(defun my-kill-cli-handle-arg ()
"Handle --kill command-line argument.
Argument was named --kill, because it kill Emacs after Emacs is load.
It useful, if you needed in only install packages, byte compile
configuration and other these things.
This is function for `command-line-functions'."
(when (string-equal argi "--kill")
(kill-emacs)))
;; --modules
(defun my-modules-cli-handle-arg ()
"Handle --modules command-line argument.
Argument was named --modules, because it build my-modules.el file (or
`my-modules-el-file'). So when this argument is specified, then build
my-modules.el file with the `my-build-config' function
This is function for `command-line-functions'."
(when (string-equal argi "--modules")
;; it was handled above
t))
;; --bcompile
(defun my-bcompile-cli-handle-arg ()
"Handle --bcompile command-line argument.
This is function for `command-line-functions'."
(when (string-equal argi "--bcompile")
;; it was handled above
t))
;; --local-projects
(defun my-local-projects-cli-handle-arg ()
"Handle --local-projects command-line argument.
Byte-compile every file of local-projects and generate autoloads file"
(when (string-equal argi "--local-projects")
;; it was handled above
t))
(defun my-install-cli-handle-arg ()
"Handle --install command-line argument (see `pam').
Byte-compile every file of install and generate autoloads file"
(when (string-equal argi "--install")
;; it was handled above
t)))
;;; Load all config files
;; the most part of the config located inside "~/.emacs.d/lisp" I join all .el
;; files into the my-modules file for fast start up
(defvar my-modules-el-file (locate-user-emacs-file "dist/my-modules.el"))
(unless (file-exists-p (file-name-directory my-modules-el-file))
(user-error "File \"my-modules.el\" didn't created, suggest use --modules option"))
(add-to-list 'load-path (file-name-directory my-modules-el-file))
(let ((file-name-handler-alist nil)
(load-suffixes '(".elc" ".el")))
(require 'my-modules))
;; Handle --local-projects flag. Part 2: byte-compile all
(when (member "--local-projects" command-line-args)
;; byte-compile every file from the "local-projects" dir (including autoloads
;; file)
(my-byte-compile-local-projects-autoloads)
(dolist (file (directory-files (locate-user-emacs-file "lisp/local-projects/")
'full
".*\\.el$"))
(byte-compile-file file)))
(put 'narrow-to-region 'disabled nil)
(provide 'init)
;;; init.el ends here