-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.el
567 lines (394 loc) · 12.4 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
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
;;; Below are fragments from my Emacs configuration file
;;; (`~/.emacs.d/init.el`) using
;;; [straight.el](https://github.com/radian-software/straight.el) instead of
;;; Emacs builtin `package.el`. (For old `package.el` based version
;;; see [here](/dotemacs/2022-02-15/)).
;;; The newest version of this config is available from a [github
;;; repo](https://github.com/lukpank/.emacs.d).
;;; Bootstrap straight.el
;;; ---------------------
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 6))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(setq package-enable-at-startup nil
straight-use-package-by-default t)
(straight-use-package 'use-package)
;;; Productivity
;;; ------------
;;; ### Key discoverability ###
(use-package which-key
:init
(setq which-key-idle-delay 2.0
which-key-idle-secondary-delay 1.0)
:config
(which-key-mode))
;;; ### More efficient buffer/file selection ###
;;; Requires: [fzf](https://github.com/junegunn/fzf) and
;;; [ripgrep](https://github.com/BurntSushi/ripgrep) (rg), and git.
(setq recentf-max-saved-items 100)
(global-set-key "\C-cq" #'bury-buffer)
(use-package prescient
:config
(prescient-persist-mode))
(use-package ivy-prescient
:after counsel
:config
(ivy-prescient-mode))
(use-package counsel
:demand
:bind (("C-c a" . swiper-all)
("C-c e" . counsel-flycheck)
("C-c f" . counsel-fzf)
("C-c g" . counsel-git)
("C-c i" . counsel-imenu)
("C-c j" . counsel-git-grep)
("C-c L" . counsel-locate)
("C-c o" . counsel-outline)
("C-c r" . counsel-rg)
("C-c R" . counsel-register)
("C-c T" . counsel-load-theme)
("C-S-s" . swiper)
([remap dired] . counsel-dired))
:init
(setq ivy-use-virtual-buffers t)
:config
(ivy-mode 1)
(counsel-mode 1))
(use-package ivy-rich
:after ivy
:config
(ivy-rich-mode 1))
(use-package helpful
:init
(setq counsel-describe-function-function #'helpful-callable)
(setq counsel-describe-variable-function #'helpful-variable))
;;; ### File explorer sidebar ###
;;; Install fonts with `M-x all-the-icons-install-fonts`.
(use-package dired-sidebar
:bind ("C-c s" . dired-sidebar-toggle-sidebar))
(use-package all-the-icons
:defer)
(use-package all-the-icons-dired
:hook (dired-mode . all-the-icons-dired-mode))
(use-package all-the-icons-ivy-rich
:after ivy-rich
:config (all-the-icons-ivy-rich-mode 1))
(use-package treemacs
:bind ("C-c S" . treemacs))
;;; ### Window selection enhancements ###
(use-package windmove
:bind (("H-w j" . windmove-down)
("H-w k" . windmove-up)
("H-w h" . windmove-left)
("H-w l" . windmove-right)))
(use-package windswap
:bind (("H-w J" . windswap-down)
("H-w K" . windswap-up)
("H-w H" . windswap-left)
("H-w L" . windswap-right)))
;;; ### In buffer movement enhancements ###
;;; Search
(use-package ctrlf
:config
(ctrlf-mode))
;;; Improved in buffer search
(use-package ace-jump-mode
:bind ("C-." . ace-jump-mode))
;;; Go to last change in the current buffer
(use-package goto-chg
:bind ("C-c G" . goto-last-change))
;;; ### Editing enhancements ###
;;; Context aware insertion of pairs of parenthesis
(use-package smartparens
:hook ((prog-mode . smartparens-mode)
(emacs-lisp-mode . smartparens-strict-mode))
:init
(setq sp-base-key-bindings 'sp)
:config
(define-key smartparens-mode-map [M-backspace] #'backward-kill-word)
(define-key smartparens-mode-map [M-S-backspace] #'sp-backward-unwrap-sexp)
(require 'smartparens-config))
;;; Edit with multiple cursors
(use-package multiple-cursors
:bind (("C-c n" . mc/mark-next-like-this)
("C-c p" . mc/mark-previous-like-this)))
;;; Fix trailing spaces but only in modified lines
(use-package ws-butler
:hook (prog-mode . ws-butler-mode))
;;; ### Switching buffers ###
;;; Bind keys from `H-r a` to `H-r z` to switch to buffers from a
;;; register from `a` to `z`.
(defalias 'pr #'point-to-register)
(defun my-switch-to-register ()
"Switch to buffer given by key binding last character."
(interactive)
(let* ((v (this-command-keys-vector))
(c (aref v (1- (length v))))
(r (get-register c)))
(if (and (markerp r) (marker-buffer r))
(switch-to-buffer (marker-buffer r))
(jump-to-register c))))
(setq my-switch-to-register-map (make-sparse-keymap))
(dolist (character (number-sequence ?a ?z))
(define-key my-switch-to-register-map
(char-to-string character) #'my-switch-to-register))
(global-set-key (kbd "H-r") my-switch-to-register-map)
;;; ### Switching tabs ###
(dolist (i (number-sequence 1 9))
(global-set-key (format "\C-c%d" i) `(lambda () (interactive) (tab-select ,i))))
(tab-bar-mode 1)
;;; ### Yasnippet and abbrev mode ###
(setq-default abbrev-mode 1)
(use-package yasnippet
:defer 2
:config
(yas-global-mode 1))
(use-package yasnippet-snippets
:defer)
(use-package ivy-yasnippet
:bind ("C-c y" . ivy-yasnippet))
;;; Programming modes
;;; -----------------
;;; ### company and lsp-mode ###
;;; For modes using [company](https://company-mode.github.io/) for tab
;;; completion add
(use-package company
:bind (:map prog-mode-map
("C-i" . company-indent-or-complete-common)
("C-M-i" . counsel-company))
:hook (emacs-lisp-mode . company-mode))
(use-package company-prescient
:after company
:config
(company-prescient-mode))
;;; For modes that also use Language Server Protocol from [lsp-mode]
;;; add
(use-package lsp-mode
:hook ((c-mode c++-mode d-mode elm-mode go-mode js-mode kotlin-mode python-mode
typescript-mode vala-mode web-mode)
. lsp)
:init
(setq lsp-keymap-prefix "H-l"
lsp-rust-analyzer-proc-macro-enable t)
:config
(lsp-enable-which-key-integration t))
(use-package lsp-ui
:init
(setq lsp-ui-doc-position 'at-point
lsp-ui-doc-show-with-mouse nil
lsp-ui-sideline-show-code-actions t)
:bind (("C-c A" . lsp-execute-code-action)
("C-c d" . lsp-ui-doc-show)
("C-c I" . lsp-ui-imenu)))
(use-package flycheck
:defer)
;;; [lsp-mode]: https://emacs-lsp.github.io/lsp-mode/
;;; Compilation
(global-set-key "\C-ck" #'compile)
;;; [company and lsp-mode]: #company-and-lsp-mode
;;; ### C and C++ ###
;;; Requires: [company and lsp-mode],
;;; [clangd](https://clangd.llvm.org/).
(use-package cc-mode
:straight nil
:bind (:map c-mode-map
("C-i" . company-indent-or-complete-common)
:map c++-mode-map
("C-i" . company-indent-or-complete-common))
:init
(setq-default c-basic-offset 8))
;;; ### D ###
;;; Requires: [company and lsp-mode], `dmd`, `dub`,
;;; [dcd](https://code.dlang.org/packages/dcd), and
;;; [dtools](https://code.dlang.org/packages/dtools) (for `rdmd`) to
;;; build [serve-d](https://code.dlang.org/packages/serve-d) (but
;;; first check for newer version) with
;;; $ dub fetch serve-d@0.7.4
;;; $ dub run serve-d --build=release
;;; $ ln -s ~/.dub/packages/serve-d-0.7.4/serve-d/serve-d ~/.local/bin/
(use-package d-mode
:bind (:map d-mode-map
("C-i" . company-indent-or-complete-common)))
;;; ### Dart ###
;;; Requires: [company and lsp-mode], `flutter` in `PATH`,
;;; `flutter doctor` should be OK, and `M-x lsp-dart-dap-setup`.
(use-package dart-mode)
(use-package lsp-dart
:hook (dart-mode . lsp)
:bind (:map lsp-mode
("C-M-x" . lsp-dart-dap-flutter-hot-reload)))
;;; ### Elm ###
;;; Requires: [company and lsp-mode].
(use-package elm-mode
:hook (elm-mode . elm-indent-mode))
;;; ### Emacs lisp ###
;;; Requires: [company and lsp-mode] (actually just `company`) and
;;; [smartparens](#editing-enhancements).
;;; ### Go ###
;;; Requires: [company and lsp-mode],
;;; [gopls](https://github.com/golang/tools/blob/master/gopls/README.md#installation).
(defun my-go-before-save ()
"Format buffer and organize imports in Go mode."
(when (eq major-mode 'go-mode)
(lsp-organize-imports)
(lsp-format-buffer)))
(use-package go-mode
:hook (before-save . my-go-before-save))
;;; ### JavaScript ###
;;; Requires: [company and lsp-mode] `ts-ls` (proposed by [lsp-mode]
;;; when missing).
(use-package js
:straight nil
:bind (:map js-mode-map
([remap js-find-symbol] . xref-find-definitions))
:init
(setq js-indent-level 4))
;;; ### Kotlin ###
;;; Requires:
;;; [kotlin-language-server](https://github.com/fwcd/kotlin-language-server).
(use-package kotlin-mode)
;;; ### Lisp ###
(use-package sly
:defer
:config
(setq inferior-lisp-program "sbcl"
sly-mrepl-pop-sylvester nil)
:custom-face
(sly-mrepl-output-face ((t (:foreground "sienna")))))
(use-package paren-face
:defer)
(use-package paredit
:defer)
(use-package highlight-parentheses
:defer)
(defun my-lisp-mode-hook-fn ()
(smartparens-mode 0)
(paredit-mode 1)
(paren-face-mode 1)
(highlight-parentheses-mode 1)
(company-mode 1))
(add-hook 'lisp-mode-hook 'my-lisp-mode-hook-fn)
(add-hook 'emacs-lisp-mode-hook 'my-lisp-mode-hook-fn)
;;; ### Meson build system ###
(use-package meson-mode
:defer
:init
(setq meson-indent-basic 4))
;;; ### Python ###
;;; Requires: [company and lsp-mode],
;;; [pylsp](https://pypi.org/project/python-lsp-server/).
;;; ### Rust ###
;;; Requires: [company and lsp-mode], `rust-src` from [Rustup]
;;; and [rust-analyzer].
;;; [Rustup]: https://www.rust-lang.org/learn/get-started
;;; [rust-analyzer]: https://rust-analyzer.github.io/manual.html#installation
(use-package rustic
:defer)
;;; ### TypeScript ###
;;; Requires: [company and lsp-mode], [web-mode settings] (for tsx),
;;; `ts-ls` (proposed by [lsp-mode] when missing),
;;; [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
(use-package typescript-mode
:defer)
;;; ### Vala ###
;;; Requires: [company and lsp-mode],
;;; [vala-language-server](https://github.com/Prince781/vala-language-server#installation).
(use-package vala-mode
:defer)
;;; ### Web mode ###
;;; Requires: [company and lsp-mode].
(use-package web-mode
:mode "\\.\\([jt]sx\\)\\'")
;;; [web-mode settings]: #web-mode
;;; Other modes
;;; -----------
(use-package ansible
:straight (:nonrecursive t))
(use-package devdocs
:bind ("C-c D" . devdocs-lookup))
(use-package diff-hl
:defer)
(use-package htmlize
:defer)
(use-package rainbow-mode
:hook css-mode)
(use-package restclient
:defer)
(use-package vterm
:defer
:init
(dolist (i (number-sequence 0 9))
(global-set-key (kbd (format "H-%d" i)) `(lambda () (interactive) (vterm ,i)))))
(use-package yaml-mode
:defer)
;;; ### Git ###
(use-package magit
:bind (("C-x g" . magit-status)
("C-x M-g" . magit-dispatch))
:init
(setq project-switch-commands nil)) ; avoid magit error on C-n/C-p
(use-package git-messenger
:bind ("C-x G" . git-messenger:popup-message)
:config
(setq git-messenger:show-detail t
git-messenger:use-magit-popup t))
(use-package git-timemachine
:bind ("C-c t" . git-timemachine))
;;; Appearance
;;; ----------
;;; ### Minimalistic look ###
(setq inhibit-startup-screen t)
(set-scroll-bar-mode 'right)
(menu-bar-mode 0)
(tool-bar-mode 0)
(scroll-bar-mode 0)
;;; ### Mode line ###
(use-package smart-mode-line
:config
(setq sml/no-confirm-load-theme t
sml/shorten-directory t
sml/shorten-modes t
sml/name-width 50
sml/mode-width 'full
sml/theme 'respectful)
(sml/setup))
;;; ### Switching themes ###
(use-package base16-theme
:defer)
(use-package faff-theme
:defer)
(setq my-dark-theme 'base16-espresso
my-light-theme 'base16-mexico-light)
(defun my-select-theme (theme)
(mapc #'disable-theme custom-enabled-themes)
(load-theme (cond
((eq theme 'dark) my-dark-theme)
((eq theme 'light) my-light-theme)
(t theme))
t)
(sml/setup))
(defun my-select-theme-if-none-selected (frame)
(if (and (eq 'x (window-system frame))
(null (seq-filter (lambda (theme)
(not (string-prefix-p "smart-mode-line-"
(symbol-name theme))))
custom-enabled-themes)))
(my-select-theme 'dark)))
(my-select-theme-if-none-selected nil)
(add-to-list 'after-make-frame-functions #'my-select-theme-if-none-selected)
(defun my-toggle-theme ()
"Toggle between dark and light themes."
(interactive)
(my-select-theme (if (custom-theme-enabled-p my-dark-theme)
my-light-theme
my-dark-theme)))
(global-set-key (kbd "C-S-<f6>") #'my-toggle-theme)