diff options
author | Case Duckworth | 2024-06-06 23:32:52 -0500 |
---|---|---|
committer | Case Duckworth | 2024-06-06 23:32:52 -0500 |
commit | e578f72d4f1325a8f5fac4cf7272c8165d57a1f2 (patch) | |
tree | e0a71c27ab543ce19fb9aa050ffcd0cc213b48cc /emacs.d/early-init.el | |
parent | Initial commit (diff) | |
download | dots-e578f72d4f1325a8f5fac4cf7272c8165d57a1f2.tar.gz dots-e578f72d4f1325a8f5fac4cf7272c8165d57a1f2.zip |
Clean up emacs stuff
Diffstat (limited to 'emacs.d/early-init.el')
-rw-r--r-- | emacs.d/early-init.el | 189 |
1 files changed, 183 insertions, 6 deletions
diff --git a/emacs.d/early-init.el b/emacs.d/early-init.el index 7e7c431..2a4f2b5 100644 --- a/emacs.d/early-init.el +++ b/emacs.d/early-init.el | |||
@@ -5,17 +5,194 @@ | |||
5 | (setopt frame-resize-pixelwise t) | 5 | (setopt frame-resize-pixelwise t) |
6 | (setopt window-resize-pixelwise t) | 6 | (setopt window-resize-pixelwise t) |
7 | (setopt default-frame-alist | 7 | (setopt default-frame-alist |
8 | '((background-color . "alice blue") | 8 | '((menu-bar-lines . 0) |
9 | (font . "Recursive Mono Casual Static 10") | ||
10 | (menu-bar-lines . 0) | ||
11 | (tool-bar-lines . 0) | 9 | (tool-bar-lines . 0) |
12 | (vertical-scroll-bars) | 10 | (vertical-scroll-bars) |
13 | (horizontal-scroll-bars))) | 11 | (horizontal-scroll-bars))) |
14 | 12 | ||
13 | (defvar *fonts* | ||
14 | '((default | ||
15 | :family ("Recursive Mono Casual Static" "DejaVu Sans Mono") | ||
16 | :height 100) | ||
17 | (variable-pitch | ||
18 | :family ("Public Sans" "DejaVu Sans") | ||
19 | :height 1.0) | ||
20 | (fixed-pitch | ||
21 | :family ("Recursive Mono Linear Static" "DejaVu Sans Mono")) | ||
22 | (fixed-pitch-serif | ||
23 | :family ("Recursive Mono Linear Static" "DejaVu Sans Mono")))) | ||
24 | |||
15 | (require 'package) | 25 | (require 'package) |
16 | (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) | 26 | (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) |
17 | (package-initialize) | 27 | (package-initialize) |
18 | 28 | ||
19 | (setopt inhibit-startup-screen t) | 29 | ;;; Custom functions |
20 | (setopt initial-buffer-choice #'eshell) | 30 | |
21 | (setopt initial-scratch-message nil) | 31 | (defun pulse@eval (start end &rest _) |
32 | "ADVICE: makes `pulse-momentary-highlight-region' accept other arities." | ||
33 | (pulse-momentary-highlight-region start end)) | ||
34 | |||
35 | (defun create-missing-directories () | ||
36 | "Automatically create missing directories." | ||
37 | (let ((target-dir (file-name-directory buffer-file-name))) | ||
38 | (unless (file-exists-p target-dir) | ||
39 | (make-directory target-dir :parents)))) | ||
40 | |||
41 | (defun delete-trailing-whitespace-except-current-line () | ||
42 | "Delete all trailing whitespace except current line." | ||
43 | (save-excursion | ||
44 | (delete-trailing-whitespace (point-min) | ||
45 | (line-beginning-position)) | ||
46 | (delete-trailing-whitespace (line-end-position) | ||
47 | (point-max)))) | ||
48 | |||
49 | (defun run-after-frame-init (func) | ||
50 | "Run FUNC after the first frame is initialized. | ||
51 | If already so, run FUNC immediately." | ||
52 | (cond | ||
53 | ((daemonp) | ||
54 | (add-hook 'server-after-make-frame-hook func) | ||
55 | (advice-add func :after (lambda () | ||
56 | (remove-hook 'server-after-make-frame-hook | ||
57 | func) | ||
58 | (advice-remove func | ||
59 | 'after-frame-init-removing-advice)) | ||
60 | |||
61 | |||
62 | '((name . after-frame-init-removing-advice)))) | ||
63 | ((not after-init-time) | ||
64 | (add-hook 'after-init-hook func)) | ||
65 | (:else (funcall func)))) | ||
66 | |||
67 | (defun first-found-font (&rest cands) | ||
68 | "Return the first font of CANDS that is installed, or nil." | ||
69 | (cl-loop with ffl = (font-family-list) | ||
70 | for font in cands | ||
71 | if (member font ffl) | ||
72 | return font)) | ||
73 | |||
74 | (defun setup-faces () | ||
75 | "Setup Emacs faces." | ||
76 | ;; Default faces | ||
77 | (cl-loop for (face . spec) in *fonts* | ||
78 | do (set-face-attribute face nil | ||
79 | :family (apply #'first-found-font | ||
80 | (plist-get spec :family)) | ||
81 | :height (or (plist-get spec :height) | ||
82 | 'unspecified))) | ||
83 | ;; Specialized fonts | ||
84 | (cl-loop with ffl = (font-family-alist) | ||
85 | for (charset . font) | ||
86 | in '((latin . "Noto Sans") | ||
87 | (han . "Noto Sans CJK SC Regular") | ||
88 | (kana . "Noto Sans CJK JP Regular") | ||
89 | (hangul . "Noto Sans CJK KR Regular") | ||
90 | (cjk-misc . "Noto Sans CJK KR Regular") | ||
91 | (khmer . "Noto Sans Khmer") | ||
92 | (lao . "Noto Sans Lao") | ||
93 | (burmese . "Noto Sans Myanmar") | ||
94 | (thai . "Noto Sans Thai") | ||
95 | (ethiopic . "Noto Sans Ethiopic") | ||
96 | (hebrew . "Noto Sans Hebrew") | ||
97 | (arabic . "Noto Sans Arabic") | ||
98 | (gujarati . "Noto Sans Gujarati") | ||
99 | (devanagari . "Noto Sans Devanagari") | ||
100 | (kannada . "Noto Sans Kannada") | ||
101 | (malayalam . "Noto Sans Malayalam") | ||
102 | (oriya . "Noto Sans Oriya") | ||
103 | (sinhala . "Noto Sans Sinhala") | ||
104 | (tamil . "Noto Sans Tamil") | ||
105 | (telugu . "Noto Sans Telugu") | ||
106 | (tibetan . "Noto Sans Tibetan") | ||
107 | ;; emojis | ||
108 | (symbol . "Noto Emoji") | ||
109 | (symbol . "Noto Color Emoji") | ||
110 | (symbol . "Segoe UI Emoji") | ||
111 | (symbol . "Apple Color Emoji") | ||
112 | (symbol . "FreeSans") | ||
113 | (symbol . "FreeMono") | ||
114 | (symbol . "FreeSerif") | ||
115 | (symbol . "Unifont") | ||
116 | (symbol . "Symbola")) | ||
117 | if (member font ffl) | ||
118 | do (set-fontset-font t charset font))) | ||
119 | |||
120 | (defmacro inhibit-messages (&rest body) | ||
121 | "Inhibit all messages in BODY." | ||
122 | (declare (indent defun)) | ||
123 | `(cl-letf (((symbol-function 'message) #'ignore)) | ||
124 | ,@body)) | ||
125 | |||
126 | (defun kill-buffer-dwim (&optional buffer-or-name) | ||
127 | "Kill BUFFER-OR-NAME or the current buffer." | ||
128 | (interactive "P") | ||
129 | (cond | ||
130 | ((bufferp buffer-or-name) | ||
131 | (kill-buffer buffer-or-name)) | ||
132 | ((null buffer-or-name) | ||
133 | (kill-current-buffer)) | ||
134 | (:else | ||
135 | (kill-buffer (read-buffer "Kill: " nil :require-match))))) | ||
136 | |||
137 | (defun other-window-dwim (&optional arg) | ||
138 | "Switch to another window/buffer. | ||
139 | Calls `other-window', which see, unless | ||
140 | - the current window is alone on its frame | ||
141 | - `other-window-dwim' is called with \\[universal-argument] | ||
142 | In these cases, switch to the last-used buffer." | ||
143 | (interactive "P") | ||
144 | (if (or arg (one-window-p)) | ||
145 | (switch-to-buffer (other-buffer) nil t) | ||
146 | (other-window 1))) | ||
147 | |||
148 | (defun delete-window-dwim () | ||
149 | "Delete the current window or bury its buffer. | ||
150 | If the current window is alone in its frame, bury the buffer | ||
151 | instead." | ||
152 | (interactive) | ||
153 | (unless (ignore-errors (delete-window) t) | ||
154 | (bury-buffer))) | ||
155 | |||
156 | (defun cycle-spacing* (&optional n) | ||
157 | "Negate N argument on `cycle-spacing'." | ||
158 | (interactive "*p") | ||
159 | (cycle-spacing (- n))) | ||
160 | |||
161 | (defmacro find-user-file (name &optional file-name) | ||
162 | "Template macro to generate user file finding functions." | ||
163 | (declare (indent 1)) | ||
164 | (let ((file-name (or file-name (intern (format "user-%s-file" name)))) | ||
165 | (func-name (intern (format "find-user-%s-file" name)))) | ||
166 | `(defun ,func-name (&optional arg) | ||
167 | ,(format "Edit `%s' in the current window. | ||
168 | With ARG, edit in the other window." file-name) | ||
169 | (interactive "P") | ||
170 | (funcall (if arg #'find-file-other-window #'find-file) | ||
171 | ,file-name)))) | ||
172 | |||
173 | (defun indent-buffer+ () | ||
174 | "Indent the current buffer and (un)`tabify'. | ||
175 | Whether it tabifies or untabifies depends on `space-indent-modes'." | ||
176 | (interactive) | ||
177 | (save-mark-and-excursion | ||
178 | (indent-region (point-min) (point-max)) | ||
179 | (if (apply #'derived-mode-p space-indent-modes) | ||
180 | (untabify (point-min) (point-max)) | ||
181 | (tabify (point-min) (point-max))))) | ||
182 | |||
183 | (defun package-ensure (pkg) | ||
184 | "Install PKG if it's not already installed." | ||
185 | (unless (package-installed-p pkg) | ||
186 | (package-install pkg))) | ||
187 | |||
188 | (defun minibuffer-delete-directory () | ||
189 | "Delete the last directory in a file-completing minibuffer." | ||
190 | (interactive) | ||
191 | (let ((here (point)) | ||
192 | (meta (completion-metadata | ||
193 | "" minibuffer-completion-table | ||
194 | minibuffer-completion-predicate))) | ||
195 | (if (eq (completion-metadata-get meta 'category) 'file) | ||
196 | (when (search-backward "/" (minibuffer-prompt-end) t) | ||
197 | (delete-region (point) here)) | ||
198 | (backward-kill-word 1)))) | ||