blob: 1e8178f5d585aa55d3d41ba07f997f8768594475 (
plain)
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
|
;; put auto-generated configs in a separate file
;; https://protesilaos.com/codelog/2024-11-28-basic-emacs-configuration/#h:7db72beb-b8ac-4c6d-a6f4-a52661208e23
(setq custom-file (locate-user-emacs-file "custom.el"))
(load custom-file :no-error-if-file-is-missing)
;; Set up package.el to work with MELPA
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
;; View package diffs on upgrade
;; https://www.reddit.com/r/emacs/comments/1rowm5i/comment/o9hzo8w/
(setq package-review-policy t
package-review-diff-command '("git" "diff" "--no-index" "--color=never" "--diff-filter=d"))
(package-initialize)
;; Use Evil Mode
(use-package evil
:ensure t
:init
(setq evil-want-keybinding nil) ;; required for evil-collection
:custom
(evil-undo-system 'undo-redo)
(evil-want-C-u-scroll t)
(evil-want-Y-yank-to-eol t)
:config
(evil-mode 1)
)
(use-package evil-collection
:after evil
:ensure t
:config
(evil-collection-init))
;; compilation keybinds
(evil-set-leader 'normal (kbd "SPC"))
(evil-define-key 'normal 'global (kbd "<leader>cc") 'compile)
(evil-define-key 'normal 'global (kbd "<leader>cp") 'project-compile)
(evil-define-key 'normal 'global (kbd "<leader>cr") 'recompile)
;; Don't show the splash screen
(setq inhibit-startup-message t)
;; Turn off unneeded UI elements
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; Set line numbers
(setq display-line-numbers-type 'relative)
(global-display-line-numbers-mode 1)
;; Remove left continuation fringe arrow (the wrapping one)
;; Source - https://stackoverflow.com/a/27854648
(setf (cdr (assq 'continuation fringe-indicator-alist))
'(nil right-curly-arrow))
;; Turn off blinking cursor
(blink-cursor-mode -1)
;; Set font
(add-to-list 'default-frame-alist
'(font . "TX-02 Condensed-13"))
;; Add nerdfont to list of fallback fonts
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Modifying-Fontsets.html
(set-fontset-font "fontset-default" nil "Symbols Nerd Font" nil 'append)
;; Theme
(use-package standard-themes
:ensure t
:custom
(modus-themes-common-palette-overrides
'((fringe unspecified) ;; make fringe invisible
))
:config
(modus-themes-load-theme 'standard-light))
;; reset current line number styling to default
(set-face-attribute 'line-number-current-line nil :inherit)
;; small amount of header spacing
(setq-default header-line-format "")
(set-face-attribute 'header-line nil
:background 'unspecified
:height (* 10 5))
;; Color output when compiling
(use-package fancy-compilation
:ensure t
:commands (fancy-compilation-mode)
:custom
(fancy-compilation-quiet-prelude nil)
(fancy-compilation-override-colors nil)
)
(with-eval-after-load 'compile
(fancy-compilation-mode))
(with-eval-after-load 'project-compile
(fancy-compilation-mode))
;; Git highlight
(use-package diff-hl
:ensure t
:hook (dired-mode . diff-hl-dired-mode)
:config
(global-diff-hl-mode))
;; Magit
(use-package magit
:ensure t)
;; Move temporary files to /var/tmp/
(setq backup-directory-alist
`(("." . "/var/tmp/")))
;; https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html#index-lock_002dfile_002dname_002dtransforms
(setq lock-file-name-transforms
'(("\\`/.*/\\([^/]+\\)\\'" "/var/tmp/\\1" t)))
(setq auto-save-file-name-transforms
'(("\\`/.*/\\([^/]+\\)\\'" "/var/tmp/\\1" t)))
;; consult
(use-package consult
:ensure t
:bind
("C-x b" . consult-buffer) ;; orig. switch-to-buffer
)
;; Set spellcheck program
(setq ispell-program-name "/usr/bin/aspell")
;; Word counter
;; Using unix wc because emacs's built-in 'count-words gives wrong count
;; https://www.emacswiki.org/emacs/WordCount#h5o-7 (the unix way)
;; https://stackoverflow.com/a/5020475 (why substring is required)
(defun unix-wc-word (str)
(substring
(shell-command-to-string (concat "echo " (shell-quote-argument str) " | wc -w"))
0 -1)
)
(defun wc (start end)
;; (interactive) TODO: not sure how to make it interactive, tbh
(unix-wc-word (buffer-substring start end))
)
(defun wci ()
(interactive)
(message
"Words: %s"
(wc (mark) (point))
)
)
;; Most code taken from https://web.archive.org/web/20160322014200/http://www.dr-qubit.org/emacs-misc/wc-mode-0.3.el
;; BUG: doesn't correctly in Evil Visual-Line mode
;; use Visual mode for correct WC of a region
(setq mode-line-position (assq-delete-all 'wc-mode mode-line-position))
;; BUG: Using this makes the buffer VERY laggy.
;; I guess it's because of the constant calls to "$ wc"
;; Manually using the above wci for now
(setq mode-line-position
(append
mode-line-position
'((wc-mode
(6 (:eval (if (use-region-p)
(format "WC:%s"
(wc (mark) (point)))
;; (count-words-region (region-beginning) (region-end)))
(format "WC:%s"
(wc (point-min) (point-max))))))
;; (count-words-region (point-min) (point-max))))))
nil))))
(define-minor-mode wc-mode
"Toggle word-count mode.
With no argument, this command toggles the mode.
A non-null prefix argument turns the mode on.
A null prefix argument turns it off.
When enabled, the total number of characters, words, and lines is
displayed in the mode-line.")
;;;;;;;;;;;;;;;
;; Languages ;;
;;;;;;;;;;;;;;;
(use-package eglot)
(use-package reformatter
:ensure t)
;; Typst
(reformatter-define typstyle
:program "typstyle")
(use-package typst-ts-mode
:vc (:url "https://codeberg.org/meow_king/typst-ts-mode.git")
:mode ("\\.typ\\'" . typst-ts-mode)
:interpreter ("Typst" . typst-ts-mode)
:config
(add-to-list 'eglot-server-programs
`((typst-ts-mode) .
,(eglot-alternatives `(,typst-ts-lsp-download-path
"tinymist"
"typst-lsp"))))
:hook (typst-ts-mode . eglot-ensure)
:hook (typst-ts-mode . typstyle-on-save-mode)
)
;; Python
(use-package python
:config
(add-to-list 'eglot-server-programs
`(python-mode . ("ruff" "server")))
;; :hook (python-mode . eglot-ensure)
;; :hook (python-mode . (lambda () (add-hook 'after-save-hook 'eglot-format nil t)))
)
;; Rust
(use-package rust-mode
:ensure t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Other Development Stuff ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; direnv
(use-package envrc
:ensure t
:hook (after-init . envrc-global-mode))
;;;;;;;;;;;;;;;
;; Clipboard ;;
;;;;;;;;;;;;;;;
;; Fixes Wayland clipboard troubles
;; see https://www.emacswiki.org/emacs/CopyAndPaste#h5o-6
(setq wl-copy-process nil)
(defun wl-copy (text)
(setq wl-copy-process (make-process :name "wl-copy"
:buffer nil
:command '("wl-copy" "-f" "-n")
:connection-type 'pipe
:noquery t))
(process-send-string wl-copy-process text)
(process-send-eof wl-copy-process))
(defun wl-paste ()
(if (and wl-copy-process (process-live-p wl-copy-process))
nil ; should return nil if we're the current paste owner
(shell-command-to-string "wl-paste -n | tr -d \r")))
(setq interprogram-cut-function 'wl-copy)
(setq interprogram-paste-function 'wl-paste)
|