summary refs log tree commit diff stats
path: root/init.el
blob: ffe7f814d051d9f963088ae5ee8f84d3c45c337c (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
;;; emacs init --- an init for emacs  -*- lexical-binding: t; -*-
;; by C. Duckworth <acdw@acdw.net>
;; URL: https://git.acdw.net/emacs
;; Bankruptcy: 9
;;
;; Everyone is permitted to do whatever they like with this software
;; without limitation.  This software comes without any warranty
;; whatsoever, but with two pieces of advice:
;; - Be kind to yourself.
;; - Make good choices.

(yoke +emacs
  (require* '+emacs '+window '+lisp)
  ;; Settings
  (setc truncate-string-ellipsis "…"
        ring-bell-function #'ignore
        read-file-name-completion-ignore-case t
        comment-auto-fill-only-comments t
        password-cache t
        password-cache-expiry (* 60 60)
        switch-to-buffer-in-dedicated-window 'pop
        switch-to-buffer-obey-display-actions t
        initial-buffer-choice (defun +initial-buffer-choose ()
                                (cond
                                 ((equal (get-buffer "*Messages*")
                                         (other-buffer))
                                  (get-buffer "*scratch*"))
                                 (:else (other-buffer)))))
  ;; "Safe" variables
  (dolist (var+pred
           '((browse-url-browser-function
              ;; All types defined by custom are safe.
              . (lambda (f)
                  ;; Whooooo boy
                  (memq f (mapcar (lambda (i)
                                    (plist-get (cdr i) :value))
                                  (seq-filter
                                   (lambda (i)
                                     (eq (car i) 'function-item))
                                   (cdr (get 'browse-url-browser-function
                                             'custom-type)))))))))
    (put (car var+pred) 'safe-local-variable (cdr var+pred)))
  ;; Keys
  (defkeys t
    "C-x C-k" #'kill-current-buffer
    "C-/" #'undo-only
    "C-?" #'undo-redo
    "C-x C-c" (defun delete-frame-or-quit (arg)
                (interactive "P")
                (cond (arg (delete-frame nil :force))
                      ((= 1 (length (frame-list)))
                       (and (yes-or-no-p "Kill emacs? ")
                            (save-buffers-kill-emacs t)))
                      (:else (delete-frame))))
    "C-x r q" (defun really-quit-emacs (arg)
                (interactive "P")
                (cond (arg (save-buffers-kill-emacs t))
                      (:else (save-buffers-kill-terminal t))))
    "M-SPC" #'+cycle-spacing
    ;; "M-/" #'hippie-expand ; `hippie-completing-read'
    "M-=" #'count-words
    "C-x C-b" #'ibuffer
    "C-x 4 n" #'clone-buffer
    "S-<down-mouse-1>" #'mouse-set-mark
    "C-x 0" #'+delete-window-or-bury-buffer
    ;; "M-j" nil ; `avy'
    "<Scroll_Lock>" nil
    "C-z" nil
    "M-o" #'other-window|switch-buffer
    "C-M-;" #'+lisp-comment-or-uncomment-sexp
    "C-x 5 z" #'suspend-frame
    "C-x f" #'find-file
    "C-c t" (defmap toggle-map
              "A map for toggling various settings."
              "d" (defmap toggle-debug-map
                    "Easily toggle debug flavors."
                    "e" #'toggle-debug-on-error
                    "q" #'toggle-debug-on-quit)
              "w" #'toggle-word-wrap
              "t" #'toggle-truncate-lines
              "c" #'column-number-mode
              "l" #'line-number-mode
              "v" (defmap toggle-view-map
                    "Easily toggle UI elements' views."
                    "c" #'display-fill-column-indicator-mode
                    "l" #'display-line-numbers-mode
                    "m" #'menu-bar-mode
                    "t" #'tool-bar-mode
                    "s" #'scroll-bar-mode)))
  (defkeys text-mode-map
    "C-M-k" #'kill-paragraph
    "C-o" (defun open-paragraph (&optional arg)
            "Open a paragraph after paragraph at point.
A paragraph is defined as continguous non-empty lines of text
surrounded by empty lines, so opening a paragraph means to make
three blank lines, then place the point on the second one.

Called with prefix ARG, open a paragraph before point."
            ;; TODO: Take an integer as ARG, allowing for skipping paragraphs up and down.
            (interactive "*P")
            ;; Go to next blank line.  This /isn't/ `end-of-paragraph-text' because
            ;; that's weird with org, and I'm guessing other modes too.
            (unless (looking-at "^$") (forward-line (if arg -1 +1)))
            (while (and (not (looking-at "^$"))
                        (= 0 (forward-line (if arg -1 +1)))))
            (newline)
            (when arg (newline) (forward-line -2))
            (delete-blank-lines)
            (newline 2)
            (previous-line)))
  ;; Hooks
  (add-hook 'after-save-hook
            #'executable-make-buffer-file-executable-if-script-p)
  (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
  (add-hook 'find-file-not-found-functions #'+auto-create-missing-dirs)
  (add-hook 'text-mode-hook #'abbrev-mode)
  (add-hook 'find-file-hook #'+vc-off-when-remote)
  (add-hook 'prog-mode-hook #'auto-fill-mode)
  ;; Advice
  (add-function :after after-focus-change-function
                #'+save-some-buffers-debounce)
  (define-advice keyboard-escape-quit (:around (fn &rest r) keep-window-open)
    "Don't close quits on `keyboard-escape-quit'."
    (let ((buffer-quit-function #'ignore))
      (apply fn r)))
  ;; Faces
  (set-face-attribute 'default nil :family "Comic Code" :height 100)
  (set-face-attribute 'bold nil :family "Comic Code" :weight 'bold)
  (set-face-attribute 'variable-pitch nil :family "Comic Code")
  ;; Modes
  (winner-mode))

(yoke custom                            ; This is `cus-edit' but meh
  (require '+custom)
  (setf custom-file (private/ "custom.el"))
  (add-to-list* '+custom-allowed-variables
    'safe-local-variable-values
    'warning-suppress-types
    'ispell-buffer-session-localwords)
  (eval-after init
    (+custom-load-some-customizations :noerror)))

;; (yoke modus-themes
;;   (setc modus-themes-bold-constructs t
;;         modus-themes-italic-constructs t
;;         modus-themes-headings '((1 monochrome bold italic)
;;                                 (2 monochrome bold)
;;                                 (3 monochrom italic)
;;                                 (t monochrome)))
;;   (defhook modus-themes-after-load-theme-hook
;;     :name modus-monochrome
;;     (modus-themes-with-colors
;;       (cl-loop for x being the symbols
;;                if (string-match-p "\\`font-lock-.*-face\\'"
;;                                   (symbol-name x))
;;                do
;;                (custom-set-faces
;;                 `(,x ((,class :foreground
;;                               ,(cond
;;                                 ((memq x '(font-lock-string-face
;;                                            font-lock-doc-face
;;                                            font-lock-doc-markup-face))
;;                                  fg-special-warm)
;;                                 ((memq x '(font-lock-warning-face))
;;                                  fg-lang-warning)
;;                                 ((memq x '(font-lock-comment-face))
;;                                  fg-alt)
;;                                 (:else 'unspecified))
;;                               :background unspecified
;;                               :weight
;;                               ,(cond
;;                                 ((memq x '(font-lock-keyword-face))
;;                                  'bold)
;;                                 (:else 'normal))
;;                               :slant
;;                               ,(cond
;;                                 ((memq x '(font-lock-doc-face
;;                                            font-lock-comment-face))
;;                                  'italic)
;;                                 (:else 'normal))
;;                               :underline
;;                               ,(cond
;;                                 ((memq x '(font-lock-warning-face))
;;                                  t)
;;                                 (:else nil)))))))))
;;   (when (or (custom-theme-enabled-p 'modus-operandi)
;;             (custom-theme-enabled-p 'modus-vivendi))
;;     (modus-monochrome))
;;   (cond ((require 'dawn nil :noerrer)
;;          (defhook +custom-after-load-hook
;;            :name dawn@custom
;;            (load-theme 'modus-operandi :noconfirm :noenable)
;;            (load-theme 'modus-vivendi :noconfirm :noenable)
;;            (dawn-schedule #'modus-themes-load-operandi
;;                           #'modus-themes-load-vivendi)))
;;         (:else (modus-themes-load-operandi))))

(yoke time
  (setc display-time-mail-function
        (defun +notmuch-new-mail-p ()
          (plist-get (cl-find "inbox+unread"
                              (ignore-errors
                                (notmuch-hello-query-counts notmuch-saved-searches))
                              :key (lambda (l) (plist-get l :name))
                              :test #'equal)
                     :count))
        display-time-use-mail-icon nil
        display-time-mail-string (format "⋅ Mail (%s)" (+notmuch-new-mail-p))
        read-mail-command #'+notmuch-goto
        display-time-format " %a %-e, %H:%M"
        ;; `display-time-format' makes these unnecessary, but I'll keep em
        display-time-24hr-format t
        display-time-day-and-date t
        display-time-default-load-average nil)
  (define-advice display-time-update (:after (&rest _) update-mail-count)
    (setq display-time-mail-string (format "⋅ Mail (%s)" (+notmuch-new-mail-p))))
  (display-time-mode))

(yoke pita
  (require 'pita)
  (advice-add 'indent-region :before #'with-region-or-buffer))

(yoke (undo-fu-session "https://codeberg.org/ideasman42/emacs-undo-fu-session")
  (setc undo-fu-session-incompatible-files '("/COMMIT_EDITMSG\\'"
                                             "/git-rebase-todo\\'")
        undo-fu-session-directory (.etc "undo/" t)
        undo-fu-session-compression (cond
                                     ((executable-find "gzip") 'gz)
                                     ((executable-find "bzip2") 'bz2)
                                     ((executable-find "xz") 'xz)
                                     (t nil)))
  (global-undo-fu-session-mode))

(yoke whitespace
  (setc  whitespace-line-column nil
         whitespace-style '( face trailing
                             tabs tab-mark
                             indentation
                             space-after-tab space-before-tab))
  (defhook (text-mode-hook prog-mode-hook read-only-mode-hook)
    :name +whitespace-mode-for-writable-buffers
    :doc "Turn on `whitespace-mode' if the buffer is writable, off otherwise."
    (whitespace-mode (if buffer-read-only -1 t)))
  (defhook before-save-hook #'whitespace-cleanup)
  (define-advice whitespace-cleanup (:around (fn &rest r) preserve-point)
    (let ((col (current-column)))
      (apply fn r)
      (move-to-column col t)
      (set-buffer-modified-p nil))))

(yoke elisp-mode
  (setc eval-expression-print-length nil ; remove ellipses from `eval-expression'
        eval-expression-print-level nil)
  (defkeys (emacs-lisp-mode-map lisp-interaction-mode-map)
    "C-c C-c" #'eval-defun
    "C-c C-k" (defun +elisp-eval-region-or-buffer ()
                (interactive)
                (cond
                 ((region-active-p)
                  (eval-region (region-beginning) (region-end))
                  (message "Region evaluated."))
                 (t
                  (eval-buffer)
                  (message "Buffer %s evaluated." (buffer-name)))))
    "C-c C-z" #'ielm)
  (define-advice eval-region (:around (fn beg end &rest args) pulse)
    (apply fn beg end args)
     (pulse-momentary-highlight-region beg end)))

(yoke isearch
  (defkeys t
    "C-s" #'isearch-forward-regexp
    "C-r" #'isearch-backward-regexp
    "C-M-s" #'isearch-forward
    "C-M-r" #'isearch-backward))

(yoke ispell
  (require* '+ispell 'ispell)
  (add-hook 'before-save-hook
            #'+ispell-move-buffer-words-to-dir-locals-hook)
  (setc ispell-program-name (or (executable-find "ispell")
                                (executable-find "aspell")))
  (put 'ispell-buffer-session-localwords
       'safe-local-variable #'+ispell-safe-local-p))


(yoke mouse
  ;; Brand new for Emacs 28: see https://ruzkuku.com/texts/emacs-mouse.html
  ;; Actually, look at this as well: https://www.emacswiki.org/emacs/Mouse3
  (when (fboundp 'context-menu-mode)
    (setc context-menu-functions '(context-menu-ffap
                                   context-menu-region
                                   context-menu-undo
                                   ;; context-menu-dictionary
                                   ))
    (context-menu-mode +1))
  (dolist (click '(;; Fix scrolling in the margin
                   wheel-down double-wheel-down triple-wheel-down
                   wheel-up double-wheel-up triple-wheel-up))
    (global-set-key (vector 'right-margin click) 'mwheel-scroll)
    (global-set-key (vector 'left-margin click) 'mwheel-scroll)))

(yoke dired
  (require 'dired-x)
  (setc dired-recursive-copies 'always
        dired-recursive-deletes 'always
        dired-create-destination-dirs 'always
        dired-do-revert-buffer t
        dired-hide-details-hide-symlink-targets nil
        dired-isearch-filenames 'dwim
        delete-by-moving-to-trash t
        dired-auto-revert-buffer t
        dired-listing-switches "-AlF"
        ls-lisp-dirs-first t
        dired-ls-F-marks-symlinks t
        dired-clean-confirm-killing-deleted-buffers nil
        dired-no-confirm '(byte-compile
                           load chgrp chmod chown
                           copy move hardlink symlink
                           shell touch)
        dired-dwim-target t)
  (setq-local-hook dired-mode-hook
    truncate-lines t)
  (defkeys t
    "C-x C-j" #'dired-jump
    [remap list-directory] #'dired)
  (defkeys ((dired-mode-map :after dired))
    "<backspace>" #'dired-up-directory
    "C-j" #'dired-up-directory)
  (defhook dired-mode-hook
    #'dired-hide-details-mode
    #'hl-line-mode))

(yoke (dired-hacks "https://github.com/Fuco1/dired-hacks")
  (defkeys dired-mode-map
    "TAB" #'dired-subtree-sycle
    "i" #'dired-subtree-toggle)
  (defhook 'dired-mode-hook
    #'dired-collapse-mode))

(yoke auth-source
  (setc auth-sources `(default "secrets:passwords"))
  (setq-local-hook authinfo-mode-hook
    truncate-lines t))

(yoke (consult "https://github.com/minad/consult")
  (require 'consult)
  (setf register-preview-delay 0
        register-preview-function #'consult-register-format
        xref-show-xrefs-function #'consult-xref
        tab-always-indent 'complete
        completion-in-region-function #'consult-completion-in-region
        consult-narrow-key "<"
        consult--regexp-compiler #'consult--default-regexp-compiler)
  (advice-add #'register-preview :override #'consult-register-window)
  (define-key* (current-global-map)
               ;; Etc
               "M-S-x" #'consult-mode-command
               ;; C-c bindings (mode-specific-map)
               "C-c h" #'consult-history
               "C-c b" #'consult-bookmark
               "C-c k" #'consult-kmacro
               ;; C-x bindings (ctl-x-map)
               "C-x M-:" #'consult-complex-command
               "C-x b" #'consult-buffer
               "C-x 4 b" #'consult-buffer-other-window
               "C-x 5 b" #'consult-buffer-other-frame
               ;; Custom M-# bindings for fast register access
               "M-#" #'consult-register-load
               "M-'" #'consult-register-store
               "C-M-#" #'consult-register
               ;; Other custom bindings
               "M-y" #'consult-yank-pop
               ;;("<f1> a" . consult-apropos)
               ;; M-g bindings (goto-map)
               "M-g e" #'consult-compile-error
               "M-g f" #'consult-flymake ; or consult-flycheck
               "M-g g" #'consult-goto-line
               "M-g M-g" #'consult-goto-line
               "M-g o" #'consult-outline ; or consult-org-heading
               "M-g m" #'consult-mark
               "M-g k" #'consult-global-mark
               "M-g i" #'consult-imenu
               "M-g M-i" #'consult-imenu
               "M-g I" #'consult-imenu-multi
               ;; M-s bindings (search-map)
               "M-s f" #'consult-find
               "M-s F" #'consult-locate
               "M-s g" #'consult-grep
               "M-s G" #'consult-git-grep
               "M-s r" #'consult-ripgrep
               "M-s l" #'consult-line
               "M-s L" #'consult-line-multi
               "M-s m" #'consult-multi-occur
               "M-s k" #'consult-keep-lines
               "M-s u" #'consult-focus-lines
               ;; Isearch integration
               "M-s e" #'consult-isearch-history)
  (eval-after isearch-mode
    (define-key* isearch-mode-map
                 "M-e" #'consult-isearch-history
                 "M-s e" #'consult-isearch-history
                 "M-s l" #'consult-line
                 "M-s L" #'consult-line-multi))
  (eval-after org
    (define-key org-mode-map (kbd "M-g o") #'consult-org-heading))
  (eval-after consult-imenu
    (setf (alist-get ?y (plist-get (alist-get 'emacs-lisp-mode
                                              consult-imenu-config)
                                   :types))
          '("Yoke"))))

(yoke (orderless "https://github.com/oantolin/orderless")
  (require 'orderless)
  (setf completion-styles '(substring orderless basic)
        completion-category-defaults nil
        completion-category-overrides
        '((file (styles basic partial-completion)))
        orderless-component-separator #'orderless-escapable-split-on-space))

(yoke (vertico "https://github.com/minad/vertico")
  (require 'vertico)
  (setf resize-mini-windows 'grow-only
        vertico-count-format nil
        vertico-cycle t)
  (vertico-mode)
  (add-to-list 'load-path (expand-file-name "vertico/extensions" yoke-dir))
  (require 'vertico-directory)
  (add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy))

(yoke (embark "https://github.com/oantolin/embark")
  (require 'embark)
  (setf prefix-help-command #'embark-prefix-help-command
        embar-keymap-prompter-key ";")
  (defkeys (t minibuffer-local-map)
    "C-." #'embark-act
    "M-." #'embark-dwim
    "<f1> B" #'embark-bindings)
  (define-key* embark-file-map
               "l" #'vlf)
  (eval-after (embark consult)
    (require 'embark-consult)
    (add-hook 'embark-collect-mode-hook #'consult-preview-at-point-mode)))

(yoke (marginalia "https://github.com/minad/marginalia/")
  (marginalia-mode))

(yoke (wgrep "https://github.com/mhayashi1120/Emacs-wgrep")
  (require 'wgrep)
  (define-key* grep-mode-map
               "C-x C-q" #'wgrep-change-to-wgrep-mode))

(yoke (slime "https://github.com/slime/slime")
  :when (executable-find "sbcl")
  (setc inferior-lisp-program (executable-find "sbcl"))
  (defhook lisp-mode-hook
    :name slime-mode-setup
    (load (expand-file-name "~/quicklisp/slime-helper.el") :noerror)
    (slime-mode))
  (eval-after slime
    (setc slime-completion-at-point-functions
          (delq 'slime-c-p-c-completion-at-point
                slime-completion-at-point-functions))))

(yoke (puni "https://github.com/amaikinono/puni")
  (electric-pair-mode)
  (defkeys puni-mode-map
    "C-)" #'puni-slurp-forward
    "C-(" #'puni-slurp-backward
    "C-}" #'puni-barf-forward
    "C-{" #'puni-barf-backward
    "M-(" (defun +puni-open-then-slurp-forward (&optional n)
            (interactive "p")
            (insert "()")
            (backward-char)
            (ignore-errors (puni-slurp-forward n))))
  (defhook (prog-mode-hook
            lisp-interaction-mode-hook emacs-lisp-mode-hook
            lisp-mode-hook scheme-mode-hook
            ielm-mode-hook eval-expression-minibuffer-setup-hook)
    #'puni-mode))

(yoke (hungry-delete "https://github.com/nflath/hungry-delete")
  (setc hungry-delete-chars-to-skip " \t"
        hungry-delete-join-reluctantly nil)
  (eval-after hungry-delete
    (add-to-list* 'hungry-delete-except-modes
      #'eshell-mode
      #'nim-mode
      #'python-mode))
  (defun +hungry-delete-or (hd-fn fn arg)
    (funcall (if (looking-back (format "[%s]" hungry-delete-chars-to-skip) arg)
                 hd-fn
               fn)
             arg))
  (defkeys puni-mode-map
    [remap puni-backward-delete-char]
    (defun +puni|hungry-delete-backward (arg)
      (interactive "p")
      (+hungry-delete-or #'hungry-delete-backward
                         #'puni-backward-delete-char
                         arg))
    [remap puni-forward-delete-char]
    (defun +puni|hungry-delete-forward (arg)
      (interactive "p")
      (+hungry-delete-or #'hungry-delete-forward
                         #'puni-forward-delete-char
                         arg)))
  (global-hungry-delete-mode))

(yoke (cape "https://github.com/minad/cape")
  ;; Insinuate in a lot of modes
  (defvar +capes '(cape-file cape-dabbrev))
  (defun +cape-insinuate (hook capf &optional capes)
    "Insinuate CAPES into a HOOK along with CAPF function.
CAPES defaults to `+capes'.  CAPF will be made un-exclusive."
    (setq-local-hook hook
      completion-at-point-functions
      (apply #'list (cape-capf-properties capf :exclusive 'no)
             (or capes +capes))))
  (+cape-insinuate 'emacs-lisp-mode-hook #'elisp-completion-at-point))

(yoke (minions "https://github.com/tarsius/minions")
  (minions-mode))

(yoke (magit "https://github.com/magit/magit"
             :load "lisp")
  :depends ((transient "https://github.com/magit/transient"
                       :load "lisp")
            (dash "https://github.com/magnars/dash.el")
            (with-editor "https://github.com/magit/with-editor"
              :load "lisp"))
  (autoload #'transient--with-suspended-override "transient")
  (autoload #'magit "magit" nil :interactive)
  (defkeys t
    "C-x g" #'magit))

(yoke (git-modes "https://github.com/magit/git-modes")
  (require 'git-modes))

(yoke (visual-fill-column "https://codeberg.org/joostkremers/visual-fill-column")
  (setc visual-fill-column-center-text t)
  (add-hook 'visual-fill-column-mode-hook #'visual-line-mode)
  (advice-add 'text-scale-adjust :after #'visual-fill-column-adjust))

(yoke (org "https://git.savannah.gnu.org/git/emacs/org-mode.git"
           :load "lisp")
  :depends ((org-contrib "https://git.sr.ht/~bzg/org-contrib"
                         :load "lisp"))
  ;; DON'T load system org
  (setc load-path
        (cl-remove-if (lambda (path) (string-match-p "lisp/org\\'" path))
                      load-path))
  (setc org-adapt-indentation nil
        org-auto-align-tags t
        org-archive-mark-done t
        org-fold-catch-invisible-edits 'show-and-error
        org-clock-clocked-in-display 'mode-line
        org-clock-frame-title-format (cons
                                      '(t org-mode-line-string)
                                      (cons " --- " frame-title-format))
        org-clock-string-limit 7     ; just the clock bit
        ;; org-clock-string-limit 25    ; gives enough information
        org-clock-persist nil
        org-confirm-babel-evaluate nil
        org-cycle-separator-lines 0
        org-directory (sync/ "org/" t)
        org-ellipsis (or truncate-string-ellipsis "…")
        org-fontify-done-headline t
        org-fontify-quote-and-verse-blocks t
        org-fontify-whole-heading-line t
        org-hide-emphasis-markers t
        org-html-coding-system 'utf-8-unix
        org-image-actual-width (list (* (window-font-width)
                                        (- fill-column 8)))
        org-imenu-depth 3
        org-indent-indentation-per-level 0
        org-indent-mode-turns-on-hiding-stars nil
        org-insert-heading-respect-content t
        org-list-demote-modify-bullet '(("-" . "+")
                                        ("+" . "-"))
        org-log-done 'time
        org-log-into-drawer t
        org-num-skip-commented t
        org-num-skip-unnumbered t
        org-num-skip-footnotes t
        org-outline-path-complete-in-steps nil
        org-pretty-entities t
        org-pretty-entities-include-sub-superscripts nil
        org-refile-targets '((nil . (:maxlevel . 2))
                             (org-agenda-files . (:maxlevel . 1)))
        org-refile-use-outline-path 'file
        org-special-ctrl-a/e t
        org-special-ctrl-k t
        org-src-fontify-natively t
        org-src-tab-acts-natively t
        org-src-window-setup 'current-window
        org-startup-truncated nil
        org-startup-with-inline-images t
        org-tags-column -77 ;; (- (- fill-column 1 (length org-ellipsis)))
        org-todo-keywords
        '((sequence "TODO(t)" "WAIT(w@/!)" "ONGOING(o@)"
                    "|" "DONE(d!)" "ASSIGNED(a@/!)")
          (sequence "|" "CANCELED(k@)")
          (sequence "MEETING(m)"))
        org-use-speed-commands t
        org-emphasis-alist '(("*" org-bold)
                             ("/" org-italic)
                             ("_" org-underline)
                             ("=" org-verbatim)
                             ("~" org-code)
                             ("+" org-strikethrough)))
  (defhook org-mode-hook
    #'variable-pitch-mode
    #'visual-fill-column-mode
    #'turn-off-auto-fill
    #'org-indent-mode
    #'prettify-symbols-mode
    #'abbrev-mode
    (defhook ((before-save-hook nil :local))
      :name before-save@org-mode
      (+org-hide-drawers-except-point)
      (org-align-tags 'all)))
  (eval-after org
    (require '+org)
    (org-clock-persistence-insinuate)
    (+org-agenda-inhibit-hooks-mode)
    (defkeys org-mode-map
      "C-M-k" #'kill-paragraph
      "C-M-t" #'transpose-paragraphs
      "RET" #'+org-return-dwim
      "S-<return>" #'+org-table-copy-down|+org-return
      "C-c C-o" #'+org-open-at-point-dwim))
  (eval-after ol                        ; org-link
    (defmacro define-org-link-type (type args &rest body)
      "Define an org link TYPE with ARGS that does something.
  If BODY is blank, message the user about the link."
      (declare (indent 2) (doc-string 3) (debug (sexp sexp def-body)))
      (let ((fn (intern (format "org-%s-open" type)))
            (body (or body `((message ,(format "%s: %%S" type) ,(car args)))))
            (type-string (format "%s" type)))
        `(prog1
             (defun ,fn ,args
               ,@body)
           (org-link-set-parameters ,type-string :follow #',fn))))
    (define-org-link-type sms (number _))
    (define-org-link-type tel (number _))))

(yoke org-word-count ; in lisp/
  (eval-after org
    (require 'org-word-count)
    (add-hook 'org-mode-hook #'org-word-count-mode)))

(yoke org-agenda
  (setq org-agenda-skip-deadline-if-done t
        org-agenda-skip-scheduled-if-done t
        org-agenda-span 10
        org-agenda-block-separator ?─
        org-agenda-time-grid
        '((daily today require-timed)
          (800 1000 1200 1400 1600 1800 2000)
          " ┄┄┄┄┄ " "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄")
        org-agenda-current-time-string
        "← now ─────────────────────────────────────────────────"
        org-agenda-include-diary nil ; I use the org-diary features
        org-agenda-todo-ignore-deadlines 'near
        org-agenda-todo-ignore-scheduled 'future
        org-agenda-include-deadlines t
        org-deadline-warning-days 0
        org-agenda-show-future-repeats 'next
        org-agenda-window-setup 'current-window
        org-agenda-file-skip-regexp "sync-conflict")
  (defcustom org-agenda-file-skip-regexp nil
    "Files matching this regexp are removed from `org-agenda-files'."
    :group 'org-agenda)
  (define-advice org-agenda-files (:filter-return (files) skip-regexp)
    (when org-agenda-file-skip-regexp
      (setq files (seq-remove (lambda (file)
                                (string-match-p org-agenda-file-skip-regexp
                                                file))
                              files)))
    files)
  (setq-local-hook org-agenda-mode-hook
    truncate-lines t)
  (add-hook 'org-agenda-mode-hook #'hl-line-mode)
  (add-hook 'org-agenda-after-show-hook #'org-narrow-to-subtree)
  (defkeys t
    "C-c c" #'org-capture
    "C-c a" #'org-agenda)
  (eval-after org-capture
    (require '+org-capture)))

(yoke ox                                ; org-export
  (eval-after org (require 'ox))
  (eval-after ox
    (require* '+ox '(ox-md nil t))
    (+org-export-pre-hooks-insinuate))
  (setq org-export-coding-system 'utf-8-unix
        org-export-headline-levels 8
        org-export-with-drawers nil
        org-export-with-section-numbers nil
        org-export-with-smart-quotes t
        org-export-with-sub-superscripts t
        org-export-with-toc nil))

(yoke (electric-cursor "https://codeberg.org/acdw/electric-cursor.el")
  (setq electric-cursor-alist '((overwrite-mode . hbar)
                                (t . bar)))
  (electric-cursor-mode))

(yoke _work
  :depends ((bbdb "https://git.savannah.nongnu.org/git/bbdb.git"
                  :load "lisp")
            (bbdb-vcard "https://github.com/tohojo/bbdb-vcard/"))
  (setf bbdb-complete-mail-allow-cycling t
        bbdb-file (private/ "bbdb"))
  (defhook +custom-after-load-hook
    :name _work@after-custom
    (require* 'private '_work)
    (require* 'bbdb 'bbdb-message)
    (bbdb-initialize 'gnus 'message)))

(yoke (org-taskwise "https://codeberg.org/acdw/org-taskwise.el"))

(yoke scule
  (require 'scule)
  (defvar scule-map (let ((map (make-sparse-keymap)))
                      (define-key map (kbd "M-u") #'scule-upcase)
                      (define-key map (kbd "M-l") #'scule-downcase)
                      (define-key map (kbd "M-c") #'scule-capitalize)
                      map)
    "Keymap for scule twiddling.")
  (define-key* (current-global-map)
               "M-c" scule-map
               "M-u" #'universal-argument)
  (define-key universal-argument-map (kbd "M-u") #'universal-argument-more))

(yoke (titlecase "https://codeberg.org/acdw/titlecase.el")
  (eval-after titlecase
    (add-to-list* 'titlecase-skip-words-regexps
      (rx word-boundary
          (+ (any upper digit))
          word-boundary)))
  (eval-after scule
    (define-key* scule-map
                 "M-t" #'titlecase-dwim)))

(yoke (flyspell-correct "https://github.com/duckwork/flyspell-correct")
  (eval-after flyspell
    (require* 'flyspell-correct
              `(+flyspell-correct ,(locate-user-emacs-file "lisp/+flyspell-correct")))
    (define-key* flyspell-mode-map
                 "C-;" #'flyspell-correct-wrapper
                 "<f7>" #'+flyspell-correct-buffer
                 "C-," nil
                 "C-." nil))
  (add-hook 'org-mode-hook #'flyspell-mode)
  (setq flyspell-correct--cr-key ";"))

(yoke (helpful "https://github.com/Wilfred/helpful")
  :depends ((dash "https://github.com/magnars/dash.el")
            (f "https://github.com/rejeep/f.el")
            (s "https://github.com/magnars/s.el")
            (elisp-refs "https://github.com/Wilfred/elisp-refs"))
  (defkeys t
    "<f1> f" #'helpful-callable
    "<f1> v" #'helpful-variable
    "<f1> k" #'helpful-key
    "<f1> ." #'helpful-at-point
    "<f1> o" #'helpful-symbol)
  (unless (featurep 'info-look)
    (run-with-idle-timer 5 nil (lambda ()
                                 (require 'info-look)
                                 (let ((inhibit-message t))
                                   (info-lookup-setup-mode 'symbol
                                                           'emacs-lisp-mode)))))
  (defhook window-configuration-change-hook
    :name side-window-setup
    (setf fit-window-to-buffer-horizontally t
          (alist-get (rx (or "*helpful" "*Help" "*info"))
                     display-buffer-alist nil nil #'string=)
          `(display-buffer-in-side-window
            ,@(if (< (frame-text-width) (frame-text-height))
                  '((side . bottom) (window-height . 24))
                '((side . right) (window-width . fit-window-to-buffer)))))))

(yoke (hippie-completing-read
       "https://codeberg.org/acdw/hippie-completing-read.el")
  (define-key* (current-global-map)
               "M-/" #'hippie-completing-read))

(yoke dictionary                        ; Comes with Emacs 29!
  (defkeys (t (org-mode-map :after org))
    "C-c d" #'dictionary-search)
  (defkeys ((embark-identifier-map :after embark))
    "@" #'dictionary-search)
  (setc dictionary-server (if (or (executable-find "dictd")
                                  (file-exists-p "/usr/sbin/dictd")) ; oh debian
                              "localhost"
                            "dict.org"))
  (setf (alist-get "^\\*Dictionary\\*" display-buffer-alist nil nil #'string=)
        '((display-buffer-in-side-window)
          (side . bottom)
          (window-height . 20))))

(yoke (anzu "https://github.com/emacsorphanage/anzu")
  (require 'anzu)
  (global-anzu-mode)
  (defkeys t
    [remap query-replace] #'anzu-query-replace-regexp
    [remap query-replace-regexp] #'anzu-query-replace)
  (defkeys (isearch-mode-map (isearch-mb-minibuffer-map :after isearch-mb))
    [remap isearch-query-replace] #'anzu-isearch-query-replace-regexp
    [remap isearch-query-replace-regexp] #'anzu-isearch-query-replace)
  (defun anzu-qr@window (fn &rest r)
    "ADVICE to query-replace from the beginning of the window."
    (let ((scroll-margin 0))
      (cond ((region-active-p)
             (apply fn r))
            (:else (save-excursion
                     (goto-char (window-start))
                     (apply fn r))))))
  (advice-add 'anzu-query-replace-regexp :around #'anzu-qr@window)
  (advice-add 'anzu-query-replace :around #'anzu-qr@window))

(yoke tempo
  (require '+tempo))

(yoke (0x0 "https://gitlab.com/willvaughn/emacs-0x0")
  (setf 0x0-default-server 'ttm)
  (define-advice 0x0-shorten-uri (:around (fn server uri) use-0x0)
    (interactive (list (cdr (assq 'envs 0x0-servers))
                       (read-string "URI: ")))
    (funcall fn server uri))
  (eval-after embark
    (define-key* embark-region-map
                 "U" #'0x0-dwim)))

(yoke (filldent "https://codeberg.org/acdw/filldent.el")
  (define-advice canonically-space-region (:around (orig &rest r) double-space)
    (let ((sentence-end-double-space t))
      (apply orig r)))
  (defkeys t
    "M-q" #'filldent-unfill-toggle))

(yoke (avy "https://github.com/abo-abo/avy")
  (require 'avy)
  (setf avy-background t
        (alist-get ?. avy-dispatch-alist)
        (defun avy-action-embark (pt)
          (unwind-protect
              (save-excursion
                (goto-char pt)
                (embark-act))
            (select-window
             (cdr (ring-ref avy-ring 0))))
          t))
  (define-key* (current-global-map)
               "M-j" #'avy-goto-char-timer)
  (define-key* isearch-mode-map
               "M-j" #'avy-isearch))

(yoke (frowny "https://codeberg.org/acdw/frowny.el")
  (setf frowny-eyes (rx (any ":=") (opt "'") (? "-")))
  (global-frowny-mode))

(yoke (isearch-mb "https://github.com/astoff/isearch-mb")
  (eval-after (consult anzu)
    (require 'isearch-mb)
    (dolist (spec '((isearch-mb--with-buffer
                     ("M-e" .  consult-isearch)
                     ("C-o" . loccur-isearch))
                    (isearch-mb--after-exit
                     ("M-%" . anzu-isearch-query-replace)
                     ("M-s l" . consult-line))))
      (let ((isearch-mb-list (car spec))
            (isearch-mb-binds (cdr spec)))
        (dolist (cell isearch-mb-binds)
          (let ((key (car cell))
                (command (cdr cell)))
            (when (fboundp command)
              (add-to-list isearch-mb-list command)
              (define-key isearch-mb-minibuffer-map (kbd key) command)))))))
  (isearch-mb-mode))

(yoke (keepassxc-shim "https://codeberg.org/acdw/keepassxc-shim.el")
  (keepassxc-shim-activate))

(yoke (keychain-environment "https://github.com/tarsius/keychain-environment")
  :when (executable-find "keychain")
  (keychain-refresh-environment))

(yoke (exec-path-from-shell "https://github.com/purcell/exec-path-from-shell")
  :when (eq system-type 'gnu/linux)
  (require 'exec-path-from-shell)
  (dolist (var '("SSH_AUTH_SOCK"
                 "SSH_AGENT_PID"
                 "GPG_AGENT_INFO"
                 "LANG"
                 "LC_CTYPE"
                 "XDG_CONFIG_HOME"
                 "XDG_CONFIG_DIRS"
                 "XDG_DATA_HOME"
                 "XDG_DATA_DIRS"
                 "XDG_CACHE_HOME"))
    (add-to-list 'exec-path-from-shell-variables var))
  (exec-path-from-shell-initialize))

(yoke (sophomore "https://codeberg.org/acdw/sophomore.el")
  (sophomore-enable-all)
  (sophomore-disable #'view-hello-file
                     #'describe-gnu-project)
  (sophomore-disable-with 'confirm #'save-buffers-kill-terminal))

(yoke (macrostep "https://github.com/joddie/macrostep")
  (eval-after elisp-mode (require 'macrostep))
  (define-key* '(emacs-lisp-mode-map
                 lisp-interaction-mode-map)
               "C-c e" #'macrostep-expand))

(yoke (expand-region "https://github.com/magnars/expand-region.el")
  (define-advice er/clear-history (:after (&rest _) refold-org)
    (when (derived-mode-p 'org-mode)
      (+org-hide-drawers-except-point)
      (org-link-descriptive-ensure)
      (font-lock-update)))
  (defkeys t
    "C-=" #'er/expand-region))

(yoke (embrace "https://github.com/cute-jumper/embrace.el")
  :depends ((expand-region "https://github.com/magnars/expand-region.el"))
  (defkeys t
    "C-\"" #'embrace-commander)
  (dolist (fnhook '((org-mode-hook embrace-org-mode-hook)
                    (ruby-mode-hook embrace-ruby-mode-hook)
                    (emacs-lisp-mode-hook embrace-emacs-lisp-mode-hook)
                    (latex-mode-hook embrace-LaTeX-mode-hook)))
    (apply #'add-hook fnhook))
  (eval-after org
    (defkeys org-mode-map
      "C-\"" #'embrace-commander)
    (defmacro org-insert-or-embrace (char)
      "Define a function to insert CHAR, or `embrace' the region with it."
      (let* ((fn-name (intern (format "org-insert-or-embrace-%s" char)))
             (char (cond ((characterp char) char)
                         ((stringp char) (string-to-char char))
                         (t (user-error "Bad format for char: %S" char)))))
        `(defun ,fn-name (n)
           ,(format "Insert N %ss, or surround the region with them."
                    (char-to-string char))
           (interactive "p")
           (if (region-active-p)
               (dotimes (_ n)
                 (embrace--add-internal (region-beginning) (region-end) ,char)
                 (forward-char 1))
             (self-insert-command n ,char)))))
    (define-key* org-mode-map
                 "*" (org-insert-or-embrace "*")
                 "/" (org-insert-or-embrace "/")
                 "_" (org-insert-or-embrace "_")
                 "=" (org-insert-or-embrace "=")
                 "~" (org-insert-or-embrace "~")
                 "+" (org-insert-or-embrace "+"))))

(yoke (notmuch "~/usr/share/emacs/site-lisp")
  (eval-after bbdb
    (require* 'notmuch '+notmuch '+message))
  (+define-dir notmuch/ (sync/ "emacs/notmuch")
    "Notmuch configuration and data.")
  (setf notmuch-init-file (notmuch/ "notmuch-init.el" t)
        notmuch-address-save-filename (notmuch/ "addresses" t)
        notmuch-address-use-company (featurep 'company)
        notmuch-search-oldest-first nil
        notmuch-archive-tags '("-inbox" "-unread")
        notmuch-draft-tags '("+draft" "-inbox" "-unread")
        mail-user-agent 'notmuch-user-agent
        bbdb-mail-user-agent 'notmuch-user-agent
        message-mail-user-agent t)
  (define-key* (current-global-map)
               "C-c m" #'notmuch-mua-new-mail
               "C-c n" #'+notmuch-goto)
  ;; Reading mail
  (setf notmuch-show-indent-content nil)
  (add-hook* '(notmuch-show-mode-hook
               notmuch-message-mode-hook)
    #'visual-fill-column-mode)
  (eval-after notmuch
    (define-key* notmuch-search-mode-map
                 "RET" #'notmuch-search-show-thread
                 "M-RET" #'notmuch-tree-from-search-thread
                 "!" #'+notmuch-search-mark-spam)
    (define-key* notmuch-tree-mode-map
                 "!" #'+notmuch-search-mark-spam-then-next
                 "M-<" (notmuch-tree--define-do-in-message-window
                        notmuch-tree-beginning-of-message beginning-of-buffer)
                 "M->" (notmuch-tree--define-do-in-message-window
                        notmuch-tree-end-of-message end-of-buffer)))
  ;; Writing mail
  (setf message-kill-buffer-on-exit t
        message-auto-save-directory nil)
  ;; Sending mail
  (setf send-mail-function #'sendmail-send-it
        mail-specify-envelope-from t
        message-sendmail-envelope-from 'header
        message-envelope-from 'header)
  ;; Extras
  (define-advice mm-save-part-to-file (:before (_handle file) create-directory)
    (let ((directory (file-name-directory file)))
      (when (yes-or-no-p (format "Directory %s doesn't exist.  Create?" directory))
        (make-directory directory :parents))))
  (eval-after notmuch
    (require '+notmuch)
    (load notmuch-init-file :noerror)
    (add-hook 'message-setup-hook #'+message-signature-setup)
    (add-hook 'message-send-hook #'+send-mail-dispatch)
    (advice-add 'notmuch-tag :filter-args #'+notmuch-correct-tags)
    (advice-add 'notmuch-bury-or-kill-this-buffer :after
                (defun +display-time@notmuch (&rest _)
                  ;; (display-time-event-handler)
                  (setq display-time-mail-string
                        (replace-regexp-in-string "(.*)"
                                                  (format "(%s)" (+notmuch-new-mail-p))
                                                  display-time-mail-string))
                  (display-time-update)
                  (force-mode-line-update)))
    (add-to-list 'notmuch-message-headers "List-Post" :append)
    (define-advice notmuch-mua-new-reply (:around (orig &rest r) list-aware)
      "Make `notmuch-mua-new-reply' list-aware."
      (let ((ml (notmuch-show-get-header :List-Post)))
        (apply orig r)
        (when ml
          (with-buffer-modified-unmodified
           (message-remove-header "To")
           (message-add-header
            (format "To: %s"
                    (replace-regexp-in-string "<mailto:\\(.*\\)>" "\\1" ml)))
           (message-goto-body)))))
    (setf notmuch-saved-searches (list
                                  (list :name "inbox+unread"
                                        :query (+notmuch-query-concat
                                                "tag:inbox"
                                                "tag:unread"
                                                "NOT tag:Spam")
                                        :key "m"
                                        :search-type 'tree)
                                  (list :name "inbox"
                                        :query (+notmuch-query-concat
                                                "tag:inbox"
                                                "NOT tag:Spam")
                                        :key "i"
                                        :search-type 'tree)
                                  (list :name "lists+unread"
                                        :query (+notmuch-query-concat
                                                "tag:/List/"
                                                "tag:unread")
                                        :key "l"
                                        :search-type 'tree)
                                  (list :name "lists"
                                        :query "tag:/List/"
                                        :key "L"
                                        :search-type 'tree)
                                  (list :name "unread"
                                        :query (+notmuch-query-concat
                                                "tag:unread"
                                                "NOT tag:Spam")
                                        :key "u"
                                        :search-type 'tree)
                                  (list :name "flagged"
                                        :query "tag:flagged"
                                        :key "f"
                                        :search-type 'tree)
                                  (list :name "sent"
                                        :query "tag:sent"
                                        :key "t"
                                        :search-type 'tree)
                                  (list :name "drafts"
                                        :query "tag:draft"
                                        :key "d"
                                        :search-type 'tree)
                                  (list :name "all mail"
                                        :query "*"
                                        :key "a"
                                        :search-type 'tree)))))

(yoke (cider "https://github.com/clojure-emacs/cider")
  :depends ((clojure-mode "http://github.com/clojure-emacs/clojure-mode")
            (parseedn "https://github.com/clojure-emacs/parseedn/")
            (parseclj "https://github.com/clojure-emacs/parseclj/") ; parseedn
            (queue "https://elpa.gnu.org/packages/queue-0.2.el" :type 'http)
            (spinner "https://github.com/Malabarba/spinner.el")
            (sesman "https://github.com/vspinu/sesman"))
  :when (executable-find "clojure"))

(yoke (web-mode "https://github.com/fxbois/web-mode")
  (setf (alist-get (rx "." (or "htm" "html" "phtml" "tpl.php"
                               "asp" "gsp" "jsp" "ascx" "aspx"
                               "erb" "mustache" "djhtml")
                       eos)
                   auto-mode-alist nil nil #'string=)
        'web-mode))

(yoke (chicken-geiser "https://gitlab.com/emacs-geiser/chicken")
  :depends ((geiser "https://gitlab.com/emacs-geiser/geiser"
                    :load "elisp"))
  :when (executable-find "csi")
  :pre ((autoload 'geiser-activate-implementation "geiser-impl"))
  (autoload 'geiser "geiser" nil :interactive)
  (add-hook 'scheme-mode-hook 'geiser-mode))

(yoke (zoom-frm "https://github.com/emacsmirror/zoom-frm")
  :depends ((frame-cmds "https://github.com/emacsmirror/frame-cmds")
            (frame-fns "https://github.com/emacsmirror/frame-fns"))
  (define-key* (current-global-map)
               "M-+" #'zoom-frm-in
               "M-_" #'zoom-frm-out))

(yoke (jabber "https://codeberg.org/acdw/emacs-jabber")
  :depends ((srv "https://github.com/legoscia/srv.el")
            (fsm "https://elpa.gnu.org/packages/fsm-0.2.1.el" :type 'http))
  (setf jabber-account-list '(("acdw@hmm.st"))
        jabber-auto-reconnect t
        jabber-chat-buffer-format "xmpp:%n"
        jabber-browse-buffer-format "xmpp-browse:%n"
        jabber-groupchat-buffer-format "xmpp-muc:%n"
        jabber-muc-private-buffer-format "xmpp-muc-private:%n"
        jabber-groupchat-prompt-format "%>10n │ "
        jabber-chat-local-prompt-format "%>10n │ "
        jabber-chat-system-prompt-format " * * * * * *"
        jabber-chat-foreign-prompt-format "%>10n │ "
        jabber-muc-private-foreign-prompt-format "%g/%n "
        jabber-last-read-marker  "----------------------------------------"
        jabber-muc-header-line-format '("" jabber-muc-topic)
        jabber-muc-decorate-presence-patterns
        '(("\\( enters the room ([^)]+)\\| has left the chatroom\\)$")
          ("." . jabber-muc-presence-dim))
        jabber-activity-make-strings
        #'jabber-activity-make-strings-shorten
        ;; (defun +jabber-activity-make-strings (jids)
        ;;   (mapcar (lambda (jid)
        ;;             (cons jid
        ;;                   (let ((s (jabber-activity-make-string-default jid)))
        ;;                     (cond
        ;;                      ((string-match-p "%" s)
        ;;                       (replace-regexp-in-string "%.*" "" s))
        ;;                      (:else s)))))
        ;;           jids))
        jabber-rare-time-format " - - - - - - %H:%M %F")
  (defhook (jabber-chat-mode-hook
            jabber-browse-mode-hook
            jabber-roster-mode-hook
            jabber-console-mode-hook)
    :name jabber-ui-setup
    (electric-pair-local-mode -1)
    (auto-fill-mode -1)
    #'visual-fill-column-mode)
  (setq-local-hook jabber-chat-mode-hook
    wrap-prefix (format "%13s" " "))
  (defun +jabber-fix-keybinds-dammit ()
    "Jabber autoloads keybinds which is really annoying."
    (define-key* (current-global-map)
                 "C-x C-j" #'dired-jump
                 "C-c j" jabber-global-keymap
                 "C-c C-SPC" #'jabber-activity-switch-to))
  (eval-after init (+jabber-fix-keybinds-dammit))
  (eval-after jabber
    (require 'jabber-httpupload nil :noerror)
    (add-hook 'jabber-post-connect-hooks #'jabber-enable-carbons)
    (remove-hook 'jabber-alert-muc-hooks 'jabber-muc-echo)
    (remove-hook 'jabber-alert-presence-hooks 'jabber-presence-echo)
    (add-hook 'jabber-alert-muc-hooks
              (defun jabber@highlight-acdw (&optional _nick _group buf _text _title)
                (when buf
                  (with-current-buffer buf
                    (let ((regexp (rx word-boundary
                                      "acdw" ; maybe get from the config?
                                      word-boundary)))
                      (hi-lock-unface-buffer regexp)
                      (highlight-regexp regexp 'hi-blue))))))
    (add-hook 'window-configuration-change-hook #'jabber-chat-update-focus)
    (+jabber-fix-keybinds-dammit)
    (defkeys jabber-chat-mode-map
      "C-l" (defun +jabber-recenter-last-read ()
              (interactive)
              (cond
               ((eq last-command '+jabber-recenter-last-read)
                (setq this-command #'recenter)
                (recenter -1))
               (:else
                (save-excursion
                  (condition-case e
                      (re-search-backward jabber-last-read-marker)
                    (search-failed nil)
                    (:success
                     (recenter 3)))))))))
  (defun jabber-chat-kill-buffers ()
    "Kill all `jabber-chat-mode' buffers."
    (interactive)
    (mapc-buffers (lambda () (message "%S" (buffer-name))) '(jabber-chat-mode)))
  (defun jabber-chat@after-modus-themes-load ()
    (modus-themes-with-colors
      (custom-set-faces
       `(jabber-chat-prompt-foreign ((t :foreground unspecified
                                        :inherit modus-themes-bold))
                                    :now)
       `(jabber-chat-prompt-local ((t :foreground unspecified
                                      :inherit modus-themes-bold))
                                  :now)
       `(jabber-chat-prompt-system ((t :foreground unspecified
                                       :inherit modus-themes-bold))
                                   :now)
       `(jabber-activity-face ((t :slant italic)))
       `(jabber-activity-personal-face ((t :slant italic :weight bold)))
       `(jabber-rare-time-face ((t :inherit font-lock-comment-face)))))
    (setq jabber-muc-nick-value
          (pcase (frame--current-backround-mode (selected-frame))
            ('light 0.5)
            ('dark 1.0))))
  (eval-after modus-themes
    (add-hook 'modus-themes-after-load-theme-hook
              #'jabber-chat@after-modus-themes-load))
  (when (or (custom-theme-enabled-p 'modus-operandi)
            (custom-theme-enabled-p 'modus-vivendi))
    (jabber-chat@after-modus-themes-load))
  (eval-after (consult jabber)
    ;; Jabber.el chat buffers source for `consult-buffer'
    (defvar jabber-chat-buffer-source
      `( :name "Jabber"
         :hidden nil
         :narrow ?j
         :category buffer
         :state ,#'consult--buffer-state
         :items ,(lambda ()
                   (mapcar #'buffer-name
                           (seq-filter (lambda (buf)
                                         (with-current-buffer buf
                                           (eq major-mode 'jabber-chat-mode)))
                                       (buffer-list))))))
    (add-to-list 'consult-buffer-sources 'jabber-chat-buffer-source :append)
    ;; Also hide xmpp buffers from regular buffer list
    (add-to-list 'consult-buffer-filter "\\`xmpp" nil #'string-equal)))

(yoke (link-hint "https://github.com/noctuid/link-hint.el/")
  :depends ((avy "https://github.com/abo-abo/avy"))
  (require '+link-hint)
  (+link-hint-open-secondary-setup)
  (+link-hint-open-chrome-setup)
  (setf link-hint-avy-style 'at-full
        link-hint-avy-all-windows t)
  (global-set-key (kbd "M-l") +link-hint-map)
  (define-key* +link-hint-map
               "M-l" #'+link-hint-open-link "l" #'+link-hint-open-link
               "M-o" #'+link-hint-open-secondary "o" #'+link-hint-open-secondary
               "M-m" #'+link-hint-open-multiple-links "m" #'+link-hint-open-multiple-links
               "M-w" #'link-hint-copy-link "w" #'link-hint-copy-link
               "M-c" #'+link-hint-open-chrome "c" #'+link-hint-open-chrome))

(yoke (elpher "git://thelambdalab.xyz/elpher.git")
  (eval-after elpher
    (define-key* elpher-mode-map
                 "l" #'elpher-back)))

(yoke (epithet "https://github.com/oantolin/epithet")
  (defhook (Info-selection-hook
            help-mode-hook
            occur-mode-hook
            shell-mode-hook)
    #'epithet-rename-buffer)
  (cond ((boundp 'eww-auto-rename-buffer)
         (setc eww-auto-rename-buffer 'title))
        (:else (defhook eww-after-render-hook #'epithet-rename-buffer))))

(yoke browse-url
  (require '+browse-url)
  (setf browse-url-browser-function #'eww-browse-url
        browse-url-chrome-program (seq-some #'executable-find
                                            '("chromium" "chrome" "google-chrome-stable"))
        browse-url-firefox-program (seq-some #'executable-find
                                             '("firefox" "firefox-esr"))
        browse-url-generic-program (or browse-url-firefox-program
                                       browse-url-chrome-program)
        browse-url-firefox-new-window-is-tab t
        browse-url-firefox-arguments "-new-tab"
        browse-url-handlers `((video-url-p . +browse-url-with-mpv)
                              (music-url-p . +browse-url-with-mpv)
                              (image-url-p . +browse-image-with-mpv)
                              (blobp . +browse-url-download)
                              (external-url-p . ,browse-url-secondary-browser-function)
                              ;; HERE FOR REFERENCE --- OPEN MASTO URLS SOME WAY
                              (,(defun mastodon-url-p (url)
                                  "Try to determine whether URL is a mastodon URL."
                                  (string-match-p "/@[^/]+\\(/\\|/[[:digit:]]+\\)?$" url))
                               . ,browse-url-secondary-browser-function)))
  (+browse-url-make-external-viewer-handler "mpv" '("--cache-pause-wait=30"
                                                    "--cache-pause-initial=yes")
                                            "Video URL: "
                                            :fallback browse-url-secondary-browser-function)
  (+browse-url-make-external-viewer-handler "mpv" '("--image-display-duration=inf")
                                            "Image URL: "
                                            :name +browse-image-with-mpv)
  (defun video-url-p (url) "Is URL a video?"
         (string-match-p (rx (or "youtube.com" "youtu.be" "invidious" "yewtu.be"
                                 (seq "." (or "mp4" "gif" "mov" "MOV" "webm") eos)))
                         url))
  (defun music-url-p (url) "Is URL music?"
         (string-match-p (rx "soundcloud.com" "bandcamp.com"
                             (seq "." (or "ogg" "mp3" "opus" "m4a" "flac") eos))
                         url))
  (defun image-url-p (url) "Is URL an image?"
         (string-match-p (rx
                          (or (: "." (or "jpeg" "jpg" "png" "bmp" "webp") eos)
                              "pbs.twimg.com"))
                         url))
  (defun external-url-p (url) "Should URL open in an external browser?"
         (string-match-p  (rx (or "github.com" "gitlab.com" "codeberg.org"
                                  "tildegit.org" "git.tilde.town" "google.com"
                                  "imgur.com" "twitch.tv" "pixelfed" "instagram.com"
                                  "bibliogram.art" "reddit.com" "teddit.net"
                                  ;; "twitter.com" "nitter" "t.co"
                                  "streamable.com" "spotify.com"
                                  "hetzner.cloud" "melpa.org"))
                          url))
  (defun blobp (url) "Is URL some other blob that can't open in Emacs?"
         (string-match-p (rx (or (: (or ".tar.gz" ".pdf")
                                    eos)))
                         url))
  (eval-after chd
    (add-to-list 'browse-url-handlers (cons chd/url-regexps #'chd/browse-url)))
  (require 'browse-url-transform)
  (setf browse-url-transform-alist `(;; Privacy-respecting alternatives
                                     ("twitter\\.com" . "nitter.snopyta.org")
                                     ("\\(?:\\(?:old\\.\\)?reddit\\.com\\)"
                                      . "libreddit.de")
                                     ("medium\\.com" . "scribe.rip")
                                     ;; Text-mode of non-text-mode sites
                                     ("www\\.npr\\.org" . "text.npr.org")
                                     ;; Ask for raw versions of paste sites
                                     ("^.*dpaste\\.com.*$" . "\\&.txt")
                                     ("bpa\\.st/\\(.*\\)" . "bpa.st/raw/\\1")
                                     ("\\(paste\\.debian\\.net\\)/\\(.*\\)"
                                      . "\\1/plain/\\2")
                                     ("\\(pastebin\\.com\\)/\\\(.*\\)"
                                      . "\\1/raw/\\2")
                                     ("gist\\.github\\.com/\\(.*\\)"
                                      . "gist.githubusercontent.com/\\1/raw/")))
  (browse-url-transform-mode))

(yoke eww
  (setc eww-use-browse-url ".")
  (eval-after eww
    (defhook eww-mode-hook
      #'visual-fill-column-mode
      (defhook ((visual-fill-column-mode-hook nil :local))
        :name eww-mode-refresh@visual-fill-column
        (eww-reload t)))
    (defkeys eww-mode-map
      "&"
      (defun +eww-browse-with-external-browser (&optional url)
        "Browse URL with an external browser and close eww."
        (interactive nil eww-mode)
        (condition-case e
            ;; This is wrapped in a `condition-case' so that the eww window
            ;; won't close if there's an error calling the browser.
            (funcall browse-url-secondary-browser-function
                     (or url (plist-get eww-data :url)))
          (:success
           (when (null url)                 ; interactive
             (quit-window)))
          (t (signal (car e) (cdr e)))))))
  (eval-after (eww link-hint)
    (defkeys eww-mode-map
      "f" #'+link-hint-open-link)))

(yoke tab-bar
  (setf tab-bar-show t
        global-mode-string
        '((jabber-activity-mode
           (:eval
            (let ((str (or (bound-and-true-p jabber-activity-mode-string)
                           "")))
              (concat (truncate-string-to-width str 20 nil nil t)
                      (if (< 0 (length str)) " ⋅" "")))))
          display-time-string
          "|"))
  (eval-after jabber
    (defhook jabber-activity-mode-hook
      (setf global-mode-string
            '((jabber-activity-mode
               (:eval
                (let ((str (or (bound-and-true-p jabber-activity-mode-string)
                               "")))
                  (concat (truncate-string-to-width str 20 nil nil t)
                          (if (< 0 (length str)) " ⋅" "")))))
              display-time-string
              "|"))))
  (add-to-list 'tab-bar-format 'tab-bar-format-align-right :append)
  (add-to-list 'tab-bar-format 'tab-bar-format-global :append)
  (tab-bar-mode))

(yoke (pdf-tools "https://github.com/vedang/pdf-tools"
                 :load "lisp")
  :depends ((tablist "https://github.com/politza/tablist/"))
  :when (executable-find "epdfinfo")    ; installed from Debian repos
  (pdf-tools-install))

(yoke which-function
  (setf (alist-get 'which-function-mode mode-line-misc-info)
        '((which-func-mode              ; Only display if buffer supports it
           (:eval (when (which-function)
                    (list "" which-func-format " "))))))
  (which-function-mode))

(yoke (zzz-to-char "https://github.com/mrkkrp/zzz-to-char")
  :depends ((avy "https://github.com/abo-abo/avy"))
  (setf zzz-to-char-reach 120)
  (defkeys t
    [remap zap-to-char]
    (defun +zzz-to-char (&optional prefix)
      "Run `zzz-up-to-char', or `zzz-to-char' with PREFIX."
      (interactive "P")
      (call-interactively (cond (prefix #'zzz-to-char)
                                (:else #'zzz-up-to-char))))))

(yoke sh-mode
  (defhook sh-mode-hook
    :name turn-off-sh-electric-here-document-mode
    (sh-electric-here-document-mode -1)))