summaryrefslogtreecommitdiff
path: root/.config/emacs/early-init.el
blob: dc8b6c2f083e59eac28690a9e772f12b28ddc3a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
;;; 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
  (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
  (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
  (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)

(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)
(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)