mirror of https://github.com/Chizi123/.emacs.d.git

Joel Grunbaum
2022-01-06 2dd99fd1da2f67767145554dfed1ba7c70dd57e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
#+TITLE: My Emacs configuration
#  LocalWords:  poppler mingw emacs eq nt gnuplot setenv mapconcat el cond minibuffer pdf color Smartparens smartparens yas aindent whitespace eldoc ielm ibuffer hippie pscp pos Spaceline spaceline powerline spacemacs seperator dir Yasnippet yasnippet flycheck magit fullscreen CEDET askifnotset semanticdb EDE ede gdb srefactor analyzer eval cdb autosetup ghostscript math unicode reftex bibtex TeXcount texcount str latin rkt PlantUML plantuml autoload alist matlab verilog ds vh src fontify natively fortran dvipng plist xcolor EXWM Zenburn setq zenburn defun dolist init config DejaVu ispell aspell flyspell kbd recentf sexp ov bg listp defadvice progn prog keyfreq autosave dabbrev hl gc linum linux utf RET ARG arg configs backends contribs AucTex tex auctex LaTeX url htmlize linter backend writegood ggtags gtags dired eshell asm cd dwim VHDL defvar ctags vhdl concat sp html awk defalias cedet mips IPython ein contrib pandoc dokuwiki EMMS MPD emms toc favicon href css stylesheet async dataLayer gtag js UA sitelinks br Github postamble isso center disqus onclick Disqus javascript dsq createElement getElementsByTagName xml urlset xmlns curr loc RSS elfeed
 
