nix/config/emacs/early-init.el

159 lines
5.7 KiB
EmacsLisp
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; early-init.el --- Early Init -*- lexical-binding: t; -*-
;;; Startup time
(defvar rs/show-startup-time t
"If non-nil, display startup time after Emacs loads.")
(defun rs/display-startup-time ()
"Display startup time in milliseconds and seconds."
(when rs/show-startup-time
(let* ((time (float-time (time-subtract after-init-time before-init-time)))
(ms (* time 1000)))
(message "Emacs loaded in %.0fms (%.2fs) with %d garbage collections."
ms time gcs-done))))
(add-hook 'emacs-startup-hook #'rs/display-startup-time 110)
;;; GC optimization
(defvar rs/backup-gc-cons-threshold gc-cons-threshold)
(defvar rs/backup-gc-cons-percentage gc-cons-percentage)
(setq gc-cons-threshold most-positive-fixnum)
(setq gc-cons-percentage 1.0)
;;; Directories
(defvar rs/emacs-dir user-emacs-directory)
(defvar rs/lib-dir (expand-file-name "lib/" rs/emacs-dir))
(defvar rs/var-dir (expand-file-name "var/" rs/emacs-dir))
(setq package-user-dir (expand-file-name "elpa/" rs/var-dir))
(setq user-emacs-directory rs/var-dir)
(setq custom-file null-device)
(setq custom-theme-directory (expand-file-name "themes/" rs/emacs-dir))
;;; Restore GC after startup
(add-hook 'emacs-startup-hook
(lambda ()
(setq gc-cons-threshold (* 64 1024 1024))
(setq gc-cons-percentage 0.1)) 105)
;;; Native compilation
(when (and (featurep 'native-compile)
(fboundp 'native-comp-available-p)
(native-comp-available-p))
(setq package-native-compile t)
(setq native-comp-async-report-warnings-errors 'silent)
(setq native-compile-prune-cache t)
(startup-redirect-eln-cache (expand-file-name "eln-cache/" rs/var-dir)))
(setq native-comp-warning-on-missing-source nil)
(setq jka-compr-verbose nil)
(setq byte-compile-warnings nil)
(setq byte-compile-verbose nil)
;;; GCC paths for macOS
(when-let* ((gcc-base "/opt/homebrew/opt/gcc/lib/gcc/current")
((file-directory-p gcc-base)))
(setenv "LIBRARY_PATH"
(string-join
(delq nil
(list gcc-base
(let ((jit-path "/opt/homebrew/opt/libgccjit/lib/gcc/current"))
(when (file-directory-p jit-path) jit-path))
(car (last (file-expand-wildcards
(concat gcc-base "/gcc/aarch64-apple-darwin*/*"))))))
":")))
;;; Misc performance
(setq load-prefer-newer t)
(setq read-process-output-max (* 2 1024 1024))
(setq process-adaptive-read-buffering nil)
(setq ffap-machine-p-known 'reject)
(setq ad-redefinition-action 'accept)
(setq warning-suppress-types '((lexical-binding)))
(setq inhibit-compacting-font-caches t)
(when (boundp 'pgtk-wait-for-event-timeout)
(setq pgtk-wait-for-event-timeout 0.001))
;;; File name handler optimization
(defvar rs/old-file-name-handler-alist (default-toplevel-value 'file-name-handler-alist))
(defun rs/restore-file-name-handler-alist ()
(set-default-toplevel-value
'file-name-handler-alist
(delete-dups (append file-name-handler-alist rs/old-file-name-handler-alist))))
(unless (daemonp)
(set-default-toplevel-value
'file-name-handler-alist
(if (locate-file-internal "calc-loaddefs.el" load-path)
nil
(list (rassq 'jka-compr-handler rs/old-file-name-handler-alist))))
(put 'file-name-handler-alist 'initial-value rs/old-file-name-handler-alist)
(add-hook 'emacs-startup-hook #'rs/restore-file-name-handler-alist 101))
;;; UI - disable before frame creation
(setq default-frame-alist '((background-color . "#072626")
(ns-appearance . dark)
(ns-transparent-titlebar . t)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(vertical-scroll-bars . nil)
(horizontal-scroll-bars . nil)
(frame-resize-pixelwise . t)))
(setq frame-resize-pixelwise t)
(setq frame-inhibit-implied-resize t)
(setq auto-mode-case-fold nil)
(setq inhibit-splash-screen t)
(setq inhibit-startup-screen t)
(setq inhibit-startup-echo-area-message user-login-name)
(setq inhibit-startup-buffer-menu t)
(setq inhibit-x-resources t)
(setq initial-buffer-choice nil)
(setq initial-scratch-message nil)
(setq initial-major-mode 'fundamental-mode)
(setq menu-bar-mode nil)
(setq tool-bar-mode nil)
(setq scroll-bar-mode nil)
(setq frame-title-format "%b Emacs")
(setq icon-title-format frame-title-format)
;; Bidirectional text optimization
(setq-default bidi-display-reordering 'left-to-right)
(setq-default bidi-paragraph-direction 'left-to-right)
(setq bidi-inhibit-bpa t)
;; Suppress startup messages
(advice-add 'display-startup-echo-area-message :override #'ignore)
(advice-add 'display-startup-screen :override #'ignore)
;; Unset irrelevant command line options
(unless (eq system-type 'darwin)
(setq command-line-ns-option-alist nil))
(unless (memq initial-window-system '(x pgtk))
(setq command-line-x-option-alist nil))
;;; Security
(setq gnutls-verify-error t)
(setq tls-checktrust t)
(setq gnutls-min-prime-bits 3072)
;;; Package archives
(setq package-enable-at-startup nil)
(setq use-package-always-ensure t)
(setq use-package-enable-imenu-support t)
(setq use-package-expand-minimally t)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")
("melpa-stable" . "https://stable.melpa.org/packages/")))
(setq package-archive-priorities '(("gnu" . 99)
("nongnu" . 80)
("melpa" . 70)
("melpa-stable" . 50)))
;;; early-init.el ends here