-
Notifications
You must be signed in to change notification settings - Fork 0
/
early-init.el
141 lines (117 loc) · 5.09 KB
/
early-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
;; early-init.el -*- lexical-binding: t; no-byte-compile: t; mode: emacs-lisp; coding:utf-8; fill-column: 80 -*-
;; Only for use with emacs 27 or higher
;; see https://www.reddit.com/r/emacs/comments/7yns85/emacs_adds_support_for_a_second_read_earlier_init/
;; and https://lists.gnu.org/archive/html/emacs-devel/2017-10/msg00372.html
;; for more information
;;; Early Startup
;;;; Native Comp
;; see https://github.com/jimeh/build-emacs-for-macos#native-comp
;; https://akrl.sdf.org/gccemacs.html#org335c0de
(setq native-comp-speed 2
native-comp-deferred-compilation t)
(when (boundp 'native-comp-eln-load-path)
(setcar native-comp-eln-load-path
(expand-file-name ".local/temp/cache/eln-cache/" user-emacs-directory)))
;; Silence nativecomp warnings popping up on 28.0.50
(setq native-comp-async-report-warnings-errors nil)
;;;; Speed up startup
;; Help speed up emacs initialization
;; See https://blog.d46.us/advanced-emacs-startup/
;; and http://tvraman.github.io/emacspeak/blog/emacs-start-speed-up.html
;; and https://www.reddit.com/r/emacs/comments/3kqt6e/2_easy_little_known_steps_to_speed_up_emacs_start/
(defvar cpm--file-name-handler-alist file-name-handler-alist)
(setq file-name-handler-alist nil)
;;;; Garbage collection
;; Defer garbage collection further back in the startup process
(setq gc-cons-threshold most-positive-fixnum)
;; Adjust garbage collection thresholds during startup, and thereafter
;; see http://akrl.sdf.org
;; https://gitlab.com/koral/gcmh
;; NOTE: The system linked above generates too many GC pauses so I'm using my own mixed setup
;; https://github.com/purcell/emacs.d/blob/3b1302f2ce3ef2f69641176358a38fd88e89e664/init.el#L24
;; (let ((normal-gc-cons-threshold (* 20 1024 1024))
;; (init-gc-cons-threshold (* 128 1024 1024)))
;; (setq gc-cons-threshold init-gc-cons-threshold)
;; (add-hook 'emacs-startup-hook
;; (lambda () (setq gc-cons-threshold normal-gc-cons-threshold))))
(defmacro k-time (&rest body)
"Measure and return the time it takes evaluating BODY."
`(let ((time (current-time)))
,@body
(float-time (time-since time))))
;; When idle for 15sec run the GC no matter what.
(defvar k-gc-timer
(run-with-idle-timer 15 t
(lambda ()
(let ((inhibit-message t))
(message "Garbage Collector has run for %.06fsec"
(k-time (garbage-collect)))))))
;;;; Prefer Newer files
;; prefer newer versions
(setq load-prefer-newer t)
;;;; Byte Compile Warnings
;; Disable certain byte compiler warnings to cut down on the noise. This is a
;; personal choice and can be removed if you would like to see any and all byte
;; compiler warnings.
(setq byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local obsolete))
;;;; Check Errors
;; Produce backtraces when errors occur
(setq debug-on-error nil)
;;;; When-let errors
;; https://github.com/alphapapa/frame-purpose.el/issues/3
;; https://github.com/alphapapa/frame-purpose.el/issues/3
(eval-and-compile
(when (version< emacs-version "26")
(with-no-warnings
(defalias 'when-let* #'when-let)
(function-put #'when-let* 'lisp-indent-function 1)
(defalias 'if-let* #'if-let)
(function-put #'if-let* 'lisp-indent-function 2))))
;;;; Variable Binding Depth
;; https://www.reddit.com/r/emacs/comments/9jp9zt/anyone_know_what_variable_binding_depth_exceeds/
(setq max-specpdl-size 13000)
;;; Package settings
(setq package-enable-at-startup nil) ;; use straight
(advice-add #'package--ensure-init-file :override #'ignore)
;; Do not allow loading from the package cache (same reason).
(setq package-quickstart nil)
;;; Clean View
;; Disable start-up screen
;; Resizing the Emacs frame can be an expensive part of changing the
;; font. By inhibiting this, we easily halve startup times with fonts that are
;; larger than the system default.
(setq-default frame-title-format nil)
(setq-default frame-inhibit-implied-resize t)
(setq-default inhibit-startup-screen t)
(setq-default inhibit-splash-screen t)
(setq-default inhibit-startup-message t)
(setq-default initial-scratch-message nil)
;; UI - Disable visual cruft
;; Prevent the glimpse of un-styled Emacs by disabling these UI elements early.
(tool-bar-mode 0)
(tooltip-mode 0)
(menu-bar-mode 0)
(setq initial-major-mode 'fundamental-mode)
(setq default-frame-alist
(append (list
'(internal-border-width . 20)
'(left-fringe . 0)
'(right-fringe . 0)
'(tool-bar-lines . 0)
'(menu-bar-lines . 0)
'(vertical-scroll-bars . nil)
'(horizontal-scroll-bars . nil)
'(height . 45)
'(width . 85)
)))
;; ;; echo buffer
;; ;; Don't display any message
;; ;; https://emacs.stackexchange.com/a/437/11934
(defun display-startup-echo-area-message ()
(message ""))
;; And bury the scratch buffer, don't kill it
(defadvice kill-buffer (around kill-buffer-around-advice activate)
(let ((buffer-to-kill (ad-get-arg 0)))
(if (equal buffer-to-kill "*scratch*")
(bury-buffer)
ad-do-it)))