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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
#+TITLE: My emacs literate configuration
#+AUTHOR: Leonardo Santiago
This org file is used as the configuration source for my emacs. Additional packages may be found at emacs.nix (those that cannot be directly installed from =use-package=). Though declared in emacs lisp, they actually are completely managed by the =nix= package manager, by parsing the declarations on this file and using them to fetch the packages, which I think is really cool.
This makes it such that it is trivial to handle complex configurations, such as pylsp with plugins or treesitter grammars installation process (which usually envolves some stateful installations outside of emacs).
In order to run this emacs configuration locally, all you need to do is run the following command:
#+begin_src shell
nix run github:o-santi/emacs --experimental-features "nix-command" --experimental-features "flakes"
#+end_src
Though you probably shouldn't, because it will most likely build all of emacs from scratch (which takes a little while).
You can also use it as a ~nixosModule~, in order to add additional packages like fonts.
* Core
** Remove bar mode
#+begin_src emacs-lisp :tangle yes
(menu-bar-mode -1)
(tool-bar-mode -1)
(setq use-short-answers t)
(setq ring-bell-function 'ignore)
(setq-default indent-tabs-mode nil)
#+end_src
** Theme and font
#+begin_src emacs-lisp :tangle yes
(use-package modus-themes)
;; (use-package kanagawa-theme)
(load-theme 'wombat t)
(set-face-attribute 'default nil
:family "Iosevka Nerd Font"
:width 'normal
:weight 'normal)
#+end_src
** Backups
#+begin_src emacs-lisp :tangle yes
(setq
backup-by-copying t ; don't clobber symlinks
backup-directory-alist '(("." . "~/.saves/")) ; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
#+end_src
** Background opacity
Remove background on terminal, and add transparency on GUI
#+begin_src emacs-lisp :tangle yes
(defun on-after-init ()
(unless (display-graphic-p (selected-frame))
(set-face-background 'default "unspecified-bg" (selected-frame))))
(add-hook 'window-setup-hook 'on-after-init)
(set-frame-parameter nil 'alpha-background 80)
(add-to-list 'default-frame-alist '(alpha-background . 80))
#+end_src
* Utility
** All the Icons
Works through nixosModules.
#+begin_src emacs-lisp :tangle yes
(use-package all-the-icons
:if (display-graphic-p))
(use-package all-the-icons-completion
:if (display-graphic-p)
:after all-the-icons
:hook (marginalia-mode . all-the-icons-completion-mode))
#+end_src
** Direnv
To integrate with nix shells.
#+begin_src emacs-lisp :tangle yes
(use-package envrc
:config (envrc-global-mode))
#+end_src
** Magit
Configurations for magit
*** Use Magit
#+begin_src emacs-lisp :tangle yes
(use-package magit
:custom (magit-process-finish-apply-ansi-colors t))
#+end_src
*** Forge
#+begin_src emacs-lisp :tangle yes
(setq auth-sources '("/run/agenix/authinfo"))
#+end_src
To interact with gitlab and github.
#+begin_src emacs-lisp :tangle yes
(use-package forge
:after magit)
#+end_src
** Vertico, Orderless, Marginalia
Pretty minibuffer support
#+begin_src emacs-lisp :tangle yes
(use-package vertico
:config (vertico-mode))
(use-package orderless
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides '((file (styles basic partial-completion)))))
(use-package marginalia
:config (marginalia-mode))
(use-package ctrlf
:config (ctrlf-mode +1))
#+end_src
** Projects
#+begin_src emacs-lisp :tangle yes
(defcustom project-root-markers
'("Cargo.toml" "flake.nix" ".git")
"Files that indicate that directory is the root of a project"
:type '(repeat string)
:group 'project)
(defun project-root-p (path)
(catch 'found
(dolist (marker project-root-markers)
(when (file-exists-p (concat path marker))
(throw 'found marker)))))
(defun project-find-root (path)
"Search up the PATH for `project-root-markers'."
(let ((path (expand-file-name path)))
(catch 'found
(while (not (equal "/" path))
(if (not (project-root-p path))
(setq path (file-name-directory (directory-file-name path)))
(throw 'found (cons 'transient path)))))))
(use-package project
:config (setq project-find-functions '(project-find-root)))
#+end_src
** Helpful and which key
Better help defaults
#+begin_src emacs-lisp :tangle yes
(use-package helpful
:config
(global-set-key (kbd "C-h f") #'helpful-callable)
(global-set-key (kbd "C-h v") #'helpful-variable)
(global-set-key (kbd "C-h x") #'helpful-command)
(global-set-key (kbd "C-h k") #'helpful-key))
(use-package which-key
:config (which-key-mode))
#+end_src
** Dired
I wanna try some QoL addons for dired.
#+begin_src emacs-lisp :tangle yes
(use-package dired
:hook (dired-mode . dired-hide-details-mode))
(use-package dired-subtree
:after dired
:config
(add-hook 'dired-mode-hook
(lambda () (local-set-key (kbd "<tab>") #'dired-subtree-toggle))))
(use-package all-the-icons-dired
:hook (dired-mode . all-the-icons-dired-mode))
#+end_src
** Windows
I wanna test out =winner-mode=
#+begin_src emacs-lisp :tangle yes
(use-package winner
:config (winner-mode))
#+end_src
** Bind key
#+begin_src emacs-lisp :tangle yes
(use-package bind-key)
#+end_src
** Eglot
Language server support. Already comes installed but used to configure additional language servers.
#+begin_src emacs-lisp :tangle yes
(use-package eglot
:config (add-to-list 'eglot-server-programs '(nix-mode . ("nil"))))
#+end_src
** Corfu
Completion popup system
#+begin_src emacs-lisp :tangle yes
(use-package corfu
:config (global-corfu-mode)
:custom
(corfu-auto t)
(corfu-cycle t)
(corfu-separator ?\s)
(corfu-quit-no-match t))
#+end_src
** Vterm
#+begin_src emacs-lisp :tangle yes
(use-package vterm)
#+end_src
** Compilation
Add support for ansi escape codes in compilation
#+begin_src emacs-lisp :tangle yes
(use-package xterm-color
:custom (compilation-environment '("TERM=xterm-256color")))
(defun my/advice-compilation-filter (f proc string)
(funcall f proc (xterm-color-filter string)))
(advice-add 'compilation-filter :around #'my/advice-compilation-filter)
#+end_src
** Pdf reader
#+begin_src emacs-lisp :tangle yes
(use-package pdf-tools
:defer t
:mode ("\\.pdf\\'" . pdf-view-mode)
:magic ("%PDF" . pdf-view-mode))
#+end_src
** View Large Files
Minor mode to allow opening files in chunks
#+begin_src emacs-lisp :tangle yes
(use-package vlf
:config
(require 'vlf-setup)
(custom-set-variables
'(vlf-application 'dont-ask)))
#+end_src
* Languages
I try to mostly use the new Treesitter modes, which comes builtin with the new emacs 29.
** Python
The package already comes builtin, so we only instantiate it to define the hooks and remap the default package for the new one.
It also relies on python lsp server with builtin ruff support.
#+begin_src emacs-lisp :tangle yes
(add-to-list 'major-mode-remap-alist '(python-mode . python-ts-mode))
(add-hook 'python-ts-mode-hook #'eglot-ensure)
#+end_src
** Nix
#+begin_src emacs-lisp :tangle yes
(use-package nix-mode
:hook (nix-mode . eglot-ensure))
#+end_src
** Rust
Try to use the package.
#+begin_src emacs-lisp :tangle yes
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-ts-mode))
(add-hook 'rust-ts-mode-hook #'eglot-ensure)
(setq rust-ts-mode-indent-offset 2)
#+end_src
** Markdown
#+begin_src emacs-lisp :tangle yes
(use-package markdown-mode
:mode "\\.md\\'")
#+end_src
** Coq
#+begin_src emacs-lisp :tangle yes
(use-package proof-general)
(use-package company-coq
:hook (coq-mode . company-coq-mode))
#+end_src
* Personal
** Org mode
#+begin_src emacs-lisp :tangle yes
(use-package org
:hook (org-mode . org-indent-mode)
:bind ("C-c a" . org-agenda)
:config
(custom-set-faces
'(org-headline-done
((((class color) (min-colors 16) (background dark))
(:foreground "gray" :strike-through t)))))
:custom
(org-todo-keywords '((sequence "IDEA" "TODO" "STUCK" "DOING" "|" "DONE")
(sequence "ASSIGNED(a@!)" "WORKING(w!)" "ON REVIEW(r!)" "|" "MERGED(m!)" "CANCELLED(c!)")
(sequence "EVENT" "|" "FULFILLED")))
(org-startup-truncated nil)
(org-ellipsis "…")
(org-pretty-entities t)
(org-hide-emphasis-markers nil)
(org-fontify-quote-and-verse-blocks t)
(org-image-actual-width nil)
(org-indirect-buffer-display 'other-window)
(org-confirm-babel-evaluate nil)
(org-edit-src-content-indentation 0)
(org-auto-align-tags nil)
(org-fontify-done-headline t)
(org-agenda-files '("~/agenda.org")))
#+end_src
*** Org Modern
#+begin_src emacs-lisp :tangle yes
(defun bg (color)
`(:background ,color :inherit (org-todo org-modern-label) :foreground "gray25"))
(use-package org-modern
:after org
:hook (org-mode . org-modern-mode)
:hook (org-agenda-finalize . org-modern-agenda)
:custom
(org-modern-todo-faces
`(("IDEA" . ,(bg "yellow"))
("TODO" . org-modern-todo)
("STUCK" . ,(bg "brown"))
("DOING" . ,(bg "green"))
("DONE" . org-modern-done)
; work tasks
("ASSIGNED" . org-modern-todo)
("WORKING" . ,(bg "green yellow"))
("ON REVIEW" . ,(bg "sandy brown"))
("MERGED" . org-modern-done)
("CANCELLED" . ,(bg "OrangeRed1"))
; one time tasks
("EVENT" . ,(bg "deep sky blue"))
("DONE" . org-modern-done)))
(org-modern-priority t))
#+end_src
*** Org Agenda
#+begin_src emacs-lisp :tangle yes
(setq
org-agenda-window-setup 'current-window
org-agenda-restore-windows-after-quit t
org-agenda-skip-deadline-prewarning-if-scheduled t
org-agenda-compact-blocks t
org-agenda-span 'week
org-agenda-skip-deadline-if-done t
org-agenda-skip-scheduled-if-done t
org-agenda-skip-timestamp-if-done t
org-agenda-format-date "%e de %B, %A"
org-agenda-deadline-leaders '("Deadline: " "Daqui a %d dias:" "%d dias atrás")
org-agenda-scheduled-leaders '("Agendado: " "%d dias atrasado:")
)
(setq
org-agenda-custom-commands
'(("w" "work"
((todo "ASSIGNED")
(todo "WORKING")
(todo "ON REVIEW")
(tags-todo "CATEGORY=\"trabalho\"")))))
#+end_src
*** Org alert
#+begin_src emacs-lisp :tangle yes
(use-package org-alert
:ensure t
:config (org-alert-enable)
:custom
(org-alert-interval 60)
(org-alert-notify-cutoff 30)
(org-alert-notification-title "Emacs Agenda")
(alert-default-style 'notifications))
#+end_src
*** Ox-hugo
In order to publish files to hugo from org.
#+begin_src emacs-lisp :tangle yes
(use-package ox-hugo
:after ox)
#+end_src
** Calendar
try out emacs calfw
#+begin_src emacs-lisp :tangle yes
(use-package calfw)
(use-package calfw-org
:bind ("C-c c l" . cfw:open-org-calendar)
:custom (cfw:org-overwrite-default-keybinding t))
#+end_src
** Email
*** RSS feed reader
#+begin_src emacs-lisp :tangle yes
(use-package elfeed
:custom
(elfeed-feeds
'(("https://xeiaso.net/blog.rss" nixos)
("https://smallcultfollowing.com/babysteps//atom.xml" rust)
("https://fasterthanli.me/index.xml" rust nixos)
("http://radar.spacebar.org/f/a/weblog/rss/1" tom7)
("https://matklad.github.io/feed.xml" rust zig)
("https://blog.m-ou.se/index.xml" rust)
("https://without.boats/index.xml" rust)
)))
#+end_src
#+RESULTS:
*** Mu4e
**** Setting up mu4e.
#+begin_src emacs-lisp :tangle yes
(setq epg-pinentry-mode 'loopback)
(setq user-mail-address "[email protected]")
#+end_src
Helper functions, to try to discover which mail pertains to which account.
#+begin_src emacs-lisp :tangle yes
(defun personal-p (msg)
(string-prefix-p "/personal/" (mu4e-message-field msg :maildir)))
(defun university-p (msg)
(string-prefix-p "/university/" (mu4e-message-field msg :maildir)))
(defun work-p (msg)
(string-prefix-p "/work/" (mu4e-message-field msg :maildir)))
#+end_src
Actual mu4e definition
#+begin_src emacs-lisp :tangle yes
(use-package mu4e
:bind ("C-c m" . mu4e)
:custom
(read-mail-command 'mu4e)
(mu4e-index-cleanup nil)
(mu4e-index-lazy-check t)
(mu4e-use-fancy-chars (display-graphic-p))
(mu4e-confirm-quit nil)
(mu4e-change-filenames-when-moving t)
(mu4e-update-interval (* 5 60))
(mu4e-get-mail-command "parallel mbsync ::: personal work university")
(mu4e-headers-fields
'((:human-date . 10)
(:flags . 6)
(:topic . 10)
(:from-or-to . 22)
(:subject . nil)))
(mu4e-drafts-folder (lambda (msg)
(cond
((personal-p msg) "/personal/[Gmail]/Rascunhos")
((university-p msg) "/university/[Gmail]/Rascunhos")
((work-p msg) "/work/[Gmail]/Drafts"))))
(mu4e-sent-folder (lambda (msg)
(cond
((personal-p msg) "/personal/[Gmail]/Enviados")
((university-p msg) "/university/[Gmail]/Enviados")
((work-p msg) "/work/[Gmail]/Sent"))))
(mu4e-refile-folder (lambda (msg)
(cond
((personal-p msg) "/personal/[Gmail]/Todos\ os\ e-mails")
((university-p msg) "/university/[Gmail]/Todos\ os\ e-mails")
((work-p msg) "/work/[Gmail]/'All mail'"))))
(mu4e-trash-folder (lambda (msg)
(cond
((personal-p msg) "/personal/[Gmail]/Lixeira")
((university-p msg) "/university/[Gmail]/Lixeira")
((work-p msg) "/work/[Gmail]/Trash"))))
:config
(add-to-list 'display-buffer-alist
`( ,(regexp-quote mu4e-main-buffer-name)
display-buffer-same-window)) ; to avoid opening in full frame everytime.
(add-to-list 'mu4e-bookmarks
'(:name "Inboxes"
:query "m:/personal/Inbox OR m:/work/Inbox OR m:/university/Inbox"
:key ?i))
(add-to-list 'mu4e-header-info-custom
'(:topic
:name "Topic"
:shortname "Topic"
:function (lambda (msg)
(cond
((personal-p msg) "Personal")
((university-p msg) "University")
((work-p msg) "Work"))))))
#+end_src
|