emacs/early-init.el

157 lines
4.9 KiB
EmacsLisp
Raw Normal View History

2021-03-08 04:14:38 +00:00
;;; early-init.el -*- lexical-binding: t; coding: utf-8-unix -*-
;; 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
;;; License:
;; Everyone is permitted to do whatever they like with this software
;; without limitation. This software comes without any warranty
;; whatsoever, but with two pieces of advice:
;; - Be kind to yourself.
2021-03-01 05:58:57 +00:00
;; - Make good choices.
2021-03-16 16:16:21 +00:00
;;; Commentary:
;; Starting with Emacs 27.1, early-init.el is sourced before
;; package.el and any graphical frames. In this file, I set up frame
;; parameters and packaging infrastructure.
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-12-31 05:08:10 +00:00
;;; Speed up init
2022-02-07 04:15:41 +00:00
;; Restore things after init
(defvar +emacs--startup-restore-alist nil
"Variables and values to restore after init.")
2021-12-31 05:08:10 +00:00
(add-hook 'emacs-startup-hook
(defun emacs-startup@restore-values ()
2022-02-07 04:15:41 +00:00
"Restore values set during init.
This applies values in `+emacs--startup-restore-alist'."
(dolist (a +emacs--startup-restore-alist)
(set (car a) (cdr a)))))
(defun +set-during-startup (variable value &optional restore)
"Set VARIABLE to VALUE during startup, but restore to RESTORE.
If RESTORE is nil or not passed, save the original value and
restore that."
2022-02-19 00:18:03 +00:00
(unless after-init-time
2022-02-07 04:15:41 +00:00
(setf (alist-get variable +emacs--startup-restore-alist)
(or restore (symbol-value variable)))
(set-default variable value)))
;; Garbage collection
(+set-during-startup 'gc-cons-threshold most-positive-fixnum (* 128 1024 1024))
2021-12-31 05:08:10 +00:00
2022-02-03 00:28:33 +00:00
;; Don't prematurely re-display
2022-02-07 04:15:41 +00:00
(+set-during-startup 'inhibit-redisplay t)
(+set-during-startup 'inhibit-message t)
;; Debug during init
2022-02-19 00:18:03 +00:00
(unless (eq debug-on-error 'startup)
(+set-during-startup 'debug-on-error 'init))
2022-02-03 00:28:33 +00:00
2021-12-31 05:08:10 +00:00
;;; Set up extra load paths and functionality
2021-12-29 04:14:21 +00:00
(push (locate-user-emacs-file "lisp") load-path)
2021-03-25 17:02:28 +00:00
(require 'acdw)
2022-01-21 22:34:55 +00:00
(require 'compat)
(+define-dir .etc (locate-user-emacs-file ".etc")
"Directory for all of Emacs's various files.
See `no-littering' for examples.")
(+define-dir sync/ (expand-file-name "~/Sync")
"My Syncthing directory.")
;;; Default frame settings
(setq default-frame-alist '((tool-bar-lines . 0)
2022-01-04 20:42:26 +00:00
(menu-bar-lines . 0)
(vertical-scroll-bars)
(horizontal-scroll-bars))
2021-09-25 18:16:09 +00:00
frame-inhibit-implied-resize t
frame-resize-pixelwise t
window-resize-pixelwise t
inhibit-x-resources t
indicate-empty-lines nil
indicate-buffer-boundaries '((top . right)
2022-01-04 20:42:26 +00:00
(bottom . right)))
2022-02-07 04:15:41 +00:00
;;; No littering!
;; We install `no-littering' package below, but we can set the variables now.
(setq no-littering-etc-directory .etc
no-littering-var-directory .etc
straight-base-dir .etc)
;; https://github.com/emacscollective/no-littering/wiki/Setting-gccemacs'-eln-cache
(when (boundp 'comp-eln-load-path)
(setcar comp-eln-load-path (expand-file-name (.etc "eln-cache" t))))
2022-01-04 20:42:26 +00:00
;;; Packages
(setq package-enable-at-startup nil
package-quickstart nil
2021-03-08 04:14:38 +00:00
straight-host-usernames '((github . "duckwork")
2022-01-04 20:42:26 +00:00
(gitlab . "acdw"))
straight-check-for-modifications '(check-on-save
2022-01-04 20:42:26 +00:00
find-when-checking))
;; Bootstrap straight.el
;; https://github.com/raxod502/straight.el
2021-03-01 05:58:57 +00:00
2022-01-12 23:40:43 +00:00
(+with-message "Bootstrapping straight"
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name
"straight/repos/straight.el/bootstrap.el"
straight-base-dir))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
(concat "https://raw.githubusercontent.com/"
"raxod502/straight.el/develop/install.el")
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage)))
2021-04-09 22:51:10 +00:00
;; Early-loaded packages -- those that, for some reason or another,
;; need to be ensured to be loaded first.
2021-08-07 02:26:02 +00:00
(require 'straight-x)
(dolist (pkg '(el-patch
2022-01-04 20:42:26 +00:00
no-littering
2022-01-20 14:28:37 +00:00
setup
2022-01-21 22:34:55 +00:00
straight ; already installed, but what the hell
))
(straight-use-package pkg)
(require pkg)
(require (intern (format "+%s" pkg)) nil :noerror))
;; Setup `setup'
(add-to-list 'setup-modifier-list 'setup-wrap-to-demote-errors)
2022-02-19 00:18:03 +00:00
(unless (memq debug-on-error '(nil init))
2022-03-12 02:04:05 +00:00
(define-advice setup (:around (fn head &rest args) +setup-report)
(+with-progress ((format "[Setup] %S..." head))
(apply fn head args))))
;;; Appendix
;; Get rid of a dumb alias. straight-ಠ_ಠ-mode really slows down all
;; minibuffer completion functions. Since it's a (rarely-used, even)
;; alias anyway, I just define it back to nil. By the way, the alias
;; is `straight-package-neutering-mode'.
(defalias 'straight-ಠ_ಠ-mode nil)
(provide 'early-init)
2021-08-21 14:10:01 +00:00
;;; early-init.el ends here