2021-03-08 04:14:38 +00:00
|
|
|
;;; early-init.el -*- lexical-binding: t; coding: utf-8-unix -*-
|
2021-02-26 17:31:50 +00:00
|
|
|
;; Author: Case Duckworth <acdw@acdw.net>
|
2021-03-01 05:58:57 +00:00
|
|
|
;; Created: Sometime during Covid-19, 2020
|
2021-02-26 17:31:50 +00:00
|
|
|
;; Keywords: configuration
|
2021-03-08 04:14:38 +00:00
|
|
|
;; URL: https://tildegit.org/acdw/emacs
|
2021-03-16 16:16:21 +00:00
|
|
|
|
2021-03-01 05:58:57 +00:00
|
|
|
;; This file is NOT part of GNU Emacs.
|
2021-03-16 16:16:21 +00:00
|
|
|
|
2021-03-01 05:58:57 +00:00
|
|
|
;;; License:
|
|
|
|
;; Everyone is permitted to do whatever with this software, without
|
|
|
|
;; limitation. This software comes without any warranty whatsoever,
|
|
|
|
;; but with two pieces of advice:
|
|
|
|
;; - Don't hurt yourself.
|
|
|
|
;; - Make good choices.
|
2021-03-16 16:16:21 +00:00
|
|
|
|
2021-03-01 05:58:57 +00:00
|
|
|
;;; Comentary:
|
|
|
|
;; Starting with Emacs 27.1, `early-init' is sourced before `package'
|
|
|
|
;; or any frames. So those are the settings I run in this file.
|
2021-03-16 16:16:21 +00:00
|
|
|
|
2021-03-01 05:58:57 +00:00
|
|
|
;;; Code:
|
2021-02-26 17:31:50 +00:00
|
|
|
|
2021-03-25 17:02:28 +00:00
|
|
|
;;; Add `acdw.el'
|
|
|
|
(push (expand-file-name "lisp/" user-emacs-directory)
|
|
|
|
load-path)
|
|
|
|
(require 'acdw)
|
2021-03-01 05:58:57 +00:00
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
;;; Speed up init
|
|
|
|
;; see doom-emacs, et al.
|
2021-03-01 05:58:57 +00:00
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
(defconst gc-cons-threshold-basis (* 800 1000)
|
|
|
|
"The basis value for `gc-cons-threshold' to return to after a jump.
|
|
|
|
800 KB is Emacs's default `gc-cons-threshold'.")
|
2021-03-01 22:57:10 +00:00
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
(defconst gc-cons-percentage-basis 0.1
|
|
|
|
"The basis value for `gc-cons-percentage' to return to after init.
|
|
|
|
0.1 is Emacs's default `gc-cons-percentage'.")
|
2021-03-01 05:58:57 +00:00
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
(defvar orig-file-name-handler-alist file-name-handler-alist
|
|
|
|
"The original value of `file-name-handler-alist' will be restored
|
|
|
|
after init.")
|
2021-03-01 05:58:57 +00:00
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
(setq gc-cons-threshold most-positive-fixnum
|
|
|
|
gc-cons-percentage 0.6
|
|
|
|
file-name-handler-alist nil)
|
|
|
|
|
|
|
|
(defun hook--post-init-reset ()
|
|
|
|
"Reset `gc-cons-threshold', `gc-cons-percentage', and
|
|
|
|
`file-name-handler-alist' to their defaults after init."
|
|
|
|
(setq gc-cons-threshold gc-cons-threshold-basis
|
2021-03-25 17:03:59 +00:00
|
|
|
gc-cons-percentage gc-cons-percentage-basis)
|
2021-03-08 04:14:38 +00:00
|
|
|
(dolist (handler file-name-handler-alist)
|
|
|
|
(add-to-list 'orig-file-name-handler-alist handler))
|
|
|
|
(setq file-name-handler-alist orig-file-name-handler-alist))
|
|
|
|
|
|
|
|
(add-hook 'after-init-hook #'hook--post-init-reset)
|
|
|
|
|
2021-03-11 18:04:18 +00:00
|
|
|
;;; Frame settings
|
2021-03-08 04:14:38 +00:00
|
|
|
|
|
|
|
(setq default-frame-alist ; Remove most UI
|
|
|
|
`((tool-bar-lines . 0) ; No tool bar
|
2021-03-25 17:03:59 +00:00
|
|
|
(menu-bar-lines . 0) ; No menu bar
|
|
|
|
(vertical-scroll-bars) ; No scroll bars
|
|
|
|
(horizontal-scroll-bars) ; ... at all
|
|
|
|
(width . 84) ; A /little/ wider than
|
|
|
|
; `fill-column' (set later)
|
|
|
|
(height . 30)
|
|
|
|
(left-fringe . 8) ; Width of fringes
|
|
|
|
(right-fringe . 8) ; (8 is default)
|
|
|
|
(font . ,(pcase acdw/system
|
|
|
|
(:home "DejaVu Sans Mono 10")
|
|
|
|
(:work "Consolas 10"))))
|
|
|
|
frame-inhibit-implied-resize t ; Don't resize randomly
|
|
|
|
frame-resize-pixelwise t ; Resize by pixels, not chars
|
|
|
|
)
|
2021-03-01 05:58:57 +00:00
|
|
|
|
|
|
|
(defun hook--disable-ui-modes ()
|
2021-03-08 04:14:38 +00:00
|
|
|
"Disable frame UI using modes, for toggling later."
|
|
|
|
(dolist (mode ;; each mode is of the form (MODE . FRAME-ALIST-VAR)
|
2021-03-25 17:03:59 +00:00
|
|
|
'((tool-bar-mode . tool-bar-lines)
|
|
|
|
(menu-bar-mode . menu-bar-lines)
|
|
|
|
(scroll-bar-mode . vertical-scroll-bars)
|
|
|
|
(horizontal-scroll-bar-mode . horizontal-scroll-bars)
|
|
|
|
))
|
2021-03-08 04:14:38 +00:00
|
|
|
(let ((setting (alist-get (cdr mode) default-frame-alist)))
|
|
|
|
(when (or (not setting)
|
2021-03-25 17:03:59 +00:00
|
|
|
(= 0 setting))
|
|
|
|
(funcall (car mode) -1)))))
|
2021-03-01 05:58:57 +00:00
|
|
|
|
|
|
|
(add-hook 'after-init-hook #'hook--disable-ui-modes)
|
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
;;; Bootstrap package manager (`straight.el')
|
2021-02-26 17:31:50 +00:00
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
;; 1. Update `exec-path'.
|
2021-03-24 16:22:39 +00:00
|
|
|
(dolist (path (list (expand-file-name "bin" user-emacs-directory)
|
2021-03-25 17:03:59 +00:00
|
|
|
(expand-file-name "~/bin")
|
|
|
|
(expand-file-name "~/.local/bin")
|
|
|
|
(expand-file-name "~/usr/bin")
|
|
|
|
(expand-file-name "~/cmd")
|
|
|
|
(expand-file-name "~/mingw64/bin")))
|
2021-03-24 16:22:39 +00:00
|
|
|
(when (file-exists-p path)
|
|
|
|
(add-to-list 'exec-path path :append)))
|
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
;; 1.5. Update $PATH to reflect changes.
|
2021-02-26 17:31:50 +00:00
|
|
|
(setenv "PATH" (mapconcat #'identity exec-path path-separator))
|
2021-03-01 05:58:57 +00:00
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
;; 2. Set `package' and `straight' variables.
|
|
|
|
(setq package-enable-at-startup nil ; not sure if strictly
|
2021-03-25 17:03:59 +00:00
|
|
|
; necessary
|
2021-03-08 04:14:38 +00:00
|
|
|
package-quickstart nil ; ditto
|
|
|
|
straight-host-usernames '((github . "duckwork")
|
2021-03-25 17:03:59 +00:00
|
|
|
(gitlab . "acdw"))
|
2021-03-08 04:14:38 +00:00
|
|
|
straight-base-dir acdw/dir ; don't clutter ~/.emacs.d
|
|
|
|
)
|
2021-03-01 05:58:57 +00:00
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
;; 3. Bootstrap `straight'.
|
2021-03-01 18:12:48 +00:00
|
|
|
(defvar bootstrap-version)
|
|
|
|
(let ((bootstrap-file
|
|
|
|
(expand-file-name
|
2021-03-25 17:03:59 +00:00
|
|
|
"straight/repos/straight.el/bootstrap.el"
|
|
|
|
straight-base-dir))
|
2021-03-01 18:12:48 +00:00
|
|
|
(bootstrap-version 5))
|
|
|
|
(unless (file-exists-p bootstrap-file)
|
|
|
|
(with-current-buffer
|
2021-03-25 17:03:59 +00:00
|
|
|
(url-retrieve-synchronously
|
|
|
|
(concat "https://raw.githubusercontent.com/"
|
|
|
|
"raxod502/straight.el/develop/install.el")
|
|
|
|
'silent 'inhibit-cookies)
|
2021-03-01 18:12:48 +00:00
|
|
|
(goto-char (point-max))
|
|
|
|
(eval-print-last-sexp)))
|
|
|
|
(load bootstrap-file nil 'nomessage))
|
2021-02-26 17:31:50 +00:00
|
|
|
|
2021-03-08 04:14:38 +00:00
|
|
|
;;; Message startup time for profiling
|
2021-03-01 05:58:57 +00:00
|
|
|
|
|
|
|
(defun hook--message-startup-time ()
|
2021-03-08 04:14:38 +00:00
|
|
|
"Show Emacs's startup time in the message buffer. For profiling."
|
2021-03-01 05:58:57 +00:00
|
|
|
(message "Emacs ready in %s with %d garbage collections."
|
2021-03-25 17:03:59 +00:00
|
|
|
(format "%.2f seconds"
|
|
|
|
(float-time (time-subtract after-init-time
|
|
|
|
before-init-time)))
|
|
|
|
gcs-done))
|
2021-03-01 05:58:57 +00:00
|
|
|
|
|
|
|
(add-hook 'emacs-startup-hook #'hook--message-startup-time)
|
2021-03-15 04:49:08 +00:00
|
|
|
|
|
|
|
;;; Install `no-littering', pointing both directories at `acdw/dir'. This will
|
|
|
|
;;; take care of the packages I don't care about configuring.
|
|
|
|
|
|
|
|
(straight-use-package 'no-littering)
|
|
|
|
(setq no-littering-etc-directory acdw/dir
|
|
|
|
no-littering-var-directory acdw/dir)
|
|
|
|
(require 'no-littering)
|