-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit.el
1390 lines (1213 loc) · 42.8 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
;;; init.el --- My emacs setup -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
;; Increase for better lsp-mode performance; see
;; https://emacs-lsp.github.io/lsp-mode/page/performance/
(setq gc-cons-threshold 100000000)
(when (boundp 'read-process-output-max)
;; New in Emacs 27
(setq read-process-output-max (* 1024 1024)))
;; Set default font size and family.
;;
;; Disable font smoothing on Big Sur:
;; defaults -currentHost write -g AppleFontSmoothing -int 0
(set-face-attribute 'default nil :height 180 :family "PragmataPro Liga")
(set-face-attribute 'fixed-pitch nil :height 180 :family "PragmataPro Liga")
(set-face-attribute 'variable-pitch nil :family "Neue Haas Grotesk Text Pro")
;; Fancy font when ligatures are available (Yamamoto Mitsuharu's Mac port)
(defconst amk-use-fancy-ligatures (fboundp #'mac-auto-operator-composition-mode))
(when amk-use-fancy-ligatures
;; Fira Code: https://github.com/tonsky/FiraCode
;; Iosevka: https://typeof.net/Iosevka/
;; PragmataPro: https://www.fsd.it/shop/fonts/pragmatapro/
(set-face-attribute 'default nil :family "PragmataPro Liga") ; Or "Fira Code" or "Iosevka"
(setq split-height-threshold 100)
(mac-auto-operator-composition-mode))
;; Set decent default fonts for Japanese and Chinese,
;; but *only* if in a graphical context.
;; Set Japanese second so that Japanese glyphs override Chinese
;; when both charsets cover the same codepoints.
(when (fboundp #'set-fontset-font)
;; Source Han Mono: https://github.com/adobe-fonts/source-han-mono
;; Source Han Code JP: https://github.com/adobe-fonts/source-han-code-jp
;; Sarasa Gothic: https://github.com/be5invis/Sarasa-Gothic
(pcase-dolist (`(,charset . ,family)
'((hangul . "Sarasa Gothic K") ; Or "Source Han Mono K"
(han . "Sarasa Gothic SC") ; Or "Source Han Mono SC"
(japanese-jisx0213.2004-1 . "Sarasa Gothic J") ; Or "Source Han Code JP"
(cyrillic . "PragmataPro Liga")
(greek . "PragmataPro Liga")
(hebrew . "PragmataPro Liga")
(thai . "Noto Sans Thai")
(arabic . "PragmataPro Liga")
(bengali . "Noto Sans Bengali")
(devanagari . "Noto Sans Devanagari")
(kannada . "Noto Sans Kannada")
(malayalam . "Noto Sans Malayalam")
(gurmukhi . "Noto Sans Gurmukhi")
(tamil . "Noto Sans Tamil")
(telugu . "Noto Sans Telugu")
(khmer . "Noto Sans Khmer")))
(set-fontset-font t charset (font-spec :family family))))
(dolist (item '(("Source Han Mono K" . 1.25)
("Source Han Mono JP" . 1.25)
("Source Han Code JP" . 1.25)
("Source Han Mono SC" . 1.25)
("Noto Sans Arabic" . 1.35)
("Noto Sans Bengali" . 1.35)
("Noto Sans Devanagari" . 1.3)
("Noto Sans Gurmukhi" . 1.15)
("Noto Sans Khmer" . 1.25)))
(add-to-list 'face-font-rescale-alist item))
;; Font scale test:
;; 0123456789|ABCDEFGHIJ|
;; 01234|あいうえお|
;; 月光下,一|颗很小的蛋|躺在一个叶子上
;; 안녕, 세상|안녕, 세상|안녕, 세상
(setq-default fill-column 80
indent-tabs-mode nil
tab-width 4
mac-command-modifier 'super
mac-option-modifier 'meta
require-final-newline t
save-interprogram-paste-before-kill t
sentence-end-double-space nil)
;; Workaround for failure when installing MacPorts packages via
;; system-packages-install
(unless (getenv "COLUMNS")
(setenv "COLUMNS" "80"))
(setq custom-file "~/.emacs.d/custom-file.el")
(load custom-file)
(defvar amk-code-directory nil "Where I keep my programming projects.")
;; Make some emacs-app-mac keys match vanilla Emacs.app
(pcase-dolist (`(,key . ,func)
'(("s-u" . revert-buffer)
("s-n" . make-frame)
("s-w" . delete-frame)
("s-a" . mark-whole-buffer)
("s-v" . yank)
("s-c" . kill-ring-save)
("s-x" . kill-region)
("s-q" . save-buffers-kill-emacs)
("s-s" . save-buffer)))
(global-set-key (kbd key) func))
;; Don't intercept Japanese IME controls
(dolist (item '("C-S-j"
"C-:"))
(global-unset-key (kbd item)))
(column-number-mode)
(electric-pair-mode)
(delete-selection-mode)
(global-prettify-symbols-mode)
(add-hook 'before-save-hook #'delete-trailing-whitespace)
(defun save-buffer-no-hook (&optional arg)
"Save buffer without invoking `before-save-hook', in case \
I want to save without deleting trailing whitespace. ARG is as
with `save-buffer'."
(interactive "p")
(let (before-save-hook)
(save-buffer arg)))
;; Only on GUI
(when (display-graphic-p)
(if (fboundp #'global-display-line-numbers-mode)
(global-display-line-numbers-mode) ; emacs 26 and later
(global-linum-mode))
;; Disable C-z (suspend-frame) in GUI because it's pointless
;; and I keep hitting it.
(global-unset-key (kbd "C-z"))
;; Run server so `emacsclient` will edit in GUI editor.
;; May have to prepend /Applications/Emacs.app/Contents/MacOS/bin
;; to PATH on OS X.
(server-start)
;; New stuff
;;
;; Undo variable-pitch mode line
(set-face-attribute 'mode-line nil :inherit 'default)
;; Pixel scrolling
(when (and (fboundp #'pixel-scroll-precision-mode)
;; Use default pixel scrolling on Mac port
(not (boundp 'mac-mouse-wheel-smooth-scroll)))
(pixel-scroll-precision-mode)))
(require 'package)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/") ; ensure https
("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")))
;; Bootstrap use-package
;; http://cachestocaches.com/2015/8/getting-started-use-package/
(unless (package-installed-p 'use-package)
(unless (string= (user-login-name) "root")
(package-refresh-contents)
(package-install 'use-package)))
(eval-when-compile
(require 'use-package))
(unless (string= (user-login-name) "root")
(package-install-selected-packages))
(setq use-package-always-ensure t)
(use-package diminish)
(use-package bind-key)
(use-package use-package-ensure-system-package)
(defconst local-custom-file "~/.emacs.d/init-local.el"
"A local version of CUSTOM-FILE for settings that should \
not be synced across machines.")
(when (file-exists-p local-custom-file)
(load local-custom-file))
(defun macosp ()
"Return non-nil if the OS is macOS."
(string= system-type "darwin"))
(use-package exec-path-from-shell
:if (macosp)
:config
(dolist (var '(
;; NS port doesn't pick up LC_ALL, which causes encoding
;; errors in e.g. org-babel execution.
"LC_ALL"
;; terraform-ls with tfenv needs this or it will try to
;; install terraform to /opt/local.
"TFENV_CONFIG_DIR"))
(add-to-list 'exec-path-from-shell-variables var))
;; Don't pick up MANPATH because I don't set it, and the value it determines
;; is missing MacPorts manpages.
(setq exec-path-from-shell-variables
(delete "MANPATH" exec-path-from-shell-variables))
;; Ensure emacs shell has regular shell environment
(exec-path-from-shell-initialize))
(use-package amk-edit
:ensure nil
:load-path "lisp"
:bind (("M-<up>" . amk-edit-move-lines-up)
("M-<down>" . amk-edit-move-lines-down)
;; For use on CLI
("ESC <up>" . amk-edit-move-lines-up)
("ESC <down>" . amk-edit-move-lines-down)))
(use-package amk-xml
:ensure nil
:load-path "lisp")
(use-package amk-mac
:ensure nil
:load-path "lisp")
(use-package amk-browse
:ensure nil
:disabled
:load-path "lisp"
:bind ("C-c C-o" . #'amk-browse-multi)
:config
(add-to-list 'amk-browse-alist '(backlog-issue-p . backlog-browse-issue)))
(use-package amk-org
:ensure nil
:load-path "lisp"
:after (amk-edit org))
(use-package backlog
:ensure nil
:disabled
:load-path "lisp/backlog"
:after (request ivy)
:bind ("C-c C-b" . #'backlog-browse-issue-at-point))
(use-package reformatter)
(use-package shfmt
:ensure nil
:load-path "lisp/shfmt"
:after reformatter
:ensure-system-package shfmt
:diminish shfmt-on-save-mode
:hook (sh-mode . shfmt-on-save-mode))
(use-package scale-to-fit
:ensure nil
:load-path "lisp")
(use-package emoji-github
:ensure nil
:load-path "lisp"
:after magit
:hook ((magit-status-mode magit-log-mode) . emoji-github-enable)
:config
(global-prettify-symbols-mode))
(use-package hl-tags-mode
:ensure nil
:load-path "lisp/hl-tags-mode"
:after nxml-mode
:hook (nxml-mode . hl-tags-mode))
(use-package macports
:ensure nil
:load-path "lisp/macports")
(use-package desktop
:ensure nil
:if (display-graphic-p)
:demand t
:hook (auto-save-mode . (lambda ()
(if (eq (desktop-owner) (emacs-pid))
(desktop-save desktop-dirname))))
:custom
(desktop-load-locked-desktop (if (>= emacs-major-version 29)
'check-pid
'ask))
:config
(desktop-save-mode t))
(use-package compile
:ensure nil
:custom
(compilation-scroll-output 'first-error))
(use-package paren
:ensure nil
:custom
(show-paren-context-when-offscreen 'overlay "From Emacs 29")
:config
(show-paren-mode))
(use-package files
:ensure nil
:if (display-graphic-p)
:custom
(confirm-kill-emacs #'yes-or-no-p))
(use-package lisp-mode
:ensure nil
:custom
(emacs-lisp-docstring-fill-column t))
(use-package subword
:ensure nil
:diminish subword-mode
:config
(global-subword-mode))
(use-package eldoc
:ensure nil
:diminish eldoc-mode)
(use-package shell
:ensure nil
:hook (shell-mode . (lambda ()
(shell-dirtrack-mode 0))))
(use-package auto-revert
:ensure nil
:mode (("\\.log\\'" . auto-revert-tail-mode)))
(use-package image-mode
:ensure nil
:hook (image-mode . (lambda () (display-line-numbers-mode -1))))
(use-package cus-edit
:ensure nil
:hook (Custom-mode . (lambda () (display-line-numbers-mode -1))))
(use-package image-dimensions-minor-mode
:ensure nil
:after (image-mode blimp)
:load-path "lisp/wiki"
:config
(advice-add #'eimp-replace-image :after #'image-dimensions-update-lighter))
(use-package flyspell
:ensure nil
:ensure-system-package (aspell . "sudo port -N install aspell aspell-dict-en")
:hook ((text-mode . flyspell-mode)
;; (prog-mode . flyspell-prog-mode)
))
(use-package ediff
:ensure nil
:if (display-graphic-p)
:custom
;; https://www.ogre.com/node/446
(ediff-split-window-function #'split-window-horizontally)
(ediff-window-setup-function #'ediff-setup-windows-plain))
(use-package dired
:ensure nil
:config
;; macOS ls doesn't support --dired
(when (macosp)
(setq dired-use-ls-dired nil)))
(use-package image-dired
:ensure nil
:hook (image-dired-thumbnail . (lambda () (display-line-numbers-mode -1))))
(use-package amk-dired-mac
:ensure nil
:load-path "lisp"
:after (dired)
:bind (:map dired-mode-map
("C-c C-o" . #'amk-dired-mac-open-in-finder)
("C-c C-r" . #'amk-dired-mac-reveal-in-finder)))
(use-package amk-dired
:ensure nil
:load-path "lisp"
:after (dired)
:bind (:map dired-mode-map
("C-c C-d" . #'amk-dired-ediff)))
(use-package dired-x
:ensure nil)
(use-package nxml-mode
:ensure nil
:hook (nxml-mode . maven-file-setup)
:mode (("\\.xaml\\'" . nxml-mode))
:custom
(nxml-child-indent 4)
:config
(put 'nxml-child-indent 'safe-local-variable #'integerp)
(put 'nxml-attribute-indent 'safe-local-variable #'integerp)
(defun maven-file-p ()
(and buffer-file-name
(string= (file-name-extension buffer-file-name) "xml")
(save-excursion
(re-search-forward "xmlns=['\"]http://maven.apache.org/[^/]+/[^'\"]+['\"]"
magic-mode-regexp-match-limit t))))
(defun maven-file-setup ()
(when (maven-file-p)
(setq-local nxml-child-indent 2))))
(use-package js
:ensure nil
:after lsp-mode
:mode (("\\.mjs\\'" . js-mode))
:ensure-system-package ((npm . npm10)
(typescript-language-server . "sudo npm install -g typescript-language-server")
(tsserver . "sudo npm install -g typescript"))
:hook (js-mode . lsp-deferred)
:custom
(js-indent-level 2))
(use-package css-mode
:ensure nil
:custom
(css-indent-offset 2))
(use-package browse-url
:ensure nil
:bind ("s-<mouse-1>" . #'amk-browse-url-at-mouse)
:config
(when (macosp)
(setq browse-url-generic-program "open"))
(defun amk-browse-url-at-mouse (click)
"Browse URL at mouse position."
(interactive "e")
(save-excursion
(posn-set-point (event-end click))
(browse-url-at-point))))
(use-package ob-passthrough
:ensure nil
:load-path "lisp")
(use-package org
:ensure org-contrib
:custom
(org-enforce-todo-checkbox-dependencies t)
(org-enforce-todo-dependencies t)
(org-startup-truncated nil "Wrap lines")
(org-refile-targets '((nil . (:maxlevel . 1))
(org-agenda-files . (:maxlevel . 1))))
(org-directory "~/org")
(org-default-notes-file (concat (file-name-as-directory org-directory) "notes.org"))
(org-src-tab-acts-natively t)
(org-log-done 'time)
(org-preview-latex-default-process 'dvisvgm)
(org-startup-with-inline-images t)
(org-adapt-indentation t)
:ensure-system-package dvisvgm
:bind (
;; Alternate mapping to avoid override by Flycheck
("C-c C-." . org-time-stamp-inactive))
:hook (org-babel-after-execute . org-redisplay-inline-images)
:config
(plist-put org-format-latex-options :scale 2.0)
(org-babel-do-load-languages
'org-babel-load-languages
`(,@org-babel-load-languages
(shell . t)
(dot . t)
(python . t)
(ruby . t)
(sqlite . t)
(passthrough . t))))
(use-package org-crypt
:ensure nil
:after org
:custom (org-tags-exclude-from-inheritance '("crypt"))
:config
(org-crypt-use-before-save-magic))
(use-package tramp
:ensure nil
:custom
(tramp-allow-unsafe-temporary-files t)
:config
;; Make Tramp respect the remote server's PATH setting, so we can pick up
;; things like rbenv shims for remote Ruby execution via bundler
(add-to-list 'tramp-remote-path 'tramp-own-remote-path))
(use-package ob-async
;; Disable on Emacs 30+ pending https://github.com/astahlman/ob-async/pull/93
:if (<= emacs-major-version 29)
:hook (ob-async-pre-execute-src-block
.
;; This can't be its own function because we'd have to redefine the
;; function in the other process, too
(lambda ()
(require 'tramp)
(add-to-list 'tramp-remote-path 'tramp-own-remote-path))))
(use-package org-agenda
:ensure nil
:after org
:bind ("C-c a" . org-agenda)
:hook (org-agenda-mode . (lambda () (display-line-numbers-mode -1)))
:config
(let ((amk-agenda-path (concat (file-name-as-directory org-directory) "agenda")))
(unless (file-directory-p amk-agenda-path)
(make-directory amk-agenda-path t))
(add-to-list 'org-agenda-files amk-agenda-path)))
(use-package org-capture
:ensure nil
:after org
:bind ("C-c c" . org-capture)
:config
;; Default template, not offered when custom templates are defined
(add-to-list 'org-capture-templates
'("t" "Task" entry (file+headline "" "Tasks") "* TODO %?\n %u\n %a"))
;; Templates for Firefox extension: https://github.com/sprig/org-capture-extension
(add-to-list 'org-capture-templates
'("p" "Protocol" entry (file+headline "" "Inbox")
"* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?"))
(add-to-list 'org-capture-templates
'("L" "Protocol Link" entry (file+headline "" "Inbox")
"* %? [[%:link][%:description]] \nCaptured On: %U")))
(use-package ol
:ensure nil
:after org
:bind ("C-c l" . org-store-link))
(use-package org-tempo
:ensure nil
:after org)
;; Backlog link support
(use-package org-backlog
:ensure nil
:after org
:load-path "lisp/backlog")
;; pdfview link support
(use-package org-pdftools
:after org)
(use-package magit
:diminish (smerge-mode auto-revert-mode)
:custom
(magit-diff-refine-hunk 'all "Always show character-level diffs")
(magit-format-file-function #'magit-format-file-all-the-icons)
:config
(when (and amk-code-directory
(file-exists-p amk-code-directory))
(add-to-list 'magit-repository-directories `(,amk-code-directory . 1))))
(use-package amk-magit
:ensure nil
:after magit
:load-path "lisp")
(use-package forge
;; To store GitHub token in macOS keychain per `auth-source' config below:
;; 0. Create token at https://github.com/settings/tokens
;; 1. Open Keychain Access
;; 2. Create new password item
;; 3. Make sure it's recognized as an Internet password by entering
;; https://api.github.com for the Keychain Item Name
;; 4. Use $username^forge as Account Name
;; 5. Enter token as password and save
;; 6. Test with `security find-internet-password -g -s api.github.com -a $username^forge'
)
(use-package orgit-forge
:after (org forge))
(use-package git-link
:custom
(git-link-use-commit t))
(use-package auth-source
:ensure nil
:config
(when (macosp)
(add-to-list 'auth-sources 'macos-keychain-internet)
(add-to-list 'auth-sources 'macos-keychain-generic)))
(use-package gnus
:ensure nil
;; To store Gmail auth info in macOS keychain per `auth-source' config above:
;; 0. Generate application-specific password
;; 1. Open Keychain Access
;; 2. Create new password item
;; 3. Make sure it's recognized as an Internet password by entering
;; https://imap.googlemail.com:993 for the Keychain Item Name
;; 4. Use whatever as Account Name
;; 5. Enter password and save
;; 6. Test with `security find-internet-password -g -s imap.googlemail.com -P 993`
;; 7. Repeat with https://smtp.googlemail.com:587
)
(use-package diff-hl
:hook ((dired-mode . diff-hl-dired-mode-unless-remote)
(magit-pre-refresh . diff-hl-magit-pre-refresh)
(magit-post-refresh . diff-hl-magit-post-refresh))
:config
(face-spec-set
'diff-hl-change
'((((class color) (min-colors 88) (background dark)) :foreground "blue" :background "steelblue4")))
(face-spec-set
'diff-hl-delete
'((((class color) (min-colors 88) (background dark)) :background "red4")))
(face-spec-set
'diff-hl-insert
'((((class color) (min-colors 88) (background dark)) :foreground "green" :background "forestgreen")))
(global-diff-hl-mode))
;; Use PCRE-style regex
(use-package pcre2el
:diminish pcre-mode
:config
(pcre-mode))
;; On-the-fly linting
(use-package flycheck
:hook (text-mode . amk-flycheck-disable-on-large-text)
:config
(global-flycheck-mode)
(defun amk-flycheck-disable-on-large-text ()
(when (> (buffer-size) 500000)
(flycheck-mode -1)
(message "flycheck-mode disabled due to buffer size"))))
(use-package flycheck-package
:after flycheck
:config
(flycheck-package-setup))
(use-package flycheck-shfmt
:ensure nil
:after flycheck
:load-path "lisp/shfmt"
:config
(flycheck-shfmt-setup))
(use-package flycheck-innosetup
:ensure nil
:after flycheck
:load-path "lisp"
:config
(flycheck-innosetup-setup))
(use-package flycheck-languagetool
:disabled ; Results are too frequently garbage
:ensure nil
:after flycheck
:ensure-system-package languagetool
:load-path "lisp"
:custom
(flycheck-languagetool-mother-tongue "en-US")
(flycheck-languagetool-disable-rules-alist
'((markdown-mode
"WHITESPACE_RULE"
"WORD_CONTAINS_UNDERSCORE"
"COMMA_PARENTHESIS_WHITESPACE"
"EN_QUOTES"
"DASH_RULE")
(t
"WHITESPACE_RULE")))
(flycheck-languagetool-line-by-line nil)
:config
(flycheck-languagetool-setup))
(use-package flycheck-sassc
:ensure nil
:after flycheck
:load-path "lisp"
:ensure-system-package sassc
:config
(flycheck-sassc-setup))
(use-package flycheck-dart-sass
:ensure nil
:after flycheck
:load-path "lisp"
:ensure-system-package (sass . dart-sass)
:config
(flycheck-dart-sass-setup))
(use-package flycheck-yard
:ensure nil
:after flycheck
:load-path "lisp"
:config
(flycheck-yard-setup))
(use-package flycheck-committed
:ensure nil
:ensure-system-package committed
:after flycheck
:load-path "lisp"
:config
(flycheck-committed-setup))
(use-package flycheck-commitlint
:ensure nil
:ensure-system-package ((npm . npm10)
(commitlint . "sudo npm install -g @commitlint/cli @commitlint/config-conventional"))
:after flycheck
:load-path "lisp"
:config
(flycheck-commitlint-setup))
(use-package crdt)
(use-package cc-mode
:ensure nil
:config
(defun objective-c-file-p ()
(and buffer-file-name
(string= (file-name-extension buffer-file-name) "m")
(re-search-forward "@interface\\|@implementation"
magic-mode-regexp-match-limit t)))
;; Can't use use-package :magic because it only supports regexp
(add-to-list 'magic-mode-alist '(objective-c-file-p . objc-mode)))
(use-package pascal
:ensure nil
:mode (("\\.iss\\'" . pascal-mode))
:config
(put 'pascal-indent-level 'safe-local-variable #'integerp))
(use-package ruby-mode
:ensure nil
:after lsp-mode
:hook ((ruby-mode . lsp-deferred)
(ruby-mode . amk-lsp-format-on-save))
:custom
(ruby-insert-encoding-magic-comment nil "Not needed in Ruby 2")
:ensure-system-package (solargraph . "gem install --user-install solargraph"))
(use-package inf-ruby)
(use-package ruby-test-mode
:after ruby-mode
:diminish ruby-test-mode
:config
(defun amk-ruby-test-pretty-error-diffs (old-func &rest args)
"Make error diffs prettier."
(let ((exit-status (cadr args)))
(apply old-func args)
(when (> exit-status 0)
(diff-mode)
;; Remove self
(advice-remove #'compilation-handle-exit #'amk-ruby-test-pretty-error-diffs))))
(defun amk-ruby-test-pretty-error-diffs-setup (old-func &rest args)
"Set up advice to enable pretty diffs when tests fail."
(advice-add #'compilation-handle-exit :around #'amk-ruby-test-pretty-error-diffs)
(apply old-func args))
(advice-add #'ruby-test-run-command :around #'amk-ruby-test-pretty-error-diffs-setup))
(use-package counsel
:demand t
:diminish (ivy-mode counsel-mode)
:ensure-system-package (rg . ripgrep)
:bind (("C-s" . swiper)
("C-r" . swiper-backward)
("C-c C-r" . ivy-resume)
("<f6>" . ivy-resume)
("<f1> l" . counsel-find-library)
("<f2> u" . counsel-unicode-char)
("C-c k" . amk-counsel-rg-here)
("C-x l" . counsel-locate)
("C-S-o" . counsel-rhythmbox)
("C-c h" . counsel-git-log)
:map minibuffer-local-map
("C-r" . counsel-minibuffer-history))
:custom
(ivy-use-virtual-buffers t)
(enable-recursive-minibuffers t)
:config
(ivy-mode)
(counsel-mode)
(defun amk-counsel-rg-here ()
"Like `counsel-rg' but always searches from the cwd, not project root."
(interactive)
(counsel-rg nil default-directory))
(defun amk-git-log-visit-in-magit (log-text &rest _)
"Visit the commit described by the git log text."
(let ((commit (car (split-string log-text))))
(magit-show-commit commit)))
(advice-add #'counsel-git-log-action :after #'amk-git-log-visit-in-magit))
(use-package all-the-icons
:if (display-graphic-p)
:after counsel
:config
(mapc (lambda (item) (add-to-list 'all-the-icons-mode-icon-alist item))
'((conf-mode all-the-icons-fileicon "config" :face all-the-icons-yellow)
(play-routes-mode all-the-icons-material "router" :face all-the-icons-dcyan)
(Info-mode all-the-icons-material "info_outline")
(octave-mode all-the-icons-fileicon "octave" :face all-the-icons-cyan-alt)
(sql-mode all-the-icons-fileicon "sqlite" :face all-the-icons-blue-alt)
(package-menu-mode all-the-icons-octicon "package" :face all-the-icons-dyellow)
(groovy-mode all-the-icons-fileicon "groovy" :face all-the-icons-blue-alt)
(flycheck-error-list-mode all-the-icons-material "error_outline" :face all-the-icons-red)
(restclient-mode all-the-icons-faicon "bed" :face all-the-icons-orange)))
(mapc (lambda (item) (add-to-list 'all-the-icons-extension-icon-alist item))
'(("\\.groovy$" all-the-icons-fileicon "groovy" :face all-the-icons-blue-alt))))
(use-package all-the-icons-ivy-rich
:ensure t
:config
(all-the-icons-ivy-rich-mode))
(use-package ivy-rich
:ensure t
:config
(ivy-rich-mode))
(use-package all-the-icons-ibuffer
:diminish all-the-icons-ibuffer-mode
:hook (ibuffer-mode . all-the-icons-ibuffer-mode))
(use-package all-the-icons-dired
:diminish all-the-icons-dired-mode
:hook (dired-mode . all-the-icons-dired-mode))
(use-package web-mode
:mode ("\\.html?\\'"
"\\.erb\\'"
"\\.vue\\'"
"\\.tsx\\'")
:ensure-system-package ((npm . npm10)
(vls . "sudo npm install -g vls"))
:after prettier
:hook (web-mode . (lambda ()
(when (or (react-file-p) (vue-file-p))
(lsp-deferred)
(prettier-mode))))
:custom
(web-mode-markup-indent-offset 2)
(web-mode-css-indent-offset 2)
(web-mode-code-indent-offset 2)
(web-mode-enable-auto-indentation nil)
:config
(defun react-file-p ()
(and buffer-file-name
(string= (file-name-extension buffer-file-name) "tsx")))
(defun vue-file-p ()
(and buffer-file-name
(string= (file-name-extension buffer-file-name) "vue"))))
(use-package prettier
:diminish prettier-mode
:ensure-system-package ((npm . npm10)
(prettier . "sudo npm install -g prettier"))
:hook ((typescript-mode . prettier-mode)
(svelte-mode . prettier-mode)
(typescript-ts-mode . prettier-mode)
(tsx-ts-mode . prettier-mode)))
(use-package expand-region
:bind ("C-=" . er/expand-region))
(use-package dired-collapse
:hook (dired-mode . dired-collapse-mode))
(use-package dash-at-point
:bind ("C-c d" . dash-at-point))
(defun rename-buffer-with-project ()
"Set the buffer name from the current Projectile project."
(let* ((proj (projectile-project-name))
(buff (replace-regexp-in-string "\\(<[^>]+>\\)+$" "" (buffer-name)))
(repl (if (string= proj "-")
buff
(format "%s<%s>" buff proj))))
(rename-buffer repl t)))
(use-package projectile
:demand t
:ensure-system-package (rg . ripgrep)
:diminish projectile-mode
:hook (shell-mode . rename-buffer-with-project)
:bind-keymap ("C-c p" . projectile-command-map)
:custom
(projectile-mode-line-prefix "")
(projectile-mode-line-function (lambda ()
(when buffer-file-name
(format " ‹%s›"
(projectile-project-name)))))
:config
(projectile-mode)
;; Workaround for https://github.com/bbatsov/projectile/issues/1816
(defun amk-safe-projectile-expand-file-name-wildcard (old-func &rest args)
"Swallow errors and return the same fallback as original function."
(condition-case nil
(apply old-func args)
(file-error (expand-file-name (car args) (cadr args)))))
(advice-add #'projectile-expand-file-name-wildcard :around #'amk-safe-projectile-expand-file-name-wildcard))
(use-package counsel-projectile
:demand t
:after (counsel projectile)
:bind (("C-c j" . counsel-projectile-rg)
("C-c g" . counsel-projectile-find-file))
:config
(defun counsel-projectile-rg--no-tramp (old-function &rest args)
(let ((path (or (buffer-file-name)
list-buffers-directory)))
(if (tramp-tramp-file-p path)
(let* ((vec (tramp-dissect-file-name default-directory))
(host (tramp-file-name-host vec))
(local (tramp-file-name-localname vec)))
(if (string= host (system-name))
;; If it's a tramp buffer BUT the file is a local one (using
;; tramp for sudo) then we can still make things work by
;; pretending for this invocation that we aren't in tramp.
(let ((default-directory local))
(apply old-function args))
(message "counsel-projectile-rg doesn't work over tramp")))
(apply old-function args))))
(advice-add #'counsel-projectile-rg :around #'counsel-projectile-rg--no-tramp)
(counsel-projectile-modify-action 'counsel-projectile-switch-project-action
'((default "v")))
(counsel-projectile-mode))
(use-package edit-string
:ensure nil
:demand t
:load-path "lisp"
:bind (:map
prog-mode-map
("C-c '" . edit-string-at-point))
:config
(defun amk-sql-p ()
(re-search-forward "\\bSELECT\\b" nil t))
(add-to-list 'edit-string-guess-mode-alist '(amk-sql-p . sql-mode))
(defun amk-js-p ()
(re-search-forward "\\b\\(function\\|var\\|let\\|const\\|return\\)\\b" nil t))
(add-to-list 'edit-string-guess-mode-alist '(amk-js-p . js-mode)))
(use-package typescript-mode
:after edit-string
:ensure-system-package ((npm . npm10)
(typescript-language-server . "sudo npm install -g typescript-language-server"))
:bind (:map typescript-mode-map
;; Alternate binding to avoid clobber via `edit-string-at-point'
("C-c C-'" . typescript-convert-to-template)
("C-c '" . edit-string-at-point))
:hook (typescript-mode . lsp-deferred)
:custom
(typescript-autoconvert-to-template-flag t)
(typescript-indent-level 2))
(use-package typescript-ts-mode
:ensure nil
:hook ((typescript-ts-mode . lsp-deferred)
(tsx-ts-mode . lsp-deferred)))
(use-package jest-test-mode
:hook (typescript-mode js-mode typescript-ts-mode)
:diminish (jest-test-mode)
:config
(put 'jest-test-command-string 'safe-local-variable #'stringp))
(use-package svelte-mode
:defer t
:ensure-system-package ((npm . npm10)
(svelteserver . "sudo npm install -g svelte-language-server"))
:hook (svelte-mode . lsp-deferred))
(use-package go-mode
:defer t
:hook ((go-mode . (lambda ()
(add-hook 'before-save-hook #'gofmt-before-save nil t)))
(go-mode . lsp-deferred))
:ensure-system-package gopls)
(use-package groovy-mode
:defer t)
(use-package python
:ensure nil
:mode ("\\.py\\'" . python-mode)
:hook (python-mode . lsp-deferred)
:ensure-system-package ((python3 . python312)
(pylsp . py312-python-lsp-server)))
(use-package py-autopep8
:after python
:ensure-system-package (autopep8 . py311-autopep8)
:hook (python-mode . py-autopep8-mode))
(use-package pyvenv
:commands (pyvenv-activate pyvenv-workon))
(use-package hideshow
:ensure nil
:diminish hs-minor-mode
:bind ("C-c \\" . hs-toggle-hiding)
:hook (prog-mode . hs-minor-mode)
:config
(add-to-list 'hs-special-modes-alist '(sh-mode "{" "}" "#" nil nil)))
(use-package dockerfile-mode