* OS dependencies
Windows and Mac have some interesting paths when starting emacs which needs to be fixed.
Using mingw64 in windows and general path in mac.
#+BEGIN_SRC emacs-lisp
  (cond ((eq system-type 'windows-nt)
         (add-to-list 'exec-path "C:/msys64/usr/bin")
         (add-to-list 'exec-path "C:/msys64/mingw64/bin")
         (add-to-list 'exec-path "C:/Program Files/gnuplot")
         (setenv "PATH" (mapconcat #'identity exec-path path-separator)))
        ((eq system-type 'darwin)
         (use-package exec-path-from-shell
           :config
           (exec-path-from-shell-initialize))
         (setq default-directory "~/")))
#+END_SRC
 
* Aesthetic changes
** Emacs theme
Theme switcher, using a cond allows loading of many preconfigured themes which can be switched between easily.
Zenburn theme is my default.
#+BEGIN_SRC emacs-lisp
  (setq emacs-theme 'zenburn)
 
  (defun disable-all-themes ()
    (dolist (i custom-enabled-themes)
      (disable-theme i)))
 
  (cond ((eq emacs-theme 'zenburn)
         (use-package zenburn-theme
           :init
           (disable-all-themes)
           :config
           (load-theme 'zenburn t)))
        ((eq emacs-theme 'doom-one)
         (use-package doom-themes
           :init
           (disable-all-themes)
           :config
           (setq doom-themes-enable-bolt t
                 doom-themes-enable-italic t)
           (load-theme 'doom-one t)
           (doom-themes-visual-bell-config)
           (doom-themes-org-config)))
        ((eq emacs-theme 'nord)
         (use-package nord-theme
           :init
           (disable-all-themes)
           :config
           (load-theme 'nord t)))
        ((eq emacs-theme 'solarized)
         (use-package solarized-theme
           :init
           (disable-all-themes)
           :config
           (load-theme 'solarized-dark t)))
        ((eq emacs-theme 'jetbrains-darcula)
         (use-package jetbrains-darcula-theme
           :init
           (disable-all-themes)
           :config
           (load-theme 'jetbrains-darcula t)))
        ((eq emacs-theme 'none)
         (disable-all-themes)))
#+END_SRC
 
** Default font
Set default font and faces.
#+BEGIN_SRC emacs-lisp 
  (cond ((member "Dank Mono" (font-family-list))
         (set-frame-font "Dank Mono-11" nil t))
        ((member "DejaVu Sans Mono" (font-family-list))
         (set-frame-font "DejaVu Sans Mono" nil t))
        ((member "Source Code Pro" (font-family-list))
         (set-frame-font "Source Code Pro-10" nil t)))
 
  (set-face-italic 'font-lock-comment-face t)
  (set-face-italic 'font-lock-keyword-face t)
#+END_SRC
 
** Remove menu bar, toolbar, and scroll bar
Make the emacs interface slightly nicer.
#+BEGIN_SRC emacs-lisp
  (menu-bar-mode 0)
  (tool-bar-mode 0)
  (scroll-bar-mode 0)
#+END_SRC
* COMMENT EXWM
Emacs window manager.
Tiling window manager that runs in emacs.
Open external applications with =s-&=
#+BEGIN_SRC emacs-lisp
  (use-package exwm
    :defer t
    :config
    (require 'exwm-config)
    (exwm-config-default))
#+END_SRC
 
* Writing requirements
** Spellchecking
Use aspell for spellchecking. 
Auto-enable in latex and org as they're the main writing modes.
#+BEGIN_SRC emacs-lisp
  (use-package flyspell
    :hook (tex-mode latex-mode TeX-mode LaTeX-mode org-mode)
    :diminish flyspell-mode
    :init (require 'ispell)
    :config
    (setq-default ispell-program-name "aspell")
    (setq-default ispell-local-dictionary "en_AU"))
#+END_SRC
** COMMENT Language Tool
Language tool is an open source grammar checker.
#+BEGIN_SRC emacs-lisp
  (use-package langtool
    :init
    (setq langtool-java-classpath "/usr/share/languagetool:/usr/share/java/languagetool/*"))
#+END_SRC
** Switch-window
Helps to change windows easily when many are open at once.
#+BEGIN_SRC emacs-lisp
  (use-package switch-window
    :config
    ;; (setq switch-window-input-style 'minibuffer)
    (setq switch-window-threshold 2)
    (setq switch-window-shortcut-style 'qwerty)
    :bind
    ([remap other-window] . switch-window))
#+END_SRC
 
** Go to new window when opened
Go to new window when its opened instead of staying with current one.
#+BEGIN_SRC emacs-lisp
  (defun split-and-follow-horizontally ()
    (interactive)
    (split-window-below)
    (balance-windows)
    (other-window 1))
  (global-set-key (kbd "C-x 2") 'split-and-follow-horizontally)
 
  (defun split-and-follow-vertically ()
    (interactive)
    (split-window-right)
    (balance-windows)
    (other-window 1))
  (global-set-key (kbd "C-x 3") 'split-and-follow-vertically)
#+END_SRC
 
** PDF-tools
Helpful pdf viewer.
#+BEGIN_SRC emacs-lisp
  (use-package pdf-tools
    :config
    (pdf-tools-install 1))
#+END_SRC
 
** COMMENT Writegood-mode
Supposedly should provide insight to writing quality.
#+BEGIN_SRC emacs-lisp
  (use-package writegood-mode
    :hook (text-mode . writegood-mode))
#+END_SRC
 
* Helm and Projectile
** Helm core
Helm aids the user interface for emacs. Adds visual and auto-complete feedback for emacs commands.
#+BEGIN_SRC emacs-lisp
  (use-package helm-config
    :ensure helm
    :bind (("M-x" . helm-M-x)
           ("C-x C-f" . helm-find-files)
           ("M-y" . helm-show-kill-ring)
           ("C-x b" . helm-mini)
           ("C-c h o" . helm-occur))
    :config
    (setq helm-mode-fuzzy-match                 t
          helm-completion-in-regionfuzzy-match  t
          helm-split-window-inside-p            t ; open helm buffer inside current window, not occupy whole other window
          helm-move-to-line-cycle-in-source     t ; move to end or beginning of source when reaching top or bottom of source.
          helm-ff-search-library-in-sexp        t ; search for library in `require' and `declare-function' sexp.
          helm-scroll-amount                    8 ; scroll 8 lines other window using M-<next>/M-<prior>
          helm-ff-file-name-history-use-recentf t
          helm-echo-input-in-header-line        t
          completion-styles                     '(flex))
    (defun spacemacs//helm-hide-minibuffer-maybe ()
      "Hide minibuffer in Helm session if we use the header line as input field."
      (when (with-helm-buffer helm-echo-input-in-header-line)
        (let ((ov (make-overlay (point-min) (point-max) nil nil t)))
          (overlay-put ov 'window (selected-window))
          (overlay-put ov 'face
                       (let ((bg-color (face-background 'default nil)))
                         `(:background ,bg-color :foreground ,bg-color)))
          (setq-local cursor-type nil))))
    (add-hook 'helm-minibuffer-set-up-hook
              'spacemacs//helm-hide-minibuffer-maybe)
    (helm-mode 1))
#+END_SRC
*** Helm git
Give helm git awareness.
#+BEGIN_SRC emacs-lisp
  (use-package helm-ls-git
    :bind (("C-x C-d" . helm-browse-project)))
#+END_SRC
** Projectile
Projectile is project management framework for emacs.
Helps in navigation and management of projects.
Identifies project layout from git.
*** Enable it
#+BEGIN_SRC emacs-lisp
  (use-package projectile
    :bind ("C-c p" . projectile-command-map)
    :diminish projectile-mode
    :config
    (projectile-global-mode)
    (setq projectile-completion-system 'helm)
    (when (eq system-type 'windows-nt)
      (setq projectile-indexing-method 'alien)))
#+END_SRC
 
*** Let it compile things
Shortcut for compilation.
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "<f5>") 'projectile-compile-project)
#+END_SRC
 
*** Enable communication with helm
Use helm to manage project.
#+BEGIN_SRC emacs-lisp
  (use-package helm-projectile
    :config
    (helm-projectile-on))
#+END_SRC
 
** COMMENT ggtags
Use GNU Global Tags. Can be useful for large projects.
#+BEGIN_SRC emacs-lisp
  (use-package ggtags
    :bind (("C-c g s" . ggtags-find-other-symbol)
           ("C-c g h" . ggtags-view-tag-history)
           ("C-c g r" . ggtags-find-reference)
           ("C-c g f" . ggtags-find-file)
           ("C-c g c" . ggtags-create-tags)
           ("C-c g u" . ggtags-update-tags))
    :config
    (add-hook 'c-mode-common-hook
              (lambda ()
                (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
                  (ggtags-mode 1))))
    )
 
  (setq
   helm-gtags-ignore-case t
   helm-gtags-auto-update t
   helm-gtags-use-input-at-cursor t
   helm-gtags-pulse-at-cursor t
   helm-gtags-prefix-key "\C-c g"
   helm-gtags-suggested-key-mapping t
   )
 
  (use-package helm-gtags
    :config
    (add-hook 'dired-mode-hook 'helm-gtags-mode)
    (add-hook 'eshell-mode-hook 'helm-gtags-mode)
    (add-hook 'c-mode-hook 'helm-gtags-mode)
    (add-hook 'c++-mode-hook 'helm-gtags-mode)
    (add-hook 'asm-mode-hook 'helm-gtags-mode)
 
    (define-key helm-gtags-mode-map (kbd "C-c g a") 'helm-gtags-tags-in-this-function)
    (define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select)
    (define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim)
    (define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
    (define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
    (define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history))
#+END_SRC
 
** COMMENT Ctags
Ctags is an older tagging program that supports more languages.
Currently setup for VHDL as I had to work with a large existing VHDL code-base.
#+BEGIN_SRC emacs-lisp
  (defvar ctags-command "ctags -e -R --languages=vhdl")
 
  (defun ctags ()
    (call-process-shell-command ctags-command nil "*Ctags*"))
 
 
  (defun ctags-find-tags-file ()
    "Recursively searches each parent directory for a file named
                TAGS and returns the path to that file or nil if a tags file is
                not found or if the buffer is not visiting a file."
    (progn
      (defun find-tags-file-r (path)
        "Find the tags file from current to the parent directories."
        (let* ((parent-directory (file-name-directory (directory-file-name path)))
               (tags-file-name (concat (file-name-as-directory path) "TAGS")))
          (cond
           ((file-exists-p tags-file-name) (throw 'found tags-file-name))
           ((string= "/TAGS" tags-file-name) nil)
           (t (find-tags-file-r parent-directory)))))
 
      (if (buffer-file-name)
          (catch 'found
            (find-tags-file-r (file-name-directory buffer-file-name)))
        nil)))
 
  (defun ctags-set-tags-file ()
    "Uses `ctags-find-tags-file' to find a TAGS file. If found,
                set 'tags-file-name' with its path or set as nil."
    (setq-default tags-file-name (ctags-find-tags-file)))
 
  (defun ctags-create-tags-table ()
    (interactive)
    (let* ((current-directory default-directory)
           (top-directory (read-directory-name
                           "Top of source tree: " default-directory))
           (file-name (concat (file-name-as-directory top-directory) "TAGS")))
      (cd top-directory)
      (if (not (= 0 (ctags)))
          (message "Error creating %s!" file-name)
        (setq-default tags-file-name file-name)
        (message "Table %s created and configured." tags-file-name))
      (cd current-directory)))
 
  (defun ctags-update-tags-table ()
    (interactive)
    (let ((current-directory default-directory))
      (if (not tags-file-name)
          (message "Tags table not configured.")
        (cd (file-name-directory tags-file-name))
        (if (not (= 0 (ctags)))
            (message "Error updating %s!" tags-file-name)
          (message "Table %s updated." tags-file-name))
        (cd current-directory))))
 
  (defun ctags-create-or-update-tags-table ()
    "Create or update a tags table with `ctags-command'."
    (interactive)
    (if (not (ctags-set-tags-file))
        (ctags-create-tags-table)
      (ctags-update-tags-table)))
 
 
  (defun ctags-search ()
    "A wrapper for `tags-search' that provide a default input."
    (interactive)
    (let* ((symbol-at-point (symbol-at-point))
           (default (symbol-name symbol-at-point))
           (input (read-from-minibuffer
                   (if (symbol-at-point)
                       (concat "Tags search (default " default "): ")
                     "Tags search (regexp): "))))
      (if (and (symbol-at-point) (string= input ""))
          (tags-search default)
        (if (string= input "")
            (message "You must provide a regexp.")
          (tags-search input)))))
#+END_SRC
 
* Small tweaks
** Remove startup screen
Start on scratch buffer instead.
#+BEGIN_SRC emacs-lisp
  (setq inhibit-startup-message t)
#+END_SRC
 
** Disable bell
Bloody bell dings every time you hit a key too much.
#+BEGIN_SRC emacs-lisp
  (setq ring-bell-function 'ignore)
#+END_SRC
 
** Pretty symbols
Why not? They make it look nice.
#+BEGIN_SRC emacs-lisp
  (use-package pretty-mode
    :diminish t
    :if window-system
    :config
    (global-pretty-mode))
#+END_SRC
 
** COMMENT Find file other window
Lets it accept more than one file. Works recursively.
#+BEGIN_SRC emacs-lisp
  (defadvice find-file-other-window (around find-files activate)
    (if (listp filename)
        (loop for f in filename do (find-file-other-window f wildcards))
      ad-do-it))
#+END_SRC
 
** Which key
Helps to explain keybindings if you get lost.
#+BEGIN_SRC emacs-lisp
  (use-package which-key
    :diminish which-key-mode
    :config
    (which-key-mode))
#+END_SRC
 
** Config shortcuts
*** Go to this file
#+BEGIN_SRC emacs-lisp
  (defun config-visit ()
    (interactive)
    (find-file "~/.emacs.d/config.org"))
  (global-set-key (kbd "C-c e d") 'config-visit)
#+END_SRC
 
*** Go to init.el
#+BEGIN_SRC emacs-lisp
  (defun init-visit ()
    (interactive)
    (find-file "~/.emacs.d/init.el"))
  (global-set-key (kbd "C-c e i") 'init-visit)
#+END_SRC
 
*** Reload configuration
#+BEGIN_SRC emacs-lisp
  (defun config-reload ()
    "Reloads ~/.emacs.d/config.org at run time"
    (interactive)
    (org-babel-load-file (expand-file-name "~/.emacs.d/config.org")))
  (global-set-key (kbd "C-c e r") 'config-reload)
#+END_SRC
 
** Smartparens
Matches brackets automatically. Added "$" for latex in org mode.
#+BEGIN_SRC emacs-lisp
  (use-package smartparens
    :diminish smartparens-mode
    :config
    (progn
      (require 'smartparens-config)
      (smartparens-global-mode 1))
    (sp-with-modes 'org-mode
      (sp-local-pair "$" "$")))
#+END_SRC
 
** COMMENT Rainbow
Its a little gimmicky but its still cool.
Colours according to code after a "#", works with 3 and 6 character hex codes.
#+BEGIN_SRC emacs-lisp
  (use-package rainbow-mode
    :diminish rainbow-mode
    :init
    (add-hook 'prog-mode-hook 'rainbow-mode))
#+END_SRC
 
** Rainbow delimiters
A bit more useful than above.
Colours the brackets so that they stand out more.
#+BEGIN_SRC emacs-lisp
  (use-package rainbow-delimiters
    :hook (prog-mode . rainbow-delimiters-mode))
#+END_SRC
 
** Following whitespace
Removes unnecessary white space
#+BEGIN_SRC emacs-lisp
  (use-package clean-aindent-mode
    :hook prog-mode)
#+END_SRC
Shows trailing white space
#+BEGIN_SRC emacs-lisp
  (add-hook 'prog-mode-hook (lambda () (interactive) (setq show-trailing-whitespace 1)))
#+END_SRC
 
** Whitespace mode
Reveals whitespace characters
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "C-c w") 'whitespace-mode)
  (add-hook 'diff-mode-hook (lambda ()
                              (setq-local whitespace-style
                                          '(face
                                            tabs
                                            tab-mark
                                            spaces
                                            space-mark
                                            trailing
                                            indentation::space
                                            indentation::tab
                                            newline
                                            newline-mark))
                              (whitespace-mode 1)))
 
#+END_SRC
 
** eldoc
Shows function arguments in echo area below mode line.
#+BEGIN_SRC emacs-lisp
  (diminish 'eldoc-mode)
  (add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
  (add-hook 'lisp-interaction-mode-hook 'eldoc-mode)
  (add-hook 'ielm-mode-hook 'eldoc-mode)
#+END_SRC
 
** Key frequency statistics
Collects interesting statistics about key presses.
Use M-x keyfreq-show to show in emacs or M-x keyfreq-html to output
#+BEGIN_SRC emacs-lisp
  (use-package keyfreq
    :config
    (keyfreq-mode 1)
    (keyfreq-autosave-mode 1))
#+END_SRC
 
** Undo tree
A more advanced undo mechanism.
Supports branched undo history (thus the tree).
Pretty neat, if seldom used.
#+BEGIN_SRC emacs-lisp
  (use-package undo-tree
    :diminish undo-tree-mode
    :config
    (global-undo-tree-mode))
#+END_SRC
 
** Volatile highlights
Colour the material just copied
#+BEGIN_SRC emacs-lisp
  (use-package volatile-highlights
    :diminish volatile-highlights-mode
    :config
    (volatile-highlights-mode t))
#+END_SRC
 
** ibuffer
View all open buffers in their own buffer rather in the temporary mini buffer.
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "C-x C-b") 'ibuffer)
  (setq ibuffer-use-other-window t)
#+END_SRC
 
** Hippie expand
Seems cool, but I don't think I ever use this.
Meant to suggest completions to beginning of a word.
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "M-/") 'hippie-expand) ;; replace dabbrev-expand
  (setq
   hippie-expand-try-functions-list
   '(try-expand-dabbrev ;; Try to expand word "dynamically", searching the current buffer.
     try-expand-dabbrev-all-buffers ;; Try to expand word "dynamically", searching all other buffers.
     try-expand-dabbrev-from-kill ;; Try to expand word "dynamically", searching the kill ring.
     try-complete-file-name-partially ;; Try to complete text as a file name, as many characters as unique.
     try-complete-file-name ;; Try to complete text as a file name.
     try-expand-all-abbrevs ;; Try to expand word before point according to all abbrev tables.
     try-expand-list ;; Try to complete the current line to an entire line in the buffer.
     try-expand-line ;; Try to complete the current line to an entire line in the buffer.
     try-complete-lisp-symbol-partially ;; Try to complete as an Emacs Lisp symbol, as many characters as unique.
     try-complete-lisp-symbol) ;; Try to complete word as an Emacs Lisp symbol.
   )
#+END_SRC
 
** Highlight line
Very useful for finding where you are.
#+BEGIN_SRC emacs-lisp
  (global-hl-line-mode)
#+END_SRC
 
** Line numbers
Everyone needs line numbers when programming.
#+BEGIN_SRC emacs-lisp
  (add-hook 'prog-mode-hook 'linum-mode)
#+END_SRC
 
** Garbage collection
Starts garbage collection every 100MB.
#+BEGIN_SRC emacs-lisp
  (setq gc-cons-threshold (* 1024 1024 100))
#+END_SRC
 
** Kill ring
Changes the kill ring size to 5000.
#+BEGIN_SRC emacs-lisp
  (setq global-mark-ring-max 5000
        mark-ring-max 5000
        mode-require-final-newline t
        kill-ring-max 5000
        kill-whole-line t)
#+END_SRC
 
** Coding style
Use java for java, awk for awk and K&R for everything else.
K&R uses 4 space tabs.
#+BEGIN_SRC emacs-lisp
  (setq c-default-style '((java-mode . "java")
                          (awk-mode . "awk")
                          (other . "k&r")))
#+END_SRC
 
** Coding system
Cause we all love UTF8.
#+BEGIN_SRC emacs-lisp
  (set-terminal-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8)
  (set-language-environment "UTF-8")
  (prefer-coding-system 'utf-8)
  (setq-default indent-tabs-mode nil
                tab-width 4
                c-basic-offset tab-width
                cperl-indent-level tab-width)
  (c-set-offset 'inline-open '0)
  (delete-selection-mode)
  (global-set-key (kbd "RET") 'newline-and-indent)
#+END_SRC
*** Smart tabs
Tabs for indentation, spaces for alignment
#+BEGIN_SRC emacs-lisp
  (use-package smart-tabs-mode
    :config
    (smart-tabs-insinuate 'c 'c++ 'java 'javascript 'cperl 'python 'ruby
                          'nxml))
#+END_SRC
 
** Move to beginning of line ignoring whitespace
Move point back to indentation of beginning of line.
Pretty good for getting to the start of what you actually wanted.
 
Move point to the first non-whitespace character on this line.
If point is already there, move to the beginning of the line.
Effectively toggle between the first non-whitespace character and
the beginning of the line.
 
If ARG is not nil or 1, move forward ARG - 1 lines first. If
point reaches the beginning or end of the buffer, stop there.
#+BEGIN_SRC emacs-lisp
  (defun prelude-move-beginning-of-line (arg)
    (interactive "^p")
    (setq arg (or arg 1))
 
    ;; Move lines first
    (when (/= arg 1)
      (let ((line-move-visual nil))
        (forward-line (1- arg))))
 
    (let ((orig-point (point)))
      (back-to-indentation)
      (when (= orig-point (point))
        (move-beginning-of-line 1))))
 
  (global-set-key (kbd "C-a") 'prelude-move-beginning-of-line)
#+END_SRC
 
** Indent region or buffer
Indent, slightly different to standard tab or C-M-\.
#+BEGIN_SRC emacs-lisp
  (defun indent-region-or-buffer ()
    "Indent a region if selected, otherwise the whole buffer."
    (interactive)
    (unless (member major-mode prelude-indent-sensitive-modes)
      (save-excursion
        (if (region-active-p)
            (progn
              (indent-region (region-beginning) (region-end))
              (message "Indented selected region."))
          (progn
            (indent-buffer)
            (message "Indented buffer.")))
        (whitespace-cleanup))))
 
  (global-set-key (kbd "C-c i") 'indent-region-or-buffer)
#+END_SRC
 
** Tramp
Remote editing mode.
Hate having to re-input passwords.
#+BEGIN_SRC emacs-lisp
  (use-package tramp
    :pin gnu
    :config
    ;; (setq tramp-default-method "ssh")
    (when (eq system-type 'windows-nt)
      (setq tramp-default-method "pscp"))
    (setq password-cache-expiry nil)
    (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
#+END_SRC
 
** COMMENT Y or N instead of yes or no
Need not type out whole word.
#+BEGIN_SRC emacs-lisp
  (defalias 'yes-or-no-p 'y-or-n-p)
#+END_SRC
 
** COMMENT Sublime-like minimap
Get a minimap preview of the file on the side like sublime text.
Want to make work but need to find a good way of doing so.
#+BEGIN_SRC emacs-lisp
  (use-package sublimity
    :config
    (require 'sublimity-scroll)
    (setq sublimity-scroll-weight 4
          sublimity-scroll-drift-length 3)
    (require 'sublimity-map)
    (setq sublimity-map-size 20
          sublimity-map-scale 0.3)
    (sublimity-map-set-delay nil)
    (sublimity-mode 1))
 
  (use-package minimap
    :config
    (minimap-mode))
#+END_SRC
 
** Highlight indentation
Vertical demarcations for indent levels
#+BEGIN_SRC emacs-lisp
  (use-package highlight-indentation
    :hook (prog-mode . highlight-indentation-mode))
#+END_SRC
 
** Auto revert mode
Update unchanged buffers if underlying file changes.
#+BEGIN_SRC emacs-lisp
  (global-auto-revert-mode)
#+END_SRC
* Mode line tweaks
Diminish is used but is included in init.el such that it can be used throughout this document
** Spaceline
A little easier to read than the default emacs mode line.
#+BEGIN_SRC emacs-lisp
  (use-package spaceline
    :config
    (require 'spaceline-config)
    (setq spaceline-buffer-encoding-abbrev-p t)
    (setq spaceline-line-column-p t)
    (setq spaceline-line-p t)
    (setq powerline-default-separator (quote arrow))
    (spaceline-spacemacs-theme)
    (spaceline-helm-mode))
#+END_SRC
 
*** Separator
Slightly nicer separator.
#+BEGIN_SRC emacs-lisp
  (setq powerline-default-separator nil)
#+END_SRC
 
** Nyan mode
Use nyan cat as a reference for buffer progression.
#+BEGIN_SRC emacs-lisp
  (use-package nyan-mode
    :config
    (nyan-mode 1))
#+END_SRC
 
* Programming tweaks
** Yasnippet
Add snippets, pretty useful.
Manually added snippets are in ~/.emacs.d/snippets/{mode}.
#+BEGIN_SRC emacs-lisp
  (use-package yasnippet
    :diminish yas-minor-mode
    :config
    (yas-global-mode 1))
 
  (use-package yasnippet-snippets
    :after yasnippet)
#+END_SRC
** Flycheck
Basic linter. Works pretty well.
#+BEGIN_SRC emacs-lisp
  (use-package flycheck
    :diminish flycheck-mode
    :config
    (global-flycheck-mode))
#+END_SRC
*** flycheck-pos-tip
Add suggestions at the cursor.
#+BEGIN_SRC emacs-lisp
  (use-package flycheck-pos-tip
    :after flycheck
    :config
    (flycheck-pos-tip-mode))
#+END_SRC
** Company
Company is auto-complete for Emacs.
Uses various backends, more of which are added later.
#+BEGIN_SRC emacs-lisp
  (use-package company
    :diminish company-mode
    :config
    (global-company-mode)
    (setq company-idle-delay 0)
    (setq company-minimum-prefix-length 1))
#+END_SRC
 
** LSP Mode
Use LSP for completion suggestions.
Causes too much memory usage, need to debug.
Need to generate ~compile_flags~ for c/c++, can use ~bear~ but may need other tools.
#+BEGIN_SRC emacs-lisp
  (use-package lsp-mode
    :hook (((c-mode
             c++-mode
             tex-mode
             latex-mode
             TeX-mode
             LaTeX-mode
             rust-mode
             sh-mode
             ;; verilog-mode
             go-mode
             python-mode) . lsp))
    :init
    (setq lsp-keymap-prefix "C-c l")
    :commands lsp
    :config
    (add-hook 'lsp-mode-hook 'lsp-enable-which-key-integration)
    (setq read-process-output-max (* 1024 1024))
    (setq lsp-completion-provider :capf)
    (setq lsp-keep-workspace-alive 'nil)
    (add-to-list 'exec-path "~/.cargo/bin"))
 
  (use-package lsp-ui
    :commands lsp-ui-mode)
 
  (use-package helm-lsp
    :commands helm-lsp-workspace-symbol)
#+END_SRC
 
** Version control
Settings for emacs' own version control system.
*** Enable version control on the mode line
#+BEGIN_SRC emacs-lisp
  (vc-mode)
#+END_SRC
 
** Magit
Emacs git client.
Pretty good and offers fairly decent features.
#+BEGIN_SRC emacs-lisp
  (use-package magit
    :commands magit-get-top-dir
    :bind ("C-x g" . magit-status)
    :init
    (progn
      ;; make magit status go full-screen but remember previous window
      ;; settings
      ;; from: http://whattheemacsd.com/setup-magit.el-01.html
      (defadvice magit-status (around magit-fullscreen activate)
        (window-configuration-to-register :magit-fullscreen)
        ad-do-it
        (delete-other-windows))
 
      ;; Close popup when committing - this stops the commit window
      ;; hanging around
      ;; From: http://git.io/rPBE0Q
      (defadvice git-commit-commit (after delete-window activate)
        (delete-window))
 
      (defadvice git-commit-abort (after delete-window activate)
        (delete-window))
 
      :config
      (progn
        ;; restore previously hidden windows
        (defadvice magit-quit-window (around magit-restore-screen activate)
          (let ((current-mode major-mode))
            ad-do-it
            ;; we only want to jump to register when the last seen buffer
            ;; was a magit-status buffer.
            (when (eq 'magit-status-mode current-mode)
              (jump-to-register :magit-fullscreen)))))
 
      ;; magit settings
      (setq
       ;; don't put "origin-" in front of new branch names by default
       magit-default-tracking-name-function 'magit-default-tracking-name-branch-only
       ;; open magit status in same window as current buffer
       magit-status-buffer-switch-function 'switch-to-buffer
       ;; highlight word/letter changes in hunk diffs
       magit-diff-refine-hunk t
       ;; ask me if I want to include a revision when rewriting
       magit-rewrite-inclusive 'ask
       ;; ask me to save buffers
       magit-save-some-buffers t
       ;; pop the process buffer if we're taking a while to complete
       magit-process-popup-time 10
       ;; ask me if I want a tracking upstream
       magit-set-upstream-on-push 'askifnotset
       ))
    )
#+END_SRC
 
*** More general yes and no prompt
The default setting can miss some.
Don't redefine the regex in case this is too general.
#+BEGIN_SRC emacs-lisp
  ;;(when-let ((regex "[\[\(]]?\\([Yy]\\(es\\)?\\)[/|]\\([Nn]o?\\)[\]\)]")
  (defun magit-process-general-yn-prompt-hook (proc str)
    "Handle [y/n] prompts"
    (when-let ((beg (string-match "[\[\(]]?\\([Yy]\\(es\\)?\\)[/|]\\([Nn]o?\\)[\]\)]" str)))
      (let ;; ((max-mini-window-height 30))
          (process-send-string
           proc
           (downcase
            (concat
             (match-string
              (if (save-match-data
                    (magit-process-kill-on-abort proc
                      (y-or-n-p (substring str 0 beg)))) 1 2)
              str)
             "\n"))))))
 
  (add-hook 'magit-process-prompt-functions
            #'magit-process-general-yn-prompt-hook)
#+END_SRC
*** COMMENT Gerrit integration
Gerrit takes ~origin:refs/for/master~ as a destination.
Enable magit to work with its oddities.
#+BEGIN_SRC emacs-lisp
  (use-package magit-gerrit)
#+END_SRC
 
** CEDET
*** COMMENT Semantic
Parser library for code, supports many other packages.
Allows emacs to be more aware of what is being written.
#+BEGIN_SRC emacs-lisp
  (use-package semantic
    :hook (prog-mode . semantic-mode)
    :config
    (global-semanticdb-minor-mode 1)
    (global-semantic-idle-scheduler-mode 1)
    (global-semantic-idle-summary-mode 1)
    (semantic-mode 1))
#+END_SRC
 
*** COMMENT EDE
Emacs Development Environment.
Can be used to manage and create build files for a project.
#+BEGIN_SRC emacs-lisp
  (use-package ede
    :config
    (global-ede-mode t))
#+END_SRC
 
*** gdb-many-windows
Enhances the use of GDB in emacs.
Shows register contents, variable contents and others in addition to GDB shell.
Also shows source code while debugging.
#+BEGIN_SRC emacs-lisp
  (setq
   gdb-many-windows t
   gdb-show-main t)
#+END_SRC
 
*** COMMENT Semantic refactor
Trying to get this to work.
Should help to refactor file.
#+BEGIN_SRC emacs-lisp
  (use-package srefactor
    :bind (("M-RET o" . 'srefactor-lisp-one-line)
           ("M-RET m" . 'srefactor-lisp-format-sexp)
           ("M-RET d" . 'srefactor-lisp-format-defun)
           ("M-RET b" . 'srefactor-lisp-format-buffer)
           :map c-mode-base-map
           ("M-RET" . 'srefactor-refactor-at-point)
           :map c++-mode-map
           ("M-RET" . 'srefactor-refactor-at-point)))
#+END_SRC
 
** Language specific configs
*** C/C++
**** Flycheck
***** Flycheck clang
Add the clang backend for linting.
#+BEGIN_SRC emacs-lisp
  (use-package flycheck-clang-analyzer
    :after flycheck
    :config
    (with-eval-after-load 'flycheck
      (require 'flycheck-clang-analyzer)
      (flycheck-clang-analyzer-setup)))
#+END_SRC
***** Flycheck project root
Flycheck tends to fail finding the project root, giving errors about missing files.
This should remove them.
#+BEGIN_SRC emacs-lisp
  (defun setup-flycheck-project-path ()
    (let ((root (ignore-errors (projectile-project-root))))
      (when root
        (add-to-list
         (make-variable-buffer-local 'flycheck-clang-include-path)
         root)
        (add-to-list
         (make-variable-buffer-local 'flycheck-gcc-include-path)
         root))))
 
  (add-hook 'c-mode-hook 'setup-flycheck-project-path)
  (add-hook 'c++-mode-hook 'setup-flycheck-project-path)
#+END_SRC
**** COMMENT Company
Add header completion as well as Irony, which uses clang for suggestions.
#+BEGIN_SRC emacs-lisp
  (use-package company-c-headers
    :after company
    :config
    (add-hook 'c++-mode-hook 'company-mode)
    (add-hook 'c-mode-hook 'company-mode))
#+END_SRC
**** COMMENT Irony
#+BEGIN_SRC emacs-lisp
  (use-package irony
    :init
    (setq w32-pipe-read-delay 0)
    (setq irony-server-w32-pipe-buffer-size (* 64 1024))
    (add-hook 'c++-mode-hook 'irony-mode)
    (add-hook 'c-mode-hook 'irony-mode)
    (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
    (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options))
 
  (use-package company-irony
    :after irony
    :config
    (add-to-list 'company-backends '(company-c-headers
                                     company-dabbrev-code
                                     company-irony)))
#+END_SRC
**** Clang-format
Automatically format buffer on save.
#+BEGIN_SRC emacs-lisp
  (defun set-clang-format-style ()
    (if (file-exists-p (concat
                        (projectile-project-root)
                        ".clang-format"))
        (setq-local clang-format-style nil)
      (setq-local clang-format-style (concat "{BasedOnStyle: LLVM,"
                                             "IndentWidth: " (format "%s" tab-width) ","
                                             "UseTab: " (if (eq indent-tabs-mode nil)
                                                            "Never"
                                                          "AlignWithSpaces")
                                             ","
                                             "BreakBeforeBraces: Linux,"
                                             "AllowShortIfStatementsOnASingleLine: false,"
                                             "IndentCaseLabels: false}"))))
  (add-hook 'c-mode-common-hook 'set-clang-format-style)
  
  (use-package clang-format)
 
  ;;   (defun clang-format-on-save ()
  ;;     (add-hook 'before-save-hook 'clang-format-buffer nil t))
  ;;   (add-hook 'c-mode-hook 'clang-format-on-save nil t)
  ;;   (add-hook 'c++-mode-hook 'clang-format-on-save nil t))
#+END_SRC
*** emacs-lisp
**** COMMENT Company
Add slime backend.
#+BEGIN_SRC emacs-lisp
  (add-hook 'emacs-lisp-mode-hook 'company-mode)
 
  (use-package slime
    :config
    (setq inferior-lisp-program "/usr/bin/sbcl")
    (setq slime-contribs '(slime-fancy)))
 
  (use-package slime-company
    :init
    (require 'company)
    (slime-setup '(slime-fancy slime-company)))
#+END_SRC
 
*** COMMENT x86
**** x86-lookup
Look up reference PDF. Use Intel manual.
#+BEGIN_SRC emacs-lisp
  (use-package x86-lookup
    :init
    (setq x86-lookup-pdf "D:/Coding/x86-instructions.pdf")
    :bind ("C-h x" . x86-lookup))
#+END_SRC
 
*** Latex
**** AucTex
AucTex contains many additions to make tex editing good.
#+BEGIN_SRC emacs-lisp
  (use-package tex
    :ensure auctex
    :config
    (setq TeX-auto-save t
          TeX-parse-self t
          TeX-view-program-selection '((output-pdf "PDF Tools"))
          TeX-source-correlate-start-server t)
    (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer))
#+END_SRC
 
**** Company
Help company complete tex math and references.
#+BEGIN_SRC emacs-lisp
  (use-package company-math
    :after company
    :config
    (add-to-list 'company-backends '(company-math-symbols-unicode company-math-symbols-latex
                                                                  company-latex-commands))
    (setq company-math-allow-latex-symbols-in-faces t))
 
  (use-package company-reftex
    :after company
    :config
    (add-to-list 'company-backends 'company-reftex-citations))
 
  (use-package company-auctex
    :after company
    :config
    (company-auctex-init))
 
  (use-package company-bibtex
    :after company
    (add-to-list 'company-backends 'company-bibtex))
#+END_SRC
 
**** TeXcount
Word counts in latex.
Uses a Perl script.
#+BEGIN_SRC emacs-lisp
  (defun get-texcount-latest()
    (if (not(file-directory-p "~/.texcount"))
        (make-directory "~/.texcount"))
    (url-copy-file "https://app.uio.no/ifi/texcount/download.php?file=texcount_3_2_0_41.zip" "~/.texcount/texcount.zip" 1)
    (shell-command "unzip -o ~/.texcount/texcount.zip -d ~/.texcount")
    (add-to-list 'exec-path "~/.texcount/texcount.pl"))
 
  (if (not(or (file-exists-p "~/.texcount/texcount.pl") (file-exists-p "/usr/bin/texcount")))
      (get-texcount-latest))
 
  (defun texcount ()
    (interactive)
    (let*
        ( (this-file (buffer-file-name))
          (enc-str (symbol-name buffer-file-coding-system))
          (enc-opt
           (cond
            ((string-match "utf-8" enc-str) "-utf8")
            ((string-match "latin" enc-str) "-latin1")
            ("-encoding=guess")
            ) )
          (word-count
           (with-output-to-string
             (with-current-buffer standard-output
               (call-process "texcount" nil t nil "-0" enc-opt this-file)
               ) ) ) )
      (message word-count)
      ) )
  (add-hook 'LaTeX-mode-hook (lambda () (define-key LaTeX-mode-map (kbd "C-c c") 'texcount)))
  (add-hook 'latex-mode-hook (lambda () (define-key latex-mode-map (kbd "C-c c") 'texcount)))
#+END_SRC
 
*** PlantUML
Sets the PlantUML path for the mode to generate models.
#+BEGIN_SRC emacs-lisp
  (use-package plantuml-mode
    :init
    (cond ((eq system-type 'windows-nt)
           (when (file-exists-p "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar")
             (setq plantuml-jar-path "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar")
             (setq planuml-default-exec-mode 'jar)))
          ((eq system-type 'gnu/linux)
           (when (file-exists-p "/usr/share/java/plantuml/plantuml.jar")
             (setq plantuml-jar-path "/usr/share/java/plantuml/plantuml.jar")
             (setq planuml-default-exec-mode 'jar)))))
#+END_SRC
 
*** COMMENT Racket
**** Major mode
Set racket path in windows and enable racket mode.
#+BEGIN_SRC emacs-lisp
  (when (eq system-type 'windows-nt)
    (add-to-list 'exec-path "c:/Program Files/Racket")
    (setenv "PATH" (mapconcat #'identity exec-path path-separator)))
 
  (use-package racket-mode
    :config
    (autoload 'racket-mode "Racket" "Racket Editing Mode" t)
    (add-to-list
     'auto-mode-alist
     '("\\.rkt$" . racket-mode)))
#+END_SRC
 
*** Verilog
**** Get latest version
Use latest version from repositories.
#+BEGIN_SRC emacs-lisp
  (use-package verilog-mode
    :pin gnu
    :config
    (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
    (add-to-list 'auto-mode-alist '("\\.[ds]?va?h?\\'" . verilog-mode))
    (setq-default verilog-align-ifelse t
                  verilog-auto-delete-trailing-whitespace t
                  verilog-auto-inst-param-value t
                  verilog-auto-lineup 'all
                  verilog-auto-newline nil
                  verilog-auto-save-policy nil
                  verilog-auto-template-warn-unused t
                  verilog-auto-endcomments nil
                  verilog-highlight-grouping-keywords t
                  verilog-highlight-modules t
                  verilog-tab-to-comment t
                  verilog-indent-begin-after-if nil
                  verilog-indent-lists nil
                  verilog-case-indent 4
                  verilog-cexp-indent 0
                  verilog-indent-level 4
                  verilog-indent-level-behavioral 4
                  verilog-indent-level-declaration 4
                  verilog-indent-level-directive 4
                  verilog-indent-level-module 4))
#+END_SRC
#+END_SRC
*** COMMENT MATLAB
Mode for editing MATLAB m-files.
#+BEGIN_SRC emacs-lisp
  (use-package matlab
    :ensure matlab-mode
    :config
    (autoload 'matlab-mode "matlab" "Matlab Editing Mode" t)
    (add-to-list
     'auto-mode-alist
     '("\\.m$" . matlab-mode))
    (setq matlab-indent-function t)
    (setq matlab-shell-command "matlab")
    (matlab-cedet-setup))
#+END_SRC
 
*** COMMENT MIPS
For editing MIPS assembly.
#+BEGIN_SRC emacs-lisp
  (use-package mips-mode
    :mode "\\.mips$")
#+END_SRC
 
*** COMMENT IPython notebooks
Allow emacs to view and use IPython notebooks
#+BEGIN_SRC emacs-lisp
  (use-package ein)
#+END_SRC
 
*** Rust
**** Major mode
Get the major mode for rust files.
#+BEGIN_SRC emacs-lisp
  (use-package rust-mode
    :config
    ;; style guide suggests spaces not tabs
    (add-hook 'rust-mode-hook (lambda () (setq indent-tabs-mode nil)))
    (setq rust-format-on-save t))
 
  (use-package toml-mode)
#+END_SRC
**** Cargo integration
Integrate Cargo, rust's package manager.
#+BEGIN_SRC emacs-lisp
  (use-package cargo
    :hook
    (rust-mode . cargo-minor-mode))
#+END_SRC
**** Flycheck
Linting with flycheck.
#+BEGIN_SRC emacs-lisp
  (use-package flycheck-rust
    :config
    (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))
#+END_SRC
*** Go
**** Major mode
#+BEGIN_SRC emacs-lisp
  (use-package go-mode
    :config
    (add-hook 'before-save-hook #'gofmt-before-save))
#+END_SRC
 
**** Flycheck
#+BEGIN_SRC emacs-lisp
  (use-package flycheck-golangci-lint
    :config
    (add-hook 'flycheck-mode-hook #'flycheck-golangci-lint-setup))
#+END_SRC
**** Company
#+BEGIN_SRC emacs-lisp
  (use-package company-go)
#+END_SRC
*** Python
**** COMMENT LSP server
Use jedi, idk why.
#+BEGIN_SRC emacs-lisp
  (use-package lsp-jedi
    :config
    (add-to-list 'lsp-disabled-clients 'pyls)
    (add-to-list 'lsp-enabled-clients 'jedi))
#+END_SRC
* Org mode
** Up to date org
Pull the latest org mode from the repository, rather than the org which comes with emacs.
#+BEGIN_SRC emacs-lisp
  (use-package org
    :ensure org-contrib)
#+END_SRC
 
** Small tweaks
Small quality of life changes to org-mode.
#+BEGIN_SRC emacs-lisp
  (setq org-src-fontify-natively t
        org-src-tab-acts-natively t
        org-confirm-babel-evaluate nil
        org-export-with-smart-quotes t
        org-src-window-setup 'current-window)
  (add-hook 'org-mode-hook 'org-indent-mode)
  (diminish 'org-indent-mode)
  (diminish 'visual-line-mode)
#+END_SRC
*** Spell checking for code and latex
#+BEGIN_SRC emacs-lisp
  (add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" . "#\\+END_SRC"))
  (add-to-list 'ispell-skip-region-alist '("\\$" . "\\$"))
  (add-to-list 'ispell-skip-region-alist '("\\$\\$" . "\\$\\$"))
#+END_SRC
 
** Line wrapping
Enable line wrapping for long lines.
#+BEGIN_SRC emacs-lisp
  (add-hook 'org-mode-hook
            '(lambda ()
               (visual-line-mode 1)))
#+END_SRC
 
** Fancy org points
Use bullets of different colours and styles instead of the "\*\*\*" to denote indentation levels.
#+BEGIN_SRC emacs-lisp
  (use-package org-superstar
    :config
    (add-hook 'org-mode-hook (lambda () (org-superstar-mode 1))))
#+END_SRC
 
** Org Babel
Allows the execution of code from within an org buffer.
Code output can also be input to the buffer.
*** Languages
Add a bunch of languages to org babel supported languages
#+BEGIN_SRC emacs-lisp
  (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t)
                                                           (C . t)
                                                           (python . t)
                                                           (latex . t)
                                                           (scheme . t)
                                                           (gnuplot . t)
                                                           (matlab . t)
                                                           (fortran . t)
                                                           (java . t)
                                                           (plantuml . t)))
#+END_SRC
 
**** PlantUML path
Org uses its own path for some reason.
#+BEGIN_SRC emacs-lisp
  (setq org-plantuml-jar-path plantuml-jar-path)
#+END_SRC
 
*** Async export
Allow the editing of files while execution of blocks is occurring.
Needs :async tag in src header.
#+BEGIN_SRC emacs-lisp
  (use-package ob-async)
#+END_SRC
 
** Latex preview fragments match colour
Make the previews match theme colour of Emacs.
Gets very annoying very quickly without it.
#+BEGIN_SRC emacs-lisp
  (let ((dvipng--plist (alist-get 'dvipng org-preview-latex-process-alist)))
    (plist-put dvipng--plist :use-xcolor t)
    (plist-put dvipng--plist :image-converter '("dvipng -D %D -T tight -o %O %f")))
#+END_SRC
 
** Org export additions
*** Pandoc
Call pandoc on org buffer from org export.
Need to add ~#+OPTIONS: H:99~ to enable large level header exports.
#+BEGIN_SRC emacs-lisp
  (when (executable-find "pandoc")
    (use-package ox-pandoc))
#+END_SRC
 
*** COMMENT Dokuwiki Wiki
Allow export to dokuwiki markup from org.
#+BEGIN_SRC emacs-lisp
  (use-package ox-wk)
#+END_SRC
 
* COMMENT EMMS
Emacs media manager.
I come back to it every now and again as an MPD front-end, but haven't quite gotten the hang of it.
#+BEGIN_SRC emacs-lisp
  (use-package emms-setup
    :ensure emms
    :init
    (add-to-list 'load-path "~/elisp/emms/")
    :config
    (emms-all)
    (emms-default-players)
    (setq emms-source-file-directory "~/Music/"))
#+END_SRC
 
* COMMENT Org Blog
I use org to write my blog and use org-static-blog to generate the HTML.
** Org static blog config
Basic configuration for site.
Copied and modified from the example configuration.
#+BEGIN_SRC emacs-lisp
  (use-package org-static-blog
    :config
    (setq org-static-blog-publish-title "Joel's Site")
    (setq org-static-blog-publish-url "https://blog.joelg.cf/")
    (setq org-static-blog-publish-directory "/backup/home/joel/Downloads/Chizi123.github.io/")
    (setq org-static-blog-posts-directory "/backup/home/joel/Downloads/Chizi123.github.io/posts/")
    (setq org-static-blog-drafts-directory "/backup/home/joel/Downloads/Chizi123.github.io/drafts/")
    (setq org-static-blog-enable-tags t)
    (setq org-export-with-toc nil)
    (setq org-export-with-section-numbers nil)
 
    ;; This header is inserted into the <head> section of every page:
    ;;   (you will need to create the style sheet at
    ;;    ~/projects/blog/static/style.css
    ;;    and the favicon at
    ;;    ~/projects/blog/static/favicon.ico)
    (setq org-static-blog-page-header
          "<meta name=\"author\" content=\"Joel Grunbaum\">
      <meta name=\"referrer\" content=\"no-referrer\">
      <link href= \"static/style.css\" rel=\"stylesheet\" type=\"text/css\" />
      <link rel=\"icon\" href=\"static/favicon.png\">
      <script async src=\"https://www.googletagmanager.com/gtag/js?id=UA-147303155-2\"></script>
      <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-147303155-2');
      </script>
      ")
 
    ;; This preamble is inserted at the beginning of the <body> of every page:
    ;;   This particular HTML creates a <div> with a simple linked headline
    (setq org-static-blog-page-preamble
          "<div class=\"header\">
        <a href=\"https://blog.joelg.cf\">Joel's Site - Personal site and constant work in progress</a>
        <div class=\"sitelinks\">
          <a href=\"https://blog.joelg.cf/about-me.html\">About Me</a> |
          <a href=\"https://github.com/Chizi123\">Github</a> |
          <a href=\"https://facebook.com/joel.grun.5\">Facebook</a>
        </div>
      </div>")
 
    ;; This postamble is inserted at the end of the <body> of every page:
    ;;   This particular HTML creates a <div> with a link to the archive page
    ;;   and a licensing stub.
    (setq org-static-blog-page-postamble
          "<div id=\"archive\">
        <a href=\"https://blog.joelg.cf/archive.html\">Other posts</a>
      </div>
      <br>
      <center><button id=\"disqus_button\" onclick=\"load_disqus()\">Load Disqus Comments</button></center>
    <div id=\"disqus_thread\"></div>
    <script type=\"text/javascript\">
      function load_disqus() {
          var dsq = document.createElement('script');
          dsq.type = 'text/javascript';
          dsq.async = true;
          dsq.src = 'https://joelg-cf.disqus.com/embed.js';
          (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          document.getElementById('disqus_button').style.visibility = 'hidden';
      };
    </script>"))
#+END_SRC
 
** Sitemap addition
Creates a sitemap.xml for the blog based on the generated HTML files output in the final directory.
#+BEGIN_SRC emacs-lisp
  (defun blog-publish()
    (interactive)
    (org-static-blog-publish)
    (setq n 0)
    (setq site "https://blog.joelg.cf/")
    (setq posts (directory-files org-static-blog-publish-directory))
    (generate-new-buffer "sitemap.xml.gen")
    (with-current-buffer "sitemap.xml.gen" (insert "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"))
    (while (< n (length (directory-files org-static-blog-publish-directory)))
      (setq curr (nth n posts))
      (if (string-match "\\(html\\)" curr)
          (if (string-match "index.html" curr)
              (with-current-buffer "sitemap.xml.gen" (insert (concat "\t<url>\n\t\t<loc>" site "</loc>\n\t</url>\n")))
            (with-current-buffer "sitemap.xml.gen" (insert (concat "\t<url>\n\t\t<loc>" site curr "</loc>\n\t</url>\n")))))
      (setq n (1+ n)))
    (with-current-buffer "sitemap.xml.gen" (insert "</urlset>"))
    (with-current-buffer "sitemap.xml.gen" (write-region (point-min) (point-max) (concat org-static-blog-publish-directory "sitemap.xml")) t)
    (kill-buffer "sitemap.xml.gen"))
#+END_SRC
 
** Emacs-htmlize
Allow org features to be exported to HTML for site.
#+BEGIN_SRC emacs-lisp
  (use-package htmlize
    :defer t)
#+END_SRC
 
* COMMENT Journaling
** Noteworthy entries
I write weekly journal entries recapping my week.
These files are in org mode.
This is inspired by org-static-blog.
#+BEGIN_SRC emacs-lisp
  (defun journal-create-new-post ()
    "Create a new entry, prompt for title and insert header"
    (interactive)
    (let ((title (read-string "Title: ")))
      (find-file (concat "~/Documents/Journal/entry/"
                         (read-string "Filename: "
                                      (concat (format-time-string "%Y-%m-%d-" (current-time))
                                              (replace-regexp-in-string "\s" "-" (downcase title))
                                              ".org"))))
      (insert "#+title: " title "\n"
              "#+date: " (format-time-string "<%Y-%m-%d %H:%M>") "\n"
              "#+filetags: ")))
#+END_SRC
*** Publish entries
Use org-publish to collate entries into a single unit.
#+BEGIN_SRC emacs-lisp
  (setq org-publish-project-alist
        '(("Journal"
           :base-directory "~/Documents/Journal/entry/"
           :publishing-directory "~/Documents/Journal/out/"
           :publishing-function org-html-publish-to-html
           ;;:htmlized-source t
           :section-numbers nil
           :html-preamble t
           :html-validation-link nil
 
           :auto-sitemap t
           :sitemap-sort-files anti-chronologically
           :sitemap-file-entry-format "%d - %t"
           :sitemap-title "Home"
           :sitemap-filename "index.html"
           :sitemap-function org-publish-sitemap)))
#+END_SRC