.emacs.d/early-init.el

73 lines
2.2 KiB
EmacsLisp

(defvar +emacs--startup-restore-alist nil
"Variables and values to restore after init.")
(add-hook 'emacs-startup-hook
(defun emacs-startup@restore-values ()
"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."
(unless nil ;after-init-time
(setf (alist-get variable +emacs--startup-restore-alist)
(or restore (symbol-value variable)))
(set-default variable value)))
;; Garbage collection
(defvar +gc-treshold (* 100 1024 1024)
"Threshold in bytes for when to start garbage collection")
(defun +gc-disable ()
"Functionally disable the Garbage collector."
(setq gc-cons-threshold most-positive-fixnum)
(setq gc-cons-percentage 0.8))
(defun +gc-enable ()
"Enable the Garbage collector."
(interactive)
(setq gc-cons-threshold +gc-treshold)
(setq gc-cons-percentage 0.2))
;; Disable gc during init
(+gc-disable)
;; Disable gc in minibuffers
;; BUG: memory leaks?
;; (add-hook 'minibuffer-setup-hook #'+gc-disable)
;; (add-hook 'minibuffer-exit-hook #'+gc-enable)
;; Enable gc after init
(add-hook 'emacs-startup-hook #'+gc-enable)
(add-hook 'after-init-hook #'+gc-enable)
;; prevent font caching for better perfomance
;; in return of bigger memory footprint
(setq inhibit-compacting-font-caches t)
(setq package-enable-at-startup nil)
;; Don't prematurely re-display
(+set-during-startup 'inhibit-redisplay t)
(+set-during-startup 'inhibit-message t)
;; Debug during init
(+set-during-startup 'debug-on-error t)
(push '(font . "Iosevka Comfy Fixed") default-frame-alist)
(set-face-font 'default "Iosevka Comfy Fixed")
(copy-face 'default 'fixed-pitch)
(set-face-attribute 'default nil :height 120)
;; prevent font caching for better perfomance
;; in return of bigger memory footprint
(setq inhibit-compacting-font-caches t)
(advice-add #'x-apply-session-resources :override #'ignore)
;; Debug during init
;; (+set-during-startup 'debug-on-error t)
(provide 'early-init)