aboutsummaryrefslogtreecommitdiff
path: root/config.org
blob: 393b13a5c3651cc4dfd1c49c8c674cb78a8cab3f (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
#+title DNW's GNU Emacs Configuration
#+PROPERTY: header-args:emacs-lisp :tangle ./init.el

* Startup Performance

Increase RAM footprint on startup to reduce load time. Display load time as well.

#+begin_src emacs-lisp

  (setq gc-cons-threshold (* 50 1000 1000))

  (defun dnw/display-startup-time ()
    (message "Emacs loaded in %s with %d garbage collections."
             (format "%2f seconds"
                     (float-time
                      (time-subtract after-init-time before-init-time)))
             gcs-done))

  (add-hook 'emacs-startup-hook #'dnw/display-startup-time)

  (server-start)

#+end_src


* General Keybinds

** Text Editing

Indent region; set TAB to complete in right circumstance

#+begin_src emacs-lisp

  (global-set-key (kbd "C->") 'indent-rigidly-right-to-tab-stop)
  (global-set-key (kbd "C-<") 'indent-rigidly-left-to-tab-stop)

  (setq tab-always-indent 'complete)
  (setq align-to-tab-stop nil)

#+end_src

* Basic Configuration UI

** Better Font

Noto Emoji is the fallback here.

#+begin_src emacs-lisp

  ;; default-frame-alist works with --daemon

  (add-to-list 'default-frame-alist
               '(font . "Iosevka-10"))

  (setf use-default-font-for-symbols nil)
  (set-fontset-font t 'unicode "Noto Emoji" nil 'append)

#+end_src

** Hide Ugly GUI Elements

#+begin_src emacs-lisp

  (setq inhibit-startup-message t)

  (menu-bar-mode -1)
  (tool-bar-mode -1)
  (scroll-bar-mode -1)
  (tooltip-mode -1)
  (set-fringe-mode 10)

#+end_src

** Line Numbers

Display cursor position on the modeline, and line numbers left of the buffer. Except where it's stupid.

#+begin_src emacs-lisp

  (column-number-mode)
  (global-display-line-numbers-mode t)

  ;; Disable in e.g. shell
  (dolist (mode '(org-mode-hook
                  term-mode-hook
                  eshell-mode-hook
                  Info-mode-hook
                  ement-room-mode-hook
                  elfeed-show-mode-hook
                  pdf-mode-hook))
    (add-hook mode (lambda () (display-line-numbers-mode 0))))

#+end_src

** Transparency

#+begin_src emacs-lisp

  (set-frame-parameter (selected-frame) 'alpha '(100 100))

  (add-to-list 'default-frame-alist '(alpha 100 100))

#+end_src

* Package Management

Declare which archives to use, syncing them on start. Always-ensure downloads needed packages not on the system.

#+begin_src emacs-lisp

  (require 'package)
  (setq package-archives '(("melpa" . "https://melpa.org/packages/")
                           ("elpa" . "https://elpa.gnu.org/packages/")))

  (package-initialize)
  (unless package-archive-contents
    (package-refresh-contents))

  (eval-when-compile
    (require 'use-package))

  (setq use-package-always-ensure t)

  (add-to-list 'load-path "/home/dnw/Code/PHYTS/phits-mode")
  (require 'phits-mode)

  (add-to-list 'auto-mode-alist '("\\.inp\\'" . phits-mode))
  (add-to-list 'auto-mode-alist '("\\.out\\'" . phits-mode))

#+end_src

* Path from Shell

Binaries on the zsh path become part of the Emacs path automatically.

#+begin_src emacs-lisp

  (use-package exec-path-from-shell

    :init
    (setq exec-path-from-shell-variables '("PATH" "MANPATH" "GUIX_PROFILE" "PHITSPATH"))
    (when (memq window-system '(mac ns x))
      (exec-path-from-shell-initialize)))

#+end_src

* No Littering!

Write backups and autosaves to .emacs.d, instead of strewing them across the filesystem.

#+begin_src emacs-lisp

  (use-package no-littering)

  (setq auto-save-file-name-transforms
        `((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))

#+end_src

* Completion Framework

** Vertico (Minibuffer UI)

#+begin_src emacs-lisp

  (use-package vertico
    :init (vertico-mode)
    :custom (vertico-cycle t))

#+end_src

** Corfu (At-Point UI)

#+begin_src emacs-lisp

  (use-package corfu
    :custom (corfu-cycle t)
    :init (global-corfu-mode))

#+end_src

*** Kind-Icon (Corfu Menu Sugar)

#+begin_src emacs-lisp

  ;; (use-package kind-icon
  ;;   :ensure t
  ;;   :after corfu
  ;;   :custom
  ;;   (kind-icon-default-face 'corfu-default) ; to compute blended backgrounds correctly
  ;;   :config
  ;;   (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))

  ;; Doesn't work :(
#+end_src

** Orderless (Candidate Filtering)

#+begin_src emacs-lisp

  (use-package orderless
    :init
    (setq completion-styles '(orderless)
          completion-category-defaults nil
          completion-category-overrides '((file (styles . (partial-completion))))))

#+end_src

** Consult (Completion Command Alternatives)

#+begin_src emacs-lisp

      (use-package consult
        :bind (("C-s" . consult-line)
               ("C-r" . consult-history))
        :custom (completion-in-region-function #'consult-completion-in-region))

#+end_src

** Marginalia (Completion Annotations)

#+begin_src emacs-lisp

  (use-package marginalia
    :after vertico
    :custom
    (marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil))
    :init (marginalia-mode))

#+end_src

** Dabbrev

#+begin_src emacs-lisp

  (use-package dabbrev
    :bind (("M-/" . dabbrev-completion)
           ("C-M-/" . dabbrev-expand)))

#+end_src

** Embark at some point?

* Auto-Insert

File templates from =auto-insert-directory= (which I have defined as =~/.emacs.d/insert/=) on opening file type.

#+begin_src emacs-lisp

  (defun dnw/prompt-date ()
    (let ((date (read-string "Due date: "))
                                            (now  (split-string (format-time-string "%e %B %Y" (current-time)))))
                                        (cond ((equal date "")
                                               (concat now))
                                              ((equal (substring date 0 1) "+")
                                               (concat (number-to-string (+ (string-to-number (car now))
                                                                            (string-to-number (substring date 1))))
                                                       " "
                                                       (cadr now)
                                                       " "
                                                       (caddr now)))
                                              ((= (length date) 2)
                                               (concat date
                                                       " "
                                                       (cadr now)
                                                       " "
                                                       (caddr now))))))

  (setq dnw/autoinsert-latex-presets
        '(("Physics" . (nil "\\documentclass{article}\n\n"

                            "\\usepackage[letterpaper]{geometry}\n"
                            "\\usepackage{tgpagella}\n"
                            "\\usepackage{amsmath}\n"
                            "\\usepackage{siunitx}\n\n"


                            "\\title{" (read-string "Title: ") "}\n"
                            "\\author{Duncan Wilkie}\n"
                            "\\date{" (dnw/prompt-date) "}\n\n"

                            "\\begin{document}\n\n"

                            "\\maketitle\n\n"

                            -

                            "\n\n\\end{document}"))
          ("Math" . (nil "\\documentclass{article}\n\n"

                         "\\usepackage[letterpaper]{geometry}\n"
                         "\\usepackage{tgpagella}\n"
                         "\\usepackage{amsmath}\n"
                         "\\usepackage{amssymb}\n"
                         "\\usepackage{amsthm}\n\n"

                         "\\title{" (read-string "Title: ") "}\n"
                         "\\author{Duncan Wilkie}\n"
                         "\\date{" (dnw/prompt-date) "}\n\n"

                         "\\begin{document}\n\n"

                         "\\maketitle\n\n"

                         -

                         "\n\n\\end{document}"))
          ("Default" . ("options, RET: " "\\documentclass[" str & 93 | -1 123
                        (read-string "class: ")
                        "}\n"
                        ("package, %s: " "\\usepackage["
                         (read-string "options, RET: ")
                         & 93 | -1 123 str "}\n")
                        _ "\n\\begin{document}\n"
                        _ "\n\\end{document}"))))

  (use-package autoinsert
    :hook (find-file . auto-insert)
    :init
    (setq auto-insert t)
    (setq auto-insert-query nil)
    (auto-insert-mode t)
    :config
    (assoc-delete-all 'latex-mode auto-insert-alist)
    (define-auto-insert 'latex-mode
      (lambda ()
        (let* ((presets (mapcar (lambda (pair)(car pair))
                                dnw/autoinsert-latex-presets))
               (choice (completing-read "Preset:" presets)))
          (skeleton-insert (assoc choice dnw/autoinsert-latex-presets))))))


#+end_src


* Helpful (Better Documentation)

Using /documentation command/ defaults to the much better helpful version.

#+begin_src emacs-lisp

  (use-package helpful
    :commands (helpful-callable helpful-variable helpful-command helpful-key)
    :custom
    (counsel-describe-function-function #'helpful-callable)
    (counsel-describe-variable-function #'helpful-variable)
    :bind
    ([remap describe-function] . helpful-function)
    ([remap describe-command] . helpful-command)
    ([remap describe-variable] . helpful-variable)
    ([remap describe-key] . helpful-key))

#+end_src

* More UI Configuration

** DOOM Modeline

A prettier and more functional modeline. All-the-icons is required for e.g. the org logo when in org mode.

#+begin_src emacs-lisp

  (use-package doom-modeline
    :ensure t
    :init (doom-modeline-mode 1))

  (use-package diminish)

  (use-package all-the-icons) ;; requires M-x all-the-icons-install-fonts on first load

#+end_src

** Set Theme

These have better integration with package-spawned buffers. And are quite tasteful.

#+begin_src emacs-lisp

  (use-package doom-themes
    :init (load-theme 'doom-tomorrow-night t))

#+end_src

** Parenthesis Management

Color pairs of region-marking characters, automatically insert and delete matching ones, & highlight matching parens.

#+begin_src emacs-lisp

    (use-package rainbow-delimiters
      :hook ((prog-mode . rainbow-delimiters-mode)
             (LaTeX-mode . rainbow-delimiters-mode)))

    (use-package smartparens
      :hook ((prog-mode . smartparens-mode)
             (LaTeX-mode . smartparens-mode)
             (org-mode . smartparens-mode))
      :config
      (require 'smartparens-latex))

    (use-package paren
      :config
      (set-face-attribute 'show-paren-match-expression nil :background "#363e4a")
      (show-paren-mode 1))

#+end_src

** Whitespace Management

Require final newline & trim trailing whitespace automatically.

#+begin_src emacs-lisp

  (setq require-final-newline t)

  (use-package ws-butler
    :hook ((text-mode . ws-butler-mode)
           (prog-mode . ws-butler-mode)))

#+end_src

* Which-key

In case of brain-fart: display all bound keystrokes.

#+begin_src emacs-lisp

  (use-package which-key
    :defer 0
    :diminish which-key-mode
    :config
    (which-key-mode)
    (setq which-key-idle-delay 1))

#+end_src

* Org Mode

** Basic Setup

Nicer collapsed heading indicator, document-like variable pitch font, etc.

#+begin_src emacs-lisp

  (defun dnw/org-mode-setup ()
    (org-indent-mode)
    (variable-pitch-mode 1)
    (visual-line-mode 1))

  (use-package org
    :commands (org-capture org-agenda)
    :hook (org-mode . dnw/org-mode-setup)
    :bind ("C-c C-x C-l" . org-latex-preview)
    :config
    (setq org-ellipsis " ▼")
    (setq org-latex-create-formula-image-program 'imagemagick))

#+end_src

** Prettier Headings

Font scaling based on tree depth with some typographical subtleties.

#+begin_src emacs-lisp

  (use-package org-bullets
    :after org
    :hook (org-mode . org-bullets-mode))

  (with-eval-after-load 'org-faces (dolist (face '((org-level-1 . 1.2)
                                                   (org-level-2 . 1.1)
                                                   (org-level-3 . 1.05)
                                                   (org-level-4 . 1.0)
                                                   (org-level-5 . 1.0)
                                                   (org-level-6 . 1.0)
                                                   (org-level-7 . 1.0)
                                                   (org-level-8 . 1.0)))
                                     (set-face-attribute (car face) nil :font "Liberation Sans" :weight 'regular :height (cdr face)))

                        (set-face-attribute 'fixed-pitch nil :font "Iosevka" :weight 'regular :height 1.0)
                        (set-face-attribute 'org-block nil :foreground nil :inherit 'fixed-pitch)
                        (set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch))
                        (set-face-attribute 'org-table nil :inherit '(shadow fixed-pitch))
                        (set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch))
                        (set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face fixed-pitch))
                        (set-face-attribute 'org-meta-line nil :inherit '(font-lock-comment-face fixed-pitch))
                        (set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch))

  (setq org-hide-emphasis-markers t)

  (use-package org-appear
    :hook (org-mode . org-appear-mode))

  (font-lock-add-keywords 'org-mode
                          '(("^ *\\([-]\\) "
                             (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))

#+end_src

** Visual Fill

Comfy padding on the margins.

#+begin_src emacs-lisp

  (defun dnw/org-mode-visual-fill ()
    (setq visual-fill-column-width 170
          visual-fill-column-center-text t)
    (visual-fill-column-mode 1))

  (use-package visual-fill-column
    :hook (org-mode . dnw/org-mode-visual-fill))

#+end_src

** Babel

Evaluation of code blocks & abbreviated syntax for generating them.

#+begin_src emacs-lisp

      (with-eval-after-load 'org
        (org-babel-do-load-languages
         'org-babel-load-languages
         '((emacs-lisp . t)
           (python . t)
           (fortran . t)))

      (setq org-confirm-babel-evaluate nil)

      (require 'org-tempo)

      (add-to-list 'org-structure-template-alist '("sh" . "src shell"))
      (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
      (add-to-list 'org-structure-template-alist '("py" . "src python"))
      (add-to-list 'org-structure-template-alist '("ft" . "src fortran")))


#+end_src

** Tangle

Dispatches code blocks from an org file to places on disk. M-x org-babel-tangle to write, or add an auto-tangle hook as below for frequently edited config files.

#+begin_src emacs-lisp

  (defun dnw/org-babel-tangle-config ()
    (when (string-equal (buffer-file-name)
                        (expand-file-name "~/.emacs.d/config.org"))

    (let ((org-confirm-babel-evaluate nil))
      (org-babel-tangle))))

  (add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook #'dnw/org-babel-tangle-config)))

#+end_src

** Roam

The magic! Add additional capture templates here; for example, a "Structure" template for a note on a mathematical structure, or a "Theorem" template for a note on a theorem, etc.

#+begin_src emacs-lisp

    (use-package org-roam
      :ensure t
      :init
      (setq org-roam-v2-ack t)
      :custom
      (org-roam-directory "/home/dnw/Roam")
      (org-roam-completion-everywhere t)
      (org-roam-db-node-include-function
       (defun dnw/org-roam-include ()
         (not (member "drill" (org-get-tags)))))
      (org-roam-capture-templates
       '(("d" "default" plain
          "%?"
          :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
          :unnarowed t)
         ("i" "idea" plain
          "* Motivation\n\n%?\n\n* Similar Work\n\n* Feasibility\n\n* Implementation"
          :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+filetags: Idea")
          :unnarrowed t)
         ("p" "project" plain
          "* Description\n\n%?\n\n** Collaborators\n\n** Stack\n\n* Tasks"
          :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+filetags: Project")
          :unnarrowed t)
         ("a" "article" plain
          "* Summary\n\n%?\n\n* Context"
          :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+filetags: Article")
          :unnarrowed t)
         ("m" "musing" plain
          "* %?"
          :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+filetags: Musing")
          :unnarrowed t)))
      :bind (("C-c n l" . org-roam-buffer-toggle)
             ("C-c n f" . org-roam-node-find)
             ("C-c n i" . org-roam-node-insert)
             :map org-mode-map
             ("C-M-i" . completion-at-point))
      :config
      (org-roam-db-autosync-mode))

#+end_src

** Drill

Use the space-repitition method to memorize information

#+begin_src emacs-lisp

  (use-package org-drill)

#+end_src

** Present

Simple, minimalist presentations in org-mode

#+begin_src emacs-lisp

  (use-package org-present)

#+end_src

* Dired

Make C-x C-j open dired at pwd. List directories first, and use all-the-icons to be pretty. Can be configured to use dired-open to use external file display programs by default
instead of needing to '&' every time.

#+begin_src emacs-lisp

  (use-package dired
    :ensure nil
    :commands (dired dired-jump)
    :bind (("C-x C-j" . dired-jump))
    :custom ((dired-listing-switches "-ahgo --group-directories-first")))

  (use-package dired-single
    :after dired)

  (use-package all-the-icons-dired
    :hook (dired-mode . all-the-icons-dired-mode))

#+end_src

* LSP-Mode

VSCode's Language Server protocol; a standard for project management that turns Emacs into a full IDE.

** Initial Configuration

Create a breadcrumbs hook that enables a path listing header on LSP mode buffers.

#+begin_src emacs-lisp

  (use-package lsp-mode
    :commands (lsp lsp-deferred)
    :hook
    ((c-mode) . lsp)
    ((LaTeX-mode) . lsp)
    (lsp-completion-mode . dnw/lsp-completion)
    :init
    (setq lsp-keymap-prefix "C-c l")
    (defun dnw/lsp-completion ()
      (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
            '(orderless)))
    :config
    (lsp-enable-which-key-integration t)
    :custom
    (lsp-completion-provider :none))

  (use-package lsp-ui
    :hook (lsp-mode . lsp-ui-mode)
    :custom
    (setq lsp-ui-doc-position 'bottom))


  (use-package flycheck
    :defer t
    :hook (lsp-mode . flycheck-mode))

#+end_src

** Company Mode

Use company-mode style point completions in LSP-mode

#+begin_src emacs-lisp

  ;; (use-package company
  ;;   :after lsp-mode
  ;;   :hook (prog-mode . company-mode)
  ;;   :bind
  ;;   (:map company-active-map
  ;;         ("<tab>" . company-complete-selection))
  ;;   (:map lsp-mode-map
  ;;         ("<tab>" . company-indent-or-complete-common))
  ;;   :custom
  ;;   (company-minimum-prefix-length 1)
  ;;   (company-idle-delay 0.0))

  ;; (eval-after-load 'company
  ;;    '(add-to-list
  ;;      'company-backends '(company-irony-c-headers
  ;;                          company-irony
  ;;                          company-rtags)))


  ;; (use-package company-box
  ;;   :hook (company-mode . company-box-mode))

#+end_src

* Source Control

** Projectile

Helps make Emacs aware of project structure like makefiles and .gitignore. I don't really use this I don't think; I should learn.

#+begin_src emacs-lisp

  ;; (use-package projectile
  ;;   :diminish projectile-mode
  ;;   :config (projectile-mode)
  ;;   :custom ((projectile-completion-system 'ivy))
  ;;   :bind-keymap
  ;;   ("C-c p" . projectile-command-map)
  ;;   :init
  ;;   (when (file-directory-p "~")
  ;;     (setq projectile-project-search-path '("~")))
  ;;   (setq projectile-switch-project-action #'projectile-dired))

  ;; (use-package counsel-projectile
  ;;   :config (counsel-projectile-mode))

#+end_src

** Magit

#+begin_src emacs-lisp

  (use-package magit
    :commands (magit-status magit-get-current-branch)
    :custom
    (magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1))

#+end_src

* Yasnippet

Code templates.

#+begin_src emacs-lisp

  ;; (use-package yasnippet
  ;;   :hook ((prog-mode LaTeX-mode) . yas-minor-mode)
  ;;   :config
  ;;   (yas-reload-all))

  ;; (use-package yasnippet-snippets)

#+end_src

* AUCTeX

Powerful LaTeX editing. Display previews with Zathura using C-c C-c to compile; C-c C-v to view. Subsequent calls to C-c C-c automatically update the Zathura window.

#+begin_src emacs-lisp

  (use-package tex
    :ensure auctex
    :config
    (setq TeX-auto-save t)
    (setq TeX-parse-self t)
    (setq-default TeX-master t)
    (setq LaTeX-command "latex -shell-escape")
    (add-hook 'LaTeX-mode-hook 'visual-line-mode)
    (add-hook 'LaTeX-mode-hook 'flyspell-mode)
    (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
    (add-hook 'LaTeX-mode-hook 'turn-on-reftex)
    (setq reftex-plug-into-AUCTeX t)
    (setq TeX-view-program-selection '((output-pdf "Zathura")))
    (setq TeX-electric-sub-and-superscript t))

#+end_src

* PDF Viewer

Interact with PDFs from Emacs. Great for working with AUCTeX apparently.

#+begin_src emacs-lisp
  ;; Done from Guix
  (pdf-loader-install)
  ;; (use-package pdf-tools
  ;;   :init
  ;;   (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)
  ;;   (pdf-loader-install))
#+end_src
* Terminal Modes

** Term

Default to zsh.

#+begin_src emacs-lisp

  (use-package term
    :commands term
    :config
    (setq explicit-shell-file-name "zsh"))

  (use-package eterm-256color
    :hook (term-mode . eterm-256color-mode))

#+end_src

** Vterm

TODO

** Eshell

TODO

* Mail

** Notmuch

Not liking the interface so far...poor documentation or I'm just dumb lol; searches default earliest-to-latest for some reason.
#+begin_src emacs-lisp

  ;; (use-package notmuch
  ;;   :config
  ;;   (setq mail-user-agent 'message-user-agent)
  ;;   (setq user-mail-address "antigravityd@gmail.com"
  ;;         user-full-name "Duncan Wilkie")
  ;;   (setq smtpmail-smtp-server "smtp.gmail.com"
  ;;         message-mail-send-function 'message-smtpmail-send-it)
  ;;   (setq smtpmail-debug-info t)
  ;;   (setq message-default-mail-headers "Cc: \nBcc: \n")
  ;;   (setq message-auto-save-directory "~/.mail/drafts")
  ;;   (setq message-kill-buffer-on-exit t)
  ;;   (setq message-directory "~/.mail/sent")
  ;;   (setq message-signature "-Duncan Wilkie"))

#+end_src

** Mu4e

#+begin_src emacs-lisp

  ;; (require 'mu4e)

  ;; (setq mail-user-agent 'mu4e-user-agent)
  ;; (setq mu4e-get-mail-command "mbsync -a")

  ;; (setq user-full-name  "Duncan Wilkie")
  ;; (setq mu4e-compose-signature  "-Duncan Wilkie")

  ;; (setq message-kill-buffer-on-exit t)

  ;; (require 'smtpmail)

  ;; (setq message-send-mail-function 'smtpmail-send-it)

  ;; ;;; Call the oauth2ms program to fetch the authentication token
  ;; (defun fetch-access-token ()
  ;;   (with-temp-buffer
  ;;     (call-process "oauth2ms" nil t nil "--encode-xoauth2")
  ;;     (buffer-string)))

  ;; ;;; Add new authentication method for xoauth2
  ;; (cl-defmethod smtpmail-try-auth-method
  ;;   (process (_mech (eql xoauth2)) user password)
  ;;   (let* ((access-token (fetch-access-token)))
  ;;     (smtpmail-command-or-throw
  ;;      process
  ;;      (concat "AUTH XOAUTH2 " access-token)
  ;;      235)))

  ;; ;;; Register the method
  ;; (with-eval-after-load 'smtpmail
  ;;   (add-to-list 'smtpmail-auth-supported 'xoauth2))

  ;; (setq message-send-mail-function   'smtpmail-send-it
  ;;       smtpmail-default-smtp-server "smtp.example.com"
  ;;       smtpmail-smtp-server         "smtp.example.com"
  ;;       smtpmail-stream-type  'starttls
  ;;       smtpmail-smtp-service 587)

  ;; (setq mu4e-contexts
  ;;       `(,(make-mu4e-context
  ;;         :name "Personal Gmail"
  ;;         :enter-func (lambda () (mu4e-message "Switching to Personal Gmail..."))
  ;;         :match-func  (lambda (msg)
  ;;                       (when msg
  ;;                         (string-match-p "/gmail-personal" (mu4e-message-field msg :maildir))))
  ;;         :vars '((user-mail-address . "antigravityd@gmail.com") ;; set up example Gmail config from manual
  ;;                 (mu4e-drafts-folder . "/gmail-personal/[Gmail].Drafts")
  ;;                 (mu4e-sent-folder . "/gmail-personal/[Gmail].Sent Mail")
  ;;                 (mu4e-trash-folder . "/gmail-personal/[Gmail].Trash")
  ;;                 (mu4e-sent-messages-behavior . delete)
  ;;                 (assoc 'mu4e-maildir-shortcuts '((:maildir "/gmail-personal/Inbox" :key ?i)
  ;;                                             (:maildir "/gmail-personal/[Gmail].Sent Mail" :key ?s)
  ;;                                             (:maildir "/gmail-personal/[Gmail].Trash" :key ?t)
  ;;                                             (:maildir "/gmail-personal/[Gmail].All Mail" :key ?a)))
  ;;                 (starttls-use-gnutls . t)
  ;;                 (assoc smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil)))
  ;;                 (assoc smtpmail-auth-credentials  '(("smtp.gmail.com" 587 "antigravityd@gmail.com" nil)))
  ;;                 (smtpmail-smtp-server . "smtp.gmail.com")
  ;;                 (smtpmail-smtp-service . 587)))
  ;;       ,(make-mu4e-context
  ;;         :name "LSU"
  ;;         :enter-func (lambda () (mu4e-message "Switching to LSU email..."))
  ;;         :match-func (lambda (msg)
  ;;                       (when msg
  ;;                         (string-match-p "/lsu" (mu4e-message-field msg :maildir))))
  ;;         :vars '((user-mail-address . "dwilk14@lsu.edu")
  ;;                 (smtpmail-smtp-server . "smtp-mail.outlook.com")
  ;;                 (smtpmail-stream-type . starttls)
  ;;                 (smtpmail-smtp-service . 587)))))
        ;; `(make-mu4e-context
        ;; 	:name "Professional Gmail"
        ;; 	:enter-func (lambda () (mu4e-message "Switching to Professional Gmail..."))
        ;; 	:match-func  (lambda (msg)
        ;; 		       (when msg
        ;; 			 (string= (mu4e-message-field msg :maildir) "/gmail-professional")))
        ;; 	:vars '((user-mail-address . "duncannwilkie@gmail.com")
        ;; 		(user-full-name . "Duncan Wilkie")
        ;; 		(mu4e-compose-signature . "-Duncan Wilkie")))
        ;; `(make-mu4e-context
        ;;   :name "Lab"
        ;;   :enter-func (lambda () (mu4e-message "Switching to Lab email..."))
        ;;   :match-func  (lambda (msg)
        ;;                  (when msg
        ;;                    (string= (mu4e-message-field msg :maildir) "/lab")))
        ;;   :vars '((user-mail-address . "duncan@spartanphysics.com")
        ;;           (user-full-name . "Duncan Wilkie")
        ;;           (mu4e-compose-signature . "-Duncan Wilkie")))

#+end_src

* Gnus

Email & news reader setup. Time to hit the mailing lists!

#+begin_src emacs-lisp

  (setq user-mail-address "antigravityd@gmail.com"
        user-full-name "Duncan Wilkie")

  (setq gnus-select-method '(nnimap "gmail"
                                    (nnimap-address "imap.gmail.com")
                                    (nnimap-server-port "imaps")
                                    (nnimap-stream ssl)))
  (setq smtpmail-smtp-server "smtp.gmail.com"
        smtpmail-smtp-service 587
        gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")

#+end_src

* ERC

IRC client configuration & QOL changes.

#+begin_src emacs-lisp

  (setq
   erc-nick "FlaminWalrus"
   erc-user-full-name "Duncan W")

  (global-set-key (kbd "C-c e")
                  (lambda ()
                    (interactive)
                    (erc-tls :server "irc.libera.chat"
                             :port "6697")))

#+end_src

* Ement

#+begin_src emacs-lisp

  ;; (package-install 'quelpa-use-package)
  ;; (require 'quelpa-use-package)

  ;; (use-package plz
  ;;   :quelpa (plz :fetcher github :repo "alphapapa/plz.el"))

  ;; (use-package plz
  ;;   :quelpa (plz :fetcher github :repo "alphapapa/plz.el"))

  ;; (use-package ement
  ;;   :quelpa (ement :fetcher github :repo "alphapapa/ement.el"))

#+end_src

* Elfeed

RSS reader configuration.

#+begin_src emacs-lisp


  (defun dnw/elfeed-show-mode-visual-fill ()
      (setq visual-fill-column-width 130
            visual-fill-column-center-text t)
      (visual-fill-column-mode 1))


  (use-package elfeed
    :hook elfeed
    (elfeed-show-mode . dnw/elfeed-show-mode-visual-fill)
    :config
    (setq elfeed-db-directory (expand-file-name "elfeed" user-emacs-directory)
          elfeed-show-entry-switch 'display-buffer)
    (setq elfeed-feeds
          '("http://feeds.aps.org/rss/allsuggestions.xml"  ;; Physics
            "http://feeds.aps.org/rss/recent/rmp.xml"

            "https://lexi-lambda.github.io/feeds/all.rss.xml" ;; CS
            "https://blog.functorial.com/feed.rss"

            "https://www.ams.org/rss/jams.rss"
            "https://jaireetschahal.substack.com/feed" ;; Math
            "https://golem.ph.utexas.edu/category/atom10.xml"))
    :bind
    ("C-x w" . elfeed ))


  ;; doesn't function. It'd be really nice to configure this from this orgfile
  ;; (use-package elfeed-org
  ;;   :config
  ;;   (setq elfeed-show-entry-switch 'display-buffer)
  ;;   (setq rmh-elfeed-org-files (list "/home/dnw/.emacs.d/feeds.org")))

#+end_src



* Parsers

#+begin_src emacs-lisp

  ;;(use-package bison-mode)
  (add-to-list 'auto-mode-alist '("\\.g4\\'" . c-mode))

#+end_src

* Haskell

#+begin_src emacs-lisp

  (use-package haskell-mode) ;; figure out how to defer loading until .hs is opened?

#+end_src

* TRAMP

#+begin_src emacs-lisp

  ;; TRAMP can't find necessary binaries on Guix machines without this after Emacs 28
  (add-to-list 'tramp-remote-path "/run/current-system/profile/bin")

#+end_src

* Info

#+begin_src emacs-lisp

  (setq Info-use-header-line nil)

#+end_src

* Markdown

#+begin_src emacs-lisp

  (setq markdown-command "pandoc")

#+end_src

* EMMS

Play audio and video.

#+begin_src emacs-lisp

    (use-package emms
      :config
      (emms-all)
      :bind
      ("<XF86AudioPlay>" . emms-start)
      ("<XF86AudioPause>" . emms-pause)
      ("<XF86AudioNext>" . emms-next)
      ("<XF86AudioNext>" . emms-previous))

#+end_src

* HTML

#+begin_src emacs-lisp

  (add-hook 'xhtml-mode-hook (lambda () (call-interactively 'shr-render-buffer)))

#+end_src

* Runtime Performance

#+begin_src emacs-lisp

  (setq gc-cons-threshold (* 2 1000 1000))

#+end_src