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
|
;;; init.el --- Emacs configuration -*- lexical-binding: t -*-
;;; Commentary:
;; Save the contents of this file to ~/.config/emacs/init.el and
;; you're ready to boot up Emacs.
;; Hack this file! One of the best ways to get started with Emacs is
;; to look at other peoples' configurations and extract the pieces
;; that work for you. That's where this configuration started. I
;; encourage you to read through the code in this file and explore the
;; functions and variables using the built-in help system (details
;; below). Happy hacking!
;; "C-<chr> means hold the CONTROL key while typing the character <chr>.
;; Thus, C-f would be: hold the CONTROL key and type f." (Emacs tutorial)
;;
;; - C-h t: Start the Emacs tutorial
;; - C-h o some-symbol: Describe symbol
;; - C-h C-q: Pull up the quick-help cheatsheet
;;; Code:
;; Performance tweaks for modern machines
(setq gc-cons-threshold 100000000) ; 100 mb
(setq read-process-output-max
(* 1024 1024)) ; 1mb
;; Remove extra UI clutter by hiding the scrollbar, menubar, and toolbar.
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; Set the font. Note: height = px * 100
;; (set-face-attribute 'default nil :font "Courier New" :height 120)
;; Add unique buffer names in the minibuffer where there are many
;; identical files. This is super useful if you rely on folders for
;; organization and have lots of files with the same name,
;; e.g. foo/index.ts and bar/index.ts.
(require 'uniquify)
;; Automatically insert closing parens
(electric-pair-mode t)
;; Visualize matching parens
(show-paren-mode 1)
;; Prefer spaces to tabs
(setq-default indent-tabs-mode nil)
;; Automatically save your place in files
(save-place-mode t)
;; Save history in minibuffer to keep recent commands easily accessible
(savehist-mode t)
;; Keep track of open files
(recentf-mode t)
;; Keep files up-to-date when they change outside Emacs
(global-auto-revert-mode t)
;; Tabs
(global-tab-line-mode)
;; Display line numbers only when in programming modes
(add-hook 'prog-mode-hook
'display-line-numbers-mode)
;; Resize text, like in a terminal
(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
;; The `setq' special form is used for setting variables. Remember
;; that you can look up these variables with "C-h v variable-name".
(setq uniquify-buffer-name-style
'forward
window-resize-pixelwise
t
frame-resize-pixelwise
t
load-prefer-newer
t
backup-by-copying
t
display-line-numbers 'relative
state-directory (concat (getenv "XDG_STATE_HOME") "/emacs")
;; Backups are placed into your Emacs directory, e.g. ~/.config/emacs/backups
backup-directory-alist `(("." . ,(concat state-directory "backups")))
;; I'll add an extra note here since user customizations are important.
;; Emacs actually offers a UI-based customization menu, "M-x customize".
;; You can use this menu to change variable values across Emacs. By default,
;; changing a variable will write to your init.el automatically, mixing
;; your hand-written Emacs Lisp with automatically-generated Lisp from the
;; customize menu. The following setting instead writes customizations to a
;; separate file, custom.el, to keep your init.el clean.
custom-file
(expand-file-name "custom.el" user-emacs-directory))
(load custom-file)
;; Bring in package utilities so we can install packages from the web.
(require 'package)
;; Add MELPA, an unofficial (but well-curated) package registry to the
;; list of accepted package registries. By default Emacs only uses GNU
;; ELPA and NonGNU ELPA, https://elpa.gnu.org/ and
;; https://elpa.nongnu.org/ respectively.
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
;; Unless we've already fetched (and cached) the package archives,
;; refresh them.
;; (unless package-archive-contents
;; (package-refresh-contents))
;; Add the :vc keyword to use-package, making it easy to install
;; packages directly from git repositories.
(unless (package-installed-p 'vc-use-package)
(package-vc-install "https://github.com/slotThe/vc-use-package"))
(require 'vc-use-package)
;; A quick primer on the `use-package' function (refer to
;; "C-h f use-package" for the full details).
;;
;; (use-package my-package-name
;; :ensure t ; Ensure my-package is installed
;; :after foo ; Load my-package after foo is loaded (seldom used)
;; :init ; Run this code before my-package is loaded
;; :bind ; Bind these keys to these functions
;; :custom ; Set these variables
;; :config ; Run this code after my-package is loaded
;; A package with a great selection of themes:
;; https://protesilaos.com/emacs/ef-themes
(use-package dracula-theme :ensure t :config
(load-theme 'dracula t))
;; Minibuffer completion is essential to your Emacs workflow and
;; Vertico is currently one of the best out there. There's a lot to
;; dive in here so I recommend checking out the documentation for more
;; details: https://elpa.gnu.org/packages/vertico.html. The short and
;; sweet of it is that you search for commands with "M-x do-thing" and
;; the minibuffer will show you a filterable list of matches.
(use-package vertico
:ensure
t
:custom
(vertico-cycle t)
(read-buffer-completion-ignore-case t)
(read-file-name-completion-ignore-case t)
(completion-styles '(basic substring partial-completion flex))
:init
(vertico-mode))
;; Improve the accessibility of Emacs documentation by placing
;; descriptions directly in your minibuffer. Give it a try:
;; "M-x find-file".
(use-package marginalia
:after
vertico
:ensure
t
:init
(marginalia-mode))
;; Adds intellisense-style code completion at point that works great
;; with LSP via Eglot. You'll likely want to configure this one to
;; match your editing preferences, there's no one-size-fits-all
;; solution.
(use-package corfu
:ensure
t
:init
(global-corfu-mode)
:custom
(corfu-auto t)
;; You may want to play with delay/prefix/styles to suit your preferences.
(corfu-auto-delay 0)
(corfu-auto-prefix 0)
(completion-styles '(basic)))
;; Adds LSP support. Note that you must have the respective LSP
;; server installed on your machine to use it with Eglot. e.g.
;; rust-analyzer to use Eglot with `rust-mode'.
(use-package eglot
:ensure
t
:bind
(("s-<mouse-1>" . eglot-find-implementation)
("C-c ." . eglot-code-action-quickfix)
("C-c r" . eglot-rename)
("C-c f" . eglot-format))
;; Add your programming modes here to automatically start Eglot,
;; assuming you have the respective LSP server installed.
:hook
((go-mode . eglot-ensure)
(web-mode . eglot-ensure)
(rust-mode . eglot-ensure)
(csharp-ts-mode . eglot-ensure)
(scheme-mode . eglot-ensure))
:config
;; You can configure additional LSP servers by modifying
;; `eglot-server-programs'. The following tells eglot to use TypeScript
;; language server when working in `web-mode'.
(add-to-list 'eglot-server-programs
'(web-mode . ("typescript-language-server" "--stdio"))
'(scheme-mode . ("guile-lsp-server"))))
;; Add extra context to Emacs documentation to help make it easier to
;; search and understand. This configuration uses the keybindings
;; recommended by the package author.
;; Add extra context to Emacs documentation to help make it easier to
;; search and understand. This configuration uses the keybindings
;; recommended by the package author.
(use-package helpful
:ensure t
:bind (("C-h f" . #'helpful-callable)
("C-h v" . #'helpful-variable)
("C-h k" . #'helpful-key)
("C-c C-d" . #'helpful-at-point)
("C-h F" . #'helpful-function)
("C-h C" . #'helpful-command)))
;; Adds vim emulation. Activate `evil-mode' to swap your default Emacs
;; keybindings with the modal editor of great infamy. There's a ton of
;; keybindings that Evil needs to modify, so this configuration also
;; includes `evil-collection' to fill in the gaps.
(use-package evil
:ensure
t
:init
(setq evil-want-integration t)
(setq evil-want-keybinding nil)
:config
(evil-mode 1))
(use-package evil-collection
:after
evil
:ensure
t
:config
(evil-collection-init))
(use-package evil-surround
:after evil
:ensure t
:config
(global-evil-surround-mode 1))
;; `org-mode' is great but Denote makes it even better by adding
;; features that you'd find in something like Obsidian (like
;; backlinks!). You can write your notes in org, markdown, or plain
;; text, though I recommend giving `org-mode' a try if you've never
;; used it before. The Denote manual is also excellent:
;; https://protesilaos.com/emacs/denote
(use-package denote
:ensure
t
:custom
(denote-known-keywords '("emacs" "journal"))
;; This is the directory where your notes live.
(denote-directory (expand-file-name "~/denote/"))
:bind
(("C-c n n" . denote) ("C-c n f" . denote-open-or-create)
("C-c n i" . denote-link)))
;; An extremely feature-rich git client. Activate it with "C-c g".
(use-package magit :ensure t :bind
(("C-c g" . magit-status)))
;; In addition to installing packages from the configured package
;; registries, you can also install straight from version control
;; with the :vc keyword argument. For the full list of supported
;; fetchers, view the documentation for the variable
;; `vc-use-package-fetchers'.
;;
;; Breadcrumb adds, well, breadcrumbs to the top of your open buffers
;; and works great with project.el, the Emacs project manager.
;;
;; Read more about projects here:
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Projects.html
(use-package breadcrumb :vc
(:fetcher github :repo joaotavora/breadcrumb) :init
(breadcrumb-mode))
;; As you've probably noticed, Lisp has a lot of parentheses.
;; Maintaining the syntactical correctness of these parentheses
;; can be a pain when you're first getting started with Lisp,
;; especially when you're fighting the urge to break up groups
;; of closing parens into separate lines. Luckily we have
;; Paredit, a package that maintains the structure of your
;; parentheses for you. At first, Paredit might feel a little
;; odd; you'll probably need to look at a tutorial (linked
;; below) or read the docs before you can use it effectively.
;; But once you pass that initial barrier you'll write Lisp
;; code like it's second nature.
;; http://danmidwood.com/content/2014/11/21/animated-paredit.html
;; https://stackoverflow.com/a/5243421/3606440
(use-package paredit :ensure t :hook
((emacs-lisp-mode . enable-paredit-mode)
(lisp-mode . enable-paredit-mode)
(ielm-mode . enable-paredit-mode)
(lisp-interaction-mode . enable-paredit-mode)
(scheme-mode . enable-paredit-mode)))
(use-package go-mode
:ensure
t
:bind
(:map go-mode-map
("C-c C-f" quote gofmt))
:hook
(before-save . gofmt-before-save))
(use-package lua-mode :ensure t)
(use-package markdown-mode
:ensure
t
;; These extra modes help clean up the Markdown editing experience.
;; `visual-line-mode' turns on word wrap and helps editing commands
;; work with paragraphs of text. `flyspell-mode' turns on an
;; automatic spell checker.
:hook
((markdown-mode . visual-line-mode)
(markdown-mode . flyspell-mode))
:init
(setq markdown-command "multimarkdown"))
;; Note that `php-mode' assumes php code is separate from HTML.
;; If you prefer working with PHP and HTML in a single file you
;; may prefer `web-mode'.
(use-package php-mode :ensure t)
;; TypeScript, JS, and JSX/TSX support.
(use-package web-mode
:ensure
t
:mode
(("\\.ts\\'" . web-mode) ("\\.js\\'" . web-mode)
("\\.mjs\\'" . web-mode)
("\\.tsx\\'" . web-mode)
("\\.jsx\\'" . web-mode))
:custom
(web-mode-content-types-alist '(("jsx" . "\\.js[x]?\\'")))
(web-mode-code-indent-offset 2)
(web-mode-css-indent-offset 2)
(web-mode-markup-indent-offset 2)
(web-mode-enable-auto-quoting nil))
(use-package rust-mode
:ensure
t
:bind
(:map rust-mode-map
("C-c C-r" quote rust-run)
("C-c C-c" quote rust-compile)
("C-c C-f" quote rust-format-buffer)
("C-c C-t" quote rust-test))
:hook
(rust-mode . prettify-symbols-mode))
(use-package yaml-mode :ensure t)
|