Skip to content

Latest commit

 

History

History
165 lines (118 loc) · 4.7 KB

early-init.org

File metadata and controls

165 lines (118 loc) · 4.7 KB

Emacs Early Init

Literate configuration for early-init.el.

Header

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

;; Copyright (c) 2022 mattiasdrp and contributors.

;; Author: mattiasdrp
;; Maintainer: mattiasdrp <https://github.com/mattiasdrp>
;; Created: 17 august 2022
;; Version: 1.0
;; Licence: MIT
;; Keywords: emacs, init, convenience, configuration
;; URL: https://github.com/mattiasdrp/pokemacs

;;; Commentary:

;; 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 early-init.org.
;; If you want to change it, edit early-init.org then M-x org-babel-tangle

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:

Decrease GC frequency

By increasing the GC threshold we ensure that it will run less frequently and thus lead to a faster start-up.

(setq gc-cons-threshold most-positive-fixnum)

Increase data read from processes

This is useful for lsp, notably

(setq read-process-output-max (* 1024 1024)) ;; 1mb

Native compilation settings

Disable warnings, async compilation and cache directory for native compilation.

;;; Native compilation settings
(when (featurep 'native-compile)
  ;; Silence compiler warnings as they can be pretty disruptive
  (setq native-comp-async-report-warnings-errors nil)

  ;; Make native compilation happens asynchronously
  (setq native-comp-deferred-compilation t)

  ;; Set the right directory to store the native compilation cache
  ;; NOTE: the method for setting the eln-cache directory depends on the emacs version
  (when (fboundp 'startup-redirect-eln-cache)
    (if (version< emacs-version "29")
        (add-to-list 'native-comp-eln-load-path (convert-standard-filename (expand-file-name "var/eln-cache/" user-emacs-directory)))
      (startup-redirect-eln-cache (convert-standard-filename (expand-file-name "var/eln-cache/" user-emacs-directory))))))

Disable package-enable-at-startup

Package initialize occurs automatically, before init.el is loaded, but after early-init.el. We handle package initialization, so we must prevent Emacs from doing it early.

(setq package-enable-at-startup nil)

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)
            (redisplay)))

Unset file-name-handler-alist

Every file opened and loaded by Emacs will run through this list to check for a proper handler for the file, but during startup, it won’t need any of them.

(defvar file-name-handler-alist-original file-name-handler-alist)
(setq file-name-handler-alist nil)

Disable site-run-file

(setq site-run-file nil)

Disable Unnecessary Interface

It will be faster to disable them here before they’ve been initialized.

(setq default-frame-alist
      '(
        ;; (min-height . 1) '(height . 45)
        ;; (min-width  . 1) '(width  . 81)
        ;; (vertical-scroll-bars)
        (internal-border-width . 0)
        (left-fringe . 8)
        (right-fringe . 8)
        (tool-bar-lines . 0)
        (menu-bar-lines . 0)))
(when (fboundp 'tool-bar-mode)
  (tool-bar-mode -1))
(when (fboundp 'menu-bar-mode)
  (menu-bar-mode -1))
(when (fboundp 'scroll-bar-mode)
  (scroll-bar-mode -1))

;; Default frame settings
(setq initial-frame-alist default-frame-alist)

Initial mode

Make the initial buffer load faster by setting its mode to fundamental-mode

(customize-set-variable 'initial-major-mode 'fundamental-mode)

End

(provide 'early-init)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; early-init.el ends here