-
Notifications
You must be signed in to change notification settings - Fork 0
/
early-init.el
183 lines (146 loc) · 6.48 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
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
;;; early-init.el --- Emacs pre-initialisation config -*- lexical-binding: t -*-
;; Copyright (c) 2023 Bruno Boal <egomet@bboal.com>
;; Author: Bruno Boal <egomet@bboal.com>
;; URL: https://git.sr.ht/~bboal/emacs-config
;; Package-Requires: ((emacs "30.0"))
;; This file is NOT part of GNU Emacs.
;; This file is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the
;; Free Software Foundation, either version 3 of the License, or (at
;; your option) any later version.
;;
;; This file is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this file. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Still a sapling dreaming of becoming a tree
;;; Code:
;; Set eln-cache dir
(startup-redirect-eln-cache ".cache/eln-cache/")
;; Disabling the custom file.
(setq-default custom-file (make-temp-file "emacs-custom-"))
;; Tweaking some variables for improved startup time
(let ((std-gc-cons-threshold (expt 1024 3)) ; 1Gb memory
(std-gc-cons-percentage gc-cons-percentage)
(std-file-name-handler-alist file-name-handler-alist))
;; Initial values
(setq gc-cons-threshold most-positive-fixnum
gc-cons-percentage 1
file-name-handler-alist nil)
(add-hook 'emacs-startup-hook
(lambda ()
(setq gc-cons-threshold std-gc-cons-threshold
gc-cons-percentage std-gc-cons-percentage
file-name-handler-alist std-file-name-handler-alist))))
(defvar hour-sets-theme nil
"Global variable that stores theme name to be loaded at startup.")
;; Setting themes and avoid flash of light during startup
(defun bb-emacs-avoid-flash-of-light-at-startup ()
"Set background according to time of day before loading the theme."
(let ((curr-hour (string-to-number (format-time-string "%H"))))
(if (and (> curr-hour 6) (< curr-hour 16))
(progn
(set-face-background 'default "#edf4f8")
(setq hour-sets-theme 'ef-maris-light))
(set-face-background 'default "#131c2b")
(setq hour-sets-theme 'ef-maris-dark))))
;; setting the UI
(modify-all-frames-parameters `((internal-border-width . 8)
(left-fringe . 12)
(right-fringe . 12)
(vertical-scroll-bars)
(background-color . ,(face-background 'default))
(menu-bar-lines . 0)
(tab-bar-lines . 1)
(tool-bar-lines . 0)))
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; (with-eval-after-load 'comp-run
;; (setq native-comp-async-report-warnings-errors 'silent))
;; Early options to consider
(setq load-prefer-newer t
package-enable-at-startup nil
use-dialog-box nil
inhibit-startup-screen t
inhibit-startup-buffer-menu t
inhibit-x-resources t
frame-resize-pixelwise t
window-resize-pixelwise t
frame-inhibit-implied-resize t
garbage-collection-messages t
mode-line-format nil)
(defvar-local bb-flymake-assoc-buffer ""
"Name of the buffer that is associated with flymake diagnostic window.")
(defun bb-flymake-win-param (window)
"Associate name of buffer to flymake diagnostic recent created WINDOW."
(let ((name (buffer-name (window-buffer (get-mru-window)))))
(with-current-buffer (window-buffer window)
(setq-local bb-flymake-assoc-buffer name))))
;; Through `display-buffer-alist' we can configure specific options for windows
;; Thanks to Prot for teaching me to successfully silence Warnings/Compile errors
(setq
display-buffer-alist
'(("\\`\\*\\(Warnings\\|vc-git\s.*\\|Compile-Log\\|Org Links\\)\\*\\'"
(display-buffer-no-window)
(allow-no-window . t))
("\\*Help\\*"
(display-buffer-reuse-window display-buffer-in-direction)
(inhibit-same-window . t)
(direction . bottom)
(reusable-frames . 0)
(window-min-width . 60)
(window-width . fit-window-to-buffer)
(window-height . full-height))
("\\*Ibuffer\\*"
(display-buffer-reuse-window display-buffer-at-bottom)
(inhibit-same-window . t)
(dedicated . t)
(reusable-frames . 0)
(window-min-height . 14)
(window-height . fit-window-to-buffer))
;; 2024-06-08 TODO => Take care of notmuch windows
;; ("\\*notmuch-saved.*\\*"
;; (display-buffer-reuse-window display-buffer-below-selected)
;; (dedicated . t)
;; (reusable-frames . 0)
;; (window-height . full-height))
("\\*Flymake.*\\*"
(display-buffer-reuse-window display-buffer-below-selected)
(inhibit-same-window . t)
(dedicated . t)
(body-function . bb-flymake-win-param)
(reusable-frames . 0)
(window-min-height . 18)
(window-height . shrink-window-if-larger-than-buffer))))
(defun bb-emacs-invisible-dividers (_theme)
"Make windows dividers for THEME invisible.
Source: https://github.com/protesilaos/dotfiles"
(let ((bg (face-background 'default)))
(custom-set-faces
`(fringe ((t :background ,bg :foreground ,bg)))
;; `(vertical-border ((t :background ,bg :foreground ,bg)))
`(window-divider ((t :background ,bg :foreground ,bg)))
`(window-divider-first-pixel ((t :background ,bg :foreground ,bg)))
`(window-divider-last-pixel ((t :background ,bg :foreground ,bg))))))
(add-hook 'enable-theme-functions #'bb-emacs-invisible-dividers)
;; User info
(setq user-full-name "Bruno Boal"
user-login-name "bb"
user-mail-address "egomet@bboal.com"
inhibit-startup-echo-area-message "bb")
(defun bb-emacs-re-enable-frame-theme (_frame)
"Re-enable active theme, if any, upon FRAME creation.
Add this to `after-make-frame-functions' so that new frames do not retain the
generic background set above. Source: https://git.sr.ht/~protesilaos/dotfiles"
(when-let ((theme (car custom-enabled-themes)))
(enable-theme theme)))
(add-hook 'after-make-frame-functions #'bb-emacs-re-enable-frame-theme)
(bb-emacs-avoid-flash-of-light-at-startup)
(provide 'early-init)
;;; early-init.el ends here