-
Notifications
You must be signed in to change notification settings - Fork 20
/
init.el
404 lines (303 loc) · 14 KB
/
init.el
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
;;; init.el --- Init -*- no-byte-compile: t; lexical-binding: t; -*-
;; Author: James Cherti
;; URL: https://github.com/jamescherti/minimal-emacs.d
;; Package-Requires: ((emacs "29.1"))
;; Keywords: maint
;; Version: 1.1.1
;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary:
;; The minimal-emacs.d project is a customizable base that provides better Emacs
;; defaults and optimized startup, intended to serve as a solid foundation for
;; your vanilla Emacs configuration.
;;; Code:
;;; Load pre-init.el
(minimal-emacs-load-user-init "pre-init.el")
;;; Networking
;; Don't ping things that look like domain names.
(setq ffap-machine-p-known 'reject)
;;; package.el
(when (bound-and-true-p minimal-emacs-package-initialize-and-refresh)
;; Initialize and refresh package contents again if needed
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
;; Install use-package if necessary
(unless (package-installed-p 'use-package)
(package-install 'use-package))
;; Ensure use-package is available at compile time
(eval-when-compile
(require 'use-package)))
;; Ensure the 'use-package' package is installed and loaded
;;; Features, warnings, and errors
;; Disable warnings from the legacy advice API. They aren't useful.
(setq ad-redefinition-action 'accept)
(setq warning-suppress-types '((lexical-binding)))
;; Some features that are not represented as packages can be found in
;; `features', but this can be inconsistent. The following enforce consistency:
(if (fboundp #'json-parse-string)
(push 'jansson features))
(if (string-match-p "HARFBUZZ" system-configuration-features) ; no alternative
(push 'harfbuzz features))
(if (bound-and-true-p module-file-suffix)
(push 'dynamic-modules features))
;;; Minibuffer
;; Allow nested minibuffers
(setq enable-recursive-minibuffers t)
;; Keep the cursor out of the read-only portions of the.minibuffer
(setq minibuffer-prompt-properties
'(read-only t intangible t cursor-intangible t face
minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
;;; User interface
;; By default, Emacs "updates" its ui more often than it needs to
(setq idle-update-delay 1.0)
;; Allow for shorter responses: "y" for yes and "n" for no.
(if (boundp 'use-short-answers)
(setq use-short-answers t)
(advice-add #'yes-or-no-p :override #'y-or-n-p))
(defalias #'view-hello-file #'ignore) ; Never show the hello file
;;; Misc
;; switch-to-buffer runs pop-to-buffer-same-window instead
(setq switch-to-buffer-obey-display-actions t)
(setq show-paren-delay 0.1
show-paren-highlight-openparen t
show-paren-when-point-inside-paren t
show-paren-when-point-in-periphery t)
(setq whitespace-line-column nil) ; whitespace-mode
;; I reduced the default value of 9 to simplify the font-lock keyword,
;; aiming to improve performance. This package helps differentiate
;; nested delimiter pairs, particularly in languages with heavy use of
;; parentheses.
(setq rainbow-delimiters-max-face-count 5)
;; Can be activated with `display-line-numbers-mode'
(setq-default display-line-numbers-width 3)
(setq-default display-line-numbers-widen t)
(setq comint-prompt-read-only t)
(setq comint-buffer-maximum-size 2048)
(setq compilation-always-kill t
compilation-ask-about-save nil
compilation-scroll-output 'first-error)
(setq truncate-string-ellipsis "…")
;; Delete by moving to trash in interactive mode
(setq delete-by-moving-to-trash (not noninteractive))
;; Increase how much is read from processes in a single chunk
(setq read-process-output-max (* 512 1024)) ; 512kb
;; Collects and displays all available documentation immediately, even if
;; multiple sources provide it. It concatenates the results.
(setq eldoc-documentation-strategy 'eldoc-documentation-compose-eagerly)
;; For some reason, `abbrev_defs` is located in ~/.emacs.d/abbrev_defs, even
;; when `user-emacs-directory` is modified. This ensures the abbrev file is
;; correctly located based on the updated `user-emacs-directory`.
(setq abbrev-file-name (expand-file-name "abbrev_defs" user-emacs-directory))
;;; Files
;; Disable the warning "X and Y are the same file". Ignoring this warning is
;; acceptable since it will redirect you to the existing buffer regardless.
(setq find-file-suppress-same-file-warnings t)
;; Resolve symlinks when opening files, so that any operations are conducted
;; from the file's true directory (like `find-file').
(setq find-file-visit-truename t
vc-follow-symlinks t)
;; Skip confirmation prompts when creating a new file or buffer
(setq confirm-nonexistent-file-or-buffer nil)
(setq uniquify-buffer-name-style 'forward)
(setq mouse-yank-at-point t)
;; Prefer vertical splits over horizontal ones
(setq split-width-threshold 170
split-height-threshold nil)
;; The native border "uses" a pixel of the fringe on the rightmost
;; splits, whereas `window-divider` does not.
(setq window-divider-default-bottom-width 1
window-divider-default-places t
window-divider-default-right-width 1)
;;; Backup files
;; Avoid generating backups or lockfiles to prevent creating world-readable
;; copies of files.
(setq create-lockfiles nil)
(setq make-backup-files nil)
(setq backup-directory-alist
`(("." . ,(expand-file-name "backup" user-emacs-directory))))
(setq tramp-backup-directory-alist backup-directory-alist)
(setq backup-by-copying-when-linked t)
(setq backup-by-copying t) ; Backup by copying rather renaming
(setq delete-old-versions t) ; Delete excess backup versions silently
(setq version-control t) ; Use version numbers for backup files
(setq kept-new-versions 5)
(setq kept-old-versions 5)
(setq vc-make-backup-files nil) ; Do not backup version controlled files
;;; Auto save
;; Enable auto-save to safeguard against crashes or data loss. The
;; `recover-file' or `recover-session' functions can be used to restore
;; auto-saved data.
(setq auto-save-default t)
;; Do not auto-disable auto-save after deleting large chunks of
;; text. The purpose of auto-save is to provide a failsafe, and
;; disabling it contradicts this objective.
(setq auto-save-include-big-deletions t)
(setq auto-save-list-file-prefix
(expand-file-name "autosave/" user-emacs-directory))
(setq tramp-auto-save-directory
(expand-file-name "tramp-autosave/" user-emacs-directory))
;; Auto save options
(setq kill-buffer-delete-auto-save-files t)
;;; Auto revert
;; Auto-revert in Emacs is a feature that automatically updates the
;; contents of a buffer to reflect changes made to the underlying file
;; on disk.
(setq revert-without-query (list ".") ; Do not prompt
auto-revert-stop-on-user-input nil
auto-revert-verbose t)
;; Revert other buffers (e.g, Dired)
(setq global-auto-revert-non-file-buffers t)
;;; recentf
;; `recentf' is an Emacs package that maintains a list of recently
;; accessed files, making it easier to reopen files you have worked on
;; recently.
(setq recentf-max-saved-items 300) ; default is 20
(setq recentf-auto-cleanup 'mode)
;;; saveplace
;; `save-place-mode` enables Emacs to remember the last location within a file
;; upon reopening. This feature is particularly beneficial for resuming work at
;; the precise point where you previously left off.
(setq save-place-file (expand-file-name "saveplace" user-emacs-directory))
(setq save-place-limit 600)
;;; savehist
;; `savehist` is an Emacs feature that preserves the minibuffer history between
;; sessions. It saves the history of inputs in the minibuffer, such as commands,
;; search strings, and other prompts, to a file. This allows users to retain
;; their minibuffer history across Emacs restarts.
(setq history-length 300)
(setq savehist-save-minibuffer-history t) ;; Default
;;; Frames and windows
;; Resizing the Emacs frame can be costly when changing the font. Disable this
;; to improve startup times with fonts larger than the system default.
(setq frame-resize-pixelwise t)
;; However, do not resize windows pixelwise, as this can cause crashes in some
;; cases when resizing too many windows at once or rapidly.
(setq window-resize-pixelwise nil)
(setq resize-mini-windows 'grow-only)
;;; Scrolling
;; Enables faster scrolling through unfontified regions. This may result in
;; brief periods of inaccurate syntax highlighting immediately after scrolling,
;; which should quickly self-correct.
(setq fast-but-imprecise-scrolling t)
;; Move point to top/bottom of buffer before signaling a scrolling error.
(setq scroll-error-top-bottom t)
;; Keeps screen position if the scroll command moved it vertically out of the
;; window.
(setq scroll-preserve-screen-position t)
;; Emacs spends excessive time recentering the screen when the cursor moves more
;; than N lines past the window edges (where N is the value of
;; `scroll-conservatively`). This can be particularly slow in larger files
;; during extensive scrolling. If `scroll-conservatively` is set above 100, the
;; window is never automatically recentered. The default value of 0 triggers
;; recentering too aggressively. Setting it to 10 reduces excessive recentering
;; and only recenters the window when scrolling significantly off-screen.
(setq scroll-conservatively 10)
;; Enables smooth scrolling by making Emacs scroll the window by 1 line whenever
;; the cursor moves off the visible screen.
(setq scroll-step 1)
;; Reduce cursor lag by :
;; 1. Prevent automatic adjustments to `window-vscroll' for long lines.
;; 2. Resolve the issue of random half-screen jumps during scrolling.
(setq auto-window-vscroll nil)
;; Number of lines of margin at the top and bottom of a window.
(setq scroll-margin 0)
;; Horizontal scrolling
(setq hscroll-margin 2
hscroll-step 1)
;;; Mouse Scroll
;; Emacs 29
(when (memq 'context-menu minimal-emacs-ui-features)
(when (and (display-graphic-p) (fboundp 'context-menu-mode))
(add-hook 'after-init-hook #'context-menu-mode)))
;;; Cursor
;; The blinking cursor is distracting and interferes with cursor settings in
;; some minor modes that try to change it buffer-locally (e.g., Treemacs).
;; Additionally, it can cause freezing, especially on macOS, for users with
;; customized and colored cursors.
(blink-cursor-mode -1)
;; Don't blink the paren matching the one at point, it's too distracting.
(setq blink-matching-paren nil)
;; Don't stretch the cursor to fit wide characters, it is disorienting,
;; especially for tabs.
(setq x-stretch-cursor nil)
;; Reduce rendering/line scan work by not rendering cursors or regions in
;; non-focused windows.
(setq-default cursor-in-non-selected-windows nil)
(setq highlight-nonselected-windows nil)
;;; Annoyances
;; No beeping or blinking
(setq visible-bell nil)
(setq ring-bell-function #'ignore)
;; This controls how long Emacs will blink to show the deleted pairs with
;; `delete-pair'. A longer delay can be annoying as it causes a noticeable pause
;; after each deletion, disrupting the flow of editing.
(setq delete-pair-blink-delay 0.03)
;;; Indent and formatting
(setq-default left-fringe-width 8)
(setq-default right-fringe-width 8)
;; Do not show an arrow at the top/bottomin the fringe and empty lines
(setq-default indicate-buffer-boundaries nil)
(setq-default indicate-empty-lines nil)
;; Continue wrapped lines at whitespace rather than breaking in the
;; middle of a word.
(setq-default word-wrap t)
;; Disable wrapping by default due to its performance cost.
(setq-default truncate-lines t)
;; If enabled and `truncate-lines' is disabled, soft wrapping will not occur
;; when the window is narrower than `truncate-partial-width-windows' characters.
(setq truncate-partial-width-windows nil)
;; Prefer spaces over tabs. Spaces offer a more consistent default compared to
;; 8-space tabs. This setting can be adjusted on a per-mode basis as needed.
(setq-default indent-tabs-mode nil
tab-width 4)
;; Enable indentation and completion using the TAB key
(setq-default tab-always-indent nil)
;; Enable multi-line commenting which ensures that `comment-indent-new-line'
;; properly continues comments onto new lines, which is useful for writing
;; longer comments or docstrings that span multiple lines.
(setq comment-multi-line t)
;; We often split terminals and editor windows or place them side-by-side,
;; making use of the additional horizontal space.
(setq-default fill-column 80)
;; Disable the obsolete practice of end-of-line spacing from the
;; typewriter era.
(setq sentence-end-double-space nil)
;; According to the POSIX, a line is defined as "a sequence of zero or
;; more non-newline characters followed by a terminating newline".
(setq require-final-newline t)
;; Remove duplicates from the kill ring to reduce clutter
(setq kill-do-not-save-duplicates t)
;; Ensures that empty lines within the commented region are also commented out.
;; This prevents unintended visual gaps and maintains a consistent appearance,
;; ensuring that comments apply uniformly to all lines, including those that are
;; otherwise empty.
(setq comment-empty-lines t)
;; Eliminate delay before highlighting search matches
(setq lazy-highlight-initial-delay 0)
;;; Mode line
;; Setting `display-time-default-load-average' to nil makes Emacs omit the load
;; average information from the mode line.
(setq display-time-default-load-average nil)
;; Display the current line and column numbers in the mode line
(setq line-number-mode t)
(setq column-number-mode t)
;;; Filetype
;; Do not notify the user each time Python tries to guess the indentation offset
(setq python-indent-guess-indent-offset-verbose nil)
(setq sh-indent-after-continuation 'always)
(setq dired-clean-confirm-killing-deleted-buffers nil
dired-recursive-deletes 'top
dired-recursive-copies 'always
dired-create-destination-dirs 'ask)
;;; Font / Text scale
;; Avoid automatic frame resizing when adjusting settings.
(setq global-text-scale-adjust-resizes-frames nil)
;;; Ediff
;; Configure Ediff to use a single frame and split windows horizontally
(setq ediff-window-setup-function #'ediff-setup-windows-plain
ediff-split-window-function #'split-window-horizontally)
;;; Load post-init.el
(minimal-emacs-load-user-init "post-init.el")
(provide 'init)
;;; init.el ends here