-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
427 lines (351 loc) · 14.2 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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
;; Copyright 2019-2021 Luka Peschke
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;; http://www.apache.org/licenses/LICENSE-2.0
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;; package installation
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
;; forward compat for old emacs versions
(require 'cl-lib)
;; checking that use-package is installed:
(defvar my-packages
'(catppuccin-theme company counsel deno-fmt dockerfile-mode dockerfile-mode drag-stuff dumb-jump
elixir-mode flycheck flycheck-kotlin flycheck-pycheckers format-all
gnu-elpa-keyring-update go-mode graphql-mode groovy-mode highlight-indentation ivy
jinja2-mode kkp kotlin-mode lsp-metals lsp-mode lsp-pyright lsp-ui multiple-cursors prettier
protobuf-mode py-isort python-mode pyvenv rainbow-delimiters rainbow-mode rust-mode
sbt-mode scala-mode string-inflection swiper terraform-mode tree-sitter tree-sitter-langs
typescript-mode use-package web-mode whitespace yaml-mode)
"A list of packages to ensure are installed at launch.")
(defun my-packages-installed-p ()
(cl-loop for p in my-packages
when (not (package-installed-p p)) do (cl-return nil)
finally (cl-return t)))
(unless (my-packages-installed-p)
;; check for new packages (package versions)
(package-refresh-contents)
;; install the missing packages
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p))))
;; end of package installation
;; VARIOUS
;; nice completion & search
(use-package ivy
:config
(ivy-mode 1)
;; ido-mode behaviour for file navigation
(define-key ivy-minibuffer-map (kbd "C-j") #'ivy-immediate-done)
(define-key ivy-minibuffer-map (kbd "RET") #'ivy-alt-done)
(global-set-key "\C-s" 'swiper)
)
(use-package counsel
:config
(counsel-mode 1)
(define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)
)
;; matching {} [] () in the same color
(use-package rainbow-delimiters
:config
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
;; automatically make pairs for (), [] and {}, and automatically
;; delete pairs
(electric-pair-mode 1)
;; Highlight matching (), {}, and []
(setq show-paren-delay 0)
(show-paren-mode 1)
;; display line AND column in bottom bar
(setq column-number-mode t)
;; Make CamelCase bevahe as two words: Camel and Case
(add-hook 'prog-mode-hook 'subword-mode)
;; Delegate cursor behaviour handling to the terminal
(setq visible-cursor nil)
;; automatically goes to a new line when a certain length is reached (useful for
;; comments).
(add-hook 'prog-mode-hook #'auto-fill-mode)
;; Break at 100th char
(setq fill-column 100
;; only enable auto-fill for comments
comment-auto-fill-only-comments t)
;; Highlight indentation
(use-package highlight-indentation
:config
(set-face-background 'highlight-indentation-face "#444444"))
;; Uncomment this line to get a spaces-only indentation
(setq-default indent-tabs-mode nil)
;; Make characters after column 101 purple and trailing spaces red
;; This also shows tabulations, delete 'tab-mark' from the lines below to
;; cancel this
(use-package whitespace
:config
(setq whitespace-style '(face trailing tab-mark lines-tail))
;; Allowing lines of up to 100 chars
(setq whitespace-line-column 101))
(add-hook 'prog-mode-hook 'whitespace-mode)
;; scroll only one line at once
(setq mouse-wheel-progressive-speed nil)
(setq scroll-step 1)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1)))
;; disable menu bar, set to 1 to enable it
(menu-bar-mode -1)
;; keybindings to toggle/wrap functions, use CTRL-c and arrow keys
(add-hook 'prog-mode-hook
(lambda()
(local-set-key (kbd "C-c <right>") 'hs-show-block)
(local-set-key (kbd "C-c <left>") 'hs-hide-block)
(local-set-key (kbd "C-c <up>") 'hs-hide-all)
(local-set-key (kbd "C-c <down>") 'hs-show-all)
(hs-minor-mode t)))
;; Bind C-x C-a to eXecute Action
(add-hook 'prog-mode-hook
(lambda()
(local-set-key (kbd "C-x C-a") 'lsp-execute-code-action)))
;; List flycheck errors on C-x C-e
(add-hook 'prog-mode-hook
(lambda()
(local-set-key (kbd "C-x C-e") 'flycheck-list-errors)))
;; remove all trailing whitespaces when saving
(add-hook 'before-save-hook 'whitespace-cleanup)
;; keybindings to move stuff around, use Meta (alt) and arrow keys
(use-package drag-stuff
:config
(global-set-key (kbd "<M-up>") 'drag-stuff-up)
(global-set-key (kbd "<M-down>") 'drag-stuff-down)
(global-set-key (kbd "<M-left>") 'drag-stuff-left)
(global-set-key (kbd "<M-right>") 'drag-stuff-right))
;; nice theme
(use-package catppuccin-theme
:config
(load-theme 'catppuccin t)
(setq catppuccin-flavor 'frappe)
(catppuccin-reload))
;; keep the original background color, ie. transparent terminal
(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)
;; Enable rst-mode for .rst files
(use-package rst
:config
(add-to-list 'auto-mode-alist '("\\.rst\\'" . rst-mode)))
;; Enable web-mode for .html and .vue files
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.vue\\'" . web-mode))
(setq web-mode-enable-auto-closing t
web-mode-enable-auto-pairing t
web-mode-enable-current-column-highlight t
web-mode-enable-current-element-highlight t
web-mode-markup-indent-offset 2)
;; disable lock files
(setq create-lockfiles nil)
;; put backup files in .emacs/backups
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "backups"))))
;; put autosave files in .emacs/auto-saves
(setq auto-save-file-name-transforms
`((".*" ,(concat user-emacs-directory "auto-saves/") t)))
;; Allow to cycle between string cases on C-c C-u
(defun java-style-string-cycle ()
(local-set-key (kbd "C-c C-u") 'string-inflection-java-style-cycle))
(defun python-style-string-cycle ()
(local-set-key (kbd "C-c C-u") 'string-inflection-python-style-cycle))
(use-package string-inflection
:config
(add-hook 'python-mode-hook 'python-style-string-cycle)
(add-hook 'rust-mode-hook 'python-style-string-cycle)
(add-hook 'scala-mode-hook 'java-style-string-cycle)
(add-hook 'js-mode-hook 'java-style-string-cycle)
(add-hook 'typescript-mode-hook 'java-style-string-cycle))
(use-package multiple-cursors
:config
(global-set-key (kbd "C-c C-c") 'mc/edit-lines)
(global-set-key (kbd "C-c >") 'mc/mark-next-like-this)
(global-set-key (kbd "C-c <") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c a") 'mc/mark-all-like-this))
;; Kitty Keyboard Protocol compat
(use-package kkp
:ensure t
:config
(global-kkp-mode +1))
;; END OF VARIOUS
;; SETTING PATH
;; golang
(add-to-list 'exec-path "~/go/bin/")
;; python
(add-to-list 'exec-path "~/.local/bin/")
;; rust
(add-to-list 'exec-path "~/.cargo/bin/")
;; custom built language servers
(add-to-list 'exec-path "~/bin/")
;; deno
(add-to-list 'exec-path "~/.deno/bin")
;; yarn
(add-to-list 'exec-path "~/.yarn/bin")
;; elixir
(add-to-list 'exec-path "~/bin/elixirls/")
;; node installed with NVM
(add-to-list 'exec-path "~/.nvm/versions/node/v18.12.1/bin/")
;; END OF SETTING PATH
;; PER-LANGUAGE CONFIG & ON SAVE HOOKS
(use-package tree-sitter
:config
:hook ((after-init . global-tree-sitter-mode)
(tree-sitter-after-on . tree-sitter-hl-mode)))
(use-package tree-sitter-langs
:demand t
:after tree-sitter)
;; formatting
(use-package format-all
:commands format-all-mode
:hook (prog-mode . format-all-mode)
:config
(setq-default format-all-formatters '(("Python" (ruff)))))
;; golang
(setq gofmt-command "goimports")
(add-hook 'before-save-hook 'gofmt-before-save)
;; JS& TS
(use-package prettier
:config
(add-hook 'typescript-mode-hook 'prettier-mode)
(add-hook 'js-mode-hook 'prettier-mode))
;; rust
(setq rust-format-on-save t
lsp-rust-server 'rust-analyzer
lsp-inlay-hints-mode t
lsp-inlay-hint-enable t
lsp-rust-analyzer-display-chaining-hints t
lsp-rust-analyzer-display-closure-return-type-hints t
lsp-rust-analyzer-display-parameter-hints t)
;; python
(use-package python-mode :init :config)
(add-hook 'python-mode-hook 'highlight-indentation-mode)
;; scala
(defun scala-mode-format-on-save-hook ()
(when (eq major-mode 'scala-mode)
(lsp-format-buffer)))
(add-hook 'before-save-hook 'scala-mode-format-on-save-hook) ;; sorting imports on save
;; END OF ON SAVE HOOKS
;; START -- Support for Language Server Protocol (LSP)
(use-package lsp-mode
:config
(setq
;; use company-capf
lsp-prefer-capf t
;; Disable Yasnippet
lsp-enable-snippet nil
gc-cons-threshold 100000000
read-process-output-max (* 1024 1024)
;; disable breadcrumbs on top of window
lsp-headerline-breadcrumb-enable nil)
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]\\.direnv\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]\\.git\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]\\__pycache__\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]\\_build\\'")
;; add your languages here
(add-hook 'python-mode-hook #'lsp)
(add-hook 'rust-mode-hook #'lsp)
(add-hook 'go-mode-hook #'lsp)
(add-hook 'typescript-mode-hook #'lsp)
(add-hook 'js-mode-hook #'lsp)
;; "language_server.sh" is assumed to be available in $PATH
(add-hook 'elixir-mode-hook #'lsp)
;; "metals" is assumed to be available in $PATH
(add-hook 'scala-mode-hook #'lsp)
;; "kotlin-language-server" is assumed to be available in $PATH
(add-hook 'kotlin-mode-hook #'lsp)
)
;; Scala
(use-package lsp-metals
:config
(setq lsp-metals-show-inferred-type t))
;; python-language-server
;; We use pyright as it is faster than palantir's
;; python-language-server and more stable than microsoft's language
;; server. However, it requires node to run. You can use microsoft's
;; LS instead by uncommenting the block below and commenting the
;; lsp-pyright block. You'll also have to updater the required packages
;; (use-package lsp-python-ms
;; :ensure t
;; :init
;; ;; Will install the ms lsp automatically, set to nil to disable
;; (setq lsp-python-ms-auto-install-server t)
;; :config
;; :hook
;; ((python-mode . (lambda ()
;; (require 'lsp-python-ms)
;; (lsp-deferred)
;; ))))
(use-package lsp-pyright
:ensure t
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp))))
;; lsp-ui allows (between other things) to display linter errors inline
(use-package lsp-ui
:requires lsp-mode flycheck
:config
(setq lsp-ui-doc-enable t
lsp-ui-doc-use-childframe t
lsp-ui-doc-position 'top
lsp-ui-doc-include-signature t
lsp-ui-sideline-enable t
lsp-ui-flycheck-enable t
lsp-ui-flycheck-list-position 'right
lsp-ui-flycheck-live-reporting t
lsp-ui-peek-enable t
lsp-ui-peek-list-width 60
lsp-ui-peek-peek-height 25)
(add-hook 'lsp-mode-hook 'lsp-ui-mode))
;; using company for auto-completion
(use-package company
:config
(setq company-idle-delay 0.0
company-minimum-prefix-length 1
company-capt t)
(global-company-mode 1)
(global-set-key (kbd "C-<tab>") 'company-complete))
;; END -- Support for Language Server Protocol (LSP)
;; CUSTOMIZATION
(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.
'(custom-safe-themes
'("713f898dd8c881c139b62cf05b7ac476d05735825d49006255c0a31f9a4f46ab" default))
'(flycheck-checker-error-threshold 1000)
'(groovy-indent-offset 2)
'(package-selected-packages
'(python-mode graphql-mode smartparens vue-mode prettier counsel swiper ivy kotlin-mode multiple-cursors string-inflection lsp-metals py-isort dumb-jump pyvenv rainbow-mode sbt-mode scala-mode blacken groovy-mode protobuf-mode elixir-mode yaml-mode use-package tangotango-theme terraform-mode rust-mode rainbow-delimiters lsp-ui jinja2-mode highlight-indentation gnu-elpa-keyring-update go-mode flycheck drag-stuff dockerfile-mode company-lsp company)))
(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.
'(default ((t (:inherit nil :stipple nil :background "unspecified-bg" :foreground "color-252" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 1 :width normal :foundry "default" :family "default"))))
'(diff-added ((t (:inherit diff-changed :extend t :background "green4"))))
'(diff-removed ((t (:inherit diff-changed :extend t :background "firebrick"))))
'(error ((t (:foreground "Red1" :weight bold))))
'(font-lock-string-face ((t (:foreground "color-153"))))
'(mode-line ((t (:background "brightblue" :foreground "black"))))
'(rst-level-1 ((t (:background "color-239"))))
'(rst-level-2 ((t (:background "color-239"))))
'(rst-level-3 ((t (:background "color-239"))))
'(smerge-base ((t (:extend t :background "orange4"))))
'(smerge-lower ((t (:extend t :background "#aaffaa"))))
'(smerge-markers ((t (:extend t :background "gray40"))))
'(smerge-refined-added ((t (:inherit smerge-refined-change :background "green"))))
'(smerge-refined-removed ((t (:inherit smerge-refined-change :background "firebrick4"))))
'(smerge-upper ((t (:extend t :background "firebrick3"))))
'(web-mode-html-tag-bracket-face ((t (:foreground "brightblack"))))
'(web-mode-html-tag-face ((t (:foreground "brightyellow" :weight bold)))))
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)