summary refs log tree commit diff stats
path: root/early-init.el
diff options
context:
space:
mode:
authorCase Duckworth2021-03-07 22:14:38 -0600
committerCase Duckworth2021-03-07 22:14:38 -0600
commit983c7330e87481227393670b2151cb0539dc4de4 (patch)
tree79c5262d8ef6db8f8f3392e0c7923b37016f7185 /early-init.el
parentMerge branch 'no-org' of tildegit.org:acdw/emacs into no-org (diff)
downloademacs-983c7330e87481227393670b2151cb0539dc4de4.tar.gz
emacs-983c7330e87481227393670b2151cb0539dc4de4.zip
5c
Diffstat (limited to 'early-init.el')
-rw-r--r--early-init.el260
1 files changed, 80 insertions, 180 deletions
diff --git a/early-init.el b/early-init.el index 1bf78eb..352d4e6 100644 --- a/early-init.el +++ b/early-init.el
@@ -1,10 +1,9 @@
1;;; early-init.el -*- lexical-binding: t; coding: utf-8 -*- 1;;; early-init.el -*- lexical-binding: t; coding: utf-8-unix -*-
2;; Copyright (C) 2020-2021 Case Duckworth
3;; 2;;
4;; Author: Case Duckworth <acdw@acdw.net> 3;; Author: Case Duckworth <acdw@acdw.net>
5;; Created: Sometime during Covid-19, 2020 4;; Created: Sometime during Covid-19, 2020
6;; Keywords: configuration 5;; Keywords: configuration
7;; URL https://tildegit.org/acdw/emacs 6;; URL: https://tildegit.org/acdw/emacs
8;; 7;;
9;; This file is NOT part of GNU Emacs. 8;; This file is NOT part of GNU Emacs.
10;; 9;;
@@ -23,174 +22,85 @@
23;; 22;;
24;;; Code: 23;;; Code:
25 24
26;; Speed up init 25;;; Define personal-use constants
27(setq gc-cons-threshold most-positive-fixnum
28 gc-cons-percentage 0.6
29 comp-deferred-compilation nil)
30
31(defconst gc-cons-basis (* 800 1024)
32 "The basis value to which to return after a max jump.
33800,000 (800 KB) is Emacs' default.")
34
35(add-hook 'after-init-hook #'(lambda ()
36 (setq gc-cons-threshold gc-cons-basis
37 gc-cons-percentage 0.1)))
38
39(defun hook--gc-cons-maximize ()
40 "Set `gc-cons-threshold' to the highest possible.
41 For memory-intensive features."
42 (setq gc-cons-threshold most-positive-fixnum))
43
44(defun hook--gc-cons-baseline ()
45 "Return `gc-cons-threshold' to `gc-cons-basis'.
46 For after memory intensive operations."
47 (setq gc-cons-threshold gc-cons-basis))
48
49(add-hook 'minibuffer-setup-hook #'hook--gc-cons-maximize)
50(add-hook 'minibuffer-exit-hook #'hook--gc-cons-baseline)
51
52;; From doom-emacs
53(unless (daemonp)
54 (defvar doom--initial-file-name-handler-alist file-name-handler-alist)
55 (setq file-name-handler-alist nil)
56 (defun hook--reset-file-handler-alist ()
57 (dolist (handler file-name-handler-alist)
58 (add-to-list 'doom--initial-file-name-handler-alist handler))
59 (setq file-name-handler-alist doom--initial-file-name-handler-alist))
60 (add-hook 'emacs-startup-hook #'hook--reset-file-handler-alist))
61
62;; Where are we?
63(defconst acdw/system (pcase system-type 26(defconst acdw/system (pcase system-type
64 ('gnu/linux :home) 27 ('gnu/linux :home)
65 ((or 'msdos 'windows-nt) :work) 28 ((or 'msdos 'windows-nt) :work)
66 (_ :other))) 29 (_ :other))
67 30 "Which system is currently being used.")
68;; Frame initiation
69 31
70;; Initialize frames with as little UI as possible. 32(defvar acdw/dir (expand-file-name
71(setq-default 33 (convert-standard-filename "var/")
72 default-frame-alist ; The default look of frames 34 user-emacs-directory)
73 `((tool-bar-lines . 0) ; Remove tool bar 35 "A directory to hold extra configuration and emacs data.")
74 (menu-bar-lines . 0) ; Remove menu bar
75 (vertical-scroll-bars) ; Remove vertical scroll bars
76 (horizontal-scroll-bars) ; Remove horizontal scroll bars
77 (width . 84) ; A /little/ wider than `fill-column'
78 (height . 30) ; Text characters
79 (left-fringe . 8) ; Width of fringes
80 (right-fringe . 8) ; (8 is the default)
81 (font . ,(pcase acdw/system ; Default font
82 (:home "Terminus 12")
83 (:work "Consolas 11")))
84 )
85 36
86 x-underline-at-descent-line t ; underline at the descent line 37;;; Speed up init
38;; see doom-emacs, et al.
87 39
88 scroll-margin 0 ; how many lines to show at window edge 40(defconst gc-cons-threshold-basis (* 800 1000)
89 scroll-conservatively 101 ; just enough to bring text into view 41 "The basis value for `gc-cons-threshold' to return to after a jump.
90 scroll-preserve-screen-position 1 ; always keep screen position 42800 KB is Emacs's default `gc-cons-threshold'.")
91
92 frame-title-format ; Titles for frames
93 '((:eval (if (buffer-file-name) ; (cf. `mode-line-format')
94 (abbreviate-file-name (buffer-file-name))
95 "%b"))
96 " "
97 mode-line-client
98 mode-line-modified
99 " - GNU Emacs")
100 43
101 mode-line-format ; Mode line 44(defconst gc-cons-percentage-basis 0.1
102 `("%e" 45 "The basis value for `gc-cons-percentage' to return to after init.
103 mode-line-front-space 460.1 is Emacs's default `gc-cons-percentage'.")
104 ;; mode-line-mule-info
105 mode-line-client
106 mode-line-modified
107 mode-line-remote
108 mode-line-frame-identification
109 mode-line-buffer-identification " "
110 mode-line-position
111 (vc-mode vc-mode) " "
112 minions-mode-line-modes
113 mode-line-misc-info
114 mode-line-end-spaces
115 ))
116 47
117;; Set the rest of the fonts after initiation 48(defvar orig-file-name-handler-alist file-name-handler-alist
118(defun hook--setup-fonts () 49 "The original value of `file-name-handler-alist' will be restored
119 (pcase acdw/system 50 after init.")
120 (:home (set-face-attribute 'default nil
121 :family "Terminus"
122 :height 120)
123 (set-face-attribute 'fixed-pitch nil
124 :family "Terminus"
125 :height 1.0)
126 (set-face-attribute 'variable-pitch nil
127 :family "DejaVu Sans"
128 :height 1.0))
129 (:work (set-face-attribute 'default nil
130 :family "Consolas"
131 :height 110)
132 (set-face-attribute 'fixed-pitch nil
133 :family "Consolas"
134 :height 1.0)
135 (set-face-attribute 'variable-pitch nil
136 :family "Cambria"
137 :height 1.0))))
138 51
139(add-hook 'after-init-hook #'hook--setup-fonts) 52(setq gc-cons-threshold most-positive-fixnum
140 53 gc-cons-percentage 0.6
141;; In case I do want the UI elements later, I also disable the modes 54 file-name-handler-alist nil)
142;; -- otherwise I'd have to run the mode twice to actually show the 55
143;; thing. 56(defun hook--post-init-reset ()
57 "Reset `gc-cons-threshold', `gc-cons-percentage', and
58 `file-name-handler-alist' to their defaults after init."
59 (setq gc-cons-threshold gc-cons-threshold-basis
60 gc-cons-percentage gc-cons-percentage-basis)
61 (dolist (handler file-name-handler-alist)
62 (add-to-list 'orig-file-name-handler-alist handler))
63 (setq file-name-handler-alist orig-file-name-handler-alist))
64
65(add-hook 'after-init-hook #'hook--post-init-reset)
66
67;; ;;; Frame settings
68
69(setq default-frame-alist ; Remove most UI
70 `((tool-bar-lines . 0) ; No tool bar
71 (menu-bar-lines . 0) ; No menu bar
72 (vertical-scroll-bars) ; No scroll bars
73 (horizontal-scroll-bars) ; ... at all
74 (width . 84) ; A /little/ wider than
75 ; `fill-column' (set later)
76 (height . 30)
77 (left-fringe . 8) ; Width of fringes
78 (right-fringe . 8) ; (8 is default)
79 (font . ,(pcase acdw/system
80 (:home "Terminus 12")
81 (:work "Consolas 10"))))
82 frame-inhibit-implied-resize t ; Don't resize randomly
83 frame-resize-pixelwise t ; Resize by pixels, not chars
84 )
144 85
145(defun hook--disable-ui-modes () 86(defun hook--disable-ui-modes ()
146 (dolist (mode '(tool-bar-mode 87 "Disable frame UI using modes, for toggling later."
147 menu-bar-mode 88 (dolist (mode ;; each mode is of the form (MODE . FRAME-ALIST-VAR)
148 scroll-bar-mode 89 '((tool-bar-mode . tool-bar-lines)
149 horizontal-scroll-bar-mode)) 90 (menu-bar-mode . menu-bar-lines)
150 (funcall mode -1))) 91 (scroll-bar-mode . vertical-scroll-bars)
92 (horizontal-scroll-bar-mode . horizontal-scroll-bars)
93 ))
94 (let ((setting (alist-get (cdr mode) default-frame-alist)))
95 (when (or (not setting)
96 (= 0 setting))
97 (funcall (car mode) -1)))))
151 98
152;; I run it on the `after-init-hook' so it doesn't slow down init so much.
153(add-hook 'after-init-hook #'hook--disable-ui-modes) 99(add-hook 'after-init-hook #'hook--disable-ui-modes)
154 100
155;; Customize the fringe 101;;; Bootstrap package manager (`straight.el')
156(setq-default
157 indicate-empty-lines t ; show an indicator at the end of the buffer
158 indicate-buffer-boundaries 'right ; show buffer boundaries on the right
159 visual-line-fringe-indicators ; show continuation indicators on the left
160 '(left-curly-arrow nil))
161
162(defun hook--setup-fringe-bitmaps ()
163 (define-fringe-bitmap 'left-curly-arrow
164 [#b11000000
165 #b01100000
166 #b00110000
167 #b00011000])
168 (define-fringe-bitmap 'right-curly-arrow
169 [#b00011000
170 #b00110000
171 #b01100000
172 #b11000000])
173 (define-fringe-bitmap 'left-arrow
174 [#b00000000
175 #b01010100
176 #b01010100
177 #b00000000])
178 (define-fringe-bitmap 'right-arrow
179 [#b00000000
180 #b00101010
181 #b00101010
182 #b00000000])
183 (remove-function after-focus-change-function #'hook--setup-fringe-bitmaps))
184(add-function :after after-focus-change-function #'hook--setup-fringe-bitmaps)
185
186;; Resize like it's 2021
187(setq-default frame-inhibit-implied-resize t
188 frame-resize-pixelwise t)
189
190;; Bootstrap package manager (`straight')
191
192;; First, I need to make sure it's in the `exec-path'.
193 102
103;; 1. Update `exec-path'.
194(let ((win-app-dir "~/Applications")) 104(let ((win-app-dir "~/Applications"))
195 (dolist (path (list 105 (dolist (path (list
196 ;; Windows 106 ;; Windows
@@ -210,26 +120,19 @@
210 )) 120 ))
211 (when (file-exists-p path) 121 (when (file-exists-p path)
212 (add-to-list 'exec-path path :append)))) 122 (add-to-list 'exec-path path :append))))
213 123;; 1.5. Update $PATH to reflect changes.
214;; Set $PATH back to `exec-path', for symmetry's sake.
215(setenv "PATH" (mapconcat #'identity exec-path path-separator)) 124(setenv "PATH" (mapconcat #'identity exec-path path-separator))
216 125
217;; Set some variables 126;; 2. Set `package' and `straight' variables.
218(defvar acdw/etc-dir 127(setq package-enable-at-startup nil ; not sure if strictly
219 (expand-file-name "etc/" user-emacs-directory) 128 ; necessary
220 "Where to put other configurations.") 129 package-quickstart nil ; ditto
221(defvar acdw/var-dir 130 straight-host-usernames '((github . "duckwork")
222 (expand-file-name "var/" user-emacs-directory) 131 (gitlab . "acdw"))
223 "Where to put variable stuff.") 132 straight-base-dir acdw/dir ; don't clutter ~/.emacs.d
133 )
224 134
225(setq-default package-enable-at-startup nil 135;; 3. Bootstrap `straight'.
226 package-quickstart nil
227 straight-use-package-by-default t
228 straight-host-usernames '((github . "duckwork")
229 (gitlab . "acdw"))
230 straight-base-dir acdw/var-dir)
231
232;; Run `straight''s bootstrap code
233(defvar bootstrap-version) 136(defvar bootstrap-version)
234(let ((bootstrap-file 137(let ((bootstrap-file
235 (expand-file-name 138 (expand-file-name
@@ -239,20 +142,17 @@
239 (unless (file-exists-p bootstrap-file) 142 (unless (file-exists-p bootstrap-file)
240 (with-current-buffer 143 (with-current-buffer
241 (url-retrieve-synchronously 144 (url-retrieve-synchronously
242 "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el" 145 (concat "https://raw.githubusercontent.com/"
146 "raxod502/straight.el/develop/install.el")
243 'silent 'inhibit-cookies) 147 'silent 'inhibit-cookies)
244 (goto-char (point-max)) 148 (goto-char (point-max))
245 (eval-print-last-sexp))) 149 (eval-print-last-sexp)))
246 (load bootstrap-file nil 'nomessage)) 150 (load bootstrap-file nil 'nomessage))
247 151
248;; `use-package' 152;;; Message startup time for profiling
249
250(straight-use-package 'use-package)
251(require 'use-package)
252 153
253;; Message startup time
254(defun hook--message-startup-time () 154(defun hook--message-startup-time ()
255 "Message Emacs' startup time." 155 "Show Emacs's startup time in the message buffer. For profiling."
256 (message "Emacs ready in %s with %d garbage collections." 156 (message "Emacs ready in %s with %d garbage collections."
257 (format "%.2f seconds" 157 (format "%.2f seconds"
258 (float-time (time-subtract after-init-time 158 (float-time (time-subtract after-init-time