My personal emacs configuration
1;;; early-init -- Early emacs initialization
2;;; Commentary:
3;;; Code:
4
5(defvar nesv/tiling-window-manager-regexp "bspwm\\|herbstluftwm\\|i3\\|hyprland"
6 "Regexp to match the name of tiling window managers.")
7
8(defmacro nesv/with-desktop-session (&rest body)
9 "Expand BODY if desktop is *not* a tiling window manager."
10 (declare (indent 0))
11 `(when-let ((session (getenv "DESKTOP_SESSION"))
12 ((not (string-match-p session nesv/tiling-window-manager-regexp))))
13 ,@body))
14
15(defun nesv/add-to-list (list element)
16 "Add ELEMENT to LIST. A simplified version of ADD-TO-LIST."
17 (set list (cons element (symbol-value list))))
18
19;; Set the window size on non-tiling window managers.
20;;
21;; INITIAL-FRAME-ALIST is the first frame that is produced when starting emacs.
22;; DEFAULT-FRAME-ALIST is all other frames.
23(nesv/with-desktop-session
24 (mapc
25 (lambda (var)
26 (nesv/add-to-list var '(width . (text-pixels . 800)))
27 (nesv/add-to-list var '(height . (text-pixels . 900)))
28 (nesv/add-to-list var '(scroll-bar-width . 10)))
29 '(default-frame-alist initial-frame-alist)))
30
31(setq frame-resize-pixelwise t
32 frame-inhibit-implied-resize t
33 frame-title-format '("%b")
34 ring-bell-function 'ignore
35 use-dialog-box t
36 use-file-dialog nil
37 use-short-answers t
38 inhibit-splash-screen t
39 inhibit-startup-screen t
40 inhibit-x-resources t
41 inhibit-startup-echo-area-message user-login-name
42 inhibit-startup-buffer-menu t)
43
44;; Disable useless graphical elements like the menu bar, the scroll bar, and
45;; the tool bar.
46(menu-bar-mode -1)
47(scroll-bar-mode -1)
48(tool-bar-mode -1)
49
50;; Temporarily increase the garbage collection threshold.
51;; This should shave about 0.5s off startup time.
52(setq gc-cons-threshold most-positive-fixnum
53 gc-cons-percentage 0.5)
54
55;; More startup optimizations.
56(defvar nesv/file-name-handler-alist file-name-handler-alist)
57(defvar nesv/vc-handled-backends vc-handled-backends)
58
59(setq file-name-handler-alist nil
60 vc-handled-backends nil)
61
62(add-hook 'emacs-startup-hook
63 (lambda ()
64 (setq gc-cons-threshold (* 1000 1000 8)
65 gc-cons-percentage 0.1
66 file-name-handler-alist nesv/file-name-handler-alist
67 vc-handled-backends nesv/vc-handled-backends)))
68
69;; Name the default frame.
70(add-hook 'after-init-hook (lambda () (set-frame-name "nesv")))
71
72;; Inititalize install packages early.
73(setq package-enable-at-startup t)
74
75(provide 'early-init)
76;;; early-init.el ends here