summaryrefslogtreecommitdiff
path: root/.config/emacs/early-init.el
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-10-16 22:04:33 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-10-16 22:04:33 +0200
commit0ee7fa9c382ae30295f0b8d88457f7856c7ff800 (patch)
tree6b5a0cf01fa0bfa4d01b0134b268f5d993055c0b /.config/emacs/early-init.el
parentd452ae1347b3711bc0a7ac80cfa2c37d9d63836e (diff)
emacs: Overhaul configuration completely
Diffstat (limited to '.config/emacs/early-init.el')
-rw-r--r--.config/emacs/early-init.el170
1 files changed, 83 insertions, 87 deletions
diff --git a/.config/emacs/early-init.el b/.config/emacs/early-init.el
index dc8b6c2..d4ee43c 100644
--- a/.config/emacs/early-init.el
+++ b/.config/emacs/early-init.el
@@ -1,113 +1,109 @@
;;; early-init.el --- Emacs early init file -*- lexical-binding: t; -*-
-(defmacro x-set (&rest body)
- (declare (indent 0))
- (unless (zerop (% (length body) 2))
- (error "Uneven number of variable+value pairs"))
- (macroexp-progn
- (mapcar
- (lambda (pair)
- `(customize-set-variable ,(macroexp-quote (car pair)) ,(cadr pair)))
- (seq-split body 2))))
-
-(defconst 1-KiB 1024
- "The number of bytes in 1 kibibyte")
-
-(defconst 1-MiB (* 1-KiB 1024)
- "The number of bytes in 1 mebibyte.")
-
-(defconst 1-GiB (* 1-MiB 1024)
- "The number of bytes in 1 gibibyte.")
-
-(defconst x-cache-directory
+;;; XDG Base Directory Specification Compliance
+(defconst mm-cache-directory
(expand-file-name
"emacs"
(or (getenv "XDG_CACHE_HOME")
(expand-file-name ".cache" (getenv "HOME"))))
"The XDG-conformant cache directory that Emacs should use.")
-(defconst x-config-directory
+(defconst mm-config-directory
(expand-file-name
"emacs"
(or (getenv "XDG_CONFIG_HOME")
(expand-file-name ".config" (getenv "HOME"))))
"The XDG-conformant config directory that Emacs should use.")
-(defconst x-data-directory
+(defconst mm-data-directory
(expand-file-name
"emacs"
(or (getenv "XDG_DATA_HOME")
(expand-file-name ".local/share" (getenv "HOME"))))
"The XDG-conformant data directory that Emacs should use.")
-;; Create standard Emacs directories
-(dolist (dir (list x-cache-directory
- x-config-directory
- x-data-directory))
- (make-directory dir 'parents))
-
-(x-set
- user-emacs-directory x-cache-directory
- auto-save-list-file-prefix (expand-file-name
- "auto-save-list/" x-cache-directory)
- backup-directory-alist `(("." . ,(expand-file-name
- "backups" x-cache-directory))))
-
-(push x-config-directory load-path)
+(mapc (lambda (directory)
+ (make-directory directory :parents))
+ (list mm-cache-directory mm-config-directory mm-data-directory))
+(setopt user-emacs-directory mm-cache-directory
+ auto-save-list-file-prefix (expand-file-name
+ "auto-save-lismm-"
+ mm-cache-directory)
+ backup-directory-alist `(("." . ,(expand-file-name
+ "backups" mm-cache-directory))))
(when (native-comp-available-p)
(startup-redirect-eln-cache
- (expand-file-name (expand-file-name "eln/" x-cache-directory))))
-
-;; Temporarily set some variables to improve startup performance. We
-;; undo this in a following hook
-(let ((saved-file-name-handler-alist file-name-handler-alist)
- (saved-vc-handled-backends vc-handled-backends))
- (x-set
- gc-cons-threshold most-positive-fixnum
- gc-cons-percentage .5
- file-name-handler-alist nil
- vc-handled-backends nil)
- (add-hook 'emacs-startup-hook
- (lambda ()
- (x-set
- gc-cons-threshold (* 8 1-MiB)
- gc-cons-percentage 0.1
- file-name-handler-alist saved-file-name-handler-alist
- vc-handled-backends saved-vc-handled-backends))))
-
-(x-set read-process-output-max
- (let ((pipe-size-file "/proc/sys/fs/pipe-max-size"))
- (if (file-exists-p pipe-size-file)
- (with-temp-buffer
- (insert-file-contents pipe-size-file)
- (number-at-point))
- 1-MiB)))
-
-(menu-bar-mode -1)
+ (expand-file-name (expand-file-name "eln/" mm-cache-directory))))
+
+
+;;; Useful Constants
+
+(defconst mm-darwin-p (eq system-type 'darwin)
+ "This variable is non-nil if Emacs is running on a Darwin system.")
+
+
+;;; Basic Frame Settings
+
+(setopt frame-resize-pixelwise t
+ frame-inhibit-implied-resize t
+ ring-bell-function #'ignore
+ use-short-answers t
+ inhibit-splash-screen t
+ inhibit-startup-buffer-menu t)
+(if mm-darwin-p
+ (progn
+ (add-to-list 'default-frame-alist '(fullscreen . maximized))
+ (when (featurep 'ns)
+ (add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))))
+ (menu-bar-mode -1))
(scroll-bar-mode -1)
(tool-bar-mode -1)
-(x-set
- frame-resize-pixelwise t
- frame-inhibit-implied-resize t
- frame-title-format '("%b")
- ring-bell-function #'ignore
- use-dialog-box t
- use-file-dialog nil
- use-short-answers t
- inhibit-splash-screen t
- inhibit-startup-screen t
- inhibit-x-resources t
- inhibit-startup-echo-area-message user-login-name
- inhibit-startup-buffer-menu t)
-
-;; Avoid the initial flash of white light when starting emacs
-(setq mode-line-format nil)
-(set-face-attribute 'default nil
- :background "#2B303B"
- :foreground "#C5C8C6")
-(set-face-attribute 'mode-line nil
- :background "#2B303B"
- :foreground "#C5C8C6"
- :box 'unspecified)
+
+;;; Startup Performance
+
+(setopt gc-cons-threshold most-positive-fixnum
+ gc-cons-percentage 0.5)
+(setopt read-process-output-max
+ (let ((pipe-size-file "/proc/sys/fs/pipe-max-size"))
+ (if (file-exists-p pipe-size-file)
+ (with-temp-buffer
+ (insert-file-contents pipe-size-file)
+ (number-at-point))
+ (* 1024 1024))))
+
+;; Set ‘file-name-handler-alist’ and ‘vc-handled-backends’ to nil
+;; temporarily and restore them over Emacs has properly initialized. We
+;; set threshold to 8 MiB which seems to be a good middleground for now.
+;; A higher threshold means less garbage collections but I’ve had issues
+;; with those garbage collections causing long freezes when they occur.
+(let ((saved-file-name-handler-alist file-name-handler-alist)
+ (saved-vc-handled-backends vc-handled-backends))
+ (setopt file-name-handler-alist nil
+ vc-handled-backends nil)
+ (add-hook
+ 'emacs-startup-hook
+ (defun mm-restore-emacs-settings ()
+ (setopt gc-cons-threshold (* 1024 1024 8)
+ gc-cons-percentage 0.1
+ file-name-handler-alist saved-file-name-handler-alist
+ vc-handled-backends saved-vc-handled-backends))))
+
+
+;;; Avoid Flashbang
+
+(setq-default mode-line-format nil) ; This will be set in init.el
+
+;; Colors taken from ‘mango-theme’
+(let ((background "#2B303B")
+ (foreground "#C5C8C6"))
+ (set-face-attribute
+ 'default nil
+ :background background
+ :foreground foreground)
+ (set-face-attribute
+ 'mode-line nil
+ :background background
+ :foreground foreground
+ :box 'unspecified))