-
Notifications
You must be signed in to change notification settings - Fork 0
/
after-init.el
2387 lines (2134 loc) · 91.7 KB
/
after-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
;;; after-init.el --- commontap -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(eval-when-compile
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))
(exordium-require 'init-lib)
(exordium-require 'init-prefs)
(exordium-require 'init-environment)
(defgroup pk/exordium nil
"PKs Exordium extras."
:group 'local)
(when (boundp 'native-comp-async-report-warnings-errors)
(setq native-comp-async-report-warnings-errors 'silent))
(use-package modus-themes
:unless (bound-and-true-p exordium-theme)
:demand t
:autoload (modus-themes--current-theme-palette)
:init
(use-package custom
:ensure nil
:after (modus-themes)
:custom
(custom-safe-themes
(progn
(append custom-safe-themes
(cl-remove-if (lambda (theme)
(member theme custom-safe-themes))
(mapcar #'symbol-name
modus-themes-items))))))
(use-package org-src
:ensure org
:defer t
:custom
(org-src-block-faces '(("clojure" modus-themes-nuanced-magenta)
("clojurescript" modus-themes-nuanced-magenta)
("elisp" modus-themes-nuanced-magenta)
("emacs-lisp" modus-themes-nuanced-magenta)
("lisp" modus-themes-nuanced-magenta)
("scheme" modus-themes-nuanced-magenta)
("c" modus-themes-nuanced-blue)
("c++" modus-themes-nuanced-blue)
("fortran" modus-themes-nuanced-blue)
("java" modus-themes-nuanced-blue)
("awk" modus-themes-nuanced-yellow)
("bash" modus-themes-nuanced-yellow)
("ipython" modus-themes-nuanced-yellow)
("js" modus-themes-nuanced-yellow)
("perl" modus-themes-nuanced-yellow)
("python" modus-themes-nuanced-yellow)
("r" modus-themes-nuanced-yellow)
("ruby" modus-themes-nuanced-yellow)
("sed" modus-themes-nuanced-yellow)
("sh" modus-themes-nuanced-yellow)
("shell" modus-themes-nuanced-yellow)
("zsh" modus-themes-nuanced-yellow)
("dot" modus-themes-nuanced-green)
("html" modus-themes-nuanced-green)
("latex" modus-themes-nuanced-green)
("org" modus-themes-nuanced-green)
("plantuml" modus-themes-nuanced-green)
("xml" modus-themes-nuanced-green)
("css" modus-themes-nuanced-red)
("scss" modus-themes-nuanced-red)
("sql" modus-themes-nuanced-red)
("conf" modus-themes-nuanced-cyan)
("docker" modus-themes-nuanced-cyan)
("json" modus-themes-nuanced-cyan)
("makefile" modus-themes-nuanced-cyan)
("yaml" modus-themes-nuanced-cyan))))
;; Add all your customizations prior to loading the themes
(defun pk/modus-themes--custom-faces ()
(require 'modus-themes nil t)
;; The following is an expanded macro `modus-themes-with-colors',
;; but need it so that it will evaluate when function is executed
;; -- begin of macro preface --
(let* ((sym (gensym))
(colors (mapcar #'car (modus-themes--current-theme-palette))))
(eval
`(let* ((c '((class color) (min-colors 256)))
(,sym (modus-themes--current-theme-palette :overrides))
,@(mapcar (lambda (color)
(list color
`(let* ((value (car (alist-get ',color ,sym))))
(if (or (stringp value)
(eq value 'unspecified))
value
(car (alist-get value ,sym))))))
colors))
(ignore c ,@colors)
;; -- end of macro preface --
(setq helm-rg--color-format-argument-alist
`((red :cmd-line "red"
:text-property ,(face-attribute 'modus-themes-completion-match-0 :foreground))))
(setopt highlight-symbol-colors `(,bg-yellow-intense
,bg-magenta-intense
,bg-cyan-intense
,bg-green-intense
,bg-red-intense
,bg-blue-intense))
(custom-theme-set-faces
'user
`(fixed-pitch ((t (,@c :family ,(face-attribute 'default :family) :height ,(face-attribute 'default :height)))))
`(scroll-bar ((t (,@c :background ,bg-inactive :foreground ,fg-dim))))
`(fill-column-indicator ((t (,@c :height 1.0 :background ,bg-main :foreground ,bg-inactive))))
`(exordium-org-work ((t (,@c :inherit 'org-todo :foreground ,rust))))
`(exordium-org-wait ((t (,@c :inherit 'org-todo :foreground ,cyan))))
`(exordium-org-stop ((t (,@c :inherit 'org-todo :foreground ,fg-dim))))
`(iedit-occurrence
((t (,@c :inherit nil
:box (:line-width -2 ,@(when-let* ((color (face-attribute 'modus-themes-completion-match-0 :foreground))
((not (eq color 'unspecified))))
(list :color color)))))))
`(iedit-read-only-occurrence
((t (,@c :inherit nil
:box (:line-width -2 ,@(when-let* ((color (face-attribute 'modus-themes-completion-match-1 :foreground))
((not (eq color 'unspecified))))
(list :color color)))))))
`(highlight-symbol-face ((t (,@c :background ,bg-cyan-nuanced))))
`(aw-leading-char-face ((t (,@c :foreground ,red-intense :bold t :height 1.5))))
;; Redoing helm, inspired by last removed version in:
;; https://github.com/protesilaos/modus-themes/commit/1efaa7ef79682ec13493351d52ed1b339fb6ace2
`(helm-selection ((t (,@c :inherit modus-themes-completion-selected))))
`(helm-match ((t (,@c :inherit modus-themes-completion-match-0))))
`(helm-match-item ((t (,@c :inherit modus-themes-completion-match-0))))
`(helm-visible-mark ((t (,@c :inherit modus-themes-subtle-cyan))))
`(helm-source-header ((t (,@c :inherit bold :foreground ,fg-main))))
`(helm-header-line-left-margin ((t (,@c :inherit bold :foreground ,yellow-intense))))
`(helm-candidate-number ((t (,@c :foreground ,cyan))))
`(helm-candidate-number-suspended ((t (,@c :foreground ,yellow))))
`(helm-locate-finish ((t (,@c :inherit success))))
`(helm-swoop-target-word-face ((t (,@c :inherit modus-themes-completion-match-0))))
`(helm-swoop-target-line-face ((t (,@c :inherit highlight :extend t))))
`(helm-swoop-target-line-block-face ((t (,@c :inherit highlight :extend t))))
`(helm-moccur-buffer ((t (,@c :inherit bold :foreground ,name))))
`(helm-resume-need-update ((t (,@c :inherit pulse-highlight-start-face))))
`(helm-grep-command ((t (,@c :inherit helm-source-header))))
`(helm-grep-match ((t (,@c :inherit modus-themes-completion-match-0))))
`(helm-grep-lineno ((t (,@c :inherit shadow))))
`(helm-grep-finish ((t (,@c :inherit bold))))
`(helm-buffer-archive ((t (,@c :foreground ,warning))))
`(helm-buffer-directory ((t (,@c :inherit dired-directory))))
`(helm-buffer-file ((t (,@c :foreground ,fg-main))))
`(helm-buffer-modified ((t (,@c :foreground ,yellow-warmer))))
`(helm-buffer-not-saved ((t (,@c :foreground ,red-warmer))))
`(helm-buffer-process ((t (,@c :foreground ,accent-1))))
`(helm-buffer-saved-out ((t (,@c :inherit bold :background ,bg-cyan-nuanced :foreground ,red))))
`(helm-buffer-size ((t (,@c :inherit shadow))))
`(helm-ff-backup-file ((t (,@c :inherit shadow))))
`(helm-ff-denied ((t (,@c :inherit dired-warning))))
`(helm-ff-directory ((t (,@c :inherit dired-directory))))
`(helm-ff-dirs ((t (,@c :inherit bold :foreground ,blue-cooler))))
`(helm-ff-dotted-directory ((t (,@c :inherit (dired-header dired-directory)))))
`(helm-ff-dotted-symlink-directory ((t (,@c :inherit (dired-symlink dired-directory)))))
`(helm-ff-executable ((t (,@c :foreground ,accent-1))))
`(helm-ff-file ((t (,@c :foreground ,fg-main))))
`(helm-ff-file-extension ((t (,@c :foreground ,variable))))
`(helm-ff-invalid-symlink ((t (,@c :inherit dired-broken-symlink))))
`(helm-ff-suid ((t (,@c :inherit dired-set-id))))
`(helm-ff-symlink ((t (,@c :inherit dired-symlink))))
`(helm-ff-pipe ((t (,@c :inherit dired-special))))
`(helm-ff-socket ((t (,@c :inherit dired-special))))
`(helm-ff-truename ((t (,@c :foreground ,fg-main))))
`(helm-ff-prefix ((t (,@c :background ,bg-ochre :foreground ,magenta))))
`(helm-history-deleted ((t (,@c :inherit shadow :strike-through t))))
`(helm-history-remote ((t (,@c :background ,bg-ochre))))
`(helm-delete-async-message ((t (,@c :inherit bold :foreground ,magenta))))
`(helm-ff-rsync-progress ((t (,@c :inherit bold :foreground ,red-warmer))))
`(helm-rg-match-text-face ((t (,@c :inherit modus-themes-completion-match-0))))
`(helm-rg-line-number-match-face ((t (,@c :inherit helm-grep-lineno))))
`(helm-rg-file-match-face ((t (,@c :inherit helm-moccur-buffer))))
`(helm-rg-preview-line-highlight ((t (,@c :inherit highlight :extend t))))
`(helm-rg-title-face ((t (,@c :inherit helm-source-header))))
`(helm-rg-base-rg-cmd-face ((t (,@c :inherit helm-source-header))))
`(helm-rg-active-arg-face ((t (,@c :foreground ,yellow-warmer))))
`(helm-rg-inactive-arg-face ((t (,@c :foreground ,fg-dim :weight thin))))
`(helm-rg-extra-arg-face ((t (,@c :foreground ,yellow-cooler))))
`(helm-rg-directory-cmd-face ((t (,@c :inherit helm-ff-directory))))
`(helm-rg-directory-header-face ((t (,@c :inherit helm-ff-directory))))
`(helm-M-x-key ((t (,@c :inherit modus-themes-key-binding))))
`(helm-M-x-short-doc ((t (,@c :inherit completions-annotations))))))))
(when (bound-and-true-p ace-window-posframe-mode)
(posframe-delete-all)))
:custom
(modus-themes-italic-constructs t)
(modus-themes-mixed-fonts t)
(modus-themes-variable-pitch-ui t)
(modus-themes-completions '((matches . (extrabold background intense))
(selection . (semibold accented intense))
(popup . (semibold accented))))
(modus-themes-headings `((agenda-date . (,exordium-height-plus-1))
(agenda-structure . (variable-pitch ,exordium-height-plus-2))
(0 . (,exordium-height-plus-4))
(1 . (variable-pitch rainbow regular ,exordium-height-plus-4))
(2 . (variable-pitch rainbow regular ,exordium-height-plus-3))
(3 . (variable-pitch rainbow regular ,exordium-height-plus-2))
(4 . (variable-pitch rainbow regular ,exordium-height-plus-1))
(t . (variable-pitch rainbow regular))))
:config
(setopt modus-themes-common-palette-overrides
`(;; (border-mode-line-active unspecified)
;; (border-mode-line-inactive unspecified)
(bg-mode-line-active bg-blue-subtle)
(fg-mode-line-active fg-main)
(fg-region unspecified)
(overline-heading-1 fg-main)
,@modus-themes-preset-overrides-faint))
:hook
(modus-themes-after-load-theme . pk/modus-themes--custom-faces)
:bind
("<f5>" . modus-themes-toggle))
(use-package auto-dark
:demand t
:diminish
:custom
(auto-dark-themes '((modus-vivendi) (modus-operandi)))
(auto-dark-detection-method (when (getenv "ci_tests")
'none))
:hook
(auto-dark-dark-mode . pk/modus-themes--custom-faces)
(auto-dark-light-mode . pk/modus-themes--custom-faces)
:config
(auto-dark-mode)
(pk/modus-themes--custom-faces))
;; emacs mac ports customisations, per
;; https://github.com/railwaycat/homebrew-emacsmacport
;; Keybonds
(when exordium-osx
(global-set-key [(hyper a)] 'mark-whole-buffer)
(global-set-key [(hyper v)] 'yank)
(global-set-key [(hyper c)] 'kill-ring-save)
(global-set-key [(hyper s)] 'save-buffer)
(global-set-key [(hyper l)] 'goto-line)
(global-set-key [(hyper w)]
(lambda () (interactive) (delete-window)))
(global-set-key [(hyper z)] 'undo)
(global-set-key [(hyper q)] 'save-buffers-kill-emacs)
(setq mac-emulate-three-button-mouse t)
(setq mac-option-modifier 'meta)
(setq mac-right-option-modifier 'meta)
(setq mac-command-modifier 'hyper)
(setq mac-frame-tabbing nil)
(defvar find-function-C-source-directory)
(setq find-function-C-source-directory
(when-let* ((emacs-src-dir
(file-name-concat (getenv "HOME") "gh" "mituharu" "emacs-mac" "src"))
((file-exists-p emacs-src-dir)))
emacs-src-dir))
;; Workaround to prevent freezes when frame is resized during startup
;; in Emacs-29.4 on macOS 15 Sequoia
(add-hook 'kill-emacs-hook #'(lambda ()
(dolist (frame (frame-list))
(when (eq 'fullscreen
(frame-parameter frame 'fullscreen))
(set-frame-parameter frame 'fullscreen nil))))))
(defun pk/iterm-cut-base64 (text)
"Take TEXT and send it to iTerm2 to copy."
(interactive)
(let ((base-64 (base64-encode-string text :no-line-break)))
(send-string-to-terminal (concat "\e]1337;Copy=:" base-64 "\a"))))
(defun pk/dispatch-cut-function (orig-fun text)
; checkdoc-params: (orig-fun)
"Dispatch the TEXT to the appropriate `interprogram-cut-function'."
(if (display-graphic-p)
(funcall orig-fun text)
(pk/iterm-cut-base64 text)))
(advice-add interprogram-cut-function :around #'pk/dispatch-cut-function)
;; https://ylluminarious.github.io/2019/05/23/how-to-fix-the-emacs-mac-port-for-multi-tty-access/
(use-package mac-pseudo-daemon
:hook
((after-init . mac-pseudo-daemon-mode)
(after-init . server-start)))
(setq disabled-command-function nil)
(setq confirm-kill-emacs 'y-or-n-p)
(setq-default display-line-numbers-widen t)
(use-package window
:ensure nil
:custom
;; Typical full screen window on built in macBook Air M2 13" is 179
;; columns. This includes line numbers and fringes. Yet windows as small as
;; 160 seems to be quite all right fitting horizontal split. On the other
;; hand, typical full screen window height on external 4k screen connected to
;; the same laptop is 88 and 55 on the built in panel. See
;; `split-window-sensibly' doc. With setting
;; `split-window-preferred-direction' to `longest' this setup basically
;; forces a horizontal split, but only up to 2 windows in a frame, followed
;; by an vertical split. Values used are compared against:
;;
;; (window-width (selected-window))
;; (window-height (selected-window))
;;
;; For testing use:
;;
;; (split-window-sensibly)
(split-height-threshold 55)
(split-width-threshold 160))
(use-package helm-core
:ensure nil
:custom
(helm-split-width-threshold split-width-threshold))
;; ITERM2 MOUSE SUPPORT from https://www.emacswiki.org/emacs/iTerm2
(unless window-system
(require 'mouse)
(xterm-mouse-mode t)
(defun track-mouse (_)))
(defconst pk/shrug-string "¯\\_(ツ)_/¯")
(defun pk/shrug ()
"Insert ¯\\_(ツ)_/¯ at point."
(interactive)
(insert (if (derived-mode-p 'markdown-mode)
(replace-regexp-in-string (rx (group (or "\\" "_")))
(rx "\\" (backref 1))
pk/shrug-string)
pk/shrug-string)))
(defun pk/shrug-as-kill ()
"Add ¯\\_(ツ)_/¯ to kill buffer."
(interactive)
(kill-new pk/shrug-string))
;; @todo remove when exordium has it
;; (use-package helm
;; :diminish
;; :custom
;; (helm-split-window-other-side-when-one-window 'right)
;; (helm-M-x-show-short-doc t)
;; :bind
;; (("C-x b" . #'helm-buffers-list)
;; :map ctl-x-map
;; ("b" . #'helm-buffers-list)
;; :map helm-command-map
;; ("g" . #'helm-google-suggest)))
;; @todo : remove when exordium has it
;; (use-package elisp-mode
;; :ensure nil
;; :bind
;; (:map emacs-lisp-mode-map
;; ("M-." . #'xref-find-definitions)
;; ("M-," . #'xref-pop-marker-stack)
;; ("M-r" . #'xref-find-references)
;; ("M-?" . #'helpful-at-point)))
(use-package eldoc
:ensure nil
:diminish)
(use-package flycheck
:autoload (flycheck-add-next-checker
flycheck-sanitize-errors
flycheck-dedent-error-messages
flycheck-rx-to-string
flycheck-buffer-saved-p
flycheck-checker-get)
:functions (pk/loaddefs-generate--filter-flycheck)
:init
(use-package project
:ensure nil
:autoload (project-root))
(defun pk/loaddefs-generate--filter-flycheck (args)
"Append flycheck_ files to ignored files in 2nd arg in ARGS.
When such temporary flycheck_ files are present they can be
scrubbed for autoloads clobbering real declarations. This only
happens in `project' directories, such that it shouldn't kick in
packages are reinstalled from MELPA."
(when-let* ((default-directory (nth 0 args))
(project-root (project-root (project-current))))
(setf (nth 2 args)
(append (nth 2 args)
(directory-files
project-root t
(rx string-start "flycheck_"
(one-or-more (or alnum punct)) ".el" string-end)))))
args)
:config
(advice-add 'loaddefs-generate
:filter-args #'pk/loaddefs-generate--filter-flycheck)
(flycheck-define-checker pk/python-blocklint
"Blocklint: blocks usage of non-inclusive wording.
See: https://github.com/PrincetonUniversity/blocklint"
:command ("blocklint" "--max-issue-threshold" "1" source-inplace)
:error-patterns
((error line-start (file-name) ":" line ":" column ": " (message) line-end))
:modes (python-mode python-ts-mode))
(add-to-list 'flycheck-checkers 'pk/python-blocklint 'append)
(mapc (lambda (checker)
(flycheck-add-next-checker checker '(warning . pk/python-blocklint) t))
'(python-flake8 python-pylint python-pycompile))
(flycheck-define-checker pk/sorbet-homebrew
"Sorbet for Homebrew"
:command ("bundle" "exec" "srb" "tc"
"--color" "never"
"--no-error-count"
"--no-error-sections"
"--suppress-error-code" "1001"
"--suppress-error-code" "1003")
:working-directory
(lambda (_)
(when-let* ((homebrew-prefix (getenv "HOMEBREW_PREFIX")))
(file-name-concat homebrew-prefix "Library" "Homebrew")))
:predicate (lambda () (flycheck-buffer-saved-p))
:error-patterns
((error
line-start (file-name) ":" (optional line ": ")
(message (one-or-more not-newline)
" https://srb.help/" (id (one-or-more digit)) "\n"
(optional
(one-or-more " ") (one-or-more digit) " |"
(one-or-more " ") (one-or-more not-newline) "\n"
(one-or-more " ") (one-or-more "^") (one-or-more "\n")))
line-end))
:error-filter
(lambda (errors)
(flycheck-sanitize-errors (flycheck-dedent-error-messages errors)))
:error-explainer
(lambda (err)
(let ((error-code (flycheck-error-id err))
(url "https://srb.help/%s"))
(and error-code `(url . ,(format url error-code)))))
:modes (ruby-mode ruby-ts-mode enh-ruby-mode)
:enabled
(lambda ()
(when-let* ((buffer-file-name)
(default-directory (file-name-directory buffer-file-name))
(homebrew-prefix (getenv "HOMEBREW_PREFIX"))
(project-current (project-current))
((string-match-p (rx-to-string `(seq string-start ,homebrew-prefix) t)
(project-root (project-current)))))
;; Ensure sorbet and gems are up to date, by running "brew typecheck"
(let ((display-buffer-alist '((t . (display-buffer-no-window)))))
(async-shell-command "brew typecheck"))
t)))
(add-to-list 'flycheck-checkers 'pk/sorbet-homebrew 'append)
(flycheck-add-next-checker 'ruby '(warning . pk/sorbet-homebrew) t)
;; Fix for https://github.com/flycheck/flycheck/issues/2092
(let* ((p '(error line-start (file-name) ":"
(zero-or-more whitespace) "Error:" (zero-or-more whitespace)
(message (or "End of file during parsing"
(seq "Invalid read syntax:" (zero-or-more (not ",")))))
(optional "," (zero-or-more whitespace) line
"," (zero-or-more whitespace) column)))
;; pre-compile pattern like `flycheck-define-command-checker' does
(pattern (cons (flycheck-rx-to-string `(and ,@(cdr p))
'no-group)
(car p))))
(unless (cl-find-if (lambda (p)
(and (eq (cdr p) (cdr pattern))
(equal (car p) (car pattern))))
(flycheck-checker-get 'emacs-lisp 'error-patterns))
(push pattern (flycheck-checker-get 'emacs-lisp 'error-patterns)))))
(use-package clang-format
:defer t
:config
(use-package cc-mode :ensure nil
:bind
(:map c-mode-map
("C-c C-f" . #'clang-format-region)
:map c++-mode-map
("C-c C-f" . #'clang-format-region)))
(use-package c-ts-mode :ensure nil
:bind
(:map c-ts-mode-map
("C-c C-f" . #'clang-format-region)
:map c++-ts-mode-map
("C-c C-f" . #'clang-format-region))))
;;@todo: disable printing from eglot - perhaps set `eglot-events-buffer-size' 0
(use-package eglot
:exordium-force-elpa "gnu"
:after flycheck
:init
(defun pk/eglot--disable-standard-c/c++-checkers ()
(mapc
(lambda (checker)
(if eglot--managed-mode
(add-to-list 'flycheck-disabled-checkers checker)
(delete checker flycheck-disabled-checkers)))
'(c/c++-clang c/c++-gcc)))
(global-unset-key (kbd "C-c e"))
(global-unset-key (kbd "C-c E"))
:hook
(eglot-managed-mode . pk/eglot--disable-standard-c/c++-checkers)
:custom
(eglot-extend-to-xref t)
:bind
(("C-c e e" . eglot)
:map eglot-mode-map
("C-c e r" . eglot-rename)
("C-c e a" . eglot-code-actions)
("C-c e q" . eglot-shutdown)
("C-c e ?" . eldoc)
("C-c e h" . eldoc)
("C-c e L" . helm-flycheck)
("C-c e l" . flycheck-list-errors)
("C-c e C" . eglot-show-workspace-configuration)
("C-c e S" . eglot-signal-didChangeConfiguration)
("C-c e x r" . eglot-reconnect)
("C-c e x l" . eglot-list-connections)
("C-c e x E" . eglot-stderr-buffer)
("C-c e x e" . eglot-events-buffer)))
(use-package flycheck-eglot
:after (flycheck eglot)
:defer t
:custom
(flycheck-eglot-exclusive nil)
:config
(global-flycheck-eglot-mode 1))
(use-package eldoc
:ensure nil
:defer t
:custom
(eldoc-idle-delay 0.25)
(eldoc-echo-area-prefer-doc-buffer t))
(use-package dumb-jump
:defer t
:config
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate))
;; @todo: remove when exordium has it
;; (use-package orderless
;; :custom
;; (helm-completion-style 'emacs)
;; (completion-styles '(orderless basic))
;; (completion-category-overrides '((file (styles basic partial-completion)))))
(use-package ispell
;; :ensure-system-package aspell
:defer t
:custom
;; spell checks as suggested by
;; http://blog.binchen.org/posts/effective-spell-check-in-emacs.html
;; http://blog.binchen.org/posts/how-to-spell-check-functionvariable-in-emacs.html
(ispell-program-name "aspell")
(ispell-extra-args `("--sug-mode=ultra"
"--run-together"
"--run-together-limit=6"
,@(when exordium-osx '("--camel-case"))))
(ispell-dictionary "british"))
(use-package flyspell
:diminish
:defer t
:config
(setq flyspell-issue-message-flag nil)
:hook
((git-commit-mode . flyspell-mode)
(org-mode . flyspell-mode)
(text-mode . flyspell-mode))
:bind
(([remap ispell-word] . #'flyspell-correct-wrapper)))
(use-package flyspell-correct-helm
:after (flyspell flyspell-correct)
:defer t
:autoload (flyspell-correct-helm)
:custom
(flyspell-correct-interface #'flyspell-correct-helm))
(set-time-zone-rule "/usr/share/zoneinfo/Europe/London")
(use-package groovy-mode
:defer t
:init
(defun pk/groovy-mode--create-test-files ()
(setq-local projectile-create-missing-test-files t))
;; Jenkinsfile is registered in autoloads of groovy-mode, let's remove it
;; and make it clear that jenkinsfile-mode will take over
(setq auto-mode-alist
(cl-remove-if (lambda (entry)
(and (string-match-p "Jenkinsfile" (car entry))
(eq 'groovy-mode (cdr entry))))
auto-mode-alist)) :hook
((groovy-mode . yas-minor-mode)
(groovy-mode . pk/groovy-mode--create-test-files)))
(use-package jenkinsfile-mode
:after (groovy-mode)
:init
(use-package flycheck
:autoload (flycheck-add-mode))
:config
(flycheck-add-mode 'groovy 'jenkinsfile-mode))
(use-package yasnippet
:defines (yas-snippet-dirs)
:defer t
:config
(when-let* ((file-name (or load-file-name
(buffer-file-name)))
(snippets-directory (file-name-concat
(file-name-directory file-name)
"snippets"))
((file-directory-p snippets-directory)))
(customize-set-variable 'yas-snippet-dirs
(cons snippets-directory yas-snippet-dirs)
"Customized with use-package yasnippet")))
(use-package projectile
:autoload (projectile-project-name
projectile-register-project-type
projectile-verify-file
projectile-verify-file-wildcard)
:functions (pk/projectile--emacs-package-build
pk/projectile--emacs-package-project-p)
:init
(defun pk/projectile--emacs-package-project-p (&optional dir)
(or (projectile-verify-file "Cask" dir)
(projectile-verify-file "init.el" dir) ;; Exordium!
(projectile-verify-file "lisp" dir)
(and (projectile-verify-file "src" dir)
(projectile-verify-file-wildcard "src/*.el" dir))))
(defun pk/projectile--emacs-package-build ()
(when-let* ((project-name (projectile-project-name))
(pkg-desc (cadr
(cl-find-if
(lambda (package)
(string-match-p
(rx string-start
(literal (symbol-name (car package)))
(zero-or-one ".el")
string-end)
project-name))
package-alist))))
(package-vc-rebuild pkg-desc)))
(defun pk/projectile--emacs-package-test ()
(call-interactively #'ert))
:config
(projectile-register-project-type
'pk/emacs-package
#'pk/projectile--emacs-package-project-p
:install #'pk/projectile--emacs-package-build
:test "make compile lint test"
:test-dir "test/"
:test-suffix ".t"))
(use-package yaml-mode
:defer t
:mode (rx ".y" (zero-or-one "a") "ml.template" string-end))
(use-package rust-mode
:defer t)
(use-package compile
:defer t
:ensure nil
:hook
(compilation-filter . ansi-color-compilation-filter)
:custom
(ansi-color-for-compilation-mode t)
(compilation-scroll-output 'first-error))
(defconst pk/gc-cons-threshold (* 16 1024 1024))
;; From DOOM FAQ:
;; https://github.com/hlissner/doom-emacs/blob/64922dd/docs/faq.org#L215-L225
(defun pk/defer-garbage-collection ()
"Use max value for gc, when in minibuffer.
It's so it won't slow expensive commands and completion frameworks."
(setf gc-cons-threshold most-positive-fixnum))
(defun pk/restore-garbage-collection ()
"Get back to the original gc threshold.
Defer it so that commands launched immediately after will enjoy the benefits."
(run-at-time
1 nil (lambda () (setf gc-cons-threshold pk/gc-cons-threshold))))
(add-hook 'minibuffer-setup-hook #'pk/defer-garbage-collection)
(add-hook 'minibuffer-exit-hook #'pk/restore-garbage-collection)
;; garbage collect magic hack from https://gitlab.com/koral/gcmh
;; tuned like in DOOM:
;; https://github.com/hlissner/doom-emacs/blob/db16e5c/core/core.el#L350-L351
;; https://github.com/hlissner/doom-emacs/blob/ed1996e/modules/lang/org/config.el#L548
(use-package gcmh
:diminish
:custom
(gcmh-idle-delay 5)
(gcmh-high-cons-threshold pk/gc-cons-threshold)
:hook
;; TODO: this also needs to be after a buffer switch, including current value of `gc-cons-threshold'
;; likely in `buffer-list-update-hook'
(org-mode . (lambda ()
(setq-local gcmh-high-cons-threshold (* 2 pk/gc-cons-threshold))))
(after-init . gcmh-mode))
(use-package deft
:config
(setq deft-extensions '("org" "txt" "md"))
(setq deft-default-extension "org")
(setq deft-use-filename-as-title t)
(setq deft-use-filter-string-for-filename t)
(setq deft-auto-save-interval 0))
;; (use-package posframe
;; :defer t)
;; (use-package ace-window
;; :defer t
;; :after (posframe)
;; :diminish "AW"
;; :custom
;; (aw-scope 'frame)
;; (aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
;; (aw-translate-char-function #'(lambda (c)
;; (if (eq ?\M-o c) ?n c)))
;; :config
;; (global-set-key (kbd "M-o") #'ace-window)
;; (when (and (require 'posframe nil t) (posframe-workable-p))
;; (ace-window-posframe-mode)))
(defun pk/read-only-mode-maybe ()
"Turn on `read-only-mode' if the current buffer visits Emacs or ELPA file."
(when-let* ((file (buffer-file-name))
((string-match-p
(rx-to-string
`(seq string-start
(or ,(expand-file-name
(file-name-parent-directory data-directory))
,(expand-file-name
(file-name-as-directory package-user-dir)))))
file)))
(read-only-mode)))
(add-hook 'find-file-hook #'pk/read-only-mode-maybe)
(use-package desktop
:ensure nil
:config
;; Don't save some buffers in desktop
(add-to-list 'desktop-modes-not-to-save 'dired-mode)
(add-to-list 'desktop-modes-not-to-save 'Info-mode)
(add-to-list 'desktop-modes-not-to-save 'info-lookup-mode)
(add-to-list 'desktop-modes-not-to-save 'fundamental-mode)
(add-to-list 'desktop-modes-not-to-save 'helpful-mode)
(add-to-list 'desktop-modes-not-to-save 'helm-major-mode)
(add-to-list 'desktop-modes-not-to-save 'magit-mode)
(add-to-list 'desktop-modes-not-to-save 'magit-log-mode)
(add-to-list 'desktop-modes-not-to-save 'magit-status-mode)
(add-to-list 'desktop-modes-not-to-save 'magit-process-mode)
(add-to-list 'desktop-modes-not-to-save 'magit-diff-mode)
(add-to-list 'desktop-modes-not-to-save 'forge-pullreq-mode)
(add-to-list 'desktop-modes-not-to-save 'forge-notifications-mode)
(add-to-list 'desktop-modes-not-to-save 'difftastic-mode)
:custom
(desktop-files-not-to-save
(rx-to-string `(or
;; original value of `desktop-files-not-to-save'
(seq string-start "/" (zero-or-more (not (any "/" ":"))) ":")
(seq "(ftp)" string-end)
;; skip also Emacs and ELPA
(seq string-start
(or ,(expand-file-name
(file-name-parent-directory data-directory))
,(expand-file-name
(file-name-as-directory package-user-dir)))))))
(desktop-restore-eager 8)
(desktop-load-locked-desktop (if (version< "29" emacs-version) 'check-pid 'ask)))
(use-package savehist
:ensure nil
:custom
(savehist-additional-variables '(Info-history
Info-search-history
bookmark-history
command-history
compile-command
compile-history
dired-regexp-history
dired-shell-command-history
extended-command-history
face-name-history
file-name-history
ivy-history
kill-ring
log-edit-comment-ring
minibuffer-history
query-replace-history
read-expression-history
recentf-list
regexp-search-ring
register-alist
search-ring
shell-command-history
swiper-history))
:config
(savehist-mode))
(use-package python
:ensure nil
:init
(use-package treesit
:ensure nil
:autoload (treesit-node-text))
(defun pk/python-mode--set-fill-column()
(when-let* ((project-root (project-root (project-current)))
;; do not override directory local variable
((not
(alist-get
'fill-column
(alist-get
major-mode
(alist-get
(car (alist-get
(file-name-as-directory project-root)
dir-locals-directory-cache nil nil #'string=))
dir-locals-class-alist)))))
(pyproject-toml (expand-file-name "pyproject.toml" project-root))
((file-exists-p pyproject-toml))
(buffer (current-buffer)))
(with-temp-buffer
(insert-file-contents pyproject-toml)
(when-let* ((line-length-node
(alist-get
'line-length
(treesit-query-capture
'toml
'(((table
(dotted_key) @table-name
(pair (bare_key) @key "=" (integer) @line-length))
(:match "tool\\.\\(ruff\\|black\\)" @table-name)
(:equal "line-length" @key))))))
(line-length (string-to-number
(treesit-node-text line-length-node))))
(with-current-buffer buffer
(setq fill-column line-length))))))
:hook
(python-ts-mode . pk/python-mode--set-fill-column)
:custom
(python-shell-dedicated 'project)
(python-shell-interpreter "python3"))
(use-package toml)
(use-package python-pytest
:after (python)
:bind (:map python-mode-map
("C-c t" . python-pytest-dispatch))
:custom
(python-pytest-executable
(concat python-shell-interpreter " -m pytest")))
(use-package pip-requirements)
;; See https://blog.adam-uhlir.me/python-virtual-environments-made-super-easy-with-direnv-307611c3a49a
;; for layout thing
(use-package direnv
;; :ensure-system-package direnv
:config
(direnv-mode))
(use-package compile
:ensure nil
:config
;; To ignore: PipDeprecationWarning: DEPRECATION:
;; file:///.#egg=package.name>=0.dev contains an egg fragment with a non-PEP
;; 508 name pip 25.0 will enforce this behaviour change. A possible
;; replacement is to use the req @ url syntax, and remove the egg
;; fragment. Discussion can be found at
;; https://github.com/pypa/pip/issues/11617
(add-to-list
'compilation-transform-file-match-alist
'("/.*/lib/python[0-9\\.]+/site-packages/pip/_internal/models/link.py\\'" nil)))
;; Diminish some modes
(diminish 'eldoc-mode)
(diminish 'auto-revert-mode)
(diminish 'undo-tree-mode)
(diminish 'git-gutter-mode)
(use-package swiper
:init
(use-package ivy
:defer t
:autoload (ivy-previous-history-element
ivy-previous-line
ivy-exit-with-action)
:init
(defun pk/swiper-C-r (&optional arg)
"Move cursor vertically up ARG candidates.
If the input is empty, select the previous history element instead."
(interactive "p")
(if (string= ivy-text "")
(ivy-previous-history-element 1)
(ivy-previous-line arg))))
(use-package helm-swoop
:defer t
:init
(defun pk/helm-swoop-from-swiper ()
(interactive)
(unless (string= ivy-text "")
(ivy-exit-with-action
(lambda (_)
(helm-swoop :query ivy-text))))))
(use-package iedit
:defer t
:autoload (iedit-lib-cleanup
iedit-start
iedit-done)
:init
(defun pk/swiper-iedit ()
(interactive)
(unless (string= ivy-text "")
(ivy-exit-with-action
(lambda (_)
;; This lambda is basically a copy of `iedit-mode-from-isearch'
(setq mark-active nil)
(run-hooks 'deactivate-mark-hook)
(when iedit-mode
(iedit-lib-cleanup))
(let ((result
(catch 'not-same-length
(iedit-start ivy-text (point-min) (point-max)))))
(cond ((not iedit-occurrences-overlays)
(message "No matches found for %s" ivy-text)
(iedit-done))
((equal result 'not-same-length)
(message "Matches are not the same length.")
(iedit-done)))))))))
:functions (pk/swiper-C-r
pk/swiper-iedit
pk/helm-swoop-from-swiper)
:bind
(("C-s" . #'swiper-isearch)
("C-r" . #'swiper-isearch-backward)
:map swiper-map
("C-r" . #'pk/swiper-C-r)
("C-c ;" . #'pk/swiper-iedit)
("C-S-s" . #'pk/helm-swoop-from-swiper)))
;; Disable some ido hooks for helm mode
(when exordium-helm-everywhere