-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinit.el
More file actions
325 lines (306 loc) · 11.4 KB
/
init.el
File metadata and controls
325 lines (306 loc) · 11.4 KB
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
;;; medicated.el --- Medicated Emacs, a minimal and modern Emacs configuration
;;
;;; Commentary:
;;
;; A lightweight, opinionated Emacs starter configuration that provides
;; modern conveniences while staying true to standard Emacs patterns.
;;
;; PHILOSOPHY:
;;
;; This config enhances Emacs without hiding it. Everything uses standard
;; Emacs patterns and conventions. If you know how to customize vanilla
;; Emacs, you know how to customize this config - there are no frameworks,
;; wrappers, or special systems to learn.
;;
;; The goal is to provide a good starting point with:
;; - Modern completion (Vertico + Orderless + Marginalia)
;; - LSP support via Eglot (built-in)
;; - Git integration (Magit + diff-hl)
;; - Quality-of-life improvements (better defaults, recent files, etc.)
;; - Common language modes pre-installed
;;
;; REQUIREMENTS:
;;
;; - Emacs 29.0 or later
;; - Internet connection (for first-time package installation)
;; - LSP servers installed separately if you want LSP features
;; (e.g., clangd for C/C++, rust-analyzer for Rust, etc.)
;;
;; INSTALLATION:
;;
;; 1. Ensure you have an empty Emacs configuration directory, or none at all.
;; Your Emacs config directory is typically one of:
;; - ~/.emacs.d/
;; - ~/.config/emacs/
;;
;; If these exist and contain files, back them up and delete them,
;; or Emacs may load conflicting configurations.
;;
;; 2. Place this file as "init.el" in one of these locations:
;; - ~/.emacs.d/init.el (traditional location, always checked first)
;; - ~/.config/emacs/init.el (XDG-compliant location)
;;
;; Note: Emacs prefers ~/.emacs.d/ if it exists. To use the XDG location,
;; ensure ~/.emacs.d/ does not exist.
;;
;; 3. Launch Emacs. On first run:
;; - All packages will be automatically downloaded and installed
;; - A message will appear: "First-time setup complete. Please restart Emacs."
;; - Emacs will automatically close after 10 seconds
;;
;; 4. Restart Emacs. Your configuration is now ready to use.
;;
;; TROUBLESHOOTING:
;;
;; If the configuration doesn't work after restarting:
;; 1. Delete ALL files (including hidden files) in your Emacs directory
;; 2. Try the installation process again
;; 3. If problems persist, file a bug report with details about your
;; Emacs version, operating system, and the exact error messages
;;
;; LEARNING EMACS:
;;
;; If you're new to Emacs, start with the built-in tutorial:
;; M-x help-with-tutorial RET
;; (That's: Alt+x, type "help-with-tutorial", press Enter)
;;
;; Learn Emacs as you would with vanilla Emacs - this config doesn't
;; change fundamental Emacs concepts or introduce special systems.
;; Standard Emacs documentation and resources apply directly.
;;
;; CUSTOMIZATION:
;;
;; Don't like something? Change it as you would in vanilla Emacs:
;; - Theme: M-x customize-themes or edit 'custom-enabled-themes
;; - Font: M-x customize-face default or set in 'default-frame-alist
;; - Keybindings: Use global-set-key or local-set-key
;; - Any setting: M-x customize-variable or edit custom-set-variables
;;
;; This config does nothing special - it's just Emacs with better defaults.
;;
;; EXPECTED BEHAVIOR:
;;
;; All behavior (both functional and errors) from this config represents
;; the normal Emacs experience, or bugs in the included third-party packages.
;;
;; EGLOT (LSP) NOTES:
;;
;; Eglot (the built-in LSP client) is enabled by default in all programming
;; modes via prog-mode-hook. This is the most common source of errors because:
;;
;; - Eglot expects LSP servers to be already installed on your system
;; - If a language server is missing, Eglot will show error messages
;; - Different languages need different LSP servers:
;; * C/C++: clangd
;; * Rust: rust-analyzer
;; * Python: pyright or pylsp
;; * Go: gopls
;; * JavaScript/TypeScript: typescript-language-server
;; * Lua: lua-language-server
;; And so on...
;;
;; If Eglot causes issues, you can:
;; 1. Remove 'eglot-ensure from prog-mode-hook in custom-set-variables
;; 2. Add it to specific language mode hooks instead:
;; (add-hook 'rust-mode-hook #'eglot-ensure)
;; 3. Or disable it entirely and use Emacs without LSP
;;
;; PACKAGE LIST:
;;
;; This config installs these third-party packages:
;; - csv-mode: CSV file editing
;; - diff-hl: Git diff indicators in the fringe
;; - doom-modeline: Modern mode-line
;; - doom-themes: Collection of themes (Gruvbox used by default)
;; - go-mode: Go language support
;; - helpful: Better help buffers
;; - json-mode: JSON highlight support
;; - lua-mode: Lua language support
;; - magit: Git interface
;; - marginalia: Completion annotations
;; - markdown-mode: Markdown editing
;; - orderless: Fuzzy completion matching
;; - rainbow-delimiters: Colored parentheses by depth
;; - rust-mode: Rust language support
;; - typescript-mode: TypeScript language support
;; - vertico: Vertical completion UI
;; - which key: Displays possible key bindings
;; - yaml-mode: YAML file editing
;;
;;; Code:
(when (< emacs-major-version 29)
(select-window (display-buffer (get-buffer-create "*Warnings*")))
(delete-other-windows)
(setq inhibit-startup-screen t)
(error "Medicated Emacs requires Emacs 29 or later, but you're running Emacs %d.%d"
emacs-major-version emacs-minor-version))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;; MELPA
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Bootstrap 'use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)
;; Local executables support
(add-to-list 'exec-path (expand-file-name "~/.local/bin"))
;;; Functions
(defun mode-has-lsp-p ()
"Check if MODE (or current major-mode) has an LSP server configured in Eglot."
(require 'eglot nil t)
(and (buffer-file-name)
(ignore-errors (cl-fourth (eglot--guess-contact)))))
(defun move-line-up (arg)
"Drag current line to previous line, keeping point on current line.
With argument ARG, takes current line and moves it past ARG lines."
(interactive "*p")
(let ((original-column (current-column)))
(dotimes (i arg)
(transpose-lines 1)
(previous-line 2)
(move-to-column original-column))))
(defun move-line-down (arg)
"Drag current line to next line, keeping point on current line.
With argument ARG, takes current line and moves it past ARG lines."
(interactive "*p")
(let ((original-column (current-column)))
(dotimes (i arg)
(next-line)
(transpose-lines 1)
(previous-line 1)
(move-to-column original-column))))
;; Packages
(use-package csv-mode)
(use-package diff-hl)
(use-package doom-modeline)
(use-package doom-themes)
(use-package go-mode)
(use-package helpful)
(use-package json-mode)
(use-package lua-mode)
(use-package magit)
(use-package marginalia)
(use-package markdown-mode)
(use-package orderless)
(use-package rainbow-delimiters)
(use-package rust-mode)
(use-package typescript-mode)
(use-package vertico)
(use-package which-key)
(use-package yaml-mode)
;; Variables
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-saves/" t)))
'(backup-directory-alist '((".*" . "~/.emacs.d/backups/")))
'(byte-compile-verbose nil)
'(byte-compile-warnings '(cl-functions))
'(c-default-style
'((c-mode . "k&r") (other . "k&r")))
'(c-offsets-alist
'((arglist-intro . +) (arglist-cont . 0) (arglist-cont-nonempty . +)
(arglist-close . 0)))
'(column-number-mode t)
'(comment-style 'multi-line)
'(completion-styles '(orderless basic))
'(custom-enabled-themes '(doom-gruvbox))
'(custom-safe-themes
'("f1e8339b04aef8f145dd4782d03499d9d716fdc0361319411ac2efc603249326" default))
'(default-frame-alist '((menu-bar-line)))
'(delete-selection-mode t)
'(dired-dwim-target t)
'(dired-listing-switches "-al --group-directories-first")
'(dired-recursive-copies 'always)
'(dired-recursive-deletes 'always)
'(dired-use-ls-dired t)
'(display-line-numbers 'visual)
'(doom-modeline-icon nil)
'(doom-modeline-mode t)
'(eglot-ignored-server-capabilities '(:documentHighlightProvider :inlayHintProvider))
'(fill-column 80)
'(global-auto-revert-mode t)
'(global-diff-hl-mode t)
'(indicate-empty-lines t)
'(initial-buffer-choice t)
'(initial-major-mode 'fundamental-mode)
'(initial-scratch-message nil)
'(lua-indent-level 2)
'(marginalia-mode t)
'(org-hide-leading-stars t)
'(package-selected-packages nil)
'(prog-mode-hook
'(subword-mode
(lambda nil (when (mode-has-lsp-p) (eglot-ensure)))
whitespace-mode))
'(recentf-mode t)
'(ring-bell-function 'ignore)
'(save-place-mode t)
'(savehist-mode t)
'(scroll-bar-mode nil)
'(scroll-conservatively 5)
'(scroll-margin 5)
'(scroll-step 1)
'(sentence-end-double-space nil)
'(size-indication-mode t)
'(text-mode-hook '(text-mode-hook-identify toggle-word-wrap))
'(tool-bar-mode nil)
'(uniquify-buffer-name-style 'forward nil (uniquify))
'(use-short-answers t)
'(vertico-mode t)
'(which-key-mode t)
'(winner-mode t))
;; Bindings
(global-set-key (kbd "C-x C-b") #'ibuffer)
(global-set-key (kbd "M-s i") #'imenu)
(global-set-key (kbd "M-<up>") #'move-line-up)
(global-set-key (kbd "M-<down>") #'move-line-down)
(global-set-key (kbd "M-p") #'move-line-up)
(global-set-key (kbd "M-n") #'move-line-down)
(global-set-key (kbd "C-c C-d") #'helpful-at-point)
(global-set-key (kbd "C-h F") #'helpful-function)
(global-set-key (kbd "C-h f") #'helpful-callable)
(global-set-key (kbd "C-h v") #'helpful-variable)
(global-set-key (kbd "C-h k") #'helpful-key)
(global-set-key (kbd "C-h x") #'helpful-command)
;; Lazy loading of rainboe del. mode
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
;; Fix a bug with Eglot: https://github.com/joaotavora/eglot/discussions/1222
(add-hook 'java-mode-hook (lambda ()
(remove-hook 'eglot-connect-hook #'eglot-signal-didChangeConfiguration t)))
;; Backups
(make-directory (expand-file-name "auto-saves" user-emacs-directory) t)
(make-directory (expand-file-name "backups" user-emacs-directory) t)
;; First-time setup
(unless (file-exists-p "~/.emacs.d/.first-run")
(write-region "" nil "~/.emacs.d/.first-run")
(run-with-timer 1 nil
(lambda ()
(ignore-errors (kill-buffer "*Compile-Log*"))
(delete-other-windows)
(message "First-time setup complete. Please restart Emacs. Closing in 10 seconds")
(run-with-timer 10 nil #'save-buffers-kill-emacs))))
(provide 'init.el)
;; Copyright (C) 2025 Roland Marchand <roland.marchand@protonmail.com>
;;
;; Permission to use, copy, modify, and/or distribute this software for
;; any purpose with or without fee is hereby granted.
;;
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
;; DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
;; PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
;; TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
;; PERFORMANCE OF THIS SOFTWARE.
;;; init.el ends here