-
Notifications
You must be signed in to change notification settings - Fork 1
/
tmn.el
1414 lines (1142 loc) Β· 46.8 KB
/
tmn.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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; tmn.el --- tmn.el configuration -*- lexical-binding: t -*-
;;; Commentary:
;; The tmn.el configuration.
;;; Code:
;; -----------------------------------------------------------------------------
;; Some basic configs
;; -----------------------------------------------------------------------------
(setq-default
auto-save-default nil
create-lockfiles nil
indent-tabs-mode nil
tab-width 2
make-backup-files nil
tab-always-indent 'complete)
(column-number-mode t)
(global-hl-line-mode 1)
(global-auto-revert-mode 1)
(save-place-mode 1)
(setq use-dialog-box nil)
(defun t/my-prog-mode ()
(display-line-numbers-mode 1)
(set-fringe-mode 10))
(add-hook 'prog-mode-hook 't/my-prog-mode)
;; -----------------------------------------------------------------------------
;; Custom file
;; -----------------------------------------------------------------------------
(setq custom-file (locate-user-emacs-file "custom-vars.el"))
(load custom-file 'noerror 'nomessage)
;; -----------------------------------------------------------------------------
;; Modify some GUI features
;; -----------------------------------------------------------------------------
;; Headerline stuff
(setq header-line-format nil)
;; Supress some defaults
(setq inhibit-startup-screen t)
;; Disable scrollbars
(add-to-list 'default-frame-alist
'(vertical-scroll-bars . nil))
(toggle-scroll-bar -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(setq visible-bell t)
;; (set-frame-parameter (selected-frame) 'alpha '(98 . 98))
;; (add-to-list 'default-frame-alist '(alpha . (98 . 98)))
;; (set-frame-parameter (selected-frame) 'fullscreen 'maximized)
;; (add-to-list 'default-frame-alist '(fullscreen . maximized))
;; Follow symlinks
(setq vc-follow-symlinks t)
;; -----------------------------------------------------------------------------
;; Configure fonts
;; -----------------------------------------------------------------------------
;; Set reusable font name variables
(defvar t/fixed-width-font "SF Mono"
"The font to use for monospaced (fixed width) text.")
(defvar t/variable-width-font "Iosevka Aile"
"The font to use for variable-pitch (document) text.")
(cond
((find-font (font-spec :family "SF Mono"))
(set-frame-font "SF Mono:pixelsize=13"))
((find-font (font-spec :family "Fira Code Retina"))
(set-frame-font "Fira Code Retina:pixelsize=12"))
((find-font (font-spec :family "Menlo"))
(set-frame-font "Menlo:pixelsize=12"))
((find-font (font-spec :family "Monaco"))
(set-frame-font "Monaco:pixelsize=12")))
;; -----------------------------------------------------------------------------
;; Some custom stuffs
;; -----------------------------------------------------------------------------
(defun t/move-line-up ()
"Move up the current line."
(interactive)
(transpose-lines 1)
(forward-line -2)
(indent-according-to-mode))
(defun t/move-line-down ()
"Move down the current line."
(interactive)
(forward-line 1)
(transpose-lines 1)
(forward-line -1)
(indent-according-to-mode))
(global-set-key (kbd "M-S-<up>") 't/move-line-up)
(global-set-key (kbd "M-S-<down>") 't/move-line-down)
;; -----------------------------------------------------------------------------
;; Confirm exit emacs
;; -----------------------------------------------------------------------------
(add-hook 'kill-emacs-query-functions
(lambda () (y-or-n-p "Dumme ape! Quitting already??? "))
'append)
;; -----------------------------------------------------------------------------
;; Native Parentheses Matching
;; -----------------------------------------------------------------------------
(setq show-paren-delay 0
show-paren-mode 1)
(defun match-paren (arg)
"Go to the matching paren using ARG if on a paren; otherwise insert ARG."
(interactive "p")
(cond ((looking-at "\\s(") (forward-list 1) (backward-char 1))
((looking-at "\\s)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))
(global-set-key "%" 'match-paren)
;; -----------------------------------------------------------------------------
;; Bootstrap configs
;; -----------------------------------------------------------------------------
(use-package diminish)
(use-package rg
:commands rg)
;; Trim spaces from end of line on save
(use-package ws-butler
:hook ((text-mode . ws-butler-mode)
(prog-mode . ws-butler-mode)))
;; -----------------------------------------------------------------------------
;; Configure themes
;; -----------------------------------------------------------------------------
(use-package modus-themes
:config
(setq modus-themes-common-palette-overrides '(
(border-mode-line-active unspecified)
(border-mode-line-inactive unspecified)
;; (bg-paren-match bg-magenta-intense)
;; (underline-paren-match fg-main)
))
(setq modus-themes-bold-constructs t
modus-themes-italic-constructs t)
(setq modus-themes-prompts '(extrabold italic))
(setq modus-themes-completions
'((matches . (extrabold underline))
(selection . (semibold italic))))
(setq modus-themes-org-blocks '(tinted-background))
;; (setq modus-themes-italic-constructs t
;; modus-themes-bold-constructs nil)
; (load-theme 'modus-operandi t)
; (disable-theme 'modus-operandi)
; (load-theme 'modus-vivendi-tinted t)
; (disable-theme 'modus-vivendi-tinted)
; (load-theme 'modus-vivendi t)
; (disable-theme 'modus-vivendi)
(define-key global-map (kbd "<f5>") #'modus-themes-toggle)
(define-key global-map (kbd "<f6>") #'blink-cursor-mode))
(use-package doom-themes
:config
(setq doom-themes-enable-bold t
doom-themes-enable-italic t
doom-themes-padded-modeline nil)
(load-theme 'doom-vibrant t)
; (disable-theme 'doom-vibrant)
; (load-theme 'doom-opera-light t)
; (disable-theme 'doom-opera-light)
; (load-theme 'doom-one-light t)
; (disable-theme 'doom-one-light)
; (load-theme 'modus-operandi t)
; (disable-theme 'modus-operandi)
; (load-theme 'doom-palenight t)
; (disable-theme 'doom-palenight)
; (load-theme 'doom-palenight t)
; (disable-theme 'doom-palenight)
(doom-themes-visual-bell-config)
(doom-themes-org-config))
(use-package doom-modeline
:init (doom-modeline-mode 1)
:config
(setq doom-modeline-height 28
doom-modeline-bar-width 4
doom-modeline-hud nil
doom-modeline-lsp t
doom-modeline-icon t
doom-modeline-major-mode-icon t
doom-modeline-major-mode-color-icon t
doom-modeline-buffer-state-icon t
doom-modeline-buffer-file-name-style 'file-name
doom-modeline-minor-modes nil
doom-modeline-buffer-encoding nil
doom-modeline-indent-info nil
doom-modeline-env-version t))
;; Display Emojis in emacs
(use-package emojify
:commands (emojify-mode))
(use-package expand-region
:bind (("M-[" . er/expand-region)
("M-]" . er/contract-region)
("C-=" . er/mark-outside-pairs)))
(use-package multiple-cursors
:bind (("C-c C-. ." . mc/mark-all-dwim)
("C-c C-. C-." . mc/mark-all-like-this-dwim)
("C-c C-. n" . mc/mark-next-symbol-like-this)
("C-c C-. P" . mc/mark-previous-symbol-like-this)
("C-c C-. A" . mc/mark-all-symbols-like-this)
("C-c C-. f" . mc/mark-all-like-this-in-defun)
("C-c C-. l" . mc/edit-lines)
("C-c C-. e" . mc/edit-ends-of-lines)
("C-c C-<" . mc/mark-all-like-this)
("C->" . mc/mark-next-like-this)
("C-<" . mc/mark-previous-like-this)))
(use-package which-key
:demand t
:config
(progn
(setq which-key-add-column-padding 1
which-key-max-display-columns nil
which-key-min-display-lines 1
which-key-separator " "
which-key-idle-delay 0.5)
(which-key-mode)))
(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))
(use-package winum
:init
(winum-mode)
:bind (("C-x w `" . winum-select-window-by-number)
("M-0" . treemacs-select-window)
("M-1" . winum-select-window-1)
("M-2" . winum-select-window-2)
("M-3" . winum-select-window-3)
("M-4" . winum-select-window-4)
("M-5" . winum-select-window-5)
("M-6" . winum-select-window-6)
("M-7" . winum-select-window-7)
("M-8" . winum-select-window-8)
("M-9" . winum-select-window-9)))
;; -----------------------------------------------------------------------------
;; Projectile
;; -----------------------------------------------------------------------------
(use-package projectile
:commands (projectile-mode
projectile-project-root
projectile-find-file)
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
("s-p" . projectile-command-map)
("C-c p" . projectile-command-map))
:config
(setq projectile-project-search-path '("~/src/"))
(setq projectile-require-project-root nil
projectile-mode-line '(:eval (format "[%s]" (projectile-project-name)))
projectile-known-projects-file (locate-user-emacs-file ".cache/projectile.projects")
projectile-enable-caching t
projectile-cache-file (locate-user-emacs-file ".cache/projectile.cache")
projectile-indexing-method 'native)
(setq projectile-enable-cmake-presets t)
(setq projectile-globally-ignored-directories
(append '("*.gradle" "*.log" ".cache" ".git" ".idea" "node_modules" ".next" "elpa-backups" "build" "dist" "target") projectile-globally-ignored-directories)
projectile-globally-ignored-files
(append '("*.bundle.js" "*.build.js" "*.bundle.css" ".DS_Store" "*.min.js" "*.min.css" "package-lock.json" "projectile.cache") projectile-globally-ignored-files)
projectile-globally-ignored-buffers
(append '("*scratch*" "*lsp-log*"))
projectile-globally-ignored-modes
(append '("help-mode" "Buffer-menu-mode" "completion-list-mode" "erc-mode"))
grep-find-ignored-files
(append '("*.bundle.js" "*.build.js" "*.bundle.css" ".DS_Store" "*.min.js" "*.min.css" "package-lock.json" "node_modules/*" ".cache/*" "./gradle/*") grep-find-ignored-files)))
(use-package corfu
:straight (corfu :type git :host github :repo "minad/corfu")
:custom
(corfu-cycle t)
(corfu-auto t)
:config
(global-corfu-mode))
;; -----------------------------------------------------------------------------
;; Tree-sitter
;; -----------------------------------------------------------------------------
(setq treesit-language-source-alist
'((bash "https://github.com/tree-sitter/tree-sitter-bash")
(c "https://github.com/tree-sitter/tree-sitter-c")
(cpp "https://github.com/tree-sitter/tree-sitter-cpp")
(cmake "https://github.com/uyha/tree-sitter-cmake")
(css "https://github.com/tree-sitter/tree-sitter-css")
(elisp "https://github.com/Wilfred/tree-sitter-elisp")
(go "https://github.com/tree-sitter/tree-sitter-go")
(html "https://github.com/tree-sitter/tree-sitter-html")
(javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src")
(json "https://github.com/tree-sitter/tree-sitter-json")
(make "https://github.com/alemuller/tree-sitter-make")
(markdown "https://github.com/ikatyang/tree-sitter-markdown")
(python "https://github.com/tree-sitter/tree-sitter-python")
(toml "https://github.com/tree-sitter/tree-sitter-toml")
(tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")
(typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")
(yaml "https://github.com/ikatyang/tree-sitter-yaml")))
;; -----------------------------------------------------------------------------
;; Eglot stuff
;; -----------------------------------------------------------------------------
(use-package eglot
:straight (:type built-in)
:commands (eglot-ensure)
:config
;; Patch pretty print of jsonrpc log making whole thing goes slooooooow
(fset #'jsonrpc--log-event #'ignore))
;; -----------------------------------------------------------------------------
;; C / C++
;; -----------------------------------------------------------------------------
(use-package c++-mode
:straight nil
:init
(setq c-default-style "linux"
c-basic-offset 4)
:hook
((c++-mode c++-ts-mode) . lsp-deferred)
:config
(setq lsp-clients-clang-args '("--compile-commands-dir=./_build/host-clang")))
(use-package c-mode
:straight nil
:init
(setq c-default-style "linux"
c-basic-offset 4)
:hook
((c-mode c-ts-mode) . lsp-deferred)
:config
(setq lsp-clients-clang-args '("--compile-commands-dir=./_build/host-clang")))
;; -----------------------------------------------------------------------------
;; Rust
;; -----------------------------------------------------------------------------
(use-package rust-mode
:init
;; Environment Variables
(setenv "RUSTUP_TOOLCHAIN" "stable")
:custom
(add-to-list 'eglot-server-programs '((rust-mode) . ("rust-analyzer" :initializationOptions
( :procMacro (:enable t)
:cargo ( :buildScripts (:enable t)
:features "all" )))))
:config
(setq rust-format-on-save t)
(use-package cargo :hook ((rust-mode . cargo-minor-mode)))
(use-package rust-playground)
(use-package toml-mode)
(defun t/rust-mode-prettifying ()
"Dired load func."
(interactive)
(prettify-symbols-mode))
:hook
((rust-mode . t/rust-mode-prettifying)
(rust-mode . eglot-ensure)))
;; -----------------------------------------------------------------------------
;; JavaScript / TypeScript
;; -----------------------------------------------------------------------------
(use-package t/typescript-mode
:straight nil
:mode (("\\.ts\\'" . typescript-ts-mode)
("\\.tsx\\'" . tsx-ts-mode))
:custom
(add-to-list 'eglot-server-programs '((typescript-ts-mode tsx-ts-mode) . ("typescript-language-server" "--stdio")))
:hook
((typescript-ts-mode tsx-ts-mode) . eglot-ensure))
(use-package t/javascript-mode
:straight nil
:mode (("\\.js\\'" . js-ts-mode)
("\\.jsx\\'" . js-ts-mode))
:custom
(add-to-list 'eglot-server-programs '((js-mode js2-mode js-ts-mode) . (eglot-deno "deno" "lsp")))
(defclass eglot-deno (eglot-lsp-server) ()
:documentation "A custom class for deno lsp.")
(cl-defmethod eglot-initialization-options ((server eglot-deno))
"Passes through required deno initialization options"
(list :enable t
:lint t))
:custom
(setq js-indent-level 2)
:hook ((js-mode js2-mode js-ts-mode) . eglot-ensure))
(use-package nodejs-repl
:config
(defun t/js-ts-mode-hook ()
(interactive)
(define-key js-mode-map (kbd "C-x C-e") 'nodejs-repl-send-last-expression)
(define-key js-mode-map (kbd "C-c C-j") 'nodejs-repl-send-line)
(define-key js-mode-map (kbd "C-c C-r") 'nodejs-repl-send-region)
(define-key js-mode-map (kbd "C-c C-c") 'nodejs-repl-send-buffer)
(define-key js-mode-map (kbd "C-c C-l") 'nodejs-repl-load-file)
(define-key js-mode-map (kbd "C-c C-z") 'nodejs-repl-switch-to-repl))
(add-hook 'js-ts-mode-hook 't/js-ts-mode-hook))
(use-package prettier-js
:commands prettier-js-mode
:hook ((json-mode
js-ts-mode
tsx-ts-mode
typescript-ts-mode) . prettier-js-mode))
;; -----------------------------------------------------------------------------
;; Swift
;; -----------------------------------------------------------------------------
(use-package swift-mode
:mode "\\.swift$"
:config
(require 'eglot)
(add-to-list 'eglot-server-programs '(swift-mode . ("xcrun" "sourcekit-lsp")))
:hook
(swift-mode . eglot-ensure))
;; -----------------------------------------------------------------------------
;; Bash
;; -----------------------------------------------------------------------------
(use-package bash-mode
:straight nil
:mode ("\\.sh$" . bash-ts-mode)
:custom
(add-to-list 'eglot-server-programs '((bash-mode bash-ts-mode) . ("bash-language-server")))
:hook
((bash-mode bash-ts-mode) . eglot-ensure))
;; -----------------------------------------------------------------------------
;; Java / Kotlin / JVM
;; -----------------------------------------------------------------------------
;; Environment Variables
(if (file-directory-p "/opt/homebrew/opt/openjdk@11")
(setenv "JAVA_HOME" "/opt/homebrew/opt/openjdk@11"))
(use-package lsp-java
:after (lsp-mode)
:config
(setq lsp-java-vmargs
`("-noverify"
"-Xmx2G"
"-XX:+UseG1GC"
"-XX:+UseStringDeduplication"
,(concat "-javaagent:" (expand-file-name "~/.emacs.d/lib/lombok.jar"))
,(concat "-Xbootclasspath/a:" (expand-file-name "~/.emacs.d/lib/lombok.jar"))))
(setq lsp-java-server-install-dir (expand-file-name "~/.emacs.d/lsp/eclipse.jdt.ls/server/"))
(setq lsp-java-workspace-dir (expand-file-name "~/.emacs.d/lsp/eclipse.jdt.ls/workspace"))
(setq lsp-java-workspace-cache-dir (expand-file-name "~/.emacs.d/lsp/eclipse.jdt.ls/workspace-cache"))
:custom
(progn
(require 'lsp-java-boot)
(add-hook 'lsp-mode-hook 'lsp-lens-mode)
(add-hook 'java-mode-hook 'lsp-java-boot-lens-mode)))
(use-package dap-java
:straight (dap-java :type git :host github :repo "emacs-lsp/lsp-java"))
;; Package `kotlin`
(use-package kotlin-mode
:mode "\\.kt$")
;;------------------------------------------------------------------------------
;; LSP mode
;;------------------------------------------------------------------------------
(use-package lsp-mode
:commands lsp
:init
(setq lsp-server-install-dir (concat user-emacs-directory "lsp/"))
(setq lsp-keymap-prefix "C-c C-l")
(defun t/lsp-mode-setup-completion ()
(setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
'(orderless))) ;; Configure orderless
:bind ("M-RET" . lsp-execute-code-action)
:custom
(lsp-print-io nil)
(lsp-auto-configure t)
(lsp-enable-snippet t)
;; (lsp-completion-provider :capf)
(lsp-completion-provider :none)
(lsp-headerline-breadcrumb-enable nil)
(lsp-idle-delay 0.2)
(lsp-eldoc-render-all t)
(lsp-idle-delay 0.6)
;; This controls the overlays that display type and other hints inline. Enable
;; / disable as you prefer. Well require a `lsp-workspace-restart' to have an
;; effect on open projects.
:config
(dolist (directories '("[/\\\\].data\\'"
"[/\\\\].github\\'"
"[/\\\\]gradle\\'"
"[/\\\\].gradle\\'"
"[/\\\\].storybook\\'"
"[/\\\\].log\\'"
"[/\\\\]eclipse.jdt.ls\\'"
"[/\\\\]build\\'"
"[/\\\\]jetty-temp\\'"
"[/\\\\]coverage\\'"
"[/\\\\].DS_Store"))
(push directories lsp-file-watch-ignored))
:hook ((lsp-completion-mode . t/lsp-mode-setup-completion)
((java-mode
python-mode
python-ts-mode) . lsp-deferred)
(lsp-mode . lsp-enable-which-key-integration)))
;;; LSP Booster
(defun lsp-booster--advice-json-parse (old-fn &rest args)
"Try to parse bytecode instead of json."
(or
(when (equal (following-char) ?#)
(let ((bytecode (read (current-buffer))))
(when (byte-code-function-p bytecode)
(funcall bytecode))))
(apply old-fn args)))
(advice-add (if (progn (require 'json)
(fboundp 'json-parse-buffer))
'json-parse-buffer
'json-read)
:around
#'lsp-booster--advice-json-parse)
(defun lsp-booster--advice-final-command (old-fn cmd &optional test?)
"Prepend emacs-lsp-booster command to lsp CMD."
(let ((orig-result (funcall old-fn cmd test?)))
(if (and (not test?) ;; for check lsp-server-present?
(not (file-remote-p default-directory)) ;; see lsp-resolve-final-command, it would add extra shell wrapper
lsp-use-plists
(not (functionp 'json-rpc-connection)) ;; native json-rpc
(executable-find "emacs-lsp-booster"))
(progn
(message "Using emacs-lsp-booster for %s!" orig-result)
(cons "emacs-lsp-booster" orig-result))
orig-result)))
(advice-add 'lsp-resolve-final-command :around #'lsp-booster--advice-final-command)
(use-package lsp-ui
:hook (lsp-mode . lsp-ui-mode)
:commands (lsp-ui-mode
lsp-ui-doc-show
lsp-ui-doc-hide)
:init
(progn
(defvar t/lsp-ui-doc-max-height 10)
(defvar t/lsp-ui-doc-max-width 60)
(setq
lsp-ui-sideline-enable t
lsp-ui-sideline-show-code-actions t
lsp-ui-sideline-show-hover nil
lsp-ui-sideline-show-symbol t
lsp-ui-sideline-show-diagnostics nil
lsp-ui-doc-enable nil
lsp-ui-peek-fontify t)
(setq
lsp-ui-doc-position 'at-point
lsp-ui-doc-max-height t/lsp-ui-doc-max-height
lsp-ui-doc-max-width t/lsp-ui-doc-max-width))
:config
(progn
(define-key lsp-command-map (kbd "d s") 'lsp-ui-doc-show)
(define-key lsp-command-map (kbd "d g") 'lsp-ui-doc-glance)
(define-key lsp-command-map (kbd "d h") 'lsp-ui-doc-hide)
(define-key lsp-ui-mode-map [remap xref-find-definitions] #'lsp-ui-peek-find-definitions)
(define-key lsp-ui-mode-map [remap xref-find-references] #'lsp-ui-peek-find-references)))
(use-package hydra)
(use-package treemacs
:bind (("C-c o p" . treemacs))
:config
(treemacs-git-mode 'deferred))
(use-package lsp-treemacs
:after lsp-mode
:commands lsp-treemacs-errors-list)
(use-package dap-mode
:after lsp-mode
:config
(setq dap-auto-configure-features '(sessions locals controls tooltip))
(require 'dap-hydra)
(require 'dap-lldb)
(require 'dap-cpptools)
(require 'dap-python)
(setq dap-python-debugger 'debugpy))
(use-package flycheck
:demand t
:commands flycheck-mode
:init
;; (global-flycheck-mode)
(add-to-list 'display-buffer-alist
`(,(rx bos "*Flycheck errors*" eos)
(display-buffer-reuse-window
display-buffer-in-side-window)
(side . bottom)
(reusable-frames . visible)
(window-height . 0.15)))
:config
;; (add-hook 'c++-mode-hook (lambda () (setq flycheck-gcc-language-standard "c++14"
;; flycheck-clang-language-standard "c++14")))
)
;; -----------------------------------------------------------------------------
;; Python
;; -----------------------------------------------------------------------------
(use-package python-mode
:hook ((python-mode python-ts-mode) . lsp-deferred)
:custom
(python-shell-interpreter "python3")
(dap-python-debugger 'debugpy)
:config
(require 'dap-python))
(use-package pyvenv
:config
(pyvenv-mode 1))
(use-package transient)
(use-package lsp-pyright
:hook ((python-mode python-ts-mode) . (lambda ()
(require 'lsp-pyright)
;; (require 'ruff-lsp)
(lsp-deferred))))
(use-package poetry)
;; -----------------------------------------------------------------------------
;; Dired
;; -----------------------------------------------------------------------------
(use-package dired
:straight nil
:ensure nil
:defer 1
:commands (dired dired-jump)
:config
(setq dired-listing-switches "-agho --group-directories-first"
dired-omit-files "^\\.[^.].*"
dired-omit-verbose nil
dired-hide-details-hide-symlink-targets nil
delete-by-moving-to-trash t)
(defun t/dired-load ()
"Dired load func."
(interactive)
(dired-collapse))
(defun t/dired-mode ()
"Dired mode func."
(interactive)
(dired-omit-mode 1)
(dired-hide-details-mode 1)
(nerd-icons-dired-mode 1)
(hl-line-mode 1))
(autoload 'dired-omit-mode "dired-x")
(add-hook 'dired-load-hook 't/dired-load)
(add-hook 'dired-mode-hook 't/dired-mode)
(use-package dired-rainbow
:defer 2
:config
(dired-rainbow-define-chmod directory "#6cb2eb" "d.*")
(dired-rainbow-define html "#eb5286" ("css" "less" "sass" "scss" "htm" "html" "jhtm" "mht" "eml" "mustache" "xhtml"))
(dired-rainbow-define xml "#f2d024" ("xml" "xsd" "xsl" "xslt" "wsdl" "bib" "json" "msg" "pgn" "rss" "yaml" "yml" "rdata"))
(dired-rainbow-define document "#9561e2" ("docm" "doc" "docx" "odb" "odt" "pdb" "pdf" "ps" "rtf" "djvu" "epub" "odp" "ppt" "pptx"))
(dired-rainbow-define markdown "#ffed4a" ("org" "etx" "info" "markdown" "md" "mkd" "nfo" "pod" "rst" "tex" "textfile" "txt"))
(dired-rainbow-define database "#6574cd" ("xlsx" "xls" "csv" "accdb" "db" "mdb" "sqlite" "nc"))
(dired-rainbow-define media "#de751f" ("mp3" "mp4" "mkv" "MP3" "MP4" "avi" "mpeg" "mpg" "flv" "ogg" "mov" "mid" "midi" "wav" "aiff" "flac"))
(dired-rainbow-define image "#f66d9b" ("tiff" "tif" "cdr" "gif" "ico" "jpeg" "jpg" "png" "psd" "eps" "svg"))
(dired-rainbow-define log "#c17d11" ("log"))
(dired-rainbow-define shell "#f6993f" ("awk" "bash" "bat" "sed" "sh" "zsh" "vim"))
(dired-rainbow-define interpreted "#38c172" ("py" "ipynb" "rb" "pl" "t" "msql" "mysql" "pgsql" "sql" "r" "clj" "cljs" "scala" "js"))
(dired-rainbow-define compiled "#4dc0b5" ("asm" "cl" "lisp" "el" "c" "h" "c++" "h++" "hpp" "hxx" "m" "cc" "cs" "cp" "cpp" "go" "f" "for" "ftn" "f90" "f95" "f03" "f08" "s" "rs" "hi" "hs" "pyc" ".java"))
(dired-rainbow-define executable "#8cc4ff" ("exe" "msi"))
(dired-rainbow-define compressed "#51d88a" ("7z" "zip" "bz2" "tgz" "txz" "gz" "xz" "z" "Z" "jar" "war" "ear" "rar" "sar" "xpi" "apk" "xz" "tar"))
(dired-rainbow-define packaged "#faad63" ("deb" "rpm" "apk" "jad" "jar" "cab" "pak" "pk3" "vdf" "vpk" "bsp"))
(dired-rainbow-define encrypted "#ffed4a" ("gpg" "pgp" "asc" "bfe" "enc" "signature" "sig" "p12" "pem"))
(dired-rainbow-define fonts "#6cb2eb" ("afm" "fon" "fnt" "pfb" "pfm" "ttf" "otf"))
(dired-rainbow-define partition "#e3342f" ("dmg" "iso" "bin" "nrg" "qcow" "toast" "vcd" "vmdk" "bak"))
(dired-rainbow-define vc "#0074d9" ("git" "gitignore" "gitattributes" "gitmodules"))
(dired-rainbow-define-chmod executable-unix "#38c172" "-.*x.*"))
(use-package dired-single
:straight (dired-single :type git :host github :repo "emacsmirror/dired-single")
:defer t)
(use-package dired-ranger
:defer t)
(use-package dired-collapse
:defer t)
(use-package dired-subtree
:defer t)
(use-package dired-sidebar
:defer t
:commands (dired-sidebar-toggle-sidebar)
:bind ("C-c o [" . dired-sidebar-toggle-sidebar)
:init
(setq dired-sidebar-window-fixed nil)
:config
(defun t/dired-sidebar-mode ()
(interactive)
(visual-line-mode 0)
(toggle-truncate-lines 1)
(unless (file-remote-p default-directory)
(auto-revert-mode)))
(add-hook 'dired-sidebar-mode-hook 't/dired-sidebar-mode)
(push 'toggle-window-split dired-sidebar-toggle-hidden-commands)
(push 'rotate-windows dired-sidebar-toggle-hidden-commands)
(setq dired-sidebar-theme 'nerd))
(add-hook 'dired-mode-hook 'dired-subtree-toggle)
:bind (:map dired-mode-map
("<tab>" . dired-subtree-toggle)
("h" . dired-single-up-directory)
("H" . dired-omit-mode)
("l" . dired-single-buffer)
("y" . dired-ranger-copy)
("X" . dired-ranger-move)
("p" . dired-ranger-paste)))
(use-package marginalia
:bind (:map minibuffer-local-map
("M-A" . marginalia-cycle))
:custom
(marginalia-max-relative-age 0)
(marginalia-align 'right)
:init
(marginalia-mode))
(use-package vertico
:demand t ; Otherwise won't get loaded immediately
:straight (vertico :files (:defaults "extensions/*") ; Special recipe to load extensions conveniently
:includes (vertico-indexed
vertico-flat
vertico-grid
vertico-mouse
vertico-quick
vertico-buffer
vertico-repeat
vertico-reverse
vertico-directory
vertico-multiform
vertico-unobtrusive
))
:bind (:map vertico-map
("<tab>" . vertico-insert)
("<escape>" . minibuffer-keyboard-quit)
("?" . minibuffer-completion-help)
("C-M-n" . vertico-next-group)
("C-M-p" . vertico-previous-group)
("<backspace>" . vertico-directory-delete-char)
("C-w" . vertico-directory-delete-word)
("C-<backspace>" . vertico-directory-delete-word)
; ("RET" . vertico-dirrectory-enter)
("C-i" . vertico-quick-insert)
("C-o" . vertico-quick-exit)
("M-o" . kb/vertico-quick-embark)
("M-G" . vertico-multiform-grid)
("M-F" . vertico-multiform-flat)
("M-R" . vertico-multiform-reverse)
("M-U" . vertico-multiform-unobtrusive)
("C-l" . kb/vertico-multiform-flat-toggle))
:hook ((rfn-eshadow-update-overlay . vertico-directory-tidy) ; Clean up file path when typing
(minibuffer-setup . vertico-repeat-save) ; Make sure vertico state is saved
)
:custom
(vertico-count 13)
(vertico-resize t)
(vertico-cycle nil)
;; Extensions
(vertico-grid-separator " ")
(vertico-grid-lookahead 50)
(vertico-buffer-display-action '(display-buffer-reuse-window))
(vertico-multiform-categories
'((file reverse)
(consult-grep buffer)
(consult-location)
(imenu buffer)
(library reverse indexed)
(org-roam-node reverse indexed)
(t reverse)
))
(vertico-multiform-commands
'(("flyspell-correct-*" grid reverse)
(org-refile grid reverse indexed)
(consult-yank-pop indexed)
(consult-flycheck)
(consult-lsp-diagnostics)
))
:init
(defun kb/vertico-multiform-flat-toggle ()
"Toggle between flat and reverse."
(interactive)
(vertico-multiform--display-toggle 'vertico-flat-mode)
(if vertico-flat-mode
(vertico-multiform--temporary-mode 'vertico-reverse-mode -1)
(vertico-multiform--temporary-mode 'vertico-reverse-mode 1)))
(defun kb/vertico-quick-embark (&optional arg)
"Embark on candidate using quick keys."
(interactive)
(when (vertico-quick-jump)
(embark-act arg)))
;; Workaround for problem with `tramp' hostname completions. This overrides
;; the completion style specifically for remote files! See
;; https://github.com/minad/vertico#tramp-hostname-completion
(defun kb/basic-remote-try-completion (string table pred point)
(and (vertico--remote-p string)
(completion-basic-try-completion string table pred point)))
(defun kb/basic-remote-all-completions (string table pred point)
(and (vertico--remote-p string)
(completion-basic-all-completions string table pred point)))
(add-to-list 'completion-styles-alist
'(basic-remote ; Name of `completion-style'
kb/basic-remote-try-completion kb/basic-remote-all-completions nil))
:config
(vertico-mode)
;; Extensions
(vertico-multiform-mode)
;; Prefix the current candidate with βΒ» β. From
;; https://github.com/minad/vertico/wiki#prefix-current-candidate-with-arrow
(advice-add #'vertico--format-candidate :around
(lambda (orig cand prefix suffix index _start)
(setq cand (funcall orig cand prefix suffix index _start))
(concat
(if (= vertico--index index)
(propertize "Β» " 'face 'vertico-current)
" ")
cand))))
(use-package recentf
:bind ("C-x C-r" . recentf-open-files)
:hook (after-init . recentf-mode)
:config
(setq recentf-max-menu-items 25
recentf-max-saved-items 500))
(defun t/get-project-root ()
"Get project root."
(when (fboundp 'projectile-project-root)
(projectile-project-root)))
(use-package consult
:bind (
("C-x C-b" . consult-buffer)
("C-s" . consult-line)
("C-M-l" . consult-imenu)
("C-c s" . consult-ripgrep)
:map minibuffer-local-map
("C-h" . consult-history))
:custom
(consult-project-root-function #'t/get-project-root)
(completion-in-region-function #'consult-completion-in-region)
:config
(consult-preview-at-point-mode))
(use-package consult-projectile
:after consult
:bind (("C-c p f" . consult-projectile-find-file)))
;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:init
(setq savehist-file "~/.emacs.d/savehist")
:config
(setq savehist-additional-variables '(search-ring regexp-search-ring)
history-length 300
savehist-autosave-interval 60
history-length t
history-delete-duplicates t
savehist-save-minibuffer-history 1)
(savehist-mode 1))
(use-package orderless
:custom
(completion-styles '(orderless))
(completion-category-defaults nil) ; I want to be in control!
(completion-category-overrides
'((file (styles basic-remote ; For `tramp' hostname completion with `vertico'
orderless
))