summary refs log tree commit diff stats
path: root/init.el
blob: ddb755cc588fe423a43a6e679faa1e9edd32e8b8 (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
;;; init.el --- Emacs initiation file -*- lexical-binding: t -*-

;; Author: Case Duckworth <acdw@acdw.net>
;; Created: Sometime during Covid-19, 2020
;; Keywords: configuration
;; URL: https://tildegit.org/acdw/emacs
;; Bankruptcy: 8

;;; License:

;; 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.

;;; Code:

(dolist (feature `((early-init . ,(locate-user-emacs-file "early-init"))
                   private
                   _work))
  (require (or (car-safe feature) feature) (cdr-safe feature) :noerror))

(setq debug-on-error t)

(setup (:require +emacs)
  ;; +emacs.el contains super-basic defaults that are basically
  ;; necessary for good functioning.  In this block, I add extra
  ;; things or more "experimental" ones that might not belong in a
  ;; separate file.
  (:global "C-x C-k" 'kill-this-buffer
           "C-x 4 n" 'clone-buffer
           "C-c v" 'visible-mode)
  ;; C-h deletes backward - see https://idiomdrottning.org/bad-emacs-defaults
  (global-set-key (kbd "C-h") 'delete-backward-char)
  (keyboard-translate ?\C-h ?\C-?))

(setup (:require +init)
  (:bind "C-c s" (lambda ()
                   (interactive)
                   (+init-sort)
                   (save-buffer)))
  (:hook '+init-add-setup-to-imenu))

(setup (:require +key)
  (+key-setup))

(setup (:require auth-source)
  (:option auth-sources (list (private/ "authinfo")
                              (private/ "authinfo.gpg")
                              "~/.authinfo"
                              "~/.authinfo.gpg")))

(setup (:require goto-addr)
  (if (fboundp #'global-goto-address-mode)
      (global-goto-address-mode)
    (add-hook 'after-change-major-mode-hook #'goto-address-mode)))

(setup (:require pulse)
  (:also-load +pulse)
  (:option pulse-flag nil
           pulse-delay 0.5
           pulse-iterations 1
           (append +pulse-location-commands) 'lui-track-jump-to-indicator)
  (+pulse-location-mode +1))

(setup (:require reading))

(setup Info
  (:hook 'variable-pitch-mode
         'reading-mode))

(setup abbrev
  (:option abbrev-file-name (sync/ "abbrev.el")
           save-abbrevs 'silent)
  (:hook-into text-mode
              circe-chat-mode))

(setup autorevert
  (:option global-auto-revert-non-file-buffers t
           auto-revert-verbose nil)
  (global-auto-revert-mode +1))

(setup browse-url
  (:require +browse-url)
  (:option browse-url-secondary-browser-function (if (executable-find "firefox")
                                                     'browse-url-firefox
                                                   'browse-url-default-browser)
           browse-url-new-window-flag nil
           browse-url-firefox-arguments '("--new-tab")
           browse-url-firefox-new-window-is-tab t)
  ;; Set up URL handlers.
  (+browse-url-set-handlers
   (list
    (cons (rx                           ; images
           "." (or "jpeg" "jpg" "png") eos)
          (lambda (&rest args)
            (apply
             (cond ((executable-find "mpv") '+browse-image-with-mpv)
                   (t 'eww-browse-url))
             args)))
    (cons (rx                           ; videos
           (or "youtube.com" "youtu.be" "yewtu.be"
               (seq "." (or "mp4" "gif" "mov" "MOV") eos)))
          (lambda (&rest args)
            (apply (if (executable-find "mpv")
                       '+browse-url-with-mpv
                     browse-url-secondary-browser-function)
                   args)))
    (cons (rx                           ; non-eww-friendly websites
           (or
            "github.com"
            "gitlab.com"
            "google.com"
            "imgur.com"
            "pixelfed" "instagram.com" "bibliogram.art"
            "reddit.com" "teddit.net"
            "tildes.net"
            "taskiq"
            "twitter.com" "nitter.net"
            ))
          browse-url-secondary-browser-function)
    (cons "."                           ; everything else
          'eww-browse-url)))
  ;; Transform URLs before passing to `browse-url'
  (:option +browse-url-transformations `((,(rx "//" (or "youtube.com"
                                                        "youtu.be"))
                                          . "//yewtu.be")
                                         ("twitter\\.com"
                                          . "nitter.net")
                                         ("instagram\\.com"
                                          . "bibilogram.art")
                                         (,(rx (or "reddit.com"
                                                   "old.reddit.com"))
                                          . "teddit.net")
                                         ("medium\\.com"
                                          . "scribe.rip")))
  (+browse-url-transform-url-global-mode +1))

(setup calendar
  (require '_location)
  (:option calendar-location-name _location-name
           calendar-latitude _location-latitude
           calendar-longitude _location-longitude))

(setup cus-edit
  ;; I don't use Custom to actually /make/ any customizations, but it's handy to
  ;; (A) see what options are available and (B) persist some changes across
  ;; restarts, for example, `safe-local-variables'.
  (:require +cus-edit)
  (:option custom-file (private/ "custom.el")
           custom-magic-show nil
           custom-magic-show-button t
           custom-raised-buttons nil
           custom-unlispify-tag-names nil
           custom-variable-default-form 'lisp
           +custom-variable-allowlist '(safe-local-variable-values))
  (when (file-exists-p custom-file)
    (+custom-load-ignoring-most-customizations t))
  (advice-add 'custom-buffer-create-internal :after '+cus-edit-expand-widgets)
  (:with-mode Custom-mode
    (:local-set imenu-generic-expression +cus-edit-imenu-generic-expression)))

(setup dired
  (:also-load dired-x)
  (:also-straight dired-subtree
                  dired-collapse
                  dired-git-info
                  dired+)
  (:option dired-recursive-copies 'top
           dired-recursive-deletes 'top
           dired-create-destination-dirs 'ask
           delete-by-moving-to-trash t
           dired-listing-switches "-Al"
           ls-lisp-dirs-first t
           dired-ls-F-marks-symlinks t
           dired-no-confirm '(byte-compile
                              chgrp chmod chown copy
                              hardlink load move
                              shell touch symlink)
           dired-dwim-target t)
  (:bind "<backspace>" 'dired-up-directory
         "TAB" 'dired-subtree-cycle
         "i" 'dired-subtree-toggle
         ")" 'dired-git-info-mode)
  (:hook 'dired-collapse-mode
         'dired-hide-details-mode
         'hl-line-mode)
  (:+key "C-x C-j" 'dired-jump)
  (with-eval-after-load 'dired
    (pcase system-type
      ((or 'ms-dos 'windows-nt)
       (:straight w32-browser))
      ((or 'gnu/linux)
       (:straight dired-open)
       (:option dired-listing-switches
                (concat dired-listing-switches " -F")))))
  (with-eval-after-load 'frowny
    (add-to-list 'frowny-inhibit-modes 'dired-mode)))

(setup eldoc
  (:hook-into elisp-mode
              lisp-interaction-mode))

(setup elisp-mode
  (:also-load +elisp)
  (:option eval-expression-print-length nil
           eval-expression-print-level nil)
  (:with-map (emacs-lisp-mode-map lisp-interaction-mode-map)
    (:bind "C-c C-c" 'eval-defun
           "C-c C-k" '+elisp-eval-region-or-buffer
           "C-c C-z" 'ielm))
  (advice-add 'eval-region :around '+eval-region@pulse))

(setup eshell
  (:also-load +eshell
              em-smart
              em-tramp)
  (:option eshell-aliases-file (.etc "eshell/aliases" t)
           eshell-destroy-buffer-when-process-dies t
           eshell-directory-name (.etc "eshell/" t)
           eshell-error-if-no-glob t
           eshell-hist-ignore-dups t
           eshell-kill-on-exit nil
           eshell-prefer-lisp-functions t
           eshell-prefer-lisp-variables t
           eshell-review-quick-commands nil
           eshell-save-history-on-exit t
           eshell-scroll-to-bottom-on-input 'all
           eshell-smart-space-goes-to-end t
           eshell-where-to-jump 'begin)
  (:local-set outline-regexp eshell-prompt-regexp
              page-delimiter eshell-prompt-regexp)
  (:bind "C-d" '+eshell-quit-or-delete-char)
  (:when-loaded
    (setenv "PAGER" "cat")))

(setup eww
  (:also-load +eww)
  (:option eww-search-prefix "https://duckduckgo.com/html?q="
           url-privacy-level '(email agent cookies lastloc))
  (add-hook 'eww-after-render-hook 'reading-mode)
  (:hook '+eww-bookmark-setup
         '+eww-track-readable-mode)
  (:bind "b" 'bookmark-set
         "B" 'bookmark-jump
         "M-n" nil
         "M-p" nil))

(setup ibuffer
  (:also-load ibuf-ext)
  (:option ibuffer-expert t
           ibuffer-show-empty-filter-groups nil
           ibuffer-saved-filter-groups
           '(("default"
              ("Org" (mode . org-mode))
              ("emacs" (or (name . "^\\*scratch\\*$")
                           (name . "^\\*Messages\\*$")
                           (name . "^\\*Warnings\\*$")
                           (name . "^\\*straight-process\\*$")
                           (name . "^\\*Calendar\\*$")))
              ("customize" (mode . Custom-mode))
              ("emacs-config" (or (filename . ".emacs.d")
                                  (mode . +init-mode)))
              ("git" (or (name . "^\*magit")
                         (name . "^\magit")))
              ("help" (or (mode . help-mode)
                          (mode . Info-mode)
                          (mode . helpful-mode)))
              ("irc" (or (mode . erc-mode)
                         (mode . circe-server-mode)
                         (mode . circe-channel-mode)))
              ("shell" (or (mode . eshell-mode)
                           (mode . shell-mode)
                           (mode . vterm-mode)))
              ("web" (or (mode . elpher-mode)
                         (mode . eww-mode))))))
  (:hook (defun ibuffer@filter-to-default ()
           (ibuffer-auto-mode +1)
           (ibuffer-switch-to-saved-filter-groups "default"))))

(setup magit
  ;; This setup is weird because of dependency issues
  (:straight (transient :host github :repo "magit/transient" :branch "master")
             (magit :host github :repo "magit/magit")
             (git-modes :host github :repo "magit/git-modes"))
  (when (eq system-type 'gnu/linux)
    (:straight (forge :host github :repo "magit/forge"))
    (with-eval-after-load 'magit
      (require 'forge)
      (add-to-list 'forge-alist
                   '("tildegit.org" "tildegit.org/api/v1" "tildegit.org"
                     forge-gitea-repository)))))

(setup minibuffer
  (:require +minibuffer)
  (:with-map minibuffer-local-map
    (:bind "M-/" '+minibuffer-complete-history)))

(setup prog
  (:local-set comment-auto-fill-only-comments t)
  (:hook 'prettify-symbols-mode
         'display-fill-column-indicator-mode
         'turn-on-auto-fill))

(setup scratch
  (:require +scratch)
  (:option initial-major-mode 'lisp-interaction-mode
           initial-scratch-message
           ";; ABANDON ALL HOPE YE WHO ENTER HERE\n\n")
  (add-hook 'kill-buffer-query-functions '+scratch-immortal))

(setup text
  (:hook 'turn-on-auto-fill))

(setup (:straight 0x0)
  (:option 0x0-default-server 'ttm)
  (with-eval-after-load 'embark
    (define-key embark-region-map (kbd "U") '0x0-dwim)))

(setup (:straight ace-window)
  (:require +ace-window)
  (:option aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)
           aw-display-mode-overlay nil)
  (:+key "M-o" '+ace-window-or-switch-buffer)
  (:face aw-mode-line-face ((t (:foreground "red"))))
  (+ace-window-display-mode +1))

(setup (:straight anzu)
  (:option anzu-cons-mode-line-p nil)
  (:+key [remap query-replace] 'anzu-query-replace-regexp
         [remap query-replace-regexp] 'anzu-query-replace-regexp)
  (global-anzu-mode +1)
  (:bind-into isearch
    [remap isearch-query-replace] 'anzu-isearch-query-replace
    [remap isearch-query-replace-regexp] 'anzu-isearch-query-replace-regexp))

(setup (:straight avy)
  (:also-load +avy)
  (:+key "M-j" 'avy-goto-char-timer)
  (:bind-into isearch
    "M-j" 'avy-isearch)
  (:when-loaded
    (setf (alist-get ?. avy-dispatch-alist) 'avy-action-embark)))

(setup (:straight (cape :host github :repo "minad/cape"))
  (dolist (fn '(;; All available cape capfs listed here.
                cape-file
                cape-dabbrev
                cape-keyword
                ;;cape-abbrev
                ;;cape-ispell
                ;;cape-dict
                ))
    (add-to-list 'completion-at-point-functions fn)))

(setup (:straight (capf-autosuggest
                   :host nil
                   :repo "https://repo.or.cz/emacs-capf-autosuggest.git"))
  (:hook-into eshell-mode
              comint-mode))

(setup (:straight circe)
  (:require _circe
            +circe)
  (:also-load circe-chanop)

  ;; Formatting options
  (:option circe-format-action (format (format "%%%ds* {nick} {body}"
                                               (- +circe-left-margin 2))
                                       " ")
           circe-format-say (format "{nick:%1$d.%1$ds} | {body}"
                                    (- +circe-left-margin 3))
           circe-format-self-action circe-format-action
           circe-format-self-say (replace-regexp-in-string "|" ">"
                                                           circe-format-say)
           circe-format-server-part (+circe-format-meta
                                     "PART {channel}: {reason}")
           circe-format-server-quit (+circe-format-meta "QUIT: {reason}")
           circe-format-server-quit-channel (+circe-format-meta
                                             "QUIT {channel}: {reason}")
           circe-format-server-join (+circe-format-meta "JOIN: {userinfo}")
           circe-format-server-rejoin (+circe-format-meta
                                       (concat "REJOIN: {userinfo} "
                                               "after {departuredelta}"))
           circe-format-server-topic (+circe-format-meta
                                      "TOPIC: {new-topic}")
           circe-prompt-string (format (format "%%%ds> "
                                               (- +circe-left-margin 2))
                                       " "))
  
  (:option +circe-server-buffer-action (lambda (buf)
                                         (message "Connected to %s" buf))
           +circe-network-inhibit-autoconnect _circe-network-inhibit-autoconnect
           circe-network-options _circe-network-options
           circe-color-nicks-everywhere t
           circe-default-part-message "See You, Space Cowpokes . . ."
           circe-default-user user-real-login-name
           circe-reduce-lurker-spam t
           circe-server-auto-join-default-type :after-auth)
  (:bind "C-c C-p" 'circe-command-PART
         "C-c C-t" '+circe-current-topic
         "C-l" 'lui-track-jump-to-indicator
         "C-<return>" '+circe-chat@set-prompt)

  (advice-add 'circe-command-PART :after '+circe-kill-buffer)
  (advice-add 'circe-command-QUIT :after '+circe-quit@kill-buffer)
  (advice-add 'circe-command-GQUIT :after '+circe-gquit@kill-buffer)
  
  (:with-mode circe-chat-mode
    (:hook 'enable-circe-color-nicks
           'enable-circe-new-day-notifier
           '+circe-chat@set-prompt)
    (:bind "C-c C-s" 'circe-command-SLAP))

  (:with-mode lui-mode
    (:option lui-fill-column (+ fill-column +circe-left-margin)
             lui-fill-type nil
             lui-time-stamp-position 'right-margin
             lui-time-stamp-format "[ %H:%M"
             lui-track-behavior 'before-switch-to-buffer
             lui-track-indicator 'fringe
             lui-fill-remove-face-from-newline nil
             lui-formatting-list `((,(+lui-make-formatting-list-rx "*")
                                    1 lui-strong-face)
                                   (,(+lui-make-formatting-list-rx "_")
                                    1 lui-emphasis-face)
                                   (,(+lui-make-formatting-list-rx "/")
                                    1 lui-emphasis-face)))
    (:hook 'visual-line-mode
           'enable-lui-track
           'visual-fill-column-mode)
    (:local-set fringes-outside-margins t
                right-margin-width (length lui-time-stamp-format)
                scroll-margin 0
                word-wrap t
                wrap-prefix (+string-repeat +circe-left-margin " ")
                line-number-mode nil
                column-number-mode nil
                file-percentage-mode nil
                visual-fill-column-extra-text-width
                (cons +circe-left-margin 0)))

  (with-eval-after-load 'topsy
    (:option (append topsy-mode-functions)
             '(circe-channel-mode . +circe-current-topic)))

  (with-eval-after-load 'circe-color-nicks
    (add-hook 'modus-themes-after-load-theme-hook 'circe-nick-color-reset))
  (add-hook 'kill-emacs-hook '+circe-quit-all@kill-emacs))

(setup (:straight consult)
  (:also-load +consult)
  ;; from Consult wiki
  (:option register-preview-delay 0
	   register-preview-function 'consult-register-format
	   xref-show-xrefs-function 'consult-xref
	   xref-show-definitions-function 'consult-xref
	   tab-always-indent 'complete
	   completion-in-region-function 'consult-completion-in-region)
  (advice-add 'register-preview :override 'consult-register-window)
  (advice-add 'completing-read-multiple :override
	      'consult-completing-read-multiple)
  (dolist (binding '(;; C-c bindings (mode-specific-map)
		     ("C-c h" . consult-history)
		     ("C-c m" . consult-mode-command)
		     ("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 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)))
    (define-key +key-mode-map (kbd (car binding)) (cdr binding)))
  (with-eval-after-load 'isearch-mode
    (dolist (binding '(("M-e" . consult-isearch-history)
		       ("M-s e" . consult-isearch-history)
		       ("M-s l" . consult-line)
		       ("M-s L" . consult-line-multi)))
      (define-key isearch-mode-map (car binding) (cdr binding))))
  (with-eval-after-load 'org-mode
    (define-key org-mode-map "M-g o" 'consult-org-heading))
  (with-eval-after-load 'consult
    (:option consult-narrow-key "<"
	     consult-project-root-function '+consult-project-root)
    (consult-customize
     consult-theme
     :preview-key '(:debounce 0.2 any)
     consult-ripgrep consult-git-grep consult-grep
     consult-bookmark consult-recent-file consult-xref
     consult--source-file consult--source-project-file
     consult--source-bookmark
     :preview-key (kbd "M-."))
    (consult-history-to-modes ((minibuffer-local-map . nil)
                               (shell-mode-map . shell-mode-hook)
                               (term-mode-map . term-mode-hook)
                               (term-raw-map . term-mode-hook)
                               (comint-mode-map . comint-mode-hook)
                               (sly-mrepl-mode-map . sly-mrepl-hook)))
    (with-eval-after-load 'orderless
      (:option consult--regexp-compiler 'consult--orderless-regexp-compiler))))

(setup (:straight crux)
  (:+key "C-o" 'crux-smart-open-line
         "C-x 4 t" 'crux-transpose-windows)

  (el-patch-feature crux)
  (with-eval-after-load 'crux
    (el-patch-defun crux-reopen-as-root ()
      "Find file as root if necessary.

Meant to be used as `find-file-hook'.
See also `crux-reopen-as-root-mode'."
      (unless (or
               ;; This helps fix for `nov-mode', and possibly others.
               (el-patch-add (null buffer-file-name))
               (tramp-tramp-file-p buffer-file-name)
               (equal major-mode 'dired-mode)
               (not (file-exists-p (file-name-directory buffer-file-name)))
               (file-writable-p buffer-file-name)
               (crux-file-owned-by-user-p buffer-file-name))
        (crux-find-alternate-file-as-root buffer-file-name))))
  (crux-reopen-as-root-mode +1))

(setup (:straight dictionary)
  (:option dictionary-use-single-buffer t)
  (autoload 'dictionary-search "dictionary"
    "Ask for a word and search it in all dictionaries" t)
  (autoload 'dictionary-match-words "dictionary"
    "Ask for a word and search all matching words in the dictionaries" t)
  (autoload 'dictionary-lookup-definition "dictionary"
    "Unconditionally lookup the word at point." t)
  (autoload 'dictionary "dictionary"
    "Create a new dictionary buffer" t)
  (autoload 'dictionary-mouse-popup-matching-words "dictionary"
    "Display entries matching the word at the cursor" t)
  (autoload 'dictionary-popup-matching-words "dictionary"
    "Display entries matching the word at the point" t)
  (autoload 'dictionary-tooltip-mode "dictionary"
    "Display tooltips for the current word" t)
  (autoload 'global-dictionary-tooltip-mode "dictionary"
    "Enable/disable dictionary-tooltip-mode for all buffers" t)
  (:hook 'reading-mode))

(setup (:straight (discord
                   :host github
                   :repo "davep/discord.el"
                   :fork (:repo "duckwork/discord.el"))))

(setup (:straight electric-cursor)
  (electric-cursor-mode +1))

(setup (:straight elfeed)
  (:also-load +elfeed)
  (:option elfeed-use-curl t
           elfeed-curl-extra-arguments '("--insecure")
           elfeed-show-unique-buffers t
           elfeed-db-directory (sync/ "elfeed/db/" t))
  (:with-mode elfeed-show-mode
    (:bind "SPC" '+elfeed-scroll-up-command
           "S-SPC" '+elfeed-scroll-down-command)
    (:hook 'reading-mode)))

(setup (:straight elfeed-org)
  (:option rmh-elfeed-org-files (list (sync/ "elfeed/elfeed.org" t)))
  (elfeed-org))

(setup (:straight embark)
  (:option prefix-help-command 'embark-prefix-help-command)
  (:+key "C-." 'embark-act
	 "M-." 'embark-dwim
	 "<f1> B" 'embark-bindings))

(setup (:straight embark-consult)
  (:load-after consult embark)
  (add-hook 'embark-collect-mode-hook 'consult-preview-at-point-mode))

(setup (:straight eros)
  (:hook-into emacs-lisp-mode
              lisp-interaction-mode))

(setup (:straight eshell-syntax-highlighting)
  (:hook-into eshell-mode))

(setup (:straight-when exec-path-from-shell
         (eq system-type 'gnu/linux))
  (when (daemonp)
    (exec-path-from-shell-initialize))
  (exec-path-from-shell-copy-envs '("XDG_CONFIG_HOME"
                                    "XDG_CONFIG_DIRS"
                                    "XDG_DATA_HOME"
                                    "XDG_DATA_DIRS"
                                    "XDG_CACHE_HOME")))

(setup (:straight expand-region)
  (:+key "C-=" 'er/expand-region))

(setup (:straight (frowny
                   :host github
                   :repo "duckwork/frowny.el"))
  (global-frowny-mode +1))

(setup (:straight gcmh)
  (:option gcmh-idle-delay 'auto)
  (gcmh-mode +1))

(setup (:straight-when geiser
         (progn
           (defvar +schemes
             (let (schemes)
               (dolist (scheme '(("scheme" . geiser-chez) ; chez
                                 ("petite" . geiser-chez) ; petite
                                 ("csi" . geiser-chicken)    ; chicken
                                 ("gsi" . geiser-gambit)
                                 ("gosh" . geiser-gauche)
                                 ("guile" . geiser-guile)
                                 ("kawa" . geiser-kawa)
                                 ("mit-scheme" . geiser-mit)
                                 ("racket" . geiser-racket)
                                 ("stklos" . geiser-stklos)))
                 (when-let (binary (executable-find (car scheme)))
                   (push binary schemes)
                   ;; and install the proper helper package
                   (straight-use-package (cdr scheme))))
               (nreverse schemes)))
           +schemes))
  (:file-match (rx ".rkt" eos)
               (rx ".scm" eos)))

(setup (:straight helpful)
  (run-with-idle-timer 0.5 nil
                       'require 'helpful)
  (:+key "<f1> f" 'helpful-callable
         "<f1> v" 'helpful-variable
         "<f1> k" 'helpful-key
         "C-c C-d" 'helpful-at-point))

(setup (:straight (hippie-completing-read
                   :host github
                   :repo "duckwork/hippie-completing-read"))
  (:+key "M-/" 'hippie-completing-read))

(setup (:straight hungry-delete)
  (:option hungry-delete-chars-to-skip " \t"
	   hungry-delete-join-reluctantly nil)
  (:bind-into paredit
    ;; I define these functions here because they really require both packages
    ;; to make any sense.  So, would I put them in `+hungry-delete' or
    ;; `+paredit' ?  There's no satisfactory answer.
    [remap paredit-backward-delete]
    (defun acdw/paredit-hungry-delete-backward (arg)
      (interactive "P")
      (if (looking-back "[ \t]" 1)
	  (hungry-delete-backward (or arg 1))
	(paredit-backward-delete arg)))
    [remap paredit-forward-delete]
    (defun acdw/paredit-hungry-delete-forward (arg)
      (interactive "P")
      (if (looking-at "[ \t]")
	  (hungry-delete-forward (or arg 1))
	(paredit-forward-delete arg))))
  (global-hungry-delete-mode +1))

(setup (:straight isearch-mb)
  ;; This complicatedness is an attempt to make it easier to add and
  ;; subtract `isearch-mb' bindings using the suggestions in the
  ;; project's README.
  (with-eval-after-load '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 +1))

(setup (:straight lacarte)
  (:+key "<f10>" 'lacarte-execute-menu-command))

(setup (:straight (lin :host gitlab :repo "protesilaos/lin"))
  (require 'lin)
  (:hook-into dired-mode
              elfeed-search-mode
              git-rebase-mode
              ibuffer-mode
              ledger-report-mode
              log-view-mode
              magit-log-mode
              notmuch-search-mode
              notmuch-tree-mode
              org-agenda-mode
              tabulated-list-mode))

(setup (:straight marginalia)
  (marginalia-mode +1))

(setup (:straight minions)
  (:option minions-prominent-modes
           '(tracking-mode))
  (minions-mode +1))

(setup (:straight mode-line-bell)
  (:option mode-line-bell-flash-time 0.1)
  (mode-line-bell-mode +1))

(setup (:straight (modus-themes
                   :host gitlab
                   :repo "protesilaos/modus-themes"))
  (require 'modus-themes (.etc "straight/build/modus-themes/modus-themes"))
  (:option modus-themes-bold-constructs t
           modus-themes-italic-constructs t
           modus-themes-headings '((t . (background))))
  (+sunrise-sunset 'modus-themes-load-operandi 'modus-themes-load-vivendi))

(setup (:straight mwim)
  (:+key "C-a" #'mwim-beginning
         "C-e" #'mwim-end))

(setup (:straight orderless)
  (:option completion-styles '(orderless)))

(setup (:straight (org
                   :type git :host nil
                   :repo "https://git.savannah.gnu.org/git/emacs/org-mode.git"
                   :local-repo "org"
                   :depth full
                   :pre-build (straight-recipes-org-elpa--build)
                   :build (:not autoloads)
                   :files (:defaults
                           "lisp/*.el"
                           ("etc/styles/" "etc/styles/*")))
                  (org-contrib
                   :type git :host nil
                   :repo "https://git.sr.ht/~bzg/org-contrib"))
  ;; DO NOT load system-installed org !!!
  (setq load-path (cl-remove-if (lambda (path)
                                  (string-match-p "lisp/org\\'" path))
                                load-path))
  (:also-load +org
              ox-md)
  (:option org-adapt-indentation nil
           org-agenda-skip-deadline-if-done t
           org-archive-mark-done t
           org-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 t
           org-confirm-babel-evaluate nil
           org-cycle-separator-lines 0
           org-directory "~/org"
           org-ellipsis "…"
           org-export-coding-system 'utf-8-unix
           org-export-headline-levels 8
           org-export-with-section-numbers nil
           org-export-with-smart-quotes t
           org-export-with-sub-superscripts t
           org-export-with-toc nil
           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-list-demote-modify-bullet '(("-" . "+")
                                           ("+" . "*")
                                           ("*" . "-"))
           org-log-done 'time
           org-log-into-drawer t
           org-outline-path-complete-in-steps nil
           org-pretty-entities t
           org-pretty-entities-include-sub-superscripts nil
           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 (- (- fill-column (length org-ellipsis))))
  (:bind "RET" '+org-return-dwim
         "<S-return>" '+org-table-copy-down
         "C-c C-l" '+org-insert-link-dwim
         "C-c C-n" '+org-next-heading-widen
         "C-c C-p" '+org-previous-heading-widen)
  (:+leader "c" 'org-capture "C-c" 'org-capture
            "a" 'org-agenda "C-a" 'org-agenda)
  (:local-hook before-save-hook '+org-before-save@prettify-buffer)
  (advice-add 'org-delete-backward-char :override '+org-delete-backward-char)
  (with-eval-after-load 'org
    (org-clock-persistence-insinuate)
    (org-link-set-parameters "tel" :follow '+org-tel-open)))

(setup (:straight org-appear)
  (:option org-appear-autoemphasis t
           org-appear-autoentities t
           org-appear-autokeywords t
           org-appear-autolinks nil
           org-appear-autosubmarkers t
           org-appear-delay 0)
  (:hook-into org-mode))

(setup (:straight org-sticky-header)
  (:hook-into org-mode))

(setup (:straight paredit)
  (:bind "DEL" 'paredit-backward-delete
         "C-<backspace>" 'paredit-backward-kill-word)
  (:hook-into emacs-lisp-mode lisp-interaction-mode
              lisp-mode scheme-mode)
  (:also-load eldoc)
  (eldoc-add-command 'paredit-backward-delete 'paredit-close-round))

(setup (:straight paren-face)
  (:hook-into emacs-lisp-mode
              ielm-mode sly-repl-mode
              lisp-mode
              lisp-interaction-mode
              scheme-mode))

(setup (:straight-when pdf-tools
         (eq system-type 'gnu/linux))
  (pdf-tools-install))

(setup (:straight (shell-command+
                   :host nil
                   :repo "https://git.sr.ht/~pkal/shell-command-plus"))
  (:option shell-command-prompt "$ ")
  (:bind-into dired
    "M-!" 'shell-command+)
  (:+key "M-!" 'shell-command+))

(setup (:straight sicp))

(setup (:straight (simple-modeline
                   :fork (:repo "duckwork/simple-modeline")))
  (:also-load +modeline)
  (:option simple-modeline-segments '((;; left
                                       +modeline-ace-window-display
                                       +modeline-modified
                                       +modeline-reading-mode
                                       +modeline-narrowed
                                       +modeline-buffer-name
                                       +modeline-position
                                       +modeline-anzu
                                       )
                                      (;; right
                                       +modeline-track
                                       +modeline-vc
                                       simple-modeline-segment-misc-info
                                       simple-modeline-segment-process
                                       +modeline-text-scale
                                       +modeline-minions
                                       +modeline-major-mode
                                       )))
  (simple-modeline-mode +1))

(setup (:straight smartscan)
  (global-smartscan-mode +1))

(setup (:straight ssh-config-mode)
  (:file-match (rx "/.ssh/config" eos)
               (rx "/ssh" (? "d") "_config" eos))
  (:with-mode ssh-known-hosts-mode
    (:file-match (rx "/knownhosts" eos)))
  (:with-mode ssh-authorized-keys-mode
    (:file-match (rx "/authorized_keys" (? "2") eos))))

(setup (:straight super-save)
  (:option auto-save-default nil
           super-save-auto-save-when-idle t
           super-save-idle-duration 60
           super-save-exclude '(".gpg")
           super-save-remote-files nil)
  (auto-save-visited-mode -1)
  (super-save-mode +1))

(setup (:straight (titlecase
                   :host github
                   :repo "duckwork/titlecase.el")))

(setup (:straight topsy)
  (:hook-into prog-mode
              circe-chat-mode)
  (:when-loaded
    (:option
     topsy-header-line-format
     '(:eval
       (list
        (propertize " "
                    'display
                    `((space 
                       :align-to 
                       ,(unless (bound-and-true-p visual-fill-column-mode)
                          0))))
        (funcall topsy-fn))))))

(setup (:straight transpose-frame))

(setup (:straight trashed)
  (:option trashed-action-confirmer #'y-or-n-p))

(setup (:straight undo-fu)
  (:+key "C-/" #'undo-fu-only-undo
         "C-?" #'undo-fu-only-redo))

(setup (:straight undo-fu-session)
  (:option undo-fu-session-incompatible-files '("/COMMIT_EDITMSG\\'"
                                                "/git-rebase-todo\\'")
           undo-fu-session-directory (.etc "undo/" t)
           undo-fu-session-compression (eq system-type 'gnu/linux))
  (global-undo-fu-session-mode +1))

(setup (:straight (vertico
                   :host github
                   :repo "minad/vertico"
                   :files ("*" "extensions/*"
                           (:exclude ".git"))))
  (:also-load +vertico)
  (:option resize-mini-windows 'grow-only
           vertico-count-format nil
           vertico-cycle t)
  (advice-add 'vertico-next :around '+vertico-ding-wrap)
  (when (boundp 'native-comp-deferred-compilation-deny-list)
    (add-to-list 'native-comp-deferred-compilation-deny-list "vertico"))
  (vertico-mode +1)
  ;; Extensions
  (:also-load vertico-directory)
  (:with-map vertico-map
    (:bind "RET" 'vertico-directory-enter
           "DEL" 'vertico-directory-delete-char
           "M-DEL" 'vertico-directory-delete-word))
  (add-hook 'rfn-eshadow-update-overlay-hook 'vertico-directory-tidy))

(setup (:straight visual-fill-column)
  (:option visual-fill-column-center-text t
           (append reading-modes) '(visual-fill-column-mode . +1))
  (:hook 'visual-line-mode)
  (:hook-into org-mode)
  (advice-add 'text-scale-adjust :after 'visual-fill-column-adjust))

(setup (:straight vlf)
  (:require vlf-setup))

(setup (:straight whitespace-cleanup-mode)
  (:option whitespace-cleanup-mode-preserve-point t)
  ;;(remove-hook 'before-save-hook 'whitespace-cleanup)
  (global-whitespace-cleanup-mode +1))

(setup (:straight zoom-frm))

(setup (:straight zzz-to-char)
  (:+key "M-z" (lambda (prefix)
                 "Call `zzz-to-char' or `zzz-up-to-char' with PREFIX arg."
                 (interactive "P")
                 (call-interactively
                  (if prefix #'zzz-up-to-char #'zzz-to-char)))))