aboutsummaryrefslogtreecommitdiff
path: root/config.org
blob: 05018e44bde4bbcc05cdfea1d00302a455666689 (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
#+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)

#+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)

#+end_src

* Basic Configuration UI

** 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

** Better Font

Noto Emoji is the fallback here.

#+begin_src emacs-lisp

  (set-face-attribute 'default nil :font "Liberation Mono")
  (set-fontset-font "fontset-default" nil
                    (font-spec :name "Noto"))
  (set-fontset-font "fontset-default" nil
                    (font-spec :name "Font Awesome"))

#+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))
    (add-hook mode (lambda () (display-line-numbers-mode 0))))

#+end_src

** Transparency

#+begin_src emacs-lisp

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

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

#+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/")
                           ("org" . "https://orgmode.org/elpa/")
                           ("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

** Auto-Updates

Prompt to update Emacs packages weekly.

#+begin_src emacs-lisp

  (use-package auto-package-update
    :custom
    (auto-package-update-interval 7)
    (auto-package-update-prompt-before-update t)
    (auto-package-update-hide-results t)
    :config
    (auto-package-update-maybe)
    (auto-package-update-at-time "12:00"))

#+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" "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 (corfu-global-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

  (use-package autoinsert
    :hook (find-file . auto-insert)
    :config
    (setq auto-insert t)
    (setq auto-insert-query nil)
    (auto-insert-mode 1)
    (setq auto-insert-directory "~/emacs.d/insert/"))

#+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-dark+ 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))
    :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)
    :config
    (setq org-ellipsis " ▼"))

#+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 '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-capture-templates
       '(("d" "default" plain
          "%?"
          :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
          :unnarowed 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

* 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
    ((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 nil)
    (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"))))

#+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

* 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

* Elfeed

RSS reader configuration. 

#+begin_src emacs-lisp

  (use-package elfeed
    :hook elfeed
    :config
    (setq elfeed-db-directory (expand-file-name "elfeed" user-emacs-directory)
          elfeed-show-entry-switch 'display-buffer)
    :bind
    ("C-x w" . elfeed ))

  (setq elfeed-feeds
        '("http://feeds.aps.org/rss/prdsuggestions.xml"
          ;;"http://feeds.aps.org/rss/recent/physics.xml"
          ))

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

* Runtime Performance

#+begin_src emacs-lisp

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

#+end_src