Emacs Early Init

Table of Contents


This file contains Emacs Lisp code that will run before the Emacs init.el file.

This file was written using Emacs Org Mode. This makes navigating and modifying my Emacs configuration much simpler as I can place different elements of my configuration under separate headings. The code in this file is placed in source code blocks that are tangled to the early-init.el file that Emacs will look for upon starting. When this file is saved, the source code blocks that are marked for tangling will write their contents to early-init.el.

1. Header for early-init.el

The following code block will add a header to the early-init.el file when it is generated on saving.

  ;;; early-init.el --- Emacs early init -*- lexical-binding: t -*-

;; Author: Thomas Freeman
;; Maintainer: Thomas Freeman
;; Created: 09 Jan 2022

;; URL: https://github.com/tfree87/.emacs.d

;; This file is an early-init file for Emacs. It will be executed before
;; init.el when emacs is loaded.

;; This file IS NOT intended to be edited! It was generated by init.org.

;;; Commentary:

;; For documentation and for editing this file, see the init.org in the
;; github repository tfree87/.emacs.d
;;; Code:

2. Decrease Garbage Collection Frequency

Emacs collects garbage very fequently slowing down the startup process. Emacs normally does a garbage collection every 800 kB. Since I always have the RAM for it, I have set the garbage collection to only happen after 500 MB. Increasing the number above this does not provide any significant gains in startup time as of yet. This idea came from https://blog.d46.us/advanced-emacs-startup/#/.emacs.d/init.el.

(setq gc-cons-threshold 500000000)

3. Prevent Unwanted Runtime Compilation

Prevent extra unnecessary runtime compilation for gccemacs. This idea came from the Doom Emacs early-init.el file.

(setq native-comp-deferred-compilation nil)

4. Disable Emacs Package Manager

In order to prevent conflicts between straight.el and the Emacs package manager, package-enable-at-startup should be set to nil. This came from the straight.el installation instructions.

(setq package-enable-at-startup nil)

5. Reduce Redisplay

To reduce slowdowns caused by early redisplays when loading, the following code will reduce the amount of times Emacs redisplays when setting up windows. This idea came from the Doom Emacs early-init.el file.

(setq-default inhibit-redisplay t
              inhibit-message t)
(add-hook 'window-setup-hook
          (lambda ()
            (setq-default inhibit-redisplay nil
                          inhibit-message nil)

6. Set Environment to UTF-8

Set the default coding system to UTF-8.This idea came from the Doom Emacs early-init.el file.

(set-language-environment "UTF-8")
(setq default-input-method nil)

7. End

;;; early-init.el ends here

Date: Time-stamp: <2022-06-07 Tue 10:57>

Author: Thomas Freeman

Created: 2022-06-07 Tue 13:40