about summary refs log tree commit diff stats
path: root/early-init.el
diff options
context:
space:
mode:
authorCase Duckworth2021-02-28 23:58:57 -0600
committerCase Duckworth2021-02-28 23:58:57 -0600
commit3f60767599db61c95333969869287d792d37159a (patch)
treea9f3b98f2a101a877ba7da7ab3bd56da753bce33 /early-init.el
parentChange acdw/bind-after-map thinking (diff)
downloademacs-3f60767599db61c95333969869287d792d37159a.tar.gz
emacs-3f60767599db61c95333969869287d792d37159a.zip
Restart shit
Diffstat (limited to 'early-init.el')
-rw-r--r--early-init.el297
1 files changed, 216 insertions, 81 deletions
diff --git a/early-init.el b/early-init.el index ef72beb..36bacbe 100644 --- a/early-init.el +++ b/early-init.el
@@ -1,21 +1,180 @@
1;;; early-init.el -*- no-byte-compile: t; coding: utf-8 -*- 1;;; early-init.el -*- lexical-binding: t; coding: utf-8 -*-
2;; Copyright (C) 2020 Case Duckworth 2;; Copyright (C) 2020-2021 Case Duckworth
3 3;;
4;; Author: Case Duckworth <acdw@acdw.net> 4;; Author: Case Duckworth <acdw@acdw.net>
5;; Created: Sometime during the Covid-19 lockdown, 2019 5;; Created: Sometime during Covid-19, 2020
6;; Keywords: configuration 6;; Keywords: configuration
7;; URL: https://tildegit.org/acdw/emacs 7;; URL https://tildegit.org/acdw/emacs
8;;
9;; This file is NOT part of GNU Emacs.
10;;
11;;; License:
12;;
13;; Everyone is permitted to do whatever with this software, without
14;; limitation. This software comes without any warranty whatsoever,
15;; but with two pieces of advice:
16;; - Don't hurt yourself.
17;; - Make good choices.
18;;
19;;; Comentary:
20;;
21;; Starting with Emacs 27.1, `early-init' is sourced before `package'
22;; or any frames. So those are the settings I run in this file.
23;;
24;;; Code:
8 25
9;; This file is not part of GNU Emacs. 26;; Speed up init
27(setq gc-cons-threshold most-positive-fixnum
28 gc-cons-percentage 0.6
29 comp-deferred-compilation nil)
10 30
11;;; Commentary: 31(defconst gc-cons-basis (* 800 1024)
12;; This file is automatically tangled from config.org. 32 "The basis value to which to return after a max jump.
13;; Hand edits will be overwritten! 33800,000 (800 KB) is Emacs' default.")
14 34
15;;; Code: 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 doom-reset-file-handler-alist-h ()
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 #'doom-reset-file-handler-alist-h))
61
62;; Where are we?
63(defconst acdw/system (pcase system-type
64 ('gnu/linux :home)
65 ((or 'msdos 'windows-nt) :work)
66 (_ :other)))
67
68;; Frame initiation
69
70;; Initialize frames with as little UI as possible.
71(setq-default
72 default-frame-alist ; The default look of frames
73 `((tool-bar-lines . 0) ; Remove tool bar
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
86 x-underline-at-descent-line t ; underline at the descent line
87
88 scroll-margin 0 ; how many lines to show at window edge
89 scroll-conservatively 101 ; just enough to bring text into view
90 scroll-preserve-screen-position 1 ; always keep screen position
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 )
101
102;; Set the rest of the fonts after initiation
103(defun hook--setup-fonts ()
104 (pcase acdw/system
105 (:home (set-face-attribute 'default nil
106 :family "Terminus"
107 :height 120)
108 (set-face-attribute 'fixed-pitch nil
109 :family "Terminus"
110 :height 1.0)
111 (set-face-attribute 'variable-pitch nil
112 :family "DejaVu Sans"
113 :height 1.0))
114 (:work (set-face-attribute 'default nil
115 :familiy "Consolas"
116 :height 110)
117 (set-face-attribute 'fixed-pitch nil
118 :family "Consolas"
119 :height 1.0)
120 (set-face-attribute 'variable-pitch nil
121 :family "Cambria"
122 :height 1.0))))
123
124(add-hook 'after-init-hook #'hook--setup-fonts)
125
126;; In case I do want the UI elements later, I also disable the modes
127;; -- otherwise I'd have to run the mode twice to actually show the
128;; thing.
129
130(defun hook--disable-ui-modes ()
131 (dolist (mode '(tool-bar-mode
132 menu-bar-mode
133 scroll-bar-mode
134 horizontal-scroll-bar-mode))
135 (funcall mode -1)))
136
137;; I run it on the `after-init-hook' so it doesn't slow down init so much.
138(add-hook 'after-init-hook #'hook--disable-ui-modes)
139
140;; Customize the fringe
141(setq-default
142 indicate-empty-lines t ; show an indicator at the end of the buffer
143 indicate-buffer-boundaries 'right ; show buffer boundaries on the right
144 visual-line-fringe-indicators ; show continuation indicators on the left
145 '(left-curly-arrow nil))
146
147(defun hook--setup-fringe-bitmaps ()
148 (define-fringe-bitmap 'left-curly-arrow
149 [#b11000000
150 #b01100000
151 #b00110000
152 #b00011000])
153 (define-fringe-bitmap 'right-curly-arrow
154 [#b00011000
155 #b00110000
156 #b01100000
157 #b11000000])
158 (define-fringe-bitmap 'left-arrow
159 [#b00000000
160 #b01010100
161 #b01010100
162 #b00000000])
163 (define-fringe-bitmap 'right-arrow
164 [#b00000000
165 #b00101010
166 #b00101010
167 #b00000000]))
168(add-hook 'after-init-hook #'hook--setup-fringe-bitmaps)
169
170;; Resize like it's 2021
171(setq-default frame-inhibit-implied-resize t
172 frame-resize-pixelwise t)
173
174;; Bootstrap package manager (`straight')
175
176;; First, I need to make sure it's in the `exec-path'.
16 177
17(message "%s..." "Loading early-init.el")
18;; BOOTSTRAP PACKAGE MANAGEMENT
19(let ((win-app-dir "~/Applications")) 178(let ((win-app-dir "~/Applications"))
20 (dolist (path (list 179 (dolist (path (list
21 ;; Windows 180 ;; Windows
@@ -31,21 +190,44 @@
31 (expand-file-name "bin" user-emacs-directory) 190 (expand-file-name "bin" user-emacs-directory)
32 (expand-file-name "~/bin") 191 (expand-file-name "~/bin")
33 (expand-file-name "~/.local/bin") 192 (expand-file-name "~/.local/bin")
34 (expand-file-name "~/Scripts") 193 (expand-file-name "~/usr/bin")
35 )) 194 ))
36 (when (file-exists-p path) 195 (when (file-exists-p path)
37 (add-to-list 'exec-path path :append)))) 196 (add-to-list 'exec-path path :append))))
38 197
39;; Set $PATH 198;; Set $PATH back to `exec-path', for symmetry's sake.
40(setenv "PATH" (mapconcat #'identity exec-path path-separator)) 199(setenv "PATH" (mapconcat #'identity exec-path path-separator))
41(setq package-enable-at-startup nil) 200
42(defun acdw/bootstrap-straight () 201;; Set some variables
43 "Bootstrap straight.el." 202(defvar acdw/etc-dir
203 (expand-file-name "etc/" user-emacs-directory)
204 "Where to put other configurations.")
205(defvar acdw/var-dir
206 (expand-file-name "var/" user-emacs-directory)
207 "Where to put variable stuff.")
208
209(setq-default package-enable-at-startup nil
210 package-quickstart nil
211 straight-use-package-by-default t
212 straight-host-usernames '((github . "duckwork")
213 (gitlab . "acdw"))
214 straight-base-dir acdw/var-dir)
215
216;; Run `straight''s bootstrap code, after gitting the code directly.
217(if (not (executable-find "git"))
218 (error "No 'git' in $PATH!")
219 (call-process "git" nil
220 (get-buffer-create "*bootstrap-straight-messages*")
221 nil
222 "clone"
223 "https://github.com/raxod502/straight.el"
224 (expand-file-name "repos/straight.el"
225 straight-base-dir))
44 (defvar bootstrap-version) 226 (defvar bootstrap-version)
45 (let ((bootstrap-file 227 (let ((bootstrap-file
46 (expand-file-name 228 (expand-file-name
47 "straight/repos/straight.el/bootstrap.el" 229 "repos/straight.el/bootstrap.el"
48 user-emacs-directory)) 230 straight-base-dir))
49 (bootstrap-version 5)) 231 (bootstrap-version 5))
50 (unless (file-exists-p bootstrap-file) 232 (unless (file-exists-p bootstrap-file)
51 (with-current-buffer 233 (with-current-buffer
@@ -57,67 +239,20 @@
57 (goto-char (point-max)) 239 (goto-char (point-max))
58 (eval-print-last-sexp))) 240 (eval-print-last-sexp)))
59 (load bootstrap-file nil 'nomessage))) 241 (load bootstrap-file nil 'nomessage)))
60(when (executable-find "git")
61 (unless (ignore-errors (acdw/bootstrap-straight))
62 (let ((msg "Straight.el didn't bootstrap correctly. Cloning directly"))
63 (message "%s..." msg)
64 (call-process "git" nil
65 (get-buffer-create "*bootstrap-straight-messages*") nil
66 "clone"
67 "https://github.com/raxod502/straight.el"
68 (expand-file-name "straight/repos/straight.el"
69 user-emacs-directory))
70 (message "%s...Done." msg)
71 (acdw/bootstrap-straight))))
72;; SETUP FRAME
73(add-to-list 'default-frame-alist
74 '(tool-bar-lines . 0))
75
76(tool-bar-mode -1)
77(add-to-list 'default-frame-alist
78 '(menu-bar-lines . 0))
79
80(menu-bar-mode -1)
81(add-to-list 'default-frame-alist
82 '(vertical-scroll-bars . nil)
83 '(horizontal-scroll-bars . nil))
84
85(scroll-bar-mode -1)
86(horizontal-scroll-bar-mode -1)
87(setq-default frame-inhibit-implied-resize t
88 frame-resize-pixelwise t)
89(setq-default indicate-empty-lines t)
90(setq-default indicate-buffer-boundaries 'right)
91(setq-default visual-line-fringe-indicators '(left-curly-arrow nil))
92(defun hook--setup-fringes-curly-arrows ()
93 "Set up curly-arrow fringes."
94 (define-fringe-bitmap 'left-curly-arrow
95 [#b11000000
96 #b01100000
97 #b00110000
98 #b00011000])
99 242
100 (define-fringe-bitmap 'right-curly-arrow
101 [#b00011000
102 #b00110000
103 #b01100000
104 #b11000000]))
105
106(add-hook 'after-init-hook #'hook--setup-fringes-curly-arrows)
107(defun hook--setup-fringes-arrows ()
108 "Setup arrow fringe bitmaps."
109 (define-fringe-bitmap 'left-arrow
110 [#b00000000
111 #b01010100
112 #b01010100
113 #b00000000])
114 243
115 (define-fringe-bitmap 'right-arrow 244;; `use-package'
116 [#b00000000 245
117 #b00101010 246(straight-use-package 'use-package)
118 #b00101010 247(require 'use-package)
119 #b00000000])) 248
120 249;; Message startup time
121(add-hook 'after-init-hook #'hook--setup-fringes-arrows) 250(defun hook--message-startup-time ()
122(message "%s... Done." "Loading early-init.el") 251 "Message Emacs' startup time."
123;;; early-init.el ends here 252 (message "Emacs ready in %s with %d garbage collections."
253 (format "%.2f seconds"
254 (float-time (time-subtract after-init-time
255 before-init-time)))
256 gcs-done))
257
258(add-hook 'emacs-startup-hook #'hook--message-startup-time)