-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.el
1834 lines (1526 loc) · 58.3 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
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
(require 'cl)
(add-to-list 'load-path (expand-file-name "~/.emacs.d/elpa"))
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa-stable" . "http://stable.melpa.org/packages/")
("melpa" . "http://melpa.org/packages/")
("non-gnu-elpa" . "https://elpa.nongnu.org/nongnu/")
("org" . "https://orgmode.org/elpa/")))
(package-initialize)
;; straight.el bootstrapping
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
;; For whatever godawful reason something in here is loading Org prior to the
;; (use-package org) block, which causes esoteric load failures, e.g. functions
;; missing that should be there.
;;
;; Remove this whenever you find the root cause.
(straight-use-package 'org)
;; The =:if= clause lets us suppress configuration/loading of a given package if
;; a provided condition doesn't hold. The following will log such cases
;; non-fatally.
(defun jjin/use-package-if-prehook (name _keyword pred rest state)
(unless pred (error "predicated failed; skipping package")))
(advice-add 'use-package-handler/:if :before 'jjin/use-package-if-prehook)
(use-package diminish :straight t)
(use-package system-packages
:straight t
:custom
(system-packages-use-sudo nil)
:init
(when (eq system-type 'darwin)
(setq system-packages-package-manager 'brew)))
(use-package dash :straight t)
(setq default-directory "~")
(setq command-line-default-directory "~")
(defvar jjin-ext-file-handlers
`((,(intern "darwin") . (:image
("open")
:video
("open" "vlc")))
(,(intern "gnu/linux") . (:image
("feh")
:video
("vlc"))))
"An alist mapping `system-type' values to priority lists of
file handlers, e.g. image viewers or video players.")
(defun jjin-kill-current-buffer ()
(interactive)
(kill-buffer (current-buffer)))
(defun jjin-window-toggle-split-direction ()
"Switch window split from horizontally to vertically, or vice versa.
i.e. change right window to bottom, or change bottom window to right."
(interactive)
(require 'windmove)
(let ((done))
(dolist (dirs '((right . down) (down . right)))
(unless done
(let* ((win (selected-window))
(nextdir (car dirs))
(neighbour-dir (cdr dirs))
(next-win (windmove-find-other-window nextdir win))
(neighbour1 (windmove-find-other-window neighbour-dir win))
(neighbour2 (if next-win (with-selected-window next-win
(windmove-find-other-window
neighbour-dir next-win)))))
(setq done (and (eq neighbour1 neighbour2)
(not (eq (minibuffer-window) next-win))))
(if done
(let* ((other-buf (window-buffer next-win)))
(delete-window next-win)
(if (eq nextdir 'right)
(split-window-vertically)
(split-window-horizontally))
(set-window-buffer (windmove-find-other-window neighbour-dir)
other-buf))))))))
(defun jjin-set-opacity (value)
"Sets the opacity of the frame window. 0=transparent/100=opaque"
(interactive "nOpacity Value (0 - 100 opaque): ")
(set-frame-parameter (selected-frame) 'alpha value))
;; credit: https://github.com/abo-abo/hydra/blob/master/hydra-examples.el
(defun jjin-move-splitter-left (arg)
"Move window splitter left."
(interactive "p")
(if (let ((windmove-wrap-around))
(windmove-find-other-window 'right))
(shrink-window-horizontally arg)
(enlarge-window-horizontally arg)))
;; credit: https://github.com/abo-abo/hydra/blob/master/hydra-examples.el
(defun jjin-move-splitter-right (arg)
"Move window splitter right."
(interactive "p")
(if (let ((windmove-wrap-around))
(windmove-find-other-window 'right))
(enlarge-window-horizontally arg)
(shrink-window-horizontally arg)))
;; credit: https://github.com/abo-abo/hydra/blob/master/hydra-examples.el
(defun jjin-move-splitter-up (arg)
"Move window splitter up."
(interactive "p")
(if (let ((windmove-wrap-around))
(windmove-find-other-window 'up))
(enlarge-window arg)
(shrink-window arg)))
;; credit: https://github.com/abo-abo/hydra/blob/master/hydra-examples.el
(defun jjin-move-splitter-down (arg)
"Move window splitter down."
(interactive "p")
(if (let ((windmove-wrap-around))
(windmove-find-other-window 'up))
(shrink-window arg)
(enlarge-window arg)))
(defun jjin-get-current-displays ()
"Get alist of attributes of displays w/ Emacs buffers."
(interactive)
(remove-if
(lambda (disp)
(eq nil (cdr (assoc 'frames disp))))
(display-monitor-attributes-list)))
(defun jjin-fontify-frame (&optional _)
"Set font and font size dynamically for the given frame."
(let* ((attrs (frame-monitor-attributes))
(width (fourth (first attrs)))
(size 12))
(when (= width 3840) ; external monitor 4k
(setq size 16))
;; FIXME: Integrate w/ jjin/font-priority-list
;; FIXME: Need a jjin/get-font-for-frame function that returns the frame's
;; currently active font if none in jjin/font-priority-list are found
(set-frame-font (format "Iosevka %s" size))))
(setq tramp-verbose 4)
(defconst jjin/secrets-file "~/.secrets.el")
(when (file-exists-p jjin/secrets-file) (load-file jjin/secrets-file))
(setq ring-bell-function 'ignore)
(setq large-file-warning-threshold nil)
(setq
inhibit-startup-screen t
inhibit-startup-message t
initial-scratch-message nil
visible-bell nil
use-dialog-box nil)
(setq-default
indent-tabs-mode nil
tab-width 4)
(setq next-line-add-newlines t)
(setq scroll-step 1
scroll-conservatively 10000
scroll-margin 3)
(setq use-short-answers t)
(when window-system
(tool-bar-mode 0)
(scroll-bar-mode 0)
(menu-bar-mode 0)
(line-number-mode 0))
(blink-cursor-mode 0)
(global-auto-revert-mode)
(setq auto-revert-remote-files t)
(global-hl-line-mode 1)
(column-number-mode 1)
(show-paren-mode 1)
(add-hook 'prog-mode-hook #'display-line-numbers-mode)
(electric-pair-mode)
(delete-selection-mode +1)
(add-hook 'prog-mode-hook 'turn-on-auto-fill)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(fringe-mode '(4 . 0))
(with-eval-after-load 'dired
(define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file))
(put 'dired-find-alternate-file 'disabled nil)
(setq echo-keystrokes 0)
(use-package image-dired
:after dash
:init
(if-let* ((handlers (alist-get system-type jjin-ext-file-handlers))
(handler (-first 'executable-find (plist-get handlers :image))))
(setq image-dired-external-viewer (executable-find handler))))
(setq term-ansi-default-program (getenv "SHELL"))
(setq enable-remote-dir-locals t)
(setq custom-file "~/.emacs-custom.el")
(when (file-exists-p custom-file) (load custom-file))
(use-package midnight
:init
(setq clean-buffer-list-delay-general 0.006)) ; 10 minutes
(setq-default fill-column 80)
(display-fill-column-indicator-mode 1)
(use-package gotham-theme
:if window-system
:disabled t
:config
(load-theme 'gotham t))
(use-package nord-theme
:if window-system
:straight t
:disabled t
:custom (nord-comment-brightness 10)
:config
(load-theme 'nord t))
(use-package kaolin-themes
:if window-system
:straight t
:config
(load-theme 'kaolin-ocean t))
(setq-default x-stretch-cursor t)
(setq custom-safe-themes t)
(defun jjin/switch-to-scratch-or-create ()
"Switches to scratch buffer if it exists, creating it if not."
(interactive)
(switch-to-buffer "*scratch*"))
(defun jjin/font-installed-p (font-name)
"Returns t if FONT-NAME is found to be installed; nil otherwise."
(not (null (x-list-fonts font-name))))
;; FIXME: This needs to tap homebrew/cask-fonts first
;; FIXME: This currently does not work, since
;; `system-packages-package-installed-p' isn't anything more than an alias to
;; `executable-find', making this useless.
;; (system-packages-ensure "font-iosevka")
;; FIXME:
;;
;; Elements in font-priority-list should consist of:
;; - Font name;
;; - Sizes for: large screens; small screens; etc.
;;
;; This can allow consuming functions e.g. jjin-fontify-frame to select both the
;; name and size based on the display the current frame resides on.
(defvar jjin/font-priority-list
'("Iosevka Nerd Font 12" "Iosevka 12" "IBM Plex Mono 12" "Source Code Pro 14" "Terminus (TTF) 16")
"Priority-sorted list of fonts to attempt to set frame to.")
;; TODO: Install font-iosevka
(if window-system
(-when-let (font-name (-first 'jjin/font-installed-p jjin/font-priority-list))
(set-frame-font font-name)))
;; (when (functionp 'set-fontset-font)
;; (set-fontset-font "fontset-default"
;; 'unicode
;; (font-spec :family "DejaVu Sans Mono")))
(jjin-set-opacity 90)
(add-hook 'window-size-change-functions #'jjin-fontify-frame)
(add-to-list 'default-frame-alist '(undecorated . t))
(when (eq system-type 'darwin)
(add-to-list 'auth-sources 'macos-keychain-internet)
(setq mac-command-modifier 'meta)
(setq mac-right-command-modifier 'meta)
(setq mac-option-modifier 'super)
(setq mac-right-option-modifier 'super)
(setq system-uses-terminfo nil))
;; =compilation-mode= invokes shell in a non-interactive shell, which means
;; that configurations in =.bashrc= do not get surfaced. This can cause
;; complications in cases where, for instance, successful compilation is
;; predicated on conditions set within a provisioned profile file that I do not
;; control. When Bash is started non-interactively, it looks for =BASH_ENV= in
;; the environment, expands its value if it appears there, and uses the
;; expanded value as the name of a file to read and execute. As such, we set
;; that environment value to our startup file here.
(when (eq system-type 'darwin) (setenv "BASH_ENV" "$HOME/.bashrc"))
;; For this to work, make sure EDITOR and/or VISUAL are set to `emacsclient'.
(use-package server
:config
(unless (server-running-p) (server-start)))
(use-package nested-dir-local
:disabled t
:straight (:repo "[email protected]:jinnovation/nested-dir-locals.el.git"))
(use-package eyebrowse
:straight t
:custom
(eyebrowse-new-workspace t)
:config
(eyebrowse-mode 1))
;; FIXME: Add eyebrowse switch window config bindings to the window hydra
(defvar jjin/help-modes '(helpful-mode
help-mode
Man-mode
woman-mode
Info-mode
godoc-mode))
(defun jjin/help-buffer-p (buf &optional act)
"Check if BUF is a 'help' buffer.
ACT is a buffer action that enables use in
`display-buffer-alist'."
(member (with-current-buffer buf major-mode) jjin/help-modes))
(add-to-list 'display-buffer-alist
`(jjin/help-buffer-p
(display-buffer--maybe-same-window
display-buffer-reuse-window
display-buffer-reuse-mode-window)
(mode . ,jjin/help-modes)
(inhibit-same-window . nil)))
;; FIXME: This doesn't play nicely w/ M-x mu4e
(add-to-list 'display-buffer-alist
'((lambda (buf act) (equal (with-current-buffer buf major-mode) 'mu4e-headers-mode))
(display-buffer--maybe-same-window
display-buffer-reuse-window
display-buffer-reuse-mode-window)
(mode . mu4e-headers-mode)
(inhibit-same-window . nil)))
(add-to-list 'tab-bar-format 'tab-bar-format-align-right t)
(add-to-list 'tab-bar-format 'tab-bar-format-global t)
(add-hook 'compilation-filter-hook 'ansi-color-compilation-filter)
;; keybindings
(define-prefix-command 'jjin-vc-map)
(bind-key "C-c v" 'jjin-vc-map)
(bind-keys :map global-map
("C-x k" . jjin-kill-current-buffer)
("C-x m" . execute-extended-command)
("RET" . newline-and-indent))
(unbind-key "<menu>")
(unbind-key "M-`")
(unbind-key "C-c C-w")
(unbind-key "C-x C-n") ; set-goal-column
(unbind-key "s-t") ; ns-popup-font-panel
(unbind-key "s-w") ; delete-frame
(unbind-key "<f10>")
(unbind-key "<f11>")
(unbind-key "M-<f10>")
(unbind-key "<escape> <f10>")
(bind-keys :map global-map
("<s-backspace>" . backward-kill-word)
("s-s" . save-buffer)
("s-b" . switch-to-buffer)
("s-`" . recompile))
(use-package hydra
:commands defhydra
:straight t)
(use-package pretty-hydra
:straight t
:after all-the-icons
:config
(pretty-hydra-define jjin-hydra-exec
(:title (with-material "apps" "Apps" 1 -0.05))
("General" ()))
(pretty-hydra-define jjin-hydra-window
(:title (with-octicon "browser" "Windows" 1 -0.05))
("Move"
(("h" windmove-left "move left")
("l" windmove-right "move right")
("j" windmove-down "move down")
("k" windmove-up "move up"))
"Split"
(("H" jjin-move-splitter-left "move splitter left")
("L" jjin-move-splitter-right "move splitter right")
("J" jjin-move-splitter-down "move splitter down")
("K" jjin-move-splitter-up "move splitter up")
("|" jjin-window-toggle-split-direction "toggle split")
("s" split-window-below "split window (below)")
("v" split-window-right "split window (right)"))
"Other"
(("q" delete-window "delete window")
("Q" kill-buffer-and-window "kill buffer, delete window")
("b" balance-windows "balance")
("S" ace-swap-window "swap places with...")
(";" ace-window "select window" :exit t))))
(pretty-hydra-define jjin-buffer-hydra
(:title (with-material "code" "Buffers" 1 -0.005) :color teal)
("Name"
(("r" rename-buffer "Rename"))))
(bind-key "C-c b" 'jjin-buffer-hydra/body)
(bind-key "C-c w" 'jjin-hydra-window/body)
(bind-key "s-<escape>" 'jjin-hydra-exec/body))
(use-package major-mode-hydra
:straight t
:bind
("s-SPC" . major-mode-hydra))
;; Virtualenv-aware shim for finding the right Python executables. Useful for
;; language server functionality etc.
(use-package pet
:straight t
:after (exec-path-from-shell)
:config
(add-hook 'python-base-mode-hook (lambda ()
(setq-local python-shell-interpreter (pet-executable-find "python")
python-shell-virtualenv-root (pet-virtualenv-root))
(pet-eglot-setup))))
;; (add-hook 'python-base-mode-hook 'pet-mode -10))
(use-package eglot
:hook ((tsx-ts-mode . eglot-ensure)
(python-ts-mode . eglot-ensure)
(typescript-ts-mode . eglot-ensure))
:ensure-system-package (typescript-language-server gopls)
:config
(defun jjin/eglot-organize-buffer-imports ()
(apply #'eglot-code-action-organize-imports (eglot--region-bounds)))
(defun jjin/setup-eglot-hooks ()
(add-hook 'before-save-hook #'jjin/eglot-organize-buffer-imports nil t)
(add-hook 'before-save-hook #'eglot-format-buffer nil t))
(add-hook 'eglot-managed-mode-hook #'jjin/setup-eglot-hooks))
(use-package lsp-mode
:straight t
:hook ((python-mode . lsp-deferred)
(go-mod-ts-mode . lsp-deferred)
(go-ts-mode . lsp-deferred))
;; (terraform-mode . lsp-deferred)
;; (yaml-mode . lsp-deferred))
;; TODO:
;; For Python, would like the following installed:
;; - python-lsp-server
;; - python-lsp-black
;; - pylsp-mypy
;; - pyls-isort
:custom
(lsp-ui-sideline-enable nil) ; Disable until the weird text
; overflow issue is fixed
(lsp-signature-render-documentation nil)
(lsp-pyls-configuration-sources ["flake8"])
(lsp-pyls-plugins-pycodestyle-enabled nil)
(lsp-pylsp-server-command '("pylsp"))
(lsp-pyls-server-command '("pylsp"))
(lsp-enable-snippet nil)
(lsp-log-io t)
(lsp-document-sync-method nil)
(lsp-print-performance t)
(lsp-before-save-edits nil)
(lsp-signature-render-documentation t)
(lsp-pyls-plugins-pydocstyle-enabled t)
(lsp-pyls-plugins-pyflakes-enabled nil)
(lsp-pyls-plugins-flake8-enabled t)
(lsp-pyls-plugins-pydocstyle-convention "pep257")
(lsp-pyls-plugins-mccabe-enabled nil)
(lsp-go-codelenses nil)
(lsp-go-use-gofumpt t)
:init
;; (setq lsp-document-sync-method 'lsp--sync-incremental)
(add-hook 'hack-local-variables-hook
(lambda () (when (derived-mode-p 'python-mode) (lsp))))
:config
(when (-contains? (lsp-session-folders (lsp-session)) (f-expand "~"))
(warn "LSP workspace folders list contains home dir; this can be problematic, consider removing."))
(lsp-register-custom-settings '(("gopls.completeUnimported" t t)
("gopls.staticcheck" t t)
("pyls.plugins.pyls_mypy.enabled" t t)
("pyls.plugins.pyls_mypy.live_mode" nil t)))
;; FIXME: Oncen gopackagesdriver is available, set up here to cooperate w/
;; Bazel projects.
(defun lsp-go-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks))
(use-package bazel-mode
:disabled t
:straight (emacs-bazel-mode :type git :host github :repo "bazelbuild/emacs-bazel-mode"))
(setq c-block-comment-prefix "* ")
(c-set-offset 'arglist-intro '+)
(c-set-offset 'arglist-close 0)
(use-package editorconfig
:straight t
:config
(editorconfig-mode 1))
(require 'go-ts-mode)
(use-package lsp-ivy
:straight t
:after (ivy lsp-mode))
(use-package lsp-ui
:straight t
:after lsp-mode
:custom
(lsp-ui-doc-enable nil "doc display on hover uses posframes (don't work well w/ macos fullscreen)")
(lsp-ui-sideline-show-hover t))
(add-to-list 'auto-mode-alist '("emacs$" . emacs-lisp-mode))
(add-to-list 'auto-mode-alist '("Cask" . emacs-lisp-mode))
(defvaralias 'js-indent-level 'tab-width)
(use-package js2-mode
:mode (("\\.js$" . js2-mode)
("\\.jsx$" . js2-jsx-mode))
:straight t)
(use-package json-mode
:straight t)
(add-to-list 'auto-mode-alist '("zshrc$" . sh-mode))
(add-to-list 'auto-mode-alist '("\\.zsh$" . sh-mode))
(add-to-list 'auto-mode-alist '("\\.bats$" . sh-mode))
(use-package graphviz-dot-mode
:straight t)
(use-package mermaid-mode
:straight t
:mode (("\\.mmd$" . mermaid-mode)))
(use-package haskell-mode
:disabled t
:config
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent))
(add-hook 'sql-interactive-mode-hook
(lambda ()
(toggle-truncate-lines t)))
(use-package protobuf-mode
:straight t)
(add-to-list 'major-mode-remap-alist
'(python-mode . python-ts-mode))
(setq python-fill-docstring-style 'pep-257)
(setq python-indent-def-block-scale 1)
(use-package pyvenv
:straight t
:init
(setenv "WORKON_HOME" "~/.pyenv/versions"))
(use-package elisp-autofmt
:straight t
:disabled t
:commands (elisp-autofmt-mode elisp-autofmt-buffer))
(use-package buttercup
:straight t)
(use-package markdown-mode
:straight t
:mode "\\.md$"
:bind (:map markdown-mode-map
("M-]" . markdown-demote)
("M-[" . markdown-promote))
:custom
(markdown-asymmetric-header t)
:config
(add-hook 'markdown-mode-hook 'auto-fill-mode))
(defun jjin/treesit-install-grammar-maybe (lang)
"Installs Tree-sitter grammar for LANG if and only if it is not already
installed and available."
(unless (treesit-language-available-p lang)
(treesit-install-language-grammar lang)))
(use-package treesit
:custom
(treesit-language-source-alist
'((tsx "https://github.com/tree-sitter/tree-sitter-typescript" "v0.20.3" "tsx/src")
(go "https://github.com/tree-sitter/tree-sitter-go" "v0.20.0" "src")
(yaml "https://github.com/ikatyang/tree-sitter-yaml" "v0.5.0" "src")
(gomod "https://github.com/camdencheek/tree-sitter-go-mod" "v1.0.2" "src")
(python "https://github.com/tree-sitter/tree-sitter-python" "v0.21.0" "src")
(typescript "https://github.com/tree-sitter/tree-sitter-typescript" "v0.20.3" "typescript/src")
(typst "https://github.com/uben0/tree-sitter-typst" "v0.10-2" "src")))
:config
(mapc #'jjin/treesit-install-grammar-maybe (mapcar #'car treesit-language-source-alist)))
(use-package typescript-ts-mode)
(use-package typst-ts-mode
:after (treesit major-mode-hydra)
:straight (typst-ts-mode :type git :host sourcehut :repo "meow_king/typst-ts-mode" :files (:defaults "*.el"))
:config
(defun jjin/run-typstfmt-maybe ()
"Runs typstfmt on the current buffer if it is installed."
(interactive)
(when (and (executable-find "typstfmt") (buffer-file-name))
(shell-command (format "typstfmt %s" (buffer-file-name)))))
;; FIXME: For some reason doesn't work?
;; (defun jjin/typst-install-save-hooks ()
;; (add-hook 'before-save-hook #'jjin/run-typstfmt-maybe t t))
;; (add-hook 'typst-ts-mode-hook #'jjin/typst-install-save-hooks)
(major-mode-hydra-define typst-ts-mode
(:title "Typst: Commands")
("Compilation"
(("C" typst-ts-mode-compile "Compile")
("c" typst-ts-mode-compile-and-preview "Compile and preview")
;; FIXME: Display whether currently on or off
("w" typst-ts-mode-watch-toggle "Watch toggle"))
"Format"
(("f" jjin/run-typstfmt-maybe "Auto-format")))))
(use-package yaml-ts-mode)
(use-package jinja2-mode
:straight t)
(use-package ace-link
:straight t
:after org ;; fn ace-link-org loads org-mode
:commands (ace-link-eww ace-link-setup-default)
:init (ace-link-setup-default))
(use-package ace-window
:commands ace-window
:straight t
:init
(setq aw-keys '(?a ?r ?s ?t ?q ?w ?f ?p))
:config
;; technically should be able to use mu4e~update-name but for whatever reason
;; the mu4e update index function uses the hardcoded string w/ space padding.
(add-to-list 'aw-ignored-buffers " *mu4e-update*"))
(use-package code-review
:straight t
:disabled t)
(use-package conf-mode
:mode
(;; systemd
("\\.service\\'" . conf-unix-mode)
("\\.timer\\'" . conf-unix-mode)
("\\.target\\'" . conf-unix-mode)
("\\.mount\\'" . conf-unix-mode)
("\\.automount\\'" . conf-unix-mode)
("\\.slice\\'" . conf-unix-mode)
("\\.socket\\'" . conf-unix-mode)
("\\.path\\'" . conf-unix-mode)
;; general
("conf\\(ig\\)?$" . conf-mode)
("rc\\(_local\\)?$" . conf-mode)))
(use-package company
:defines company-backends
:diminish company-mode
:straight t
:custom
(company-dabbrev-downcase nil)
:config
(add-hook 'after-init-hook 'global-company-mode)
(setq company-idle-delay 0.1))
(setq dired-listing-switches "-alh")
(use-package dired-open
:straight t
:after dash
:init
(if-let* ((handler-vid (-first 'executable-find
(plist-get
(alist-get system-type jjin-ext-file-handlers)
:video)))
(path (executable-find handler-vid)))
(setq dired-open-extensions `(("mp4" . ,(executable-find handler-vid))
("avi" . ,(executable-find handler-vid))))))
(use-package dirvish
:straight t
:init
(pretty-hydra-define+ jjin-hydra-exec nil
("General" (("d" dirvish "dirvish" :exit t))))
:config
(dirvish-override-dired-mode))
(use-package doc-view
:init
(setq doc-view-resolution 200))
(use-package docker
:straight t)
(use-package dockerfile-mode
:straight t)
(use-package ediff
:custom
(ediff-window-setup-function 'ediff-setup-windows-plain))
(use-package exec-path-from-shell
:straight t
:custom
(exec-path-from-shell-variables '("PATH"
"MANPATH"
"GOPATH"
"GOROOT"
"GO111MODULE"
"JENKINS_USER"
"JENKINS_API_TOKEN"))
;; (exec-path-from-shell-shell-name "zsh")
(exec-path-from-shell-shell-name shell-file-name)
:config
(exec-path-from-shell-initialize))
(use-package vterm
;; :ensure-system-package cmake
:straight t
:bind (:map global-map
("s-v" . vterm))
:hook
(vterm-mode . goto-address-mode)
:custom
(vterm-shell "/bin/zsh")
(vterm-kill-buffer-on-exit t)
:config
(with-eval-after-load 'evil
(add-to-list 'evil-emacs-state-modes 'vterm-mode)))
(use-package evil
:straight t
:defines evil-normal-state-map
:custom
(evil-esc-delay 0)
:config
(evil-set-leader '(normal motion) (kbd "SPC"))
(evil-define-key 'normal 'global (kbd "<leader>s") 'save-buffer)
(mapc (lambda (m) (add-to-list 'evil-emacs-state-modes m t))
'(eshell-mode
calendar-mode
finder-mode
info-mode
eww-mode
eww-bookmark-mode
dired-mode
image-mode
image-dired-thumbnail-mode
image-dired-display-image-mode
git-rebase-mode
help-mode
sql-interactive-mode
org-capture-mode))
;; FIXME: what's the diff between set-initial-state and adding to list directly?
(evil-set-initial-state 'term-mode 'emacs)
(bind-keys :map evil-emacs-state-map
("<escape>" . evil-execute-in-normal-state))
(evil-mode 1))
(use-package evil-numbers
:after evil
:straight t
:config
(bind-keys :map evil-normal-state-map
("C-a" . evil-numbers/inc-at-pt)
("C-c -" . evil-numbers/dec-at-pt)))
(use-package evil-search-highlight-persist
:after evil
:straight t
:config
(bind-key "C-l" 'evil-search-highlight-persist-remove-all
evil-normal-state-map)
(global-evil-search-highlight-persist t)
(set-face-attribute
'evil-search-highlight-persist-highlight-face
nil
:background (face-attribute 'match :background)))
(use-package evil-surround
:after evil
:straight t
:config
(global-evil-surround-mode 1))
(use-package evil-nerd-commenter
:after evil
:straight t
:pretty-hydra
((:color teal)
("Commenting"
(("i" evilnc-comment-or-uncomment-lines "Comment/Uncomment Lines")
("c" evilnc-copy-and-comment-lines "Copy and comment"))))
:bind ("C-c c" . evil-nerd-commenter-hydra/body)
:config
(evil-define-key '(normal motion) 'global (kbd "<leader>c") 'evil-nerd-commenter-hydra/body))
(use-package flycheck
:straight t
:defines flycheck-mode-hook
:config
(add-hook 'after-init-hook #'global-flycheck-mode))
(use-package gif-screencast
:straight t
:custom
(gif-screencast-args '("-x"))
;; I have no idea why this value works but it does so whatever
(gif-screencast-scale-factor 2.0)
(gif-screencast-cropping-program "mogrify")
(gif-screencast-capture-format "ppm"))
(bind-keys :map jjin-vc-map
("g" . vc-git-grep))
(setq vc-handled-backends '(git))
(use-package git-commit-mode
:commands git-commit-mode)
(use-package gitconfig-mode
:disabled t
:straight t
:mode "gitconfig")
(use-package gitignore-mode
:disabled t
:straight t
:mode "gitignore")
;; Merge commits can sometimes be massive -- particularly in monorepo
;; environments. Since showing the diff during commit in such scenarios is of
;; questionable utility, we suppress its behavior with the following advice.
(defun jjin/do-if-merge-not-in-progress (oldfun)
"Displays the diff during commit only in cases where a merge is
not in progress."
(when (not (magit-merge-in-progress-p)) (funcall oldfun)))
(defun jjin/magit-fetch-from-origin-master ()
(interactive)
(magit-git-fetch "origin" "master"))
(defun jjin/magit-checkout-previous-branch ()
(interactive)
(if-let ((p (magit-get-previous-branch)))
(magit-checkout p)
(error "No previous branch")))
;; TODO: Magit has migrated to using transient, so all commented sections will
;; eventually need to be updated or removed.
(use-package transient
:straight (:source melpa)
:init
(setq transient-show-common-commands nil))
(use-package git-modes
:straight t)
(use-package magit
:straight t
:custom
(magit-log-arguments '("--graph" "--decorate" "--color"))
(magit-display-buffer-function 'magit-display-buffer-same-window-except-diff-v1)
(magit-status-initial-section '(((unstaged) (status))
((staged) (status))))
:hook
(magit-revision-mode . goto-address-mode)
:init
;; On status buffer init, jump to either unstaged changes or staged changes,
;; if present
(add-to-list
'safe-local-variable-values
'(magit-status-headers-hook . (list
magit-insert-error-header
magit-insert-diff-filter-header
magit-insert-head-branch-header
magit-insert-upstream-branch-header
magit-insert-push-branch-header)))
(defun jjin/magit-status-at (dir)
"Open Magit status buffer for project at root DIR."
(magit-status dir))
:bind (:map jjin-vc-map
("!" . magit-git-command-topdir)
("C" . magit-branch-and-checkout)
("F" . magit-pull)
("P" . magit-push)
("b" . magit-blame)
("c" . magit-checkout)
("d" . magit-diff)
("f" . magit-fetch)
("l" . magit-log)
("m" . magit-merge)
("v" . magit-status)
("z" . magit-stash)
:map magit-mode-map
("X" . magit-reset-hard))
:commands (magit-status)
:config
(with-eval-after-load 'git-rebase
(bind-keys :map git-rebase-mode-map ("u" . git-rebase-undo)))
;; removes 1.4.0 warning in arguably cleaner way
(remove-hook 'after-init-hook 'magit-maybe-show-setup-instructions)
(defadvice magit-blame-mode (after switch-to-emacs-state activate)
(if magit-blame-mode
(evil-emacs-state 1)
(evil-normal-state 1)))
(with-eval-after-load 'evil
(add-to-list 'evil-emacs-state-modes 'magit-popup-mode))
(transient-append-suffix 'magit-commit 'magit-commit:--reuse-message