aboutsummaryrefslogtreecommitdiff
path: root/config/emacs/emacs.d/emacs.org
blob: a229b0c88e3f6e1c237039fb5ee92451228c96cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
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
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
* =~/.config/emacs.d/=
:PROPERTIES:
:ID:       defa5909-a6c9-4310-9237-b01c8db940ee
:header-args: elisp: :results none
:END:

Tangle all the things from orgmode!

** =early-init.el=
:PROPERTIES:
:ID:       7ba2781f-2040-4345-a188-f610f1e798b4
:header-args:elisp: :tangle ./early-init.el :tangle-mode (identity #o444)
:END:

#+begin_src elisp
;;; This file is generated from tangled output of emacs.org.  Do NOT
;;; edit this file directly!
#+end_src

#+begin_src elisp
(setq package-enable-at-startup nil)
(setq frame-inhibit-implied-resize t)
(setq gc-cons-threshold 402653184)
(setq gc-cons-percentage 0.6)
#+end_src

#+begin_src elisp
(defvar file-name-handler-alist-original file-name-handler-alist)
(setq file-name-handler-alist nil)
(defvar contrib/after-load-theme-hook nil
  "Hook run after a color theme is loaded using `load-theme'.")
(defun contrib/run-after-load-theme-hook (&rest _)
  "Run `contrib/after/load-theme-hook'"
  (run-hooks 'contrib/after-load-theme-hook))

(advice-add #'load-theme :after #'contrib/run-after-load-theme-hook)
(require 'modus-operandi-theme)

(defun kb/modus-operandi ()
  "Enable some Modus Operandi variables and load the theme.

This is used internally by `vde/modus-themes-toggle'.
https://git.sr.ht/~vdemeester/home/tree/master/item/tools/emacs/early-init.el#L26"
  (setq modus-themes-slanted-constructs t)
  (setq modus-themes-bold-constructs nil)
  (setq modus-themes-no-mixed-fonts nil)
  (setq modus-themes-subtle-line-numbers nil)
  (setq modus-themes-success-deuteranopia t)

  (setq modus-themes-fringes nil)
  (setq modus-themes-lang-checkers '())
  (setq modus-themes-mode-line '(3d))
  (setq modus-themes-syntax '())
  (setq modus-themes-hl-line '(underline))
  (setq modus-themes-paren-match '(subtle bold))
  (setq modus-themes-links '(neutral-underline))
  (setq modus-themes-prompts '(subtle gray))
  (setq modus-themes-completions '(opinionated))
  (setq modus-themes-region '(bg-only no-extend))
  (setq modus-themes-diffs 'desaturated)
  (setq modus-themes-org-blocks 'grayscale)
  (setq modus-themes-org-habit nil)

  (setq modus-themes-headings ; this is an alist: read the manual or its doc string
        (quote ((1 . (background overline variable-pitch 1.5))
                (2 . (overline rainbow 1.3))
                (3 . (overline 1.1))
                (t . (monochrome)))))

  (setq modus-themes-variable-pitch-ui nil)
  (setq modus-themes-variable-pitch-headings nil)
  (setq modus-themes-scale-headings t)
  (setq modus-themes-scale-1 1.1)
  (setq modus-themes-scale-2 1.15)
  (setq modus-themes-scale-3 1.21)
  (setq modus-themes-scale-4 1.27)
  (setq modus-themes-scale-5 1.33)
  (load-theme 'modus-operandi t))

(defun vde/modus-operandi-custom ()
  "Customize modus-operandi theme"
  ;; (if (member 'modus-operandi custom-enabled-themes)
  ;;     (modus-operandi-theme-with-color-variables ; this macro allows us to access the colour palette
  ;;      (custom-theme-set-faces
  ;;       'modus-operandi
  ;;       `(whitespace-tab ((,class (:background "#ffffff" :foreground "#cccccc"))))
  ;;       `(whitespace-space ((,class (:background "#ffffff" :foreground "#cccccc"))))
  ;;       `(whitespace-hspace ((,class (:background "#ffffff" :foreground "#cccccc"))))
  ;;       `(whitespace-newline ((,class (:background "#ffffff" :foreground "#cccccc"))))
  ;;       `(whitespace-indentation ((,class (:background "#ffffff" :foreground "#cccccc"))))
  ;;       )))
  )

(add-hook 'contrib/after-load-theme-hook 'vde/modus-operandi-custom)
(kb/modus-operandi)

#+end_src

Font Config

#+begin_src elisp :tangle no
(set-face-attribute 'default nil
                    :family "DejaVuSansMono Nerd Font Mono"
                    :height 110
                    :weight 'normal
                    :width 'normal)

(defconst font-height 110
  "Default font-height to use.")
(defconst font-family-mono "DejaVu Mono"
  "Default monospace font-family to use.")
(defconst font-family-sans "DejaVu Sans Mono"
  "Default sans font-family to use")
;; Middle/Near East: ืฉืœื•ื, ุงู„ุณู‘ู„ุงู… ุนู„ูŠูƒู…
(when (member "Noto Sans Arabic" (font-family-list))
  (set-fontset-font t 'arabic "Noto Sans Arabic"))
(when (member "Noto Sans Hebrew" (font-family-list))
  (set-fontset-font t 'arabic "Noto Sans Hewbrew"))
;; East Asia: ไฝ ๅฅฝ, ๆ—ฉๆ™จ, ใ“ใ‚“ใซใกใฏ, ์•ˆ๋…•ํ•˜์„ธ์š”
;;
;; Make sure you use the right font. See
;; https://www.google.com/get/noto/help/cjk/.
;;
;; This font requires "Regular". Other Noto fonts dont.
;; ยฏ\_(ใƒ„)_/ยฏ
(when (member "Noto Sans CJK" (font-family-list))
  (set-fontset-font t 'han "Noto Sans CJK SC Regular")
  (set-fontset-font t 'kana "Noto Sans CJK JP Regular")
  (set-fontset-font t 'hangul "Noto Sans CJK KR Regular")
  (set-fontset-font t 'cjk-misc "Noto Sans CJK KR Regular"))
;; South East Asia: แž‡แŸ†แžšแžถแž”แžŸแžฝแžš, เบชเบฐเบšเบฒเบเบ”เบต, แ€™แ€„แ€บแ€นแ€‚แ€œแ€ฌแ€•แ€ซ, เธชเธงเธฑเธชเธ”เธตเธ„เธฃเธฑเธš
(when (member "Noto Sans Khmer" (font-family-list))
  (set-fontset-font t 'khmer "Noto Sans Khmer"))
(when (member "Noto Sans Lao" (font-family-list))
  (set-fontset-font t 'lao "Noto Sans Lao"))
(when (member "Noto Sans Myanmar" (font-family-list))
  (set-fontset-font t 'burmese "Noto Sans Myanmar"))
(when (member "Noto Sans Thai" (font-family-list))
  (set-fontset-font t 'thai "Noto Sans Thai"))

;; Africa: แˆ แˆ‹แˆ
(when (member "Noto Sans Ethiopic" (font-family-list))
  (set-fontset-font t 'ethiopic "Noto Sans Ethiopic"))

;;  South Asia: เชจเชฎเชธเซเชคเซ‡, เคจเคฎเคธเฅเคคเฅ‡, เฒจเฒฎเฒธเณเฒ•เฒพเฒฐ, เดจเดฎเดธเตเด•เดพเดฐเด‚, เฌถเญเฌฃเฌฟเฌฌเญ‡,
;;              เถ†เถบเท”เถถเทเท€เถฑเทŠ, เฎตเฎฃเฎ•เฏเฎ•เฎฎเฏ, เฐจเฐฎเฐธเฑเฐ•เฐพเฐฐเฐ‚, เฝ–เฝ€เพฒเผ‹เฝคเฝฒเฝฆเผ‹เฝ–เฝ‘เฝบเผ‹เฝฃเฝบเฝ‚เฝฆเผŽ
(when (member "Noto Sans Gujarati" (font-family-list))
  (set-fontset-font t 'gujarati "Noto Sans Gujarati"))
(when (member "Noto Sans Devanagari" (font-family-list))
  (set-fontset-font t 'devanagari "Noto Sans Devanagari"))
(when (member "Noto Sans Kannada" (font-family-list))
  (set-fontset-font t 'kannada "Noto Sans Kannada"))
(when (member "Noto Sans Malayalam" (font-family-list))
  (set-fontset-font t 'malayalam "Noto Sans Malayalam"))
(when (member "Noto Sans Oriya" (font-family-list))
  (set-fontset-font t 'oriya "Noto Sans Oriya"))
(when (member "Noto Sans Sinhala" (font-family-list))
  (set-fontset-font t 'sinhala "Noto Sans Sinhala"))
(when (member "Noto Sans Tamil" (font-family-list))
  (set-fontset-font t 'tamil "Noto Sans Tamil"))
(when (member "Noto Sans Telugu" (font-family-list))
  (set-fontset-font t 'telugu "Noto Sans Telugu"))
(when (member "Noto Sans Tibetan" (font-family-list))
  (set-fontset-font t 'tibetan "Noto Sans Tibetan"))


;; If font-family-mono or font-family-sans are not available, use the default Emacs face
(when (member font-family-mono (font-family-list))
  (set-face-attribute 'default nil
                      :family font-family-mono
                      :height font-height)
  (set-face-attribute 'fixed-pitch nil
                      :family font-family-mono))
(when (member font-family-sans (font-family-list))
  (set-face-attribute 'variable-pitch nil
                      :family font-family-sans
                      :weight 'regular))

(set-fontset-font t 'symbol "Noto Emoji")
(set-fontset-font t 'symbol "all-the-icons" nil 'append)
(set-fontset-font t '(#xF0000 . #xF14FF) "Material Design Icons" nil 'append)
(set-fontset-font t 'symbol "Symbola" nil 'append)

#+end_src

#+begin_src elisp
                                        ; Ignore X resources; its settings would be redundant with the other settings
;; in this file and can conflict with later config (particularly where the
;; cursor color is concerned).
(advice-add #'x-apply-session-resources :override #'ignore)

;; - Resetting Garbage Collection and file-name-handler values.
(add-hook 'after-init-hook
          (lambda ()
            (setq gc-cons-threshold 100000000)
            (setq gc-cons-percentage 0.1)
            (setq file-name-handler-alist file-name-handler-alist-original)
            (garbage-collect)) t)
#+end_src

#+begin_src elisp
(provide 'early-init)
;;; early-init.el ends here
#+end_src

** =init.el=
:PROPERTIES:
:ID:       828c7a64-b5e4-4314-a146-9f4cd1813543
:header-args:elisp: :tangle init.el :tangle-mode (identity #o444)
:END:

#+begin_src elisp
;;; This file is generated from tangled output of emacs.org.  Do NOT
;;; edit this file directly!
#+end_src

*** Custom
:PROPERTIES:
:ID:       75a69bbb-23be-49c5-a79d-12b3b9209b07
:END:

#+begin_src elisp
(setq byte-complile-warnings '(not cl-functions))
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))

(defconst *spell-check-support-enabled* t)

(setq read-process-output-max (* 4096 1024))

;; customize interface configuration
(when (file-exists-p custom-file)
  (load custom-file))
#+end_src

*** Server Configuration
:PROPERTIES:
:ID:       bf099ae8-4a4e-4348-aa7f-89ff3baeabbd
:END:

#+begin_src elisp
;; https://www.emacswiki.org/emacs/EmacsAsDaemon
(defun signal-restart-server ()
  "Handler for SIGUSR1 signal, to (re)start an Emacs server.

Can be tested from within Emacs with:
  (signal-process (emacs-pid) 'sigusr1)

or from the command line with:
$ kill -USR1 <emacs-pid>
$ emacsclient -c"
  (interactive)
  (server-force-delete)
  (server-start))

(define-key special-event-map [sigusr1] 'signal-restart-server)
#+end_src

*** DBus Configuration
:PROPERTIES:
:ID:       957c50a7-cf5f-4f44-8548-bed26b132cd5
:END:

#+begin_src elisp
(require 'desktop)
(require 'dbus)

;; Loosely borrowed from https://github.com/jmibanez/jmi-dotemacs/blob/master/linux/000.init.el
;; Session handling -- Exit Emacs on D-BUS signal from session manager
(defun kb/dbus-handle-gnome-session-manager-exit ()
  "Perform some cleanup than shutdown Emacs server."
  (message "Closing session at request of DBus")
  (desktop-save (concat desktop-path desktop-base-file-name) t)
  (save-buffers-kill-emacs t))

(defvar kb/dbus-session-exit-handler "DBus Handler for Session Exits.")
(setq kb/dbus-session-exit-handler (dbus-register-signal
                                    :session
                                    "org.gnome.SessionManager"
                                    "/org/gnome/SessionManager"
                                    "org.gnome.SessionManager"
                                    "SessionOver"
                                    #'kb/dbus-handle-gnome-session-manager-ext))
#+end_src

*** Emacs Defaults
:PROPERTIES:
:ID:       51b73308-55a1-4d0d-9c9f-615d067cddc0
:END:

#+begin_src elisp
;; https://matthewbauer.us/blog/bauer.html

(setq-default mouse-yank-at-point t)
(setq-default next-error-recenter t)
(setq-default notmuch-show-logo nil)
(setq-default nrepl-log-messages t)
(setq-default ns-function-modifier 'hyper)
(setq-default ns-pop-up-frames nil)
(setq-default nsm-save-host-names t)
(setq-default org-deadline-warning-days 30)
(setq-default org-export-in-background nil)
(setq-default org-log-done 'time)
(setq-default org-log-done-with-time t)
(setq-default org-return-follows-links t)
(setq-default org-special-ctrl-a/e t)
(setq-default org-src-fontify-natively t)
(setq-default org-src-preserve-indentation t)
(setq-default org-src-tab-acts-natively t)
(setq-default org-startup-folded 'fold)
(setq-default parens-require-spaces t)
(setq-default projectile-globally-ignored-files
              '("TAGS"
                "GPATH"
                "GTAGS"
                "GRTAGS"))
(setq-default TeX-auto-save t)
(setq-default TeX-engine 'xetex)
(setq-default ad-redefinition-action 'accept)
(setq-default apropros-do-all t)
(setq-default async-shell-command-buffer 'new-buffer)
(setq-default auth-source-save-behavior t)
(setq-default auto-revert-check-vc-info nil)
(setq-default auto-revert-remote-files nil)
(setq-default auto-revert-verbose nil)
(setq-default auto-window-vscroll nil)
(setq-default backward-delete-char-untabify-method 'hungry)
(setq-default blink-cursor-interval 0.4)
(setq-default bookmark-default-file (expand-file-name ".bookmarks.el" user-emacs-directory))
(setq-default bookmark-save-flag t)
(setq-default buffers-menu-max-size 30)
(setq-default c-syntactic-indentation t)
(setq-default case-fold-search t)
(setq-default checkdoc-spellcheck-documentation-flag t)
(setq-default column-number-mode t)
(setq-default comint-input-ignoredups t)
(setq-default comint-process-echoes t)
(setq-default comint-prompt-read-only t)
(setq-default comint-scroll-show-maximum-output nil)
(setq-default company-auto-complete
              (lambda () (and (company-tooltip-visible-p) (company-explicit-action-p))))
(setq-default company-continue-commands
              '(not save-buffer
                    save-some-buffers
                    save-buffers-kill-terminal
                    save-buffers-kill-emacs
                    comint-previous-matching-input-from-input
                    comint-next-matching-input-from-input))
(setq-default company-frontends
              '(company-pseudo-tooltip-unless-just-one-frontend
                company-preview-frontend
                company-echo-metadata-frontend))
(setq-default company-require-match nil)
(setq-default company-selection-wrap-around t)
(setq-default compilation-always-kill nil)
(setq-default compilation-ask-about-save nil)
(setq-default compilation-auto-jump-to-first-error nil)
(setq-default compilation-environment '("TERM=xterm-256color"))
(setq-default compilation-scroll-output nil)
(setq-default completion-cycle-threshold 5)
(setq-default completions-format 'vertical)
(setq-default counsel-find-file-at-point t)
(setq-default counsel-mode-override-describe-bindings t)
(setq-default create-lockfiles t)
(setq-default default-tab-width 4)
(setq-default delete-by-moving-to-trash t)
(setq-default delete-old-versions t)
(setq-default delete-selection-mode t)
(setq-default dired-auto-revert-buffer t)
(setq-default dired-dwim-target t)
(setq-default dired-hide-details-hide-symlink-targets nil)
(setq-default dired-listing-switches "-alhv")
(setq-default dired-omit-files "^\\.")
(setq-default dired-omit-verbose nil)
(setq-default dired-recursive-copies 'always)
(setq-default dired-recursive-deletes 'always)
(setq-default disabled-command-function nil)
(setq-default dtrt-indent-verbosity 0)
(setq-default echo-keystrokes 1)
(setq-default ediff-split-window-function 'split-window-horizontally)
(setq-default ediff-window-setup-function 'ediff-setup-windows-plain)
(setq-default enable-recursive-minibuffers nil)
(setq-default erc-autoaway-idle-seconds 600)
(setq-default erc-autojoin-timing 'ident erc-fill-prefix " ")
(setq-default erc-insert-timestamp-function 'erc-insert-timestamp-left)
(setq-default erc-interpret-mirc-color t)
(setq-default erc-kill-buffer-on-part t)
(setq-default erc-kill-queries-on-quit t)
(setq-default erc-kill-server-buffer-on-quit t)
(setq-default erc-prompt (lambda () (concat "[" (buffer-name) "]")))
(setq-default erc-prompt-for-password nil)
(setq-default erc-query-display 'buffer)
(setq-default erc-server-coding-system '(utf-8 . utf-8))
(setq-default erc-timestamp-format "%H:%M:%S ")
(setq-default erc-timestamp-only-if-changed-flag nil)
(setq-default erc-try-new-nick-p nil)
(setq-default eshell-banner-message "")
(setq-default eshell-buffer-maximum-lines 100000)
(setq-default eshell-cd-on-directory t)
(setq-default eshell-cmpl-autolist t)
(setq-default eshell-cmpl-cycle-completions t)
(setq-default eshell-cmpl-cycle-cutoff-length 2)
(setq-default eshell-cp-interactive-query t)
(setq-default eshell-cp-overwrite-files nil)
(setq-default eshell-default-target-is-dot t)
(setq-default eshell-destroy-buffer-when-process-dies t)
(setq-default eshell-highlight-prompt t)
(setq-default eshell-hist-ignoredups t)
(setq-default eshell-history-size 10000)
(setq-default eshell-list-files-after-cd t)
(setq-default eshell-ln-interactive-query t)
(setq-default eshell-mv-interactive-query t)
(setq-default eshell-output-filter-functions
              '(eshell-handle-ansi-color
                eshell-handle-control-codes
                eshell-watch-for-password-prompt
                eshell-truncate-buffer))
(setq-default eshell-plain-echo-behavior nil)
(setq-default eshell-review-quick-commands t)
(setq-default eshell-rm-interactive-query nil)
(setq-default eval-expression-print-length 20)
(setq-default eval-expression-print-level nil)
(setq-default expand-region-contract-fast-key "j")
(setq-default explicit-shell-args
              '("-c" "export EMACS= INSIDE_EMACS=; stty echo; shell"))
(setq-default fill-column 79)
(setq-default flycheck-check-syntax-automatically
              '(save idle-change mode-enabled new-line))
(setq-default flycheck-display-errors-function
              'flycheck-display-error-messages-unless-error-list)
(setq-default flycheck-global-modes
              '(not
                erc-mode
                message-mode
                git-commit-mode
                view-mode
                outline-mode
                text-mode
                org-mode))
(setq-default flycheck-idle-change-delay 0.001)
(setq-default flycheck-standard-error-navigation nil)
(setq-default flyspell-abbrev-p nil)
(setq-default flyspell-auto-correct nil)
(setq-default flyspell-highlight-properties t)
(setq-default flyspell-incorrect-hook nil)
(setq-default flyspell-issue-welcome-flag nil)
(setq-default global-auto-revert-non-file-buffers t)
(setq-default highlight-nonselected-windows nil)
(setq-default hippie-expand-verbose nil)
(setq-default history-delete-duplicates t)
(setq-default history-length 20000)
(setq-default hscroll-margin 5)
(setq-default hscroll-step 5)
(setq-default iedit-toggle-key-default nil)
(setq-default imenu-auto-rescan t)
(setq-default indent-tabs-mode nil)
(setq-default indicate-empty-lines t)
(setq-default inhibit-startup-echo-area-message t)
(setq-default inhibit-startup-screen t)
(setq-default ispell-extra-args '("--sug-mode=ultra"))
(setq-default ispell-quietly t)
(setq-default ispell-silently-savep t)
(setq-default jit-lock-defer-time 0)
(setq-default js2-mode-show-parse-errors nil)
(setq-default js2-mode-show-strict-warnings nil)
(setq-default kill-do-not-save-duplicates t)
(setq-default kill-whole-line nil)
(setq-default load-prefer-newer t)
(setq-default magit-clone-set-remote.pushDefault t)
(setq-default magit-ediff-dwim-show-on-hunks t)
(setq-default magit-fetch-arguments nil)
(setq-default magit-log-auto-more t)
(setq-default magit-process-popup-time 15)
(setq-default magit-stage-all-confirm nil)
(setq-default magit-unstage-all-confirm nil)
(setq-default minibuffer-prompt-properties
              '(read-only t cursor-intangible t face minibuffer-prompt))
(setq-default mmm-global-mode 'buffers-with-submode-classes)
(setq-default mmm-submode-decoration-level 2)
(setq-default projectile-do-log nil)
(setq-default projectile-enable-caching t)
(setq-default projectile-ignored-project-function 'file-remote-p)
(setq-default projectile-switch-project-action 'projectile-dired)
(setq-default projectile-verbose nil)
(setq-default reb-re-syntax 'string)
(setq-default require-final-newline t)
(setq-default resize-mini-windows t)
(setq-default ring-bell-function 'ignore)
(setq-default rtags-completions-enabled t)
(setq-default rtags-imenu-syntax-highlighting 10)
(setq-default ruby-insert-encoding-magic-comment nil)
(setq-default same-window-buffer-names
              '("*eshell*"
                "*shell*"
                "*mail*"
                "*inferior-lisp*"
                "*ielm*"
                "*scheme"))
(setq-default save-abbrevs 'silently)
(setq-default save-interprogram-paste-before-kill t)
(setq-default savehist-additional-variables
              '(search-ring
                regexp-search-ring
                kill-ring
                comint-input-ring))
(setq-default savehist-autosave-interval 60)
(setq-default scroll-preserve-screen-position 'always)
(setq-default scroll-preserve-screen-position 'always)
(setq-default send-mail-function 'smtpmail-send-it)
(setq-default sentence-end-double-space t)
(setq-default set-mark-command-repeat-pop t)
(setq-default set-mark-command-repeat-pop t)
(setq-default sh-guess-basic-offset t)
(setq-default shell-completion-execonly nil)
(setq-default shell-input-autoexpand nil)
(setq-default show-trailing-whitespace nil)
(setq-default sp-autoskip-closing-pair 'always)
(setq-default tab-always-indent 'complete)
(setq-default tab-width 4)
(setq-default term-input-autoexpand t)
(setq-default term-input-ignoredups t)
(setq-default term-input-ring-file-name t)
(setq-default text-quoting-style 'grave)
(setq-default tls-checktrust t)
(setq-default tooltip-delay 1.5)
(setq-default tramp-default-proxies-alist
              '(((regexp-quote (system-name)) nil nil)
                (nil "\\`root\\'" "/ssh:%h:")
                (".*" "\\`root\\'" "/ssh:%h:")))
(setq-default tramp-default-user nil)
(setq-default truncate-lines nil)
(setq-default truncate-partial-width-windows nil)
(setq-default undo-limit 80000)
(setq-default uniquify-after-kill-buffer-p t)
(setq-default use-dialog-box nil)
(setq-default use-file-dialog nil)
(setq-default use-package-enable-imenu-support t)
(setq-default use-package-expand-minimally nil)
(setq-default vc-handled-backends '(Git))
(setq-default version-control t)
(setq-default view-inhibit-help-message t)
(setq-default view-read-only t)
(setq-default visiable-bell nil)
(setq-default visible-cursor t)
(setq-default whitespace-auto-cleanup t)
(setq-default whitespace-line-column 80)
(setq-default whitespace-rescan-timer-time nil)
(setq-default whitespace-silent t)
(setq-default woman-imenu t)

(setq-default next-error-message-highlight t)
(setq-default read-minibuffer-restore-windows nil)
#+end_src

*** Package Configuration
:PROPERTIES:
:ID:       4931bd29-9293-47b5-810b-5103cf3cbfa6
:END:

**** Elpa
:PROPERTIES:
:ID:       f6d0347d-0517-454a-9ee9-cdcdbc3dd133
:END:

#+begin_src elisp
(require 'package)

(setq package-archives nil)

(let ((local-package-el (locate-library "package")))
  (when (string-match-p (concat "^" (regexp-quote user-emacs-directory))
                        local-package-el)
    (warn "Please remove the local package.el, which is no longer supported (%s)."
          (local-package-el))))

;;; Fire up package.el
(setq package-enable-at-startup nil)
(package-initialize)

(when (not package-archive-contents)
  (package-refresh-contents))
#+end_src

**** =use-package=
:PROPERTIES:
:ID:       06e19deb-b0e4-46d1-a322-202e3f303bad
:END:

#+begin_src elisp
(eval-when-compile
  (require 'use-package))

(setq use-package-always-ensure nil)

(use-package bind-key)
(use-package diminish)
#+end_src

*** Execution Path
:PROPERTIES:
:ID:       0e42516d-f87a-46a4-a62c-774a5f46450d
:END:

#+begin_src elisp
(use-package exec-path-from-shell
  :config
  (progn
    (dolist (var '("SSH_AUTH_SOCK"
                   "SSH_AGENT_PID"
                   "GPG_AGENT_INFO"
                   "LANG"
                   "LC_CTYPE"))
      (add-to-list 'exec-path-from-shell-variables var))))


(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))
#+end_src

*** Backupfiles
:PROPERTIES:
:ID:       e9e68a37-0d3e-4d72-89e4-b33d104d5dd8
:END:

#+begin_src elisp
;; Snippet taken from https://stackoverflow.com/a/18330742/7492588
(defconst --backup-directory (concat user-emacs-directory "backups/"))
(defconst --lockfile-directory (concat user-emacs-directory "lockfiles/")
  "Lockfiles and Autosave files directory.")
(unless (file-exists-p --backup-directory)
  (make-directory --backup-directory t)
  (set-file-modes --backup-directory #o700))
(unless (file-exists-p --lockfile-directory)
  (make-directory --lockfile-directory)
  (set-file-modes --lockfile-directory #o700))
(setq backup-directory-alist `(("." . ,--backup-directory)))
(setq auto-save-file-name-transforms `((".*" ,--lockfile-directory t)))
(setq make-backup-files nil)
(setq backup-by-copying nil)
(setq version-control t)
(setq delete-old-versions t)
(setq delete-by-moving-to-trash nil)
(setq kept-old-versions 6)
(setq kept-new-versions 9)
(setq auto-save-default t)
(setq auto-save-timeout 20)
(setq auto-save-interval 200)
#+end_src

*** Environment Variables
:PROPERTIES:
:ID:       492a29c0-56b5-40df-9f4a-a2a3a6dd85af
:END:

#+begin_src elisp :tangle no
(require 'eshell)
(require 'subr-x)
(require 'dash)

(defun kb/join-paths (paths &optional path-separator)
  "Join the given PATHS together using the PATH-SEPARATOR."
  (or path-separator (setq path-separator ":"))
  ;; Remove duplicate path entries
  (let* ((paths (-remove (lambda (p) (not p)) paths))
         (split-paths (lambda (p) (split-string p path-separator)))
         (paths-to-join (-flatten (mapcar split-paths paths))))
    (string-join (seq-uniq paths-to-join) path-separator)))

(let* ((user-home (getenv "HOME"))
       (user-nix-profile (concat user-home "/.nix-profile/"))
       (python-path (getenv "PYTHONPATH"))
       (c-include-path (getenv "C_INCLUDE_PATH"))
       (cpp-include-path (getenv "CPLUS_INCLUDE_PATH"))
       (library-path (getenv "LIBRARY_PATH"))
       (ghc-package-path (getenv "GHC_PACKAGE_PATH")))
  (progn
    (eshell/addpath (concat user-nix-profile "/bin"))
    ;; (setenv "PATH" (concat (getenv "PATH")))
    (setenv "PYTHONPATH" (kb/join-paths
                          (list (concat user-nix-profile
                                        "/lib/python3.7/site-packages")
                                python-path)))
    (setenv "C_INCLUDE_PATH" (kb/join-paths
                              (list (concat user-nix-profile "/include")
                                    c-include-path)))
    (setenv "CPLUS_INCLUDE_PATH" (kb/join-paths
                                  (list (concat user-nix-profile "/include")
                                        cpp-include-path)))))
#+end_src

#+begin_src elisp
(let ((ssh-auth-sock (string-trim (shell-command-to-string "gpgconf --list-dirs agent-ssh-socket"))))
  (setenv "SSH_AUTH_SOCK" ssh-auth-sock))
#+end_src

*** EasyPG
:PROPERTIES:
:ID:       d5df41e6-a853-4690-a654-ee04e22f2e5c
:END:

#+begin_src elisp
(use-package pinentry
  :config
  (setq epa-pinentry-mode 'loopback)
  (pinentry-start))
#+end_src

*** Preload Local -- Disabled
:PROPERTIES:
:ID:       9f9b83a9-96c2-4d5e-838c-965f9dab90ad
:END:

#+begin_src elisp :tangle no
(require 'init-preload-local nil t)
#+end_src

*** wgrep -- Disabled
:PROPERTIES:
:ID:       bd064283-ecbc-42e8-8c81-1cd8a3ae3a66
:END:

#+begin_src elisp :tangle no
(use-package wgrep)
#+end_src

*** FullFrame
:PROPERTIES:
:ID:       a002f934-38fc-4d0b-a9a6-d741d05adaff
:END:

#+begin_src elisp
(use-package fullframe)

(fullframe list-packages quit-window)
#+end_src

*** Icons
:PROPERTIES:
:ID:       8a1e42a0-0055-4f91-8a50-cbebf4f6c2a4
:END:

#+begin_src elisp
(use-package all-the-icons)
#+end_src

*** Spaceline -- Disabled
:PROPERTIES:
:ID:       06593606-1e9f-4b05-8f52-2047fb85fb46
:END:

#+begin_src elisp :tangle no
(use-package spaceline
  :demand t)

(use-package spaceline-config
  :after spaceline
  :demand t
  :config
  (spaceline-helm-mode 1)
  (spaceline-emacs-theme)
  (spaceline-toggle-minor-modes-off)
  (spaceline-toggle-mu4e-alert-segment-off))
#+end_src

*** Powerline
:PROPERTIES:
:ID:       c878a9ac-2e3d-464e-a481-f95f9309ab18
:END:

#+begin_src elisp
(use-package powerline
  :init
  (powerline-default-theme))
#+end_src

*** GUI Frame Configurations
:PROPERTIES:
:ID:       1274a1b0-b4b0-45af-94bd-9cee35d3dc23
:END:

#+begin_src elisp
;; suppress gui features
(setq use-file-dialog nil)
(setq use-dialog-box nil)
(setq inhibit-startup-screen t)
(setq inhibit-startup-echo-area-message t)

;; window size
(when (fboundp 'tool-bar-mode)
  (tool-bar-mode -1))
(when (fboundp 'scroll-bar-mode)
  (scroll-bar-mode -1))
(when (fboundp 'menu-bar-mode)
  (menu-bar-mode -1))

(let ((no-border '(internal-border-width . 0)))
  (add-to-list 'default-frame-alist no-border)
  (add-to-list 'initial-frame-alist no-border))

(defun sanityinc/adjust-opacity (frame incr)
  "Adjust the background opacity of FRAME by increment INCR."
  (unless (display-graphic-p frame)
    (error "Cannot adjust opacity of this frame"))
  (let* ((oldalpha (or (frame-parameter frame 'alpha) 100))
         (oldalpha (if (listp oldalpha) (car oldalpha) oldalpha))
         (newalpha (+ incr oldalpha)))
    (when (and (<= frame-alpha-lower-limit newalpha) (>= 100 newalpha))
      (modify-frame-parameters frame (list (cons 'alpha newalpha))))))

(setq frame-title-format
      '((:eval (if (buffer-file-name)
                   (abbreviate-file-name (buffer-file-name))
                 "%b"))))

;; non-zero values for `line-spacing' can mess up ansi-term and co,
;; so we zero it explicitly in those cases.
(add-hook 'term-mode-hook
          (lambda ()
            (setq line-spacing 0)))

(defvar disable-mouse)
(use-package disable-mouse
  :diminish)

;;scroll margin
(defvar smooth-scrolling)
(defvar smooth-scrolling-margin)
(use-package smooth-scrolling
  :init
  (setq smooth-scrolling-margin 10))
#+end_src

*** dired
:PROPERTIES:
:ID:       f67852f8-d563-4fbe-bf98-30afc3239cf8
:END:

https://matthewbauer.us/blog/bauer.html

#+begin_src elisp
(use-package dired
  :init (require 'dired)
  :bind (:map dired-mode-map
              ("C-c C-c" . compile)
              ("r" . browse-url-of-dired-file))
  :config
  (setq dired-listing-switches "-lh"))

;; http://pragmaticemacs.com/emacs/quickly-preview-images-and-other-files-with-peep-dired/
;; preview files in dired
(use-package peep-dired
  :bind (:map dired-mode-map
              ("P" . peep-dired)))
#+end_src

Disable mouse open files.

#+begin_src elisp
(define-key dired-mode-map [mouse-2] nil)
#+end_src

#+begin_src elisp
(require 'dired-x)
(setq dired-guess-shell-alist-user '(("\\.pdf\\'" "evince")
                                     ("\\.doc\\'" "libreoffice")
                                     ("\\.docx\\'" "libreoffice")
                                     ("\\.ppt\\'" "libreoffice")
                                     ("\\.pptx\\'" "libreoffice")
                                     ("\\.xls\\'" "libreoffice")
                                     ("\\.xlsx\\'" "libreoffice")
                                     ("\\.csv\\'" "libreoffice")
                                     ("\\.tsv\\'" "libreoffice")
                                     ("\\.jpg\\'" "eog")
                                     ("\\.png\\'" "eog")
                                     ("\\.svg\\'" "eog")))
#+end_src

*** isearch
:PROPERTIES:
:ID:       85846a98-5932-49de-8f88-abbc558dfecb
:END:

#+begin_src elisp
;; show number of matches while searching
(use-package anzu
  :init
  (global-anzu-mode t)
  (setq anzu-mode-lighter "")
  :config
  (global-set-key [remap query-replace-regexp] 'anzu-query-replace-regexp)
  (global-set-key [remap query-replace] 'anzu-query-replace))

;; Activate occur easily inside isearch
(when (version< emacs-version "24.3")
  (define-key isearch-mode-map (kbd "C-c C-o") 'isearch-occur))

;; DEL during isearch should edit the search string
;; not jump back to the previous result
(define-key isearch-mode-map [remap isearch-delete-char] 'isearch-del-char)
#+end_src

*** Grep
:PROPERTIES:
:ID:       4ee080b9-ae28-45f4-ba10-6e358e9e5ebe
:END:

#+begin_src elisp
(setq-default grep-highlight-matches t
              grep-scroll-output t)

(use-package ag)

(when (and (executable-find "ag")
           (require 'ag))
  (use-package wgrep-ag)
  (setq-default ag-highlight-search t))
#+end_src

*** uniquify
:PROPERTIES:
:ID:       a1fca4d1-46aa-4481-93ec-4b175f7943ba
:END:

Nicer naming of buffers for files with identitcal names.

#+begin_src elisp
(require 'uniquify)

(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator " โ€ข ")
(setq uniquify-after-kill-buffer-p t)
(setq uniquify-ignore-buffers-re "^\\*")
#+end_src

*** ibuffer
:PROPERTIES:
:ID:       46338344-4b74-4a15-8081-bcbf4a1f6d6c
:END:

#+begin_src elisp
(use-package ibuffer
  :config
  (fullframe ibuffer ibuffer-quit))

(use-package ibuffer-vc
  :after (ibuffer)
  :config
  (defun ibuffer-set-up-preferred-filters ()
    "Setup ibuffer sorting and filtering."
    (ibuffer-vc-set-filter-groups-by-vc-root)
    (unless (eq ibuffer-sorting-mode 'filename/process)
      (ibuffer-do-sort-by-filename/process)))
  (add-hook 'ibuffer-hook #'ibuffer-set-up-preferred-filters))

(global-set-key (kbd "C-x C-b") 'ibuffer)
#+end_src

*** RecentF
:PROPERTIES:
:ID:       834fcbae-7640-45b4-8e0b-0cc96f42ba75
:END:

#+begin_src elisp
(add-hook 'after-init-hook (lambda () (recentf-mode 1)))
(setq-default recentf-max-save-items 1000)
(setq-default recentf-exclude '("/tmp/", "/ssh:"))
#+end_src

*** helm -- Disabled
:PROPERTIES:
:ID:       453f4b85-ed7d-420b-8f40-38b40a6883b8
:END:

https://tuhdo.github.io/helm-intro.html

#+begin_src elisp :tangle no
(use-package helm
  :diminish)

(use-package helm-config
  :diminish)

(use-package helm-descbinds
  :after (helm helm-config)
  :config
  (helm-descbinds-mode))

(use-package swiper-helm
  :after helm
  :bind (("C-s" . swiper-helm)))

;; The default "C-x c" is quite close to "C-x C-c", which quits Emacs.
;; Changed to "C-c h".  Note: We must set "C-c h" globally, because we
;; cannot change `helm-command-prefix-key' once `helm-config' is loaded.
(global-set-key (kbd "C-c h") 'helm-command-prefix)
(global-unset-key (kbd "C-x c"))

;; rebind tab to run persistent action
(define-key helm-map (kbd "<tab>") #'helm-execute-persistent-action)
;; make TAB work in terminal
(define-key helm-map (kbd "C-i") #'helm-execute-persistent-action)
;; list actions using C-z
(define-key helm-map (kbd "C-z") #'helm-select-action)
;; Default to helm-M-x
(global-set-key (kbd "M-x") #'helm-M-x)
;; helm show kill ring
(global-set-key (kbd "M-y") #'helm-show-kill-ring)
;; use helm-mini
(global-set-key (kbd "C-x b") #'helm-mini)
;; use helm-find-files
(global-set-key (kbd "C-x C-f") #'helm-find-files)
;; "better" binding for all mark rings
(global-set-key (kbd "C-h SPC") #'helm-all-mark-rings)
;; more "convenient" keybinding for helm-occur
(global-set-key (kbd "C-c h o") #'helm-occur)
;; helm mini buffer history
(define-key minibuffer-local-map (kbd "C-c C-l") #'helm-minibuffer-history)


(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)

(setq helm-autoresize-max-height 30)
(setq helm-autoresize-min-height 20)
(setq helm-apropos-fuzzy-match t)
(setq helm-M-x-fuzzy-match t) ;; optional fuzzy matching for helm-M-x
(setq helm-buffers-fuzzy-matching t)
(setq helm-recentf-fuzzy-match t)
(setq helm-lisp-fuzzy-completion t)
(setq helm-locate-fuzzy-match t)
(setq helm-semantic-fuzzy-match t)
(setq helm-imenu-fuzzy-match t)
(setq helm-ff-search-library-in-sexp nil)
(setq helm-ff-file-name-history-use-recentf nil)
(setq helm-ff-keep-cached-candidates nil)
(setq helm-split-window-inside-p t)
(helm-autoresize-mode t)

(add-to-list 'helm-sources-using-default-as-input 'helm-source-man-pages)

(helm-mode t)

(when (executable-find "ack-grep")
  (setq helm-grep-default-command "ack-grep -Hn --no-group --no-color %e %p %f"
        helm-grep-default-recurse-command "ack-grep -H --no-group --no-color %e %p %f"))

(when (executable-find "rg")
  (use-package helm-rg))
#+end_src

*** mct -- Disabled
:PROPERTIES:
:ID:       4361a82f-27b4-495c-a80e-a03f5337f26a
:END:

#+begin_src elisp :tangle no
(use-package mct
  :commands mct-mode
  :config
  (setq mct-apply-completion-stripes t)
  (setq mct-completion-blocklist nil)
  (setq mct-completion-passlist
	    '(imenu
	      Info-goto-node
	      Info-index
	      Info-menu))
  (setq mct-completions-format 'one-column)
  (setq mct-hide-completion-mode-line nil)
  (setq mct-live-update-delay 0.6)
  (setq mct-minimum-input 3)
  (setq mct-remove-shadowed-file-names t)
  (setq mct-show-completion-line-numbers nil)
  :init
  (mct-mode 1))

(setq completion-styles
      '(basic substring initial flex partial-completion))
(setq completion-category-overrides
      '((file (styles . (basic partial-completion initials substring)))))

(setq completion-cycle-threshold 2)
(setq completion-ignore-case t)
(setq completion-show-inline-help nil)

(setq completions-detailed t)

(setq enable-recursive-minibuffers t)
(setq minibuffer-eldef-shorten-default t)
(setq read-buffer-completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
(setq resize-mini-windows t)
(minibuffer-depth-indicate-mode 1)
(minibuffer-electric-default-mode 1)

(setq minibuffer-prompt-properties
      '(read-only t cursor-intangible-mode t face minibuffer-prompt))

(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)

(require 'savehist)
(setq savehist-file (locate-user-emacs-file "savehist"))
(setq history-length 10000)
(setq history-delete-duplicates t)
(setq savehist-save-minibuffer-history t)
(add-hook 'after-init-hook #'savehist-mode)
#+end_src

*** ido
:PROPERTIES:
:ID:       bfe3ad2a-292d-421b-a93e-72149b0197fa
:END:

#+begin_src elisp
(setq ido-create-new-buffer 'always)
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(setq ido-ignore-extensions t)
(ido-mode 1)
#+end_src

*** Move where I mean
:PROPERTIES:
:ID:       264bf804-2c85-4f31-ba01-8881e0f3b033
:END:

https://matthewbauer.us/blog/bauer.html

#+begin_src elisp
(use-package mwim
  :bind (([remap move-beginning-of-line] . mwim-beginning-of-code-or-line)
         ([remap move-end-of-line] . mwim-end-of-code-or-line)))
#+end_src

*** Company Mode
:PROPERTIES:
:ID:       3b06402b-29ad-42a1-8476-fb0664176dea
:END:

https://github.com/purcell/emacs.d/blob/master/lisp/init-company.el

#+begin_src elisp
(use-package company
  :diminish
  :hook ((prog-mode . company-mode)
         (comint-mode . company-mode))
  :bind (("C-M-/" . company-complete)
         :map company-mode-map
         ("M-/" . company-complete)
         :map company-active-map
         ("M-/" . company-select-next)
         ("C-n" . company-select-next)
         ("C-p" . company-select-previous))
  :config
  (defun sanityinc/local-push-company-backend (backend)
    "Add BACKEND to a buffer-local version of `company-backends'."
    (make-local-variable 'company-backends)
    (push backend company-backends)))
#+end_src

*** Multi-Major Mode
:PROPERTIES:
:ID:       5b51870f-8e94-49f8-8244-663cef107085
:END:

https://matthewbauer.us/blog/bauer.html

#+begin_src elisp
(use-package mmm-mode
  :commands mmm-mode
  :config
  (setq mmm-global-mode 'buffers-with-submode-classes)
  (setq mmm-submode-decoration-level 2)
  (use-package mmm-auto
    :demand))
#+end_src

*** PolyMode
:PROPERTIES:
:ID:       2ce1b6ec-dd37-481f-be6a-ee244a322ab1
:END:

https://masteringemacs.org/article/polymode-multiple-major-modes-how-to-use-sql-python-in-one-buffer

#+begin_src elisp
(use-package polymode)
#+end_src

*** Editing Utilities
:PROPERTIES:
:ID:       9f8278b6-6d17-40e1-aff8-42ea08151fe7
:END:

#+begin_src elisp
(use-package unfill)

(use-package list-unicode-display)

(use-package autorevert
  :diminish auto-revert-mode
  :demand
  :commands auto-revert-mode
  :init
  (add-hook 'dired-mode-hook #'auto-revert-mode)
  :config
  (global-auto-revert-mode t))

(transient-mark-mode t)

;;; A simple visible bell which works in all terminal types
(defun sanityinc/flash-mode-line ()
  "Flash mode line on bell."
  (invert-face 'mode-line)
  (run-with-timer 0.05 nil 'invert-face 'mode-line))

(setq-default
 ring-bell-function 'sanityinc/flash-mode-line)


;;; Newline behaviour
(global-set-key (kbd "RET") 'newline-and-indent)
(defun sanityinc/newline-at-end-of-line ()
  "Move to end of line, enter a newline, and reindent."
  (interactive)
  (move-end-of-line 1)
  (newline-and-indent))

(global-set-key (kbd "S-<return>") 'sanityinc/newline-at-end-of-line)

(defun kb/enable-line-numbers ()
  "Turn on line number display."
  (setq-local display-line-numbers t))

;; explicitly enable line numbers modes
(dolist (hook '(prog-mode-hook text-mode-hook conf-mode-hook))
  (add-hook hook #'kb/enable-line-numbers))

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

(when (fboundp 'global-prettify-symbols-mode)
  (global-prettify-symbols-mode))

;; Zap *up* to char is a handy pair for zap-to-char
(autoload 'zap-up-to-char "misc" "Kill up to, but not including ARGth occurrence of CHAR.")
(global-set-key (kbd "M-Z") 'zap-up-to-char)


(use-package browse-kill-ring)
(defvar browse-kill-ring-separator)
(defvar browse-kill-ring-mode-map)
(setq browse-kill-ring-separator "\f")
(global-set-key (kbd "M-Y") 'browse-kill-ring)
(with-eval-after-load 'browse-kill-ring
  (define-key browse-kill-ring-mode-map (kbd "C-g") 'browse-kill-ring-quit))


;; Don't disable narrowing commands
(put 'narrow-to-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-defun 'disabled nil)

;; Show matching parens
(show-paren-mode 1)

;; Expand region
(use-package expand-region
  :bind (("C-=" . #'er/expand-region)))

;; Don't disable case-change functions
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)


;; Handy key bindings
(global-set-key (kbd "C-.") 'set-mark-command)
(global-set-key (kbd "C-x C-.") 'pop-global-mark)

(use-package avy
  :commands avy-goto-char-timer
  :bind ("C-;" . #'avy-goto-char-timer))

(use-package multiple-cursors
  :commands (mc/edit-lines mc/edit-ends-of-lines mc/edit-beginnings-of-lines)
  :bind (("C-c m c" . #'mc/edit-lines)
         ("C-c m e" . #'mc/edit-ends-of-lines)
         ("C-c m a" . #'mc/edit-beginnings-of-lines)))

(global-set-key (kbd "C-c m r") 'set-rectangular-region-anchor)

;; Train myself to use M-f and M-b instead
(global-unset-key [M-left])
(global-unset-key [M-right])


;; Fix backward-up-list to understand quotes, see http://bit.ly/h7mdIL
(defun backward-up-sexp (arg)
  "Jump up to the start of the ARG'th enclosing sexp."
  (interactive "p")
  (let ((ppss (syntax-ppss)))
    (cond ((elt ppss 3)
           (goto-char (elt ppss 8))
           (backward-up-sexp (1- arg)))
          ((backward-up-list arg)))))

(global-set-key [remap backward-up-list] 'backward-up-sexp) ; C-M-u, C-M-up


;;----------------------------------------------------------------------------
;; Cut/copy the current line if no region is active
;;----------------------------------------------------------------------------
(use-package whole-line-or-region
  :diminish whole-line-or-region-local-mode
  :commands whole-line-or-region-global-mode
  :config
  (whole-line-or-region-global-mode t))

;; (use-package highlight-escape-sequences
;;   :init
;;   (hes-mode))

;; (global-hl-line-mode t)

(use-package olivetti
  :config
  (setq olivetti-minimum-body-width 100))

(setq backward-delete-char-untabify-method 'hungry)



(use-package page-break-lines
  :diminish
  :config
  (global-page-break-lines-mode t))



(use-package editorconfig
  :diminish
  :config
  (editorconfig-mode t))



(use-package smartparens
  :diminish)



#+end_src

#+begin_src elisp :tangle no
(use-package auto-highlight-symbol
  :diminish)
#+end_src

#+begin_src elisp


(diminish 'abbrev-mode)
(diminish 'eldoc-mode)


#+end_src

**** Dictionary
:PROPERTIES:
:ID:       c17c3bc7-0d74-43c3-92d2-82f8e853783f
:END:

#+begin_src elisp
(require 'dictionary)

(setq dictionary-server "localhost")

(bind-key (kbd "M-#") #'dictionary-lookup-definition)
#+end_src

#+begin_src elisp
(use-package define-word)

(bind-key (kbd "C-c h d") #'define-word-at-point)
#+end_src

**** Thesauri
:PROPERTIES:
:ID:       a86b1a05-5518-4b80-9bca-94060959b49b
:END:

#+begin_src elisp
(use-package synosaurus
  :delight
  :hook text-mode
  :config
  (unbind-key (kbd "C-c C-s l"))
  (unbind-key (kbd "C-c C-s r"))
  (unbind-key (kbd "C-c C-s i"))
  (setq synosaurus-backend #'synosaurus-backend-wordnet)
  (setq synosaurus-choose-method 'ido))
#+end_src

**** LTEX Language Server
:PROPERTIES:
:ID:       b170b85a-3d40-4bb6-973c-a9f6a5862719
:END:

#+begin_src elisp :tangle no
(use-package lsp-ltex
  :after lsp
  :hook (text-mode . kb/enable-ltex)
  :init
  (defun kb/enable-ltex ()
    (require 'lsp-ltex)
    (lsp-deferred))
  :config
  (setq lsp-ltex-ls-path (string-join (list user-emacs-directory "/lsp-ltex/")))
  (setq lsp-ltex-version "15.2.0"))
#+end_src

**** detex
:PROPERTIES:
:ID:       e9352fe8-02e4-4082-9f90-34460f51c9e7
:END:

Simple function which returns buffer contents untexified.

#+begin_src elisp :tangle no
(defun detex-filter (contents)
  "Return buffer contents without (La)TeX commands via `detex'."
  (2text-filter "detex" contents))

(defun ws-filter (contents)
  "Return buffer contents without extra whitespace via `sed'."
  (2text-filter "sed" contents "s/^\\s+//g"))

(defun 2text-filter (program contents &rest ARGS)
  "Return buffer contents after passing `CONTENTS' to `PROGRAM'."
  (with-temp-buffer
    (goto-char (point-min))
    (insert contents)
    (apply #'call-process-region (point-min) (point-max) program t t nil ARGS)
    (buffer-substring-no-properties (point-min) (point-max))))
#+end_src

**** LanguageTool
:PROPERTIES:
:ID:       c084445a-9d5c-4a05-8273-f1d6d6cc772d
:END:

#+begin_src elisp
(use-package flycheck-languagetool
  :after flycheck
  :hook (text-mode . flycheck-languagetool-setup)
  :init
  (setq flycheck-languagetool-language "en-US")
  (setq flycheck-languagetool-server-port "9090")
  (setq flycheck-languagetool-url (format "http://localhost:%s"
                                          flycheck-languagetool-server-port))
  (setq flycheck-languagetool-check-params '(("disabledRules" . "WHITESPACE_RULE")))
  :config
  (flycheck-add-next-checker 'languagetool 'vale)
  (flycheck-remove-next-checker 'languagetool 'proselint))
#+end_src

#+begin_src elisp :tangle no
(defun flycheck-languagetool--start (_checker callback)
  "Flycheck start function for _CHECKER `languagetool', invoking CALLBACK."
  (when (or flycheck-languagetool-server-command
            flycheck-languagetool-server-jar)
    (unless flycheck-languagetool--started-server
      (setq flycheck-languagetool--started-server t)
      (flycheck-languagetool--start-server)))

  (let* ((url-request-method "POST")
         (url-request-extra-headers
          '(("Content-Type" . "application/x-www-form-urlencoded")))
         (disabled-rules
          (flatten-tree (list
                         (cdr (assoc "disabledRules"
                                     flycheck-languagetool-check-params))
                         (when (bound-and-true-p flyspell-mode)
                           flycheck-languagetool--spelling-rules))))
         (other-params (assoc-delete-all "disabledRules"
                                         flycheck-languagetool-check-params))
         (url-request-data
          (mapconcat
           (lambda (param)
             (concat (url-hexify-string (car param)) "="
                     (url-hexify-string (cdr param))))
           (append other-params
                   `(("language" . ,flycheck-languagetool-language)
                     ("text" . ,(detex-filter (buffer-substring-no-properties (point-min) (point-max)))))
                   (when disabled-rules
                     (list (cons "disabledRules"
                                 (string-join disabled-rules ",")))))
           "&")))
    (url-retrieve
     (concat (or flycheck-languagetool-url
                 (format "http://localhost:%s"
                         flycheck-languagetool-server-port))
             "/v2/check")
     #'flycheck-languagetool--read-results
     (list (current-buffer) callback)
     t)))
#+end_src

**** Pulsar
:PROPERTIES:
:ID:       207e8513-d6e5-4ee3-a3d8-425ab3c8c6e4
:END:

Replace global hl-mode with pulsar package.

#+begin_src elisp
(require 'pulsar)

(customize-set-variable
 'pulsar-pulse-functions
 '(recenter-top-bottom
   move-to-window-line-top-bottom
   reposition-window
   bookmark-jump
   other-window
   delete-window
   delete-other-windows
   forward-page
   backward-page
   scroll-up-command
   scroll-down-command
   windmove-right
   windmove-left
   windmove-up
   windmove-down
   windmove-swap-states-right
   windmove-swap-states-left
   windmove-swap-states-up
   windmove-swap-states-down
   tab-new
   tab-close
   tab-next
   org-next-visible-heading
   org-previous-visible-heading
   org-forward-heading-same-level
   org-backward-heading-same-level
   outline-backward-same-level
   outline-forward-same-level
   outline-next-visible-heading
   outline-previous-visible-heading
   outline-up-heading))

(setq pulsar-face 'pulsar-magenta)
(setq pulsar-delay 0.05)
(setq pulsar-pulse t)
(pulsar-global-mode 1)
#+end_src

Wrap [[help:recenter-top-bottom][recenter-top-bottom]] so that it pulses as well.

#+begin_src elisp
(defun kb/recenter-top-bottom (&optional ARG)
    "Recenter-top-bottom with pulse effect."
  (interactive)
  (pulsar-pulse-line)
  (recenter-top-bottom ARG))

(bind-key "C-l" #'kb/recenter-top-bottom)
#+end_src

*** Buffer Move
:PROPERTIES:
:ID:       238e7ac9-7b59-4f88-9adb-32bfcc30ae7a
:END:

https://matthewbauer.us/blog/bauer.html

#+begin_src elisp
(use-package buffer-move
  :commands (buf-move-up buf-move-down buf-move-left buf-move-right)
  :bind (("C-x w p" . #'buf-move-up)
         ("C-x w n" . #'buf-move-down)
         ("C-x w a" . #'buf-move-left)
         ("C-x w b" . #'buf-move-left)
         ("C-x w e" . #'buf-move-right)
         ("C-x w f" . #'buf-move-right)))
#+end_src

#+begin_src elisp :tangle no
;; https://nullprogram.com/blog/2013/02/06/
;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Minor-Modes.html
(defvar window-resize-mode-delta 5)
(define-minor-mode kb/window-resize-mode
  "Resize current window and then exit."
  :init-value t
  :lighter " R3S+ZE"
  :keymap '(([C-n] . (#'shrink-window (* -1 window-resize-mode-delta)))
            ([C-p] . (#'shrink-window window-resize-mode-delta))
            ([C-a] . (#'shrink-window-horizontally window-resize-mode-delta))
            ([C-b] . (#'shrink-window-horizontally window-resize-mode-delta))
            ([C-e] . (#'shrink-window-horizontally (* -1 window-resize-mode-delta)))
            ([C-f] . (#'shrink-window-horizontally (* -1 window-resize-mode-delta)))
            ([q] . (#'kb/window-resize-mode nil))))

(global-set-key [C-x w r] (kb/window-resize-mode 1))
#+end_src

*** Whitespace
:PROPERTIES:
:ID:       ad29e6dd-b48a-49d9-a56c-9aaff64e3798
:END:

#+begin_src elisp
(use-package whitespace
  :delight
  :delight global-whitespace-mode
  :config
  (global-whitespace-mode t))
(use-package whitespace-cleanup-mode
  :delight
  :config
  (global-whitespace-cleanup-mode t))

(use-package unicode-whitespace
  :delight
  :after (whitespace))

;;; Whitespace

(defun sanityinc/show-trailing-whitespace ()
  "Enable display of trailing whiteSpace in this buffer."
  (setq-local show-trailing-whitespace t))

;; Explicitly show trailing whiteSpace in these modes
(dolist (hook '(prog-mode-hook text-mode-hook conf-mode-hook))
  (add-hook hook #'sanityinc/show-trailing-whitespace))

(global-set-key [remap just-one-space] 'cycle-spacing)

(defvar whitespace-display-mappings)
(setq whitespace-display-mappings
      '(
        (newline-mark ?\n  [8617 ?\n] [?$ ?\n])
        (tab-mark ?\t [8677 ?\t] [92 ?\t])
        ))

(defvar whitespace-style)
(setq whitespace-style
      (quote (face
              trailing-mark
              tab-mark
              newline)))

(defun kb/text-mode-setup ()
  "text-mode setup hook."
  (whitespace-mode t)
  (set-fill-column 79)
  (turn-on-auto-fill))

(add-hook 'text-mode-hook #'kb/text-mode-setup)

(diminish 'auto-fill-function)

;; Indent
(setq standard-indent 4)

;;newlines
(setq require-final-newline t)
#+end_src

*** Version Control
:PROPERTIES:
:ID:       3fc70c47-fb7a-4b4f-94e7-d59b1a87d89d
:END:

**** VC
:PROPERTIES:
:ID:       4c1e42fe-5e91-4317-a00e-34ee83b81473
:END:

#+begin_src elisp
(use-package diff-hl
  :hook ((prog-mode . diff-hl-mode)
         (vc-dir-mode . diff-hl-mode)))
#+end_src

**** Git
:PROPERTIES:
:ID:       58f3380b-ffa3-475d-bbd7-a33a73f327dd
:END:

#+begin_src elisp
(use-package gitignore-mode)
(use-package gitconfig-mode)
(use-package git-timemachine
  :defer 1
  :diminish)

;; (use-package forge)

(use-package magit
  :preface
  (defun magit-dired-other-window ()
    (interactive)
    (dired-other-window (magit-toplevel)))
  :commands (magit-clone
             magit-toplevel
             magit-read-string-ns
             magit-remote-arguments
             magit-get
             magit-remote-add
             magit-define-popup-action)
  :bind (("C-x g" . magit-status)
         ("C-x M-G" . magit-dispatch-popup)
         :map magit-mode-map
         ("C-o" . magit-dired-other-window))
  :init
  (setq-default magit-diff-refine-hunk t)
  (defvar magit-last-seen-setup-instructions "1.4.0")
  :config
  (fullframe magit-status magit-mode-quit-window)
  (setq magit-openpgp-default-signing-key "B74CC4B41148C3DB364BC21182D94B35744E1B34")
  )

(use-package magit-extras
  :after magit
  :init
  (setq magit-pop-revision-stack-format '("%h (\"%s\", %ad)")))

(use-package with-editor)

;; Some added additions from
;; https://www.reddit.com/r/emacs/comments/96r8us/tip_how_to_get_started_with_git/
(use-package git-commit
  :after with-editor magit
  :hook
  (git-commit-mode . my/git-commit-config-setup)
  :preface
  (defun my/git-commit-config-setup ()
    "Configures several commit message settings."
    (goto-address-mode)
    (set-fill-column 72)
    (setq-local comment-auto-fill-only-comments nil)
    (global-whitespace-mode nil))
  :custom
  (git-commit-summary-max-length 50))
#+end_src

*** Projectile
:PROPERTIES:
:ID:       ef251479-852f-429a-80be-556cafaefe76
:END:

#+begin_src elisp :tangle no
(use-package projectile
  :bind-keymap
  ("C-c p" . projectile-command-map)
  :config

  (setq projectile-switch-project-action 'projectile-dired)
  (setq projectile-enable-caching t)
  (setq projectile-per-project-compilation-buffer t)

  (add-to-list 'projectile-globally-ignored-files "node-modules")

  ;; Shorter modeline
  (setq-default projectile-mode-line-function
                (lambda ()
                  (if (file-remote-p default-directory)
                      "Projectile"
                    (format " Proj[%s]" (projectile-project-name)))))
  :init
  (add-hook 'after-init-hook (lambda () (projectile-mode))))

#+end_src

#+begin_src elisp :tangle no
(use-package helm-projectile
  :after (projectile helm)
  :config
  (helm-projectile-on))
#+end_src

#+begin_src elisp :tangle no
(use-package persp-projectile
  :after perspective)
#+end_src

#+begin_src elisp
(projectile-mode -1)
#+end_src

*** Project.el
:PROPERTIES:
:ID:       a26fa6d9-d2f8-430b-9d4b-f9a41d8ae0f1
:END:

#+begin_src elisp
(defun project-root-override (dir)
  "Find DIR's project root by searching for a '.project.el' file.

If this file exists, it marks the project root.  For convenient
compatibility with Projectile, '.projectile' is also considered a project root marker.

https://blog.jmthornton.net/p/emacs-project-override"
  (let ((root (or (locate-dominating-file dir ".project.el")
                  (locate-dominating-file dir ".projectile")))
              (backend (ignore-errors (vc-responsible-backend dir))))
    (when root (if (version<= emacs-version "28")
                   (cons 'vc root)
                 (list 'vc backend root)))))
#+end_src

#+begin_src elisp
(use-package project
  :config
  (setq project-compilation-buffer-name-function #'project-prefixed-buffer-name)
  (add-hook 'project-find-functions #'project-root-override))
#+end_src

*** Grand Unified Debugger
:PROPERTIES:
:ID:       f71600a2-9e68-4450-9f38-180d1138274a
:END:

#+begin_src elisp :tangle no
(use-package realgud)
#+end_src

#+begin_src elisp :tangle no
(use-package realgud-jdb
  :after realgud)
#+end_src

*** Compilation
:PROPERTIES:
:ID:       65a3e1d7-df5e-4aec-8b17-f3e64441a1ca
:END:

#+begin_src elisp
(setq-default compilation-scroll-output t)

(use-package alert)

;; Customize `alert-default-style' to get messages after compilation

(defun sanityinc/alert-after-compilation-finish (buf result)
  "If BUF is hidden, use `alert' to report compilation RESULT."
  (when (buffer-live-p buf)
    (unless (catch 'is-visible
              (walk-windows (lambda (w)
                              (when (eq (window-buffer w) buf)
                                (throw 'is-visible t))))
              nil)
      (alert (concat "Compilation " result)
             :buffer buf
             :category 'compilation))))

(with-eval-after-load 'compile
  (add-hook 'compilation-finish-functions
            'sanityinc/alert-after-compilation-finish))

(defvar sanityinc/last-compilation-buffer nil
  "The last buffer in which compilation took place.")

(with-eval-after-load 'compile
  (defadvice compilation-start (after sanityinc/save-compilation-buffer activate)
    "Save the compilation buffer to find it later."
    (setq sanityinc/last-compilation-buffer next-error-last-buffer))

  (defadvice recompile (around sanityinc/find-prev-compilation (&optional edit-command) activate)
    "Find the previous compilation buffer, if present, and recompile there."
    (if (and (null edit-command)
             (not (derived-mode-p 'compilation-mode))
             sanityinc/last-compilation-buffer
             (buffer-live-p (get-buffer sanityinc/last-compilation-buffer)))
        (with-current-buffer sanityinc/last-compilation-buffer
          ad-do-it)
      ad-do-it)))

(global-set-key [f6] 'recompile)

(defadvice shell-command-on-region
    (after sanityinc/shell-command-in-view-mode
           (start end command &optional output-buffer &rest other-args)
           activate)
  "Put \"*Shell Command Output*\" buffers into view-mode."
  (unless output-buffer
    (with-current-buffer "*Shell Command Output*"
      (view-mode 1))))

(with-eval-after-load 'compile
  (require 'ansi-color)
  (defun sanityinc/colourise-compilation-buffer ()
    (when (eq major-mode 'compilation-mode)
      (ansi-color-apply-on-region compilation-filter-start (point-max))))
  (add-hook 'compilation-filter-hook 'sanityinc/colourise-compilation-buffer))
#+end_src

*** Regular Expressions
:PROPERTIES:
:ID:       c73096db-e04b-40dc-8fb4-b7b3150f9c17
:END:

#+begin_src elisp
(use-package regex-tool
  :init
  (setq-default regex-tool-backend 'perl))

(use-package re-builder
  :bind (:map reb-mode-map
              ;;support a slightly more idomatic quit binding in re-builder
              ("C-c C-k" . reb-quit)))
#+end_src

*** Perspective
:PROPERTIES:
:ID:       c10c11ef-f5d6-4716-b828-4b7c8afdca41
:END:

#+begin_src elisp :tangle no
(use-package perspective
  :config
  (setq persp-mode-prefix-key (kbd "C-x p"))
  (setq persp-state-default-file (concat user-emacs-directory "perspective.state"))
  :init
  (add-hook 'kill-emacs-hook #'persp-state-save)
  (persp-mode))
#+end_src

*** Spelling
:PROPERTIES:
:ID:       15719b4a-9179-4a0a-8005-1e306263cc8f
:END:

#+begin_src elisp
(use-package ispell
  :config
  (setq ispell-program-name "aspell")
  (setq ispell-extra-args '("--sug-mode=ultra" "--lang=en_US" "--camel-case")))

(use-package flyspell
  :after ispell
  :diminish
  :if (executable-find ispell-program-name)
  :bind (:map flyspell-mode-map
              ("C-;" . nil)
              ("C-c $" . nil))
  :when (executable-find ispell-program-name)
  :commands (flyspell-mode flyspell-prog-mode)
  :config
  (setq flyspell-use-meta-tab nil)
  (add-to-list 'flyspell-prog-text-faces 'nxml-text-face)
  :init
  (add-hook 'text-mode-hook #'flyspell-mode)
  (add-hook 'prog-mode-hook #'flyspell-prog-mode))

(use-package flyspell-correct
  :commands flyspell-correct-wrapper
  :after flyspell
  :bind (:map flyspell-mode-map
              ("C-c ." . flyspell-correct-wrapper)))
#+end_src

*** Miscellaneous Configuration
:PROPERTIES:
:ID:       c94fa191-604a-4101-a089-43f626aee32c
:END:

#+begin_src elisp
(use-package f)

(fset 'yes-or-no-p 'y-or-n-p)

(add-hook 'prog-mode-hook 'goto-address-prog-mode)
(setq goto-address-mail-face 'link)

(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
(add-hook 'after-save-hook 'sanityinc/set-mode-for-new-scripts)

(defun sanityinc/set-mode-for-new-scripts ()
  "Invoke `normal-mode' if this file is a script and in `fundamental-mode'."
  (and
   (eq major-mode 'fundamental-mode)
   (>= (buffer-size) 2)
   (save-restriction
     (widen)
     (string= "#!" (buffer-substring (point-min) (+ 2 (point-min)))))
   (normal-mode)))

(add-to-list 'auto-mode-alist '("Procfile" . 'conf-mode))

(use-package multiple-cursors)

(defun kb/init-window-split ()
  "Initialize automatic split thresholds for X."
  (interactive)
  (if (display-graphic-p)
      (progn
        (if (> (x-display-pixel-width) 1080)
            (setq split-height-threshold 160)
          (setq split-height-threshold 80)))))

(kb/init-window-split)

;; https://trey-jackson.blogspot.com/2010/04/emacs-tip-36-abort-minibuffer-when.html
(defun stop-using-minibuffer ()
  "Kill the minibuffer."
  (when (and (>= (recursion-depth) 1) (active-minibuffer-window))
    (abort-recursive-edit)))

(add-hook 'mouse-leave-buffer-hook #'stop-using-minibuffer)

;; unset goal column
;; I don't really have a use for this
(unbind-key (kbd "C-x C-n") 'global-map)

;; advice
;; https://github.com/Fuco1/.emacs.d/blob/master/site-lisp/my-advices.el
;; from simple.el
(defadvice kill-line (before kill-line-autoreindent activate)
  "Kill excess whitespace when joining lines.
If the next line is joined to the current line, kill the extra indent whitespace in front of the next line."
  (when (and (eolp) (not (bolp)))
    (save-excursion
      (forward-char 1)
      (just-one-space 1))))
#+end_src

**** Hide Async shell command output
:PROPERTIES:
:ID:       304c8888-785c-4d03-89b7-fe420fb16a07
:END:

https://stackoverflow.com/questions/13901955/how-to-avoid-pop-up-of-async-shell-command-buffer-in-emacs

#+begin_src elisp
(add-to-list 'display-buffer-alist
             (cons shell-command-buffer-name-async (cons #'display-buffer-no-window nil)))
#+end_src

*** Emacs Windows
:PROPERTIES:
:ID:       c94e750f-1d56-403e-ab36-2e72c3c0e359
:END:

Partially taken from:
https://github.com/purcell/emacs.d/blob/b2aea30bff7ca4bbb62f579ca7e3ff0e895a7911/lisp/init-windows.el
This is not about the "Windows" OS, but rather Emacs's "windows"
concept: these are the panels within an Emacs frame which contain
buffers.


#+begin_src elisp
(use-package switch-window
  :commands switch-window
  :config
  (setq switch-window-shortcut-style 'alphabet)
  (setq switch-window-timeout nil)
  :init
  (global-set-key (kbd "C-x o") #'switch-window))
#+end_src

*** Folding
:PROPERTIES:
:ID:       030b8515-2f65-4cd4-b660-837595bfbbb6
:END:

#+begin_src elisp
(use-package fold-dwim)
#+end_src

*** Tags and Code Search
:PROPERTIES:
:ID:       27c669eb-5d62-4690-ac57-ff00cc953523
:END:

**** xref
:PROPERTIES:
:ID:       6ebf6e4c-f2f2-4d07-ba45-7875afd72eb4
:END:

#+begin_src elisp
(use-package gxref
  :config
  (add-to-list 'xref-backend-functions 'gxref-xref-backend))
#+end_src

**** Tags
:PROPERTIES:
:ID:       7a081f26-4bef-4cb7-a09c-b0f6800c4120
:END:

#+begin_src elisp
(use-package ggtags
  :delight
  :hook (prog-mode . ggtags-mode))
#+end_src

#+begin_src elisp :tangle no
(use-package helm-gtags
  :diminish
  :after (helm)
  :commands (helm-gtags-find-tag
             helm-gtags-find-rtag
             helm-gtags-find-symbol
             helm-gtags-parse-file
             helm-gtags-previous-history
             helm-gtags-next-history
             helm-gtags-pop-stack)
  :hook (prog-mode . helm-gtags-mode)
  :init
  (setq helm-gtags-path-style 'relative
        helm-gtags-ignore-case t
        helm-gtags-auto-update nil)
  :config
  (define-key helm-gtags-mode-map (kbd "M-t") #'helm-gtags-find-tag)
  (define-key helm-gtags-mode-map (kbd "M-r") #'helm-gtags-find-rtag)
  (define-key helm-gtags-mode-map (kbd "M-s") #'helm-gtags-find-symbol)
  (define-key helm-gtags-mode-map (kbd "M-g M-p") #'helm-gtags-parse-file)
  (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

*** Flycheck
:PROPERTIES:
:ID:       a670c02f-5b74-4584-ac02-b3a0c43fb1cc
:END:

#+begin_src elisp
(use-package flycheck
  :defer 2
  :diminish
  :hook (after-init . global-flycheck-mode)
  :commands flycheck-add-mode
  :config
  (setq flycheck-global-modes
        '(not outline-mode diff-mode shell-mode eshell-mode term-mode))
  (setq flycheck-emacs-lisp-load-path 'inherit)
  (setq flycheck-indication-mode (if (display-graphic-p) 'left-fringe 'left-margin))
  (setq flycheck-display-errors-function
        #'flycheck-display-error-messages-unless-error-list)
  (add-to-list 'flycheck-disabled-checkers 'python-pylint)
  (setq flycheck-display-errors-delay .3))
#+end_src

#+begin_src elisp :tangle no
(use-package flycheck-posframe
  :after flycheck
  ;;:if (display-graphic-p)
  :hook (flycheck-mode . flycheck-posframe-mode)
  :config
  (setq flycheck-posframe-border-width 4)
  (setq flycheck-posframe-inhibit-functions
        '((lambda (&rest _) (bound-and-true-p company-backend)))))
#+end_src

#+begin_src elisp :tangle no
(use-package flycheck-pos-tip
  :after flycheck
  ;;:if (display-graphic-p)
  :defines flycheck-pos-tip-timeout
  :hook (flycheck-mode . flycheck-pos-tip-mode)
  :config
  (setq flycheck-pos-tip-timeout 30))
#+end_src

#+begin_src elisp
(use-package flycheck-popup-tip
  :after flycheck
  ;;:if (display-graphic-p)
  :hook (flycheck-mode . flycheck-popup-tip-mode))
#+end_src

#+begin_src elisp
(use-package flycheck-vale
  :after flycheck
  :commands flycheck-vale-setup
  :init
  (flycheck-vale-setup)
  :config
  (dolist (mode '(gfm-mode
                  latex-mode
                  message-mode
                  tex-mode))
    (flycheck-add-mode 'vale mode)))

(use-package flycheck-color-mode-line
  :after flycheck
  :init (flycheck-color-mode-line-mode))
#+end_src

#+begin_src elisp :tangle no
(use-package helm-flycheck
  :after (helm flycheck))
#+end_src

*** Tramp
:PROPERTIES:
:ID:       6b79c1d2-ab14-4bee-a9e5-b676c98c695e
:END:

#+begin_src elisp :tangle no
(use-package helm-tramp
  :after helm)

(define-key global-map (kbd "C-c s") #'helm-tramp)
#+end_src

#+begin_src elisp
(setq tramp-default-method "ssh")
(setq tramp-verbose 1)
#+end_src

#+begin_src elisp :tangle no
(add-hook 'helm-tramp-pre-command-hook #'(lambda ()
                                           (projectile-mode 0)
                                           (editorconfig-mode 0)))

(add-hook 'helm-tramp-quit-hook #'(lambda ()
                                    (projectile-mode 1)
                                    (editorconfig-mode 1)))
#+end_src

*** Snippets
:PROPERTIES:
:ID:       9899a82d-6b93-4118-af10-b943386b2a18
:END:

#+begin_src elisp
(use-package yasnippet
  :diminish (yas-minor-mode)
  :hook ((prog-mode LaTeX-mode org-mode) . yas-minor-mode)
  :config
  (setq yas-snippet-dirs
        (list (expand-file-name "snippets" user-emacs-directory)))
  (yas-reload-all))
#+end_src

*** Zeal
:PROPERTIES:
:ID:       6ec32762-7757-4f5b-a74e-25dadbe095ba
:END:

#+begin_src elisp :tangle no
(use-package zeal-at-point
  :commands zeal-at-point
  :bind ("C-c h d" . #'zeal-at-point))
#+end_src

*** Help ((wo)man/info)
:PROPERTIES:
:ID:       3c59a4db-1f1b-4681-b488-5c2d89e5276f
:END:

#+begin_src elisp
(bind-key (kbd "C-c h m") #'man)
(bind-key (kbd "C-c h w") #'woman)
#+end_src

*** Shells and Terms
:PROPERTIES:
:ID:       989e30d3-f0b8-475c-8fb6-60c2074ea65a
:END:

#+begin_src elisp
(require 'shell)
(require 'sh-script)

;; https://www.masteringemacs.org/article/shell-comint-secrets-history-commands
(define-key shell-mode-map (kbd "SPC") #'comint-magic-space)

;; helm comint input ring "history"
(define-key shell-mode-map (kbd "C-c C-l") #'helm-comint-input-ring)

;; execute region
(define-key sh-mode-map (kbd "C-x C-e") #'sh-send-line-or-region-and-step)

;; https://github.com/szermatt/emacs-bash-completion
(autoload 'bash-completion-dynamic-complete
  "bash-completion"
  "BASH completion hook")
(add-hook 'shell-dynamic-complete-functions
          'bash-completion-dynamic-complete)

;; (with-eval-after-load 'shell
;;   (native-complete-setup-bash))

(defun shell-mode-hook-setup ()
  "Setup `shell-mode'."
  (add-hook 'completion-at-point-functions #'native-complete-at-point nil t)
  (setq-local company-backends '((company-files company-native-complete)))
  (local-set-key (kbd "TAB") #'company-complete))
(add-hook 'shell-mode-hook #'shell-mode-hook-setup)

;; (use-package vterm)
#+end_src

#+begin_src elisp
(require 'eshell)
(require 'em-term)
(require 'helm-eshell)

(setq eshell-banner-message "\n\n")

;;; https://www.emacswiki.org/emacs/EshellFunctions#toc2
(defun eshell/emacs (&rest args)
  "Open a file or files, ARGS, in Emacs.  Some habits die hard."
  (if (null args)
      ;; If I just ran "emacs", I probably expect to be launching
      ;; Emacs, which is rather silly since I'm already in Emacs.
      ;; So just pretend to do what I ask.
      (bury-buffer)
    ;; We have to expand the file names or else naming a directory in an
    ;; argument causes later arguments to be looked for in that directory,
    ;; not the starting directory
    (mapc #'find-file (mapcar
                       #'expand-file-name
                       (eshell-flatten-list (reverse args))))))

(defun eshell/valgrind (&rest args)
  "Open valgrind with ARGS process into compiling output buffer."
  (let ((command (concat "valgrind" " " (string-join args " "))))
    (if (and (eshell-interactive-output-p)
             (not eshell-in-pipeline-p)
             (not eshell-in-subcommand-p))
        (compile command)
      (compile command t))))

(defun eshell/make (&rest args)
  "Open make with ARGS process into compilation output Buffer."
  (let ((command (concat "make" " " (string-join args " "))))
    (if (and (eshell-interactive-output-p)
             (not eshell-in-pipeline-p)
             (not eshell-in-subcommand-p))
        (compile command)
      (compile command t))))

;;; https://www.emacswiki.org/emacs/EshellPrompt
(defmacro with-face (str &rest properties)
  "Add face properties to STR using PROPERTIES list."
  `(propertize ,str 'face (list ,@properties)))

(defun kb/system-name ()
  "Return the current system name.

Includes remote system names"
  (replace-regexp-in-string "\n$"
                            ""
                            (shell-command-to-string "hostname")))

(defun shortened-path (path max-len)
  "Return a modified version of PATH up to MAX-LEN.
Replace some components with single characters starting from the
left to try and get the PATH down to, at most, MAX-LEN."
  (let* ((components (split-string (abbreviate-file-name path)
                                   (f-path-separator)))
         (len (+ (1- (length components))
                 (reduce '+ components :key 'length)))
         (str ""))
    (while (and (> len max-len)
                (cdr components))
      (setq str (concat str (if (= 0 (length (car components)))
                                (f-path-separator)
                              (string (elt (car components) 0) ?/)))
            len (- len (1- (length (car components))))
            components (cdr components)))
    (concat str (reduce
                 (lambda (a b) (concat a (f-path-separator) b)) components))))

(defun kb-eshell-prompt ()
  "Modified version of `shk-eshell-prompt-function' from Emacs wiki."
  (defun git-changes-symbol ()
    "Return git change symbol if changes."
    (let ((status (string-to-number
                   (shell-command-to-string
                    "git status --porcelain 2> /dev/null | wc -l"))))
      (if (> status 0)
          (concat "(" (with-face "ฯŸ" :foreground "#7F9F7F") ")")
        "")))
  (defun git-branch-name ()
    "Return the current git branch, or 'root' if nil."
    (let* ((branches (vc-git-branches))
           (branch (car branches)))
      (if (eq branch nil)
          "(root new-repo)"
        branch)))
  (concat
   "(@"
   (kb/system-name)
   ")("
   (shortened-path (eshell/pwd) 20)
   ")"
   (if (ignore-errors (vc-responsible-backend default-directory))
       (concat "["
               (with-face (git-branch-name) :foreground "#9D6D8E")
               (git-changes-symbol)
               "]ยฑ ")
     "% ")
   ))

(setq eshell-prompt-function #'kb-eshell-prompt)
(setq eshell-highlight-prompt nil)
(setq eshell-history-size 4096)
(setq eshell-history-ignoredups t)
(setq eshell-prompt-regexp "(.*)(.*)\\(\\[.*\\]\\)?[%ยฑ] ")
(dolist (cmd '("vim"
               "yarn"
               "composer"
               "pip"
               "qemu-system-x86_64"))
  (add-to-list 'eshell-visual-commands cmd))
(dolist (subcmd '(("git" "log" "diff" "show" "help")
                  ("docker" "build" "run" "exec" "logs")
                  ("make" "nconfig" "menuconfig" "dev-run" "run")
                  ("mix" "test")))
  (add-to-list 'eshell-visual-subcommands subcmd))

(setenv "PAGER" "")

;; disable slime in eshell
(add-hook 'eshell-mode-hook
          (lambda () (setq slime-mode nil)))



;; https://github.com/szermatt/emacs-bash-completion
(defun bash-completion-from-eshell ()
  (interactive)
  (let ((completion-at-point-functions
         '(bash-completion-eshell-capf)))
    (completion-at-point)))

(defun bash-completion-eshell-capf ()
  (bash-completion-dynamic-complete-nocomint
   (save-excursion (eshell-bol) (point))
   (point) t))



(add-hook 'eshell-mode-hook
          #'(lambda ()
              (define-key eshell-mode-map(kbd "C-c C-l") #'helm-eshell-history)
              (define-key eshell-mode-map (kbd "TAB") #'bash-completion-from-eshell)))


#+end_src

#+begin_src elisp :tangle no
(use-package eshell-vterm
  :after eshell
  :config
  (eshell-vterm-mode))


#+end_src

#+begin_src elisp
(use-package pcmpl-args)
(use-package pcmpl-git)
(use-package pcmpl-pip)
(use-package pcomplete-extension)
#+end_src

*** Languages and Language Modes
:PROPERTIES:
:ID:       436be882-9c6b-462b-9b1c-9219031e33d3
:END:

**** Direnv
:PROPERTIES:
:ID:       3a4cfdc1-82bf-41e8-bd17-e016ba0a1d59
:END:

#+begin_src elisp
(use-package direnv
  :config
  (direnv-mode))
#+end_src

**** Semantic Mode
:PROPERTIES:
:ID:       9c4fdc58-6a6f-415f-a30e-eea3bcfffd6a
:END:

#+begin_src elisp
(require 'semantic)

(semantic-mode t)
#+end_src

**** ElDoc
:PROPERTIES:
:ID:       e83e8cbe-4f96-4b92-a4d1-3801f32ba1b3
:END:

#+begin_src elisp
(use-package eldoc
  :config
  (setq eldoc-echo-area-use-multiline-p 'truncate-sym-name-if-fit))
#+end_src

**** Language Server Protocol
:PROPERTIES:
:ID:       f8dcd5bb-073f-4f38-b359-1e23fce6f40d
:END:

#+begin_src elisp
(use-package lsp-mode
  :init
  (setq lsp-keymap-prefix "C-c e")
  :config
  (setq lsp-log-io nil)
  (setq lsp-trace nil)
  (setq lsp-auto-configure nil)
  (setq lsp-print-performance nil)
  (setq lsp-auto-guess-root t)
  (setq lsp-document-sync-method 'incremental)
  (setq lsp-diagnostics-provider :flycheck)
  (setq lsp-response-timeout 10)
  (setq lsp-prefer-flymake nil)
  (setq lsp-idle-delay 0.500)
  (setq lsp-inhibit-message t)
  (setq lsp-eldoc-render-all t)
  (setq lsp-enable-file-watchers nil)
  (setq lsp-highlight-symbol-at-point nil)
  (setq lsp-modeline-code-actions-enable nil)
  (setq lsp-modeline-diagnostics-enable nil)
  (setq lsp-clients-clangd-args '("-j=4"
                                  "--index"
                                  "-log=error"))
  (setq lsp-clients-go-server-args '("--cache-style=always"
                                     "--diagnostics-style=onsave"))
  (setq lsp-file-watch-ignored
        '("[/\\\\]\\.direnv$"
          "[/\\\\]\\.git$"
          "[/\\\\]\\.hg$"
          "[/\\\\]\\.bzr$"
          "[/\\\\]_darcs$"
          "[/\\\\]\\.svn$"
          "[/\\\\]_FOSSIL_$"
          "[/\\\\]\\.idea$"
          "[/\\\\]\\.ensime_cache$"
          "[/\\\\]\\.eunit$"
          "[/\\\\]node_modules$"
          "[/\\\\]\\.fslckout$"
          "[/\\\\]\\.tox$"
          "[/\\\\]\\.stack-work$"
          "[/\\\\]\\.bloop$"
          "[/\\\\]\\.metals$"
          "[/\\\\]target$"
          "[/\\\\]\\.deps$"
          "[/\\\\]\\.build-aux$"
          "[/\\\\]autom4te.cache$"
          "[/\\\\]\\.reference$"))
  (setq lsp-semantic-tokens-enable t)
  (setq lsp-completion-provider ':capf))

(use-package lsp-ui
  :after lsp-mode
  :commands lsp-ui-mode
  :config
  (setq lsp-ui-doc-delay 0.3)
  (setq lsp-ui-sideline-enable nil)
  (setq lsp-ui-flycheck-enable t)
  (setq lsp-ui-imenu-enable t)
  (setq lsp-ui-imenu-kind-position 'top)
  (setq lsp-ui-peek-enable t)
  (setq lsp-ui-peek-fontify 'on-demand)
  (setq lsp-ui-peek-list-width 50)
  (setq lsp-ui-peek-list-height 20)
  (setq lsp-ui-sideline-code-actions-prefix "๏€")
  (setq lsp-ui-sideline-ignore-duplicate t)
  (setq lsp-ui-sideline-show-code-actions nil)
  (setq lsp-ui-sideline-show-diagnostics nil)
  (setq lsp-ui-sideline-show-hover nil)
  (setq lsp-ui-sideline-show-symbol nil)
  (setq lsp-ui-doc-show-with-cursor t)
  (setq lsp-ui-doc-position 'top)
  (setq lsp-ui-doc-alignment 'window))
#+end_src

#+begin_src elisp :tangle no
(use-package helm-lsp :after (lsp-mode helm))

(use-package lsp-treemacs :commands lsp-treemacs-errors-list)
#+end_src

#+begin_src elisp :tangle no
(use-package eglot
  :bind (:map eglot-keymap
              ("C-c e r" . #'eglot-rename))
  :config
  (setq eglot-confirm-server-initiated-edits t))
#+end_src

**** Debug Adapter Protocol
:PROPERTIES:
:ID:       d4f6107b-d1f1-4448-bfe3-ed207bf44a26
:END:

#+begin_src elisp
(use-package dap-mode
  :after lsp-mode
  :config
  (dap-mode t)
  (dap-auto-configure-mode)
  (dap-ui-mode t)
  (dap-tooltip-mode t)
  (bind-key (kbd "<f7>") #'dap-step-in dap-mode-map)
  (bind-key (kbd "<f8>") #'dap-next dap-mode-map)
  (bind-key (kbd "<f9>") #'dap-continue dap-mode-map))

(use-package dap-hydra
  :after dap-mode)
#+end_src

**** Ascii Doc
:PROPERTIES:
:ID:       dfacb21e-e11b-4c4a-b6b9-a653a510fc44
:END:

#+begin_src elisp
(use-package adoc-mode)
#+end_src

**** C/C++
:PROPERTIES:
:ID:       7ea956bf-01fc-4e39-ad3c-8e491c91ef2a
:END:

#+begin_src elisp
(setq c-default-style '((java-mode . "java")
                        (awk-mode . "awk")
                        (c-mode . "linux")
                        (other . "gnu")))

(defun kb/c-mode ()
  "C minor mode configurations."
  (lsp-mode)
  (lsp-deferred))

(add-hook 'c-mode-hook #'kb/c-mode)
(add-hook 'c++-mode-hook #'kb/c-mode)
#+end_src

**** Clojure
:PROPERTIES:
:ID:       f7801ab7-23ee-43e0-80c8-3f917fc60c67
:END:

#+begin_src elisp
(use-package cljsbuild-mode)
#+end_src

#+begin_src elisp :tangle no
(use-package elein)
#+end_src

#+begin_src elisp
(use-package clojure-mode
  :after (cljsbuild-mode elein)
  :hook ((clojure-mode-hook . subword-mode)))
#+end_src

#+begin_src elisp
(use-package cider
  :init
  (setq nrepl-popup-stacktraces nil)
  :hook ((cider-mode-hook . eldoc-mode)
         (cider-repl-mode-hook . subword-mode)
         (cider-repl-mode-hook . paredit-mode)))

(use-package flycheck-clojure
  :after (clojure flycheck)
  :config
  (flycheck-clojure-setup))
#+end_src

**** CSV
:PROPERTIES:
:ID:       a53fd8b3-53ce-4409-8a0c-30ad0a9d7f79
:END:

#+begin_src elisp
(use-package csv-mode)
#+end_src

**** CSS
:PROPERTIES:
:ID:       26dd375e-8686-4122-95fa-d2c17bcd1670
:END:

#+begin_src elisp
;;; Colourise CSS colour literals
(require 'rainbow-mode)

(dolist (hook '(css-mode-hook html-mode-hook sass-mode-hook))
  (add-hook hook 'rainbow-mode))

;;; Embedding in HTML
(require 'mmm-mode)
(with-eval-after-load 'mmm-vars
  (mmm-add-group
   'html-css
   '((css-cdata
      :submode css-mode
      :face mmm-code-submode-face
      :front "<style[^>]*>[ \t\n]*\\(//\\)?<\\[CDATA\\[[ \t]*\n?"
      :back "[ \t]*\\(//\\)?]]>[ \t\n]*</style>"
      :insert ((?j js-tag nil @ "<style type=\"text/css\">"
                   @ "\n" _ "\n" @ "</style>" @)))
     (css
      :submode css-mode
      :face mmm-code-submode-face
      :front "<style[^>]*>[ \t]*\n?"
      :back "[ \t]*</style>"
      :insert ((?j js-tag nil @ "<style type=\"text/css\">"
                   @ "\n" _ "\n" @ "</style>" @)))
     (css-inline
      :submode css-mode
      :face mmm-code-submode-face
      :front "style=\""
      :back "\"")))
  (dolist (mode (list 'html-mode 'nxml-mode))
    (mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?\\'" 'html-css)))
#+end_src

#+begin_src elisp :tangle no
;;; SASS and SCSS
(use-package sass-mode)
(use-package scss-mode)
(setq-default scss-compile-at-save nil)
#+end_src

#+begin_src elisp
;;; LESS
(use-package less-css-mode)
(use-package skewer-less
  :after less-css-mode
  :hook (less-css-mode-hook . skewer-less-mode))

;; Skewer CSS
(use-package skewer-mode
  :hook css-mode-hook)

;;; Use eldoc for syntax hints
(use-package css-eldoc
  :hook (css-mode-hook . turn-on-css-eldoc)
  :init
  (autoload 'turn-on-css-eldoc "css-eldoc"))
#+end_src

**** Docker
:PROPERTIES:
:ID:       a3c5e3a6-423c-405d-a494-e1077b81881c
:END:

#+begin_src elisp
(use-package docker)
(use-package dockerfile-mode)
(use-package docker-compose-mode)
#+end_src

#+begin_src elisp
(use-package tramp-container)
#+end_src

**** Elixir/Erlang
:PROPERTIES:
:ID:       7e98b3e6-0bc8-41ba-8695-1bcf4f9806f4
:END:

#+begin_src elisp :tangle no
(use-package alchemist
  :diminish
  :config
  (diminish 'alchemist-phoenix-mode))

(use-package elixir-mode
  :after lsp-mode
  :init
  (defun kb/elixir-mode ()
    (lsp-mode)
    (lsp-deferred))
  :hook (elixir-mode . kb/elixir-mode))

(use-package flycheck-credo
  :after elixir-mode
  :hook (elixir-mode . flycheck-credo-setup))
(use-package flycheck-elixir
  :after elixir-mode)
#+end_src

#+begin_src elisp :tangle no
(use-package erlang
  :config
  (require 'erlang-start))

(use-package edts)
#+end_src

**** Elm Lang
:PROPERTIES:
:ID:       2443ea14-efb9-411f-81e0-a9f35315aceb
:END:

#+begin_src elisp
(use-package flycheck-elm
  :after flycheck)

(use-package elm-mode
  :after (flycheck flycheck-elm)
  :diminish
  :config
  (flycheck-elm-setup)
  (when (executable-find "elm-oracle")
    (add-hook 'elm-mode-hook 'elm-oracle-setup-completion))
  (when (executable-find "elm-format")
    (setq-default elm-format-on-save t))
  (setq elm-reactor-arguments nil)
  (diminish 'elm-indent-mode))
#+end_src

**** Gnuplot
:PROPERTIES:
:ID:       648f8ece-c160-478c-8903-fca52b0a5b88
:END:

#+begin_src elisp
(add-to-list 'auto-mode-alist '("\\.plt\\'" . gnuplot-mode))
#+end_src

**** Go Lang
:PROPERTIES:
:ID:       c558816b-0c2b-48af-98ac-6116fd8b64d5
:END:

#+begin_src elisp
(use-package go-mode
  :after (lsp-mode)
  :commands (gofmt-before-save)
  :init
  (defun kb/golang-mode ()
    (setq-local indent-tabs-mode t)
    (setq-local tab-width 4)
    (lsp-mode)
    (lsp-deferred))
  :config
  (add-hook 'before-save-hook #'gofmt-before-save)
  :hook (go-mode . kb/golang-mode))

(use-package go-stacktracer)
#+end_src

**** Guix
:PROPERTIES:
:ID:       f6828526-1eff-4447-9284-0ffe6139772d
:END:

#+begin_src elisp
(use-package guix)
#+end_src

**** Haskell
:PROPERTIES:
:ID:       9092b182-d559-401d-80ac-ec35a7eb6c4e
:END:

#+begin_src elisp
(use-package lsp-haskell
  :config
  (setq lsp-haskell-process-path-hie "ghcide")
  (setq lsp-haskell-process-args-hie '()))

(use-package haskell-mode
  :after (flycheck lsp-haskell)
  :init
  (setq-default haskell-stylish-on-save t)
  (defun kb/haskell-mode ()
    (eldoc-mode)
    (lsp-mode)
    (lsp-deferred))
  :hook (haskell-mode . kb/haskell-mode)
  :bind (:map haskell-mode-map
              ("C-c h" . hoogle)
              ("C-o" . open-line)))

(use-package flycheck-haskell
  :after (haskell-mode flycheck))
#+end_src

**** HTML
:PROPERTIES:
:ID:       d0433080-6de5-4568-9e7c-1c5699c46f6e
:END:

#+begin_src elisp
(use-package tagedit)
(with-eval-after-load 'sgml-mode
  (add-hook 'sgml-mode-hook (lambda () (tagedit-mode 1))))

(add-to-list 'auto-mode-alist '("\\.\\(jsp\\|tpml\\)\\'" . html-mode))

;; Note: ERB is configured in init-ruby-mode
#+end_src

**** Java
:PROPERTIES:
:ID:       c4321042-dcb0-4960-84a1-974dc3c774f7
:END:

#+begin_src elisp
(use-package autodisass-java-bytecode)
#+end_src

#+begin_src elisp :tangle no
(use-package eglot-java
  :init
  (defun kb/java-mode ()
    "Configure java mode settings."
    (subword-mode)
    (setq-local tab-width 4)
    (setq-local c-basic-offset 4)
    (elgot-ensure))
  :hook (java-mode . kb/java-mode))
#+end_src

#+begin_src elisp
;; Loosely borrowed from
;; https://github.com/jmibanez/jmi-dotemacs/blob/master/development.init.el#L139
;; Other changes from Torstein as well
;; https://gitlab.com/skybert/my-little-friends/-/blob/master/emacs/.emacs.d/tkj-java.el
(use-package lsp-java
  :init
  (defun kb/java-mode ()
    "Configure java mode settings."
    (subword-mode)
    (setq-local tab-width 4)
    (setq-local c-basic-offset 4)
    (lsp-java-boot-lens-mode t)
    (lsp-deferred))
  :config

  ;; Enable dap-java
  (require 'dap-java)

  (setq lsp-java-server-install-dir (concat user-emacs-directory "lsp/eclipse.jdt.ls/server/"))
  (setq lsp-java-workspace-dir (expand-file-name (concat user-emacs-directory "eclipse.jdt.ls/workspace/")))
  (setq lsp-java-workspace-cache-dir (expand-file-name (concat user-emacs-directory "eclipse.jdt.ls/workspace/.cache/")))
  (setq lsp-java-java-path (expand-file-name "~/.guix-home/profile/bin/java"))
  (setq lsp-java-vmargs
        (list "-noverify"
              "-Xms100m"
              "-Xmx2G"
              "-XX:+UnlockExperimentalVMOptions"
              "-XX:+UseZGC"
              "-XX:+UseStringDeduplication"
              "-XX:AdaptiveSizePolicyWeight=90"
              "-Dsun.zip.disableMemoryMapping=true"))
  (setq lsp-file-watch-ignored '(".idea" ".ensime_cache" ".eunit" "node_modules"
                                 ".git" ".hg" ".fslckout" "_FOSSIL_" ".bzr"
                                 "_darcs" ".tox" ".svn" ".stack-work" "build"))

  (setq lsp-java-save-action-organize-imports nil)
  (setq lsp-java-completion-max-results 20)
  (setq lsp-enable-on-type-formatting nil)
  (setq lsp-enable-indentation t)
  (setq lsp-java-import-maven-enabled t)
  (setq lsp-java-import-gradle-enabled t)
  (setq lsp-java-maven-download-sources t)
  (setq lsp-java-format-settings-url (expand-file-name (concat user-emacs-directory "/lsp-java/GoogleStyles.xml")))
  (setq lsp-java-format-settings-profile "GoogleStyle")

  :hook (java-mode . kb/java-mode)
  :after (lsp-mode dap-mode))

(use-package dap-java
  :ensure nil
  :after (lsp-java)
  :config
  (dap-register-debug-template
   "debug..."
   (list :type "java"
         :request "attach"
         :hostName "localhost"
         :port 5005)))
#+end_src

**** JavaScript
:PROPERTIES:
:ID:       92ec9790-21a5-4b8b-b5c4-00b3f659e239
:END:

#+begin_src elisp
(use-package json-mode)
(use-package js2-mode
  :init
  (defun kb/js2-mode ()
    (lsp-mode)
    (lsp-deferred))
  :hook (js2-mode . kb/js2-mode)
  :config
  (setq-default js2-basic-offset 4)
  (setq-default js2-bounce-indent-p nil))
#+end_src

#+begin_src elisp :tangle no
(use-package coffee-mode)
#+end_src

#+begin_src elisp
(use-package typescript-mode
  :init
  (defun kb/typescript-mode ()
    (lsp-mode)
    (lsp-deferred))
  :hook (typescript-mode . kb/typescript--mode))

(defconst preferred-javascript-indent-level 4)

(add-to-list 'auto-mode-alist '("\\.\\(js\\|es6\\)\\(\\.erb\\)?\\'" . js2-mode))

;; js-2 mode
;; change some defaults

(with-eval-after-load 'js2-mode
  ;; Disable js2-mode's syntax error highlighting by default ...
  (setq-default js2-mode-show-parse-errors nil
	            js2-mode-show-strict-warnings nil)
  ;; ... but enable it if flycheck can't handle javascript
  (autoload 'flycheck-get-checker-for-buffer "flycheck")
  (defun sanityinc/disable-js2-checks-if-flycheck-active ()
    (unless (flycheck-get-checker-for-buffer)
      (set (make-local-variable 'js2-mode-show-parse-errors) t)
      (set (make-local-variable 'js2-mode-show-strict-warnings) t)))
  (add-hook 'js2-mode-hook 'sanityinc/disable-js2-checks-if-flycheck-active)

  (add-hook 'js2-mode-hook (lambda () (setq mode-name "JS2")))

  (with-eval-after-load 'js2-mode
    (js2-imenu-extras-setup)))

;; js-mode
(setq-default js-indent-level preferred-javascript-indent-level)

(add-to-list 'interpreter-mode-alist '("node" . js2-mode))

(use-package xref-js2
  :after js2-mode
  :config
  (add-to-list 'xref-backend-functions #'xref-js2-xref-backend))

(when (fboundp 'coffee-mode)
  (add-to-list 'auto-mode-alist '("\\.coffee\\.erb\\'" . coffee-mode)))

;; Run and interact with an inferior JS via js-comint.el

(use-package js-comint
  :init
  (setq inferior-js-program-command "node")

  (defvar inferior-js-minor-mode-map (make-sparse-keymap))
  (define-key inferior-js-minor-mode-map (kbd "C-x C-e") 'js-send-last-sexp)
  (define-key inferior-js-minor-mode-map (kbd "C-M-x") 'js-send-last-sexp-and-go)
  (define-key inferior-js-minor-mode-map (kbd "C-c b") 'js-send-buffer)
  (define-key inferior-js-minor-mode-map (kbd "C-c C-b") 'js-send-buffer-and-go)
  (define-key inferior-js-minor-mode-map (kbd "C-c l") 'js-load-file-and-go)

  (define-minor-mode inferior-js-keys-mode
    "Bindings for communicating with inferior js interpreter."
    :init-value nil
    :lighter "InfJS"
    :keymap inferior-js-minor-mode-map)

  (dolist (hook '(js2-mode-hook js-mode-hook))
    (add-hook hook 'inferior-js-keys-mode)))

;;; Alternatively, use skewer mode
(use-package skewer-mode
  :init
  (add-hook 'skewer-mode-hook
	        (lambda () (inferior-js-keys-mode -1))))

(use-package add-node-modules-path
  :after (typescript-mode js2-mode)
  :hook ((typescript-mode . add-node-modules-path)
         (js2-mode . add-node-modules-path)))
#+end_src

**** Lua
:PROPERTIES:
:ID:       ae884fcc-b5fd-4dd1-ba9d-cf468c599eec
:END:

#+begin_src elisp
(use-package lua-mode)
#+end_src

**** Markdown
:PROPERTIES:
:ID:       18e54165-4fe4-4ed8-ba70-c45f2cbaf7c6
:END:

#+begin_src elisp
(use-package markdown-mode
  :mode "\\.md\\.html\\'")
#+end_src

**** Nix
:PROPERTIES:
:ID:       66d5872f-7ef5-4480-8864-8054c02396c7
:END:

#+begin_src elisp
(use-package nix-mode)
#+end_src

#+begin_src elisp :tangle no
(use-package nix-buffer)
(use-package nix-update)
#+end_src

**** XML
:PROPERTIES:
:ID:       2f63ad13-7e07-443e-9032-1af398ccfd23
:END:

#+begin_src elisp
(dolist (regexmode (list '("\\.xml\\'" . #'nxml-mode)
                         '("\\.xsd\\'" . #'nxml-mode)
                         '("\\.sch\\'" . #'nxml-mode)
                         '("\\.rng\\'" . #'nxml-mode)
                         '("\\.xlst\\'" . #'nxml-mode)
                         '("\\.svg\\'" . #'nxml-mode)
                         '("\\.rss\\'" . #'nxml-mode)
                         '("\\.gpx\\'" . #'nxml-mode)
                         '("\\.tcx\\'" . #'nxml-mode)
                         '("\\.plist\\'" . #'nxml-mode)))
  (add-to-list 'auto-mode-alist regexmode))

(setq magic-mode-alist (cons '("<\\?xml " . nxml-mode) magic-mode-alist))
(add-to-list 'magic-mode-alist '("<\\?xml " . nxml-mode))
(fset 'xml-mode 'nxml-mode)
(add-hook 'nxml-mode-hook (lambda ()
                            (set (make-local-variable 'ido-use-filename-at-point) nil)))
(setq nxml-slash-auto-complete-flag t)

;; See: http://sinewalker.wordpress.com/2008/06/26/pretty-printing-xml-with-emacs-nxml-mode/
(defun sanityinc/pp-xml-region (beg end)
  "Pretty format XML markup region. The function inserts
linebreaks to separate tags that have nothing but whitespace
between them. It then indents the markup by using nxml's
indentation rules."
  (interactive "r")
  (unless (use-region-p)
    (setq beg (point-min)
          end (point-max)))
  ;; Use markers because our changes will move END
  (setq beg (set-marker (make-marker) begin)
        end (set-marker (make-marker) end))
  (save-excursion
    (goto-char beg)
    (while (search-forward-regexp "\>[ \\t]*\<" end t)
      (backward-char) (insert "\n"))
    (nxml-mode)
    (indent-region begin end)))
#+end_src

**** PHP
:PROPERTIES:
:ID:       e9260043-3239-415d-95a8-727eb9a87615
:END:

#+begin_src elisp
(use-package php-mode)
#+end_src

#+begin_src elisp :tangle no
(use-package geben)
#+end_src

#+begin_src elisp :tangle no
(use-package geben-helm-projectile
  :after (helm projectile geben))
#+end_src

**** Python
:PROPERTIES:
:ID:       7c301063-a3df-47a4-9201-05ed34c74107
:END:

#+begin_src elisp
(use-package python
  :init
  (defun kb/python-mode ()
    (lsp-mode)
    (lsp-deferred))
  :hook (python-mode . kb/python-mode))

(use-package pip-requirements
  :after (python))
#+end_src

#+begin_src elisp :tangle no
(use-package virtualenvwrapper
  :after (python)
  :init
  (setq venv-dirlookup-names '(".venv" "pyenv" ".virtual"))
  (setq venv-location (expand-file-name "~/.cache/venvs")))
#+end_src

#+begin_src elisp
(use-package ein
  :after (python))
#+end_src

#+begin_src elisp :tangle no
(use-package lsp-python-ms
  :init
  (setq lsp-python-ms-executable (executable-find "python-language-server")))
#+end_src

**** Ruby
:PROPERTIES:
:ID:       bd6d4185-b917-4666-a9ce-438052e0d602
:END:

#+begin_src elisp :tangle no
(use-package ruby-hash-syntax)
(use-package rspec-mode)
(use-package inf-ruby)
(use-package ruby-compilation
  :config
  (defalias 'rake 'ruby-compilation-rake))
(use-package yari
  :config
  (defalias 'ri 'yari))
(use-package robe)
(use-package bundler)

(use-package ruby-mode
  :after (rspec-mode inf-ruby ruby-compilation)
  :mode (("Rakefile\\'" . ruby-mode)
         ("\\.rake\\'" . ruby-mode)
         ("\\.rxml\\'" . ruby-mode)
         ("\\.rjs\\'" . ruby-mode)
         ("\\.librc\\'" . ruby-mode)
         ("\\.pryrc\\'" . ruby-mode)
         ("\\.builder\\'" . ruby-mode)
         ("\\.ru\\'" . ruby-mode)
         ("\\.gemspec\\'" . ruby-mode)
         ("Gemfile\\'" . ruby-mode)
         ("Kirkfile\\'" . ruby-mode))
  :init
  (setq-default ruby-use-encoding-map nil)
  (setq-default ruby-insert-encoding-magic-comment nil)
  (defun kb/ruby-mode ()
    (unless derived-mode-p #'prog-mode
            (run-hook 'prog-mode-hook))
    (subword-mode)
    (lsp-mode)
    (lsp-deferred))
  :hook (ruby-mode . kb/ruby-mode))

;;; ERB
(require 'mmm-mode)
(defun sanityinc/ensure-mmm-erb-loaded ()
  "Load mmm-erb mode."
  (require 'mmm-erb))

(require 'derived)

(defun sanityinc/set-up-mode-for-erb (mode)
  (add-hook (derived-mode-hook-name mode) 'sanityinc/ensure-mmm-erb-loaded)
  (mmm-add-mode-ext-class mode "\\.erb\\'" 'erb))

(let ((html-erb-modes '(html-mode html-erb-mode nxml-mode)))
  (dolist (mode html-erb-modes)
    (sanityinc/set-up-mode-for-erb mode)
    (mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?\\'" 'html-js)
    (mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?\\'" 'html-css)))

(mapc 'sanityinc/set-up-mode-for-erb
      '(coffee-mode js-mode js2-mode js3-mode markdown-mode textile-mode))

(mmm-add-mode-ext-class 'html-erb-mode "\\.jst\\.ejs\\'" 'ejs)

(dolist (regxmode (list '("\\.rhtml\\'" . 'html-erb-mode)
                        '("\\.html\\.erb\\'". 'html-erb-mode)
                        '("\\.jst\\.ejs\\'" . html-erb-mode)))
  (add-to-list 'auto-mode-alist regxmode))

(mmm-add-mode-ext-class 'yaml-mode "\\.yaml\\(\\.erb\\)?\\'" 'erb)
(sanityinc/set-up-mode-for-erb 'yaml-mode)

(dolist (mode (list 'js-mode 'js2-mode 'js3-mode))
  (mmm-add-mode-ext-class mode "\\.js\\.erb\\'" 'erb))
#+end_src

**** Rust
:PROPERTIES:
:ID:       084ae377-9c75-4b07-831d-284cb1f56889
:END:

#+begin_src elisp
(use-package racer
  :hook ((racer-mode-hook . eldoc-mode)))

(use-package rust-mode
  :after racer
  :init
  (defun kb/rust-mode ()
    (racer-mode)
    (lsp-mode)
    (lsp-deferred))
  :hook (rust-mode-hook . kb/rust-mode))
#+end_src

**** Scala
:PROPERTIES:
:ID:       e1ebb5d1-695d-40d0-bac1-e30fd277431f
:END:

#+begin_src elisp
#+end_src

**** Scheme
:PROPERTIES:
:ID:       068c32e6-47ac-486c-84ed-a1f407e647b2
:END:

#+begin_src elisp
(setq geiser-active-implementations '(guile racket))

(use-package geiser)
#+end_src

**** Slurm
:PROPERTIES:
:ID:       ac5233d9-3a78-43f8-9409-896774a03efb
:END:

#+begin_src elisp
(use-package slurm-mode)
(use-package slurm-script-mode)
#+end_src

**** SQL
:PROPERTIES:
:ID:       bb191ba6-5c08-4fb8-aca5-72573d0e57d1
:END:

#+begin_src elisp
(require 'sql)

(with-eval-after-load 'sql
  ;; sql-mode basically requires an uncustomized environment
  (push "--no-psqlrc" sql-postgres-options)
  (sql-set-product-feature 'mysql
                           :prompt-regexp
                           "^\\(MariaDB\\|MySQL\\) \\[[_a-zA-Z]*\\]> "))

(defun sanityinc/pop-to-sqli-buffer ()
  "Switch to the corresponding sqli buffer."
  (interactive)
  (if sql-buffer
      (progn
        (pop-to-buffer sql-buffer)
        (goto-char (point-max)))
    (sql-set-sqli-buffer)
    (when sql-buffer
      (sanityinc/pop-to-sqli-buffer))))

(setq-default sql-input-ring-file-name
              (expand-file-name ".sqli_history" user-emacs-directory))

;;  https://emacs.stackexchange.com/questions/657/why-do-sql-mode-and-sql-interactive-mode-not-highlight-strings-the-same-way/673
(defun sanityinc/font-lock-everything-in-sql-interactive-mode ()
  "Font lock all the things."
  (unless (eq 'oracle sql-product)
    (sql-product-font-lock nil nil)))

(add-hook 'sql-interactive-mode-hook
          (lambda ()
            (sanityinc/font-lock-everything-in-sql-interactive-mode)
            (toggle-truncate-lines t)
            ))

(setq sql-postgres-login-params
      '((user :default "postgres")
        (database :default "postgres")
        (server :default "postgres")
        (port :default 5432)))

(setq-default sql-connection-alist '())

;; https://truongtx.me/2014/08/23/setup-emacs-as-an-sql-database-client
(defun open-sql-connection (product connection)
  "Open SQL prompt for PRODUCT using CONNECTION."
  ;; remember to set the sql-product, otherwise, it will fail for the
  ;; first time you call the function
  (setq sql-product product)
  (sql-connect connection))
#+end_src

**** TeX
:PROPERTIES:
:ID:       6923b5dc-353f-403e-85c1-2d5e8e061305
:END:

#+begin_src elisp
(use-package reftex
  :commands turn-on-reftex
  :config
  (setq reftex-plugin-into-AUCTeX t)
  (setq reftex-enable-partial-scans t)
  (setq reftex-save-parse-info t)
  (setq reftex-use-multiple-selection-buffers t)
  (setq bibtex-entry-format '(opts-or-alts required-fields numerical-fields realign braces))
  (setq bibtex-align-at-equal-sign t))

(use-package tex
  :mode ("\\.tex\\'" . LaTeX-mode)
  :init
  (defun kb/tex-mode ()
    "Configure TeX/LaTeX mode settings."
    (turn-on-reftex)
    (LaTeX-math-mode t)
    (reftex-isearch-minor-mode t)
    (flycheck-select-checker 'tex-chktex)
    (setq TeX-PDF-mode t)
    (setq TeX-source-correlate-start-server t))
  ;; temporary fix for auctex-latexmk tex-buf issue.
  ;; https://github.com/tom-tan/auctex-latexmk/issues/44
  (provide 'tex-buf)
  :config
  (setq TeX-parse-self t)
  (setq TeX-auto-save t)
  (setq TeX-save-query nil)
  (setq LaTeX-eqnarray-label "eq")
  (setq LaTeX-equation-label "eq")
  (setq LaTeX-figure-label "fig")
  (setq LaTeX-table-label "tab")
  (setq LaTeX-myChapter-label "chap")
  (setq TeX-newline-function #'reindent-then-newline-and-indent)
  (setq LaTeX-section-hook '(LaTeX-section-heading
                             LaTeX-section-title
                             LaTeX-section-toc
                             LaTeX-section-section
                             LaTeX-section-label))
  (setq TeX-view-program-selection '(((output-dvi has-no-display-manager)
                                      "dvi2tty")
                                     ((output-dvi style-pstricks)
                                      "dvips and gv")
                                     (output-dvi "xdvi")
                                     (output-pdf "evince" "pdf-tools")
                                     (output-html "xdg-open")))
  (setq TeX-view-program-list '(("pdf-tools" "TeX-pdf-tools-sync-view")))
  (setq TeX-source-correlate-method '((dvi . source-specials)
                                      (pdf . synctex)))
  (setq TeX-source-correlate-start-server t)
  (setq-default TeX-master nil)
  (setq TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)
  (setq bibtex-dialect 'biblatex)
  :hook ((LaTeX-mode . kb/tex-mode)
         (TeX-mode . kb/tex-mode)))


;; These values are set in `init-local.el'
;; (setq bibtex-completion-bibliography nil)
;; (setq bibtex-completion-notes-path nil)
;; (setq bibtex-completion-library-path nil)
(setq bibtex-completion-additional-search-fields '(journal booktitle))
(setq bibtex-completion-display-formats
      '((article       . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*} ${journal:40}")
        (inbook        . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*} Chapter ${chapter:32}")
        (incollection  . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*} ${booktitle:40}")
        (inproceedings . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*} ${booktitle:40}")
        (t             . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*}")))
(setq bibtex-completion-pdf-symbol "โŒ˜")
(setq bibtex-completion-notes-symbol "โœŽ")
(setq bibtex-completion-pdf-field nil)
(setq bibtex-completion-pdf-extension '(".pdf" ".djvu"))
(setq bibtex-completion-format-citation-functions
      '((org-mode      . bibtex-completion-format-org-link-to-PDF)
        (latex-mode    . bibtex-completion-format-citation-cite)
        (markdown-mode . bibtex-completion-format-citation-pandoc-citeproc)
        (default       . bibtex-completion-format-citation-default)))
#+end_src

Functionality to generate plain text references to the current bibliographic
entry.

#+begin_src elisp
(require 'bibtex-to-plain-text)
#+end_src

After some digging, I discovered =bibtex-autokey= and friends.  Instead of
agonizing over a "scheme" for organizing keys, we can simply use a program
written specifically for this to perform the key generation for us!

Some references used for this:

- https://www.reddit.com/r/emacs/comments/a9n9el/setup_pdf_tools_in_emacs/

- https://jblevins.org/log/bibtex

#+begin_src elisp
(setq bibtex-autokey-year-length 4)
(setq bibtex-autokey-name-year-separator "-")
(setq bibtex-autokey-year-title-separator "-")
(setq bibtex-autokey-titleword-separator "-")
(setq bibtex-autokey-titleword-ignore (list "the" "a" "if" "and" "an"))
(setq bibtex-autokey-titlewords 2)
(setq bibtex-autokey-titlewords-stretch 1)
(setq bibtex-autokey-titleword-length 5)
#+end_src

#+begin_src elisp
(use-package auctex-latexmk
  :after tex
  :config
  (setq auctex-latexmk-inherit-TeX-PDF-mode t)
  :init
  (auctex-latexmk-setup))
#+end_src

Some common Bib/reftex/org-ref actions that are useful to have around.

#+begin_src elisp
(bind-key "C-c o i" #'org-ref-cite-insert-helm)
(bind-key "C-c o o" #'org-ref-open-bibtex-pdf)
(bind-key "C-c o n" #'org-ref-open-bibtex-notes)
(bind-key "C-c o t" #'bibtex-create-plain-text-reference)
(bind-key "C-c o d" #'doi-insert-bibtex)
(bind-key "C-c o p" #'doi-utils-get-bibtex-entry-pdf)
#+end_src

Add =languagetool= to =tex-chktex= checker chain.

#+begin_src elisp
(eval-after-load 'flycheck-languagetool
  (lambda () (flycheck-add-next-checker 'tex-chktex '(warning . languagetool))))
#+end_src

**** TOML
:PROPERTIES:
:ID:       3841af44-134f-48f6-a323-fc5eacfa5957
:END:

#+begin_src elisp
(use-package toml-mode
  :hook ((toml-mode-hook . goto-address-prog-mode)))
#+end_src

**** OCaml
:PROPERTIES:
:ID:       240bb299-dc24-443f-a65d-aca36db62512
:END:

#+begin_src elisp
(use-package tuareg
  :init
  (defun kb/ocaml-mode ()
    (lsp-mode)
    (lsp-deferred))
  :hook (tuareg-mode-hook . kb/ocaml-mode))
#+end_src

**** Z3/SMTLIB
:PROPERTIES:
:ID:       f1d205f2-df81-4891-8fd1-be10a6ea3276
:END:

#+begin_src elisp
(use-package z3-mode
  :mode (("\\.smt2\\'" . z3-mode)
         ("\\.z3\\'" . z3-mode))
  :config
  (setq z3-solver-cmd "z3"))
#+end_src

*** Org Mode
:PROPERTIES:
:ID:       4f622896-6d42-4913-bb17-297a038f9c94
:END:

Started from purcell:
https://github.com/purcell/emacs.d/blob/master/lisp/init-org.el
Various inclusions from glynnforrest:
https://github.com/glynnforrest/emacs.d/blob/master/site-lisp/setup-org.el
Various inclusions from jcf:
https://github.com/jcf/emacs.d/blob/master/init-org.org
Reworked with offerings from
http://cachestocaches.com/2016/9/my-workflow-org-agenda/
And
http://doc.norang.ca/org-mode.htm

#+begin_src elisp
(require 'org)
(require 'org-id)
(require 'holidays)
(require 'ox-md)
#+end_src

#+begin_src elisp :tangle no
(use-package ob-ditaa
  :config
  (setq org-ditaa-jar-path (expand-file-name "~/.nix-profile/lib/ditaa.jar")))
#+end_src

#+begin_src elisp
(use-package graphviz-dot-mode)
;; (use-package org-cliplink)
(use-package ess)
(use-package ox-gfm)
;; (use-package org-babel-eval-in-repl)
(use-package org-ref
  :config
  (setq bibtex-completion-notes-template-multiple-files "* ${author-or-editor}, ${title}, ${journal}, (${year}) :${=type=}: \n\nSee [[cite:&${=key=}]]\n"))
;; https://www.reddit.com/r/emacs/comments/57gteu/org_export_html_source_code_blocks_adds_trailing/
;; https://github.com/kaushalmodi/.emacs.d/blob/15df5b075a4cd4a8ed7332237c0e33e75b430a36/setup-files/setup-htmlize.el#L10-L28
(use-package htmlize
  :config
  (progn

    ;; `flyspell-mode' also has to be disabled because depending on the
    ;; theme, the squiggly underlines can either show up in the html file
    ;; or cause elisp errors like:
    ;; (wrong-type-argument number-or-marker-p (nil . 100))
    (with-eval-after-load 'flyspell
      (defvar modi/htmlize-initial-flyspell-mode nil
        "Variable to store state of `flyspell-mode' when
  `htmlize-buffer` is called.")

      (defun modi/htmlize-before-hook-flyspell-disable ()
        (setq modi/htmlize-initial-flyspell-mode flyspell-mode)
        (when flyspell-mode
          (setq flyspell-mode -1)))

      (defun modi/htmlize-after-hook-flyspell-enable-maybe ()
        (when modi/htmlize-initial-flyspell-mode
          (setq flyspell-mode 1)))

      (add-hook 'htmlize-before-hook
                #'modi/htmlize-before-hook-flyspell-disable)
      (add-hook 'htmlize-after-hook
                #'modi/htmlize-after-hook-flyspell-enable-maybe))))

(define-key global-map (kbd "C-c l") 'org-store-link)
(define-key global-map (kbd "C-c a") 'org-agenda)
(define-key global-map (kbd "C-c c") 'org-capture)
(unbind-key "<M-S-left>" org-mode-map)
(unbind-key "<M-S-right>" org-mode-map)
#+end_src

#+begin_src elisp
;; Various preferences
(setq org-log-done 'time)
(setq org-directory "~/.org/")
(setq org-id-locations-file (expand-file-name (concat user-emacs-directory ".org-id-locations")))
(setq org-id-link-to-org-use-id 'use-existing)
(setq org-ellipsis "โคต")
(setq org-special-ctrl-a/e t)
(setq org-edit-timestamp-down-means-later t)
(setq org-archive-location "%s_archive::datetree/")
(setq org-archive-mark-done nil)
(setq org-hide-emphasis-markers t)
(setq org-catch-invisible-edits 'show-and-error)
(setq org-export-coding-system 'utf-8)
(setq org-html-validation-link nil)
(setq org-export-kill-product-buffer-when-displayed t)
(setq org-tags-column 75)
(setq org-search-view-always-boolean t)
(setq org-refile-targets (quote ((nil :maxlevel . 9)
                                 (org-agenda-files :maxlevel . 9))))
(setq org-outline-path-complete-in-steps nil)
(setq org-refile-use-outline-path t)
(setq org-indirect-buffer-display 'current-window)
(setq org-enforce-todo-dependencies t)
(setq org-fast-tag-selection-include-todo t)
(setq org-use-fast-todo-selection t)
(setq org-treat-S-cursor-todo-selection-as-state-change nil)
(setq org-confirm-babel-evaluate nil)
(setq org-src-fontify-natively t)
(setq org-src-tab-acts-natively t)
(setq org-agenda-dim-blocked-tasks nil)
(setq org-agenda-compact-blocks t)
(setq org-agenda-show-future-repeats t)
(setq org-agenda-skip-deadline-if-done t)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-include-diary t)
(setq org-todo-repeat-to-state "TODO")
(setq org-files (append
                 (file-expand-wildcards (concat org-directory "*.org"))
                 (file-expand-wildcards (concat org-directory "*/*.org"))
                 (file-expand-wildcards (concat org-directory "*/*/*.org"))))
(setq org-log-state-notes-into-drawer t)
(setq org-clock-persistence-insinuate t)
(setq org-clock-out-remove-zero-time-clocks t)
(setq org-clock-persist t)
(setq org-clock-in-resume t)
(setq org-clock-into-drawer "CLOCK")
(setq org-duration-format (quote (("d" . nil) ("h" . t) ("min" . t))))
(setq org-babel-clojure-backend 'cider)
(setq org-src-preserve-indentation nil)
(setq org-edit-src-content-indentation 0)
;; Agenda log mode items to display (closed and state changes by default)
(setq org-agenda-log-mode-items (quote (closed clock state)))
(setq org-attach-id-dir (expand-file-name "~/.org/data"))
(setq org-startup-folded t)
(setq calendar-time-display-form '(24-hours
                                   ":"
                                   minutes
                                   (if time-zone " (")
                                   time-zone
                                   (if time-zone ")")))
#+end_src

#+begin_src elisp
(setq org-latex-prefer-user-labels t)
(setq org-latex-listings t)
(setq org-latex-listings-options
      '(("breaklines" "true")
        ("firstnumber" "auto")
        ("frame" "single")
        ("mathescape" "true")
        ("numbers" "left")
        ("numbersep" "5pt")
        ("numberstyle" "\\tiny")
        ("showspaces" "false")
        ("showstringspaces" "false")
        ("stepnumber" "1")
        ("title" "\\lstname")))

(add-to-list 'org-latex-listings-langs '(scheme "Lisp"))

(add-to-list 'org-latex-default-packages-alist '("" "listings" t))

(setq org-latex-pdf-process
      '("pdflatex -interaction nonstopmode -output-directory %o %f"
        "bibtex %b"
        "pdflatex -interaction nonstopmode -output-directory %o %f"
        "pdflatex -interaction nonstopmode -output-directory %o %f"))

#+end_src

#+begin_src elisp
;;;; Refile settings
(defun bh/verify-refile-target ()
  "Exclude todo keywords with a done state from refile targets."
  (not (member (nth 2 (org-heading-components)) org-done-keywords)))

(setq org-refile-target-verify-function #'bh/verify-refile-target)

(defvar org-projects-dir (expand-file-name (concat org-directory "projects")))
(defvar kb/org-refile (concat org-directory "refile.org"))
(defvar kb/org-notes-file (concat org-directory "notes.org"))
(defvar kb/org-daily-file (concat org-directory "daily.org"))
(defvar kb/org-journal-file (concat org-directory "journal.org"))
(defvar kb/org-work-journal-file (concat org-directory "work.org"))
(defvar kb/org-bookmarks-file (concat org-directory "bookmarks.org"))
(defvar kb/org-logbook-file (concat org-directory "logbook.org"))
(defvar kb/org-contacts (concat org-directory "contacts.org"))
(setq org-default-notes-file kb/org-refile)

(defun kb/org-clocking-p ()
  "Return non-nil if currently tracking time, otherwise, nil."
  (not (eq nil (org-clock-is-active))))

(defun kb/org-not-clocking-p ()
  "Return nil if not tracking time, otherwise, non-nil."
  (eq nil (org-clock-is-active)))

(setq org-capture-templates
      '(("t" "todo" entry (file kb/org-refile)
         (file "~/.config/emacs/org-captures/TODO") :clock-in t :clock-resume t)
        ("r" "respond" entry (file kb/org-refile)
         (file "~/.config/emacs/org-captures/RESPOND")
         :clock-in t :clock-resume t :immediate-finish t)
        ("tn" "note on task" entry (file+olp+datetree kb/org-logbook-file)
         (file "~/.config/emacs/org-captures/TASK_NOTE") :empty-lines 1)
        ("n" "logbook entry" entry (file+olp+datetree kb/org-logbook-file)
         (file "~/.config/emacs/org-captures/TASK_LOG_NOTE") :empty-lines 1)
        ("tr" "related task" entry (clock)
         (file "~/.config/emacs/org-captures/RELATED_TODO"))
        ("tm" "todo from mail" entry (file kb/org-refile)
         (file "~/.config/emacs/org-captures/TODO_MAIL") :clock-in t :clock-resume t)
        ("j" "Journal" entry (file+olp+datetree kb/org-journal-file)
         (file "~/.config/emacs/org-captures/JOURNAL")
         :clock-in t
         :clock-resume t)
        ("w" "Work Log" entry (file+olp+datetree kb/org-work-journal-file)
         (file "~/.config/emacs/org-captures/JOURNAL")
         :clock-in t
         :clock-resume t)
        ("d" "Daily Schedule" entry (file+olp+datetree kb/org-daily-file)
         (file "~/.config/emacs/org-captures/JOURNAL")
         :clock-resume t)
        ("o" "org-protocol" entry (file kb/org-refile)
         (file "~/.config/emacs/org-captures/ORG-PROTOCOL")
         :immediate-finish t)
        ("m" "Meeting" entry (file+olp+datetree kb/org-logbook-file)
         (file "~/.config/emacs/org-captures/MEETING")
         :clock-in t
         :clock-resume t)
        ("b" "Bookmark" entry (file kb/org-bookmarks-file)
         (file "~/.config/emacs/org-captures/BOOKMARK")
         :clock-resume t)
        ("p" "Phone call" entry (file+olp+datetree kb/org-journal-file)
         (file "~/.config/emacs/org-captures/PHONE")
         :clock-in t
         :clock-resume t)
        ("P" "Project" entry (file kb/org-refile)
         (file "~/.config/emacs/org-captures/PROJECT")
         :clock-in t
         :clock-resume t)
        ("a" "Contact" entry (file+olp kb/org-contacts "unsorted")
         (file "~/.config/emacs/org-captures/CONTACT")
         :clock-resume t)
        ))

(setq org-capture-templates-contexts
      '(("n" "tn" (kb/org-clocking-p))
        ("r" "tr" (kb/org-clocking-p))
        ("n" "n" (kb/org-not-clocking-p))
        ("t" "tm" ((in-mode . "mu4e-view")
                   (in-mode . "mu4e-headers")))
        ("t" "t" ((not-in-mode . "mu4e-view")
                  (not-in-mode . "mu4e-headers")))
        ("r" ((in-mode . "mu4e-view")
              (in-mode . "mu4e-headers")))))

(add-hook 'org-capture-mode-hook (lambda () (setq fill-column 72)))
;; https://stackoverflow.com/a/16247032/7492588
(add-hook 'org-capture-prepare-finalize-hook #'org-id-get-create)

   ;;; https://emacs.stackexchange.com/q/51631/17096
(add-hook 'org-log-buffer-setup-hook (lambda () (setq-local fill-column 72)))
#+end_src

Update project status when updating the cookie statistics.

#+begin_src elisp
(defun kb/org-update-project-status (n-done n-incomplete)
  "Update PROJECT_STATUS property if project cookie complete."
  (let ((current-tags (org-get-tags)))
    (if (member "project" (org-get-tags))
        (cond ((and (= n-done 0)
                    (= n-incomplete 0))
               (org-set-property "PROJECT_STATUS" "idea"))
              ((= n-incomplete 0)
               (org-set-property "PROJECT_STATUS" "closed"))
              (t
               nil)))))

    (add-hook 'org-after-todo-statistics-hook #'kb/org-update-project-status)
#+end_src

#+begin_src elisp
(setq org-todo-keywords
      (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!/!)")
              (sequence "WAITING(w@/!)" "HOLD(h)" "INACTIVE(i)" "|" "CANCELLED(c@/!)"))))

(setq org-todo-keyword-faces
      (quote (("TODO" :foreground "#9C6363" :weight bold)
              ("NEXT" :foreground "#8CD0D3" :weight bold)
              ("DONE" :foreground "#8FB28F" :weight bold)
              ("WAITING" :foreground "#DFAF8F" :weight bold)
              ("HOLD" :foreground "#DC8CC3" :weight bold)
              ("INACTIVE" :foreground "#DC8CC3" :weight bold)
              ("CANCELLED" :foreground "#8FB28F" :weight bold)
              ("PHONE" :foreground "#8FB28F" :weight bold))))

(setq org-todo-state-tags-triggers
      (quote (("CANCELLED" ("CANCELLED" . t))
              ("WAITING" ("WAITING" . t))
              ("HOLD" ("WAITING") ("HOLD" . t))
              (done ("WAITING") ("HOLD"))
              ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
              ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
              ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
#+end_src

#+begin_src elisp
(setq org-agenda-custom-commands
      (quote (("M" "3 Month" agenda "3 month view"
               ((org-agenda-span 90)))
              ("D" "Deadlines" agenda "Upcoming Deadlines over the next 3 months"
               ((org-agenda-span 90)
                (org-deadline-warning-days 90)
                (org-agenda-entry-types '(:deadline))))
              ("Y" "Holidays" agenda "Year view"
               ((org-agenda-category-filter-preset (quote ("+Holiday")))
                (org-agenda-span 'year)
                (org-agenda-time-grid nil)
                ))
              ("l" "Logbook" tags "RECORD"
               ((org-agenda--insert-overriding-header "Logbook")
                (org-tags-match-list-sublevels t)
                (org-agenda-filter-by-category (quote ("+logbook")))
                (org-agenda-span 'day)))
              ("d" "Today"
               ((agenda "" ((org-agenda-span 'day)
                            (org-deadline-warning-days 14)
                            (org-agenda-log-mode t)))
                (tags "REFILE"
                      ((org-agenda-overriding-header "Tasks to Refile:")
                       (org-tags-match-list-sublevels nil)))
                (tags-todo "-INACTIVE-HOLD-CANCELLED-ARCHIVE/!NEXT"
                           ((org-agenda-overriding-header "Next Tasks:")))
                (search "+PROJECT_STATUS {open}"
                      ((org-agenda-overriding-header "Open Projects:")
                       (org-tags-match-list-sublevels nil)))
                ()
                ("/home/kb/.cache/agenda.html")))
              ("P" . "Projects")
              ("Po" "Open Projects" search "+PROJECT_STATUS {open}")
              ("Pc" "Cancelled Projects" search "+PROJECT_STATUS {cancelled}")
              ("Pd" "Completed Projects" search "+PROJECT_STATUS {closed}")
              ("Ph" "Stuck/Held Projects" search "+PROJECT_STATUS {hold}")
              ("Pi" "Project Ideas" search "+PROJECT_STATUS {idea}")
              )))


(setq org-agenda-exporter-settings
      '((ps-number-of-columns 2)
        (ps-landscape-mode t)
        (org-agenda-add-entry-text-maxlines 5)
        (htmlize-output-type 'css)))

#+end_src

#+begin_src elisp
(defun kb/org-switch-to-current-notes-file ()
  "Open current notes file."
  (interactive)
  (find-file (concat org-directory "notes.org")))

(defun gf/create-org-path (path)
  "Create a name suitable for an org file from the last part of the file PATH."
  (let ((last (car (last (split-string (if (equal (substring path -1) "/")
                                           (substring path 0 -1) path) "/")))))
    (concat org-projects-dir "/"
            (downcase
             (replace-regexp-in-string
              "\\." "-" (if (equal (substring last 0 1) ".")
                            (substring last 1) last)))
            ".org")))

(defun kb/create-org-path (path)
  "Transform path name into suitable org file name from last part(s) of PATH.
   A new version of `gf/create-org-path'."
  (defun suitable-name (name)
    "Transform NAME into suitable name."
    (downcase
     (replace-regexp-in-string
      "\\." "-" (if (equal (substring name 0 1) ".")
                    (substring name 1) name))))
  (let* ((path-components (kb/get-qualified-project-pair path))
         (org-name (car path-components))
         (project-name (car (cdr path-components))))
    (concat org-projects-dir "/"
            (suitable-name org-name) "/"
            (suitable-name project-name) ".org")))

(defun kb/get-qualified-project-pair (project-folder)
  "Return tuple of parent and project directory for PROJECT-FOLDER."
  (let* ((path-components (split-string
                           (directory-file-name project-folder)
                           (f-path-separator)))
         (org-name (car (last path-components 2)))
         (project-name (car (last path-components))))
    (list org-name project-name)))


(defvar gf/org-project-file-override-alist '()
  "An association list of projectile directories and the project org file.
   This enables overriding the default behaviour of
   `gf/org-resolve-project-org-file'.  CAR must be an absolute path
   to a project, including a trailing slash.  CDR must be a path to
   an org file, relative to `org-directory'.
   Example:
   \'((\"/home/emacs/some-company/some-project\"
   \"projects/some-company.org\")
   \(\"/home/emacs/some-company/different-project\" \"projects/some-company.org\"))")

(defun gf/org-resolve-project-org-file ()
  "Get the path of the org file for the current project.
   This version uses Glynn Forrest's assoc list, but uses a different version of
   `create-org-path'.
   \(https://github.com/glynnforrest/emacs.d/blob/master/site-lisp/setup-org.el\)"
  (if (assoc (projectile-project-root) gf/org-project-file-override-alist)
      (concat org-directory (cadr (assoc (projectile-project-root)
                                         gf/org-project-file-override-alist)))
    (kb/create-org-path (projectile-project-root))))


(defun gf/org-switch-to-project-org-file ()
  "Switch to the org file for the current project."
  (interactive)
  (find-file (gf/org-resolve-project-org-file)))

#+end_src

#+begin_src elisp
(defun kb/org-switch-to-notes ()
  "Switch to notes.
   Open either current project notes, or default notes file"
  (interactive)
  (if (and (projectile-project-p)
           (not (equal (projectile-project-name) ".org")))
      (gf/org-switch-to-project-org-file)
    (kb/org-switch-to-current-notes-file)))
#+end_src

#+begin_src elisp
(defhydra help/hydra/timestamp (:hint nil :exit t)
  "
   _t_s:  Inactive timestamp with seconds
   _u_tc: Ianctive timestamp with seconds in UTC
   _d_:   Inactive date Local time
   "
  ("q" exit)
  ("t" help/org-time-stamp-with-seconds-now)
  ("u" help/org-time-stamp-with-seconds-now-utc)
  ("d" help/org-date))

(defun help/org-time-stamp-with-seconds-now ()
  "Insert inactive Org timestamp with seconds."
  (interactive)
  (insert (format-time-string "[%Y-%m-%d %a %H:%M:%S]")))

(defun help/org-time-stamp-with-seconds-now-utc ()
  "Insert inactive Org timestamp with seconds in UTC."
  (interactive)
  (insert (format-time-string "[%Y-%m-%d %a %H:%M:%S]" nil t)))

(defun help/org-date ()
  "Insert inactive Org date."
  (interactive)
  (insert (format-time-string "[%Y-%m-%d %a]")))

(define-key org-mode-map (kbd "C-c t") #'help/hydra/timestamp/body)
#+end_src

#+begin_src elisp
(defvar kb/org-id-ignored-filenames (list "README"
                                          "outline")
  "Base filenames to ignore when saving org files.")

(defun kb/org-id-get-create-all-items ()
  "Add ORG ID attributes to all tasks/items in the current buffer.
   https://stackoverflow.com/a/13349772/7492588
   https://stackoverflow.com/a/16247032/7492588"
  (interactive)
  (if (and (eq major-mode 'org-mode)
           (not (member (file-name-base (buffer-file-name)) kb/org-id-ignored-filenames)))
      (org-map-entries #'org-id-get-create)))

(add-hook 'org-mode-hook
          (lambda ()
            (add-hook 'before-save-hook #'kb/org-id-get-create-all-items)))
#+end_src

#+begin_src elisp
(use-package org-pomodoro
  :config
  (setq org-pomodoro-long-break-frequency 2)
  (setq org-pomodoro-ticking-sound-p nil))
#+end_src

#+begin_src elisp
(require 'org-depend)
#+end_src

#+begin_src elisp
(require 'org-dblock-gantt)
#+end_src

**** Org Mime
:PROPERTIES:
:ID:       44e6e5a4-d7e7-4089-8406-3472e11820e5
:END:

#+begin_src elisp
(use-package org-mime
  :config
  (setq org-mime-export-options '(:with-latex dvipng
                                  :section-numbers nil
                                  :with-author nil
                                  :with-toc nil))
  (setq org-mime-ascii 'utf-8))
#+end_src

**** Org Babel
:PROPERTIES:
:ID:       41d5ffaf-4b44-4436-b3ae-c4e9f9fc0cf6
:END:

#+begin_src elisp
(with-eval-after-load 'org
  (org-babel-do-load-languages
   'org-babel-load-languages
   `((clojure . t)
     (dot . t)
     (emacs-lisp . t)
     (gnuplot . t)
     (java . t)
     (js . t)
     (latex . t)
     (ledger . nil)
     (octave . t)
     (perl . t)
     (python . t)
     (R . t)
     (scheme . t)
     (screen . nil)
     (,(if (locate-library "ob-sh") 'sh 'shell) . t)
     (ocaml . t)
     (sql . t)
     (sqlite . t))))

;; (setq org-babel-python-command (expand-file-name "~/.guix-profile/bin/python"))

(defun org-babel-scheme-session-buffer (session)
  "Return the current session of SESSION otherwise nil."
  (org-babel-scheme-get-session-buffer session))

(defun org-babel-scheme-initiate-session (&optional session params)
  "Create a session named SESSION according to PARAMS."
  (let ((name (org-babel-scheme-make-session-name "" session 'guile)))
    (org-babel-scheme-set-session-buffer name (org-babel-scheme-get-repl
                                               'guile session))))

(defun org-babel-bash-initiate-session (&optional session _params)
  "Initiate a session named SESSION according to PARAMS."
  (org-babel-sh-initiate-session session _params))
#+end_src

#+begin_src elisp
(defun org-babel-execute:z3 (body params)
  "Execute Z3 on BODY formula.  Currently, we ignore PARAMS."
  (with-temp-buffer
    (insert body)
    (shell-command-on-region (point-min) (point-max) "z3 -in")))
#+end_src

**** Org Brain
:PROPERTIES:
:ID:       094c4fc2-8596-498a-bb4b-d1772e318ce1
:END:

#+begin_src elisp :tangle no
(use-package org-brain
  :init
  (setq org-brain-path (concat org-directory "/brain"))
  :config
  (bind-key "C-c b" 'org-brain-prefix-map org-mode-map)
  (push '("b" "Brain" plain (function org-brain-goto-end)
          "* %i%?" :empty-lines 1)
        org-capture-templates)
  (setq org-brain-visualize-default-choices 'all)
  (setq org-brain-title-max-length 12)
  (setq org-brain-include-file-entries nil)
  (setq org-brain-file-entries-use-title nil))
#+end_src

**** Org Roam
:PROPERTIES:
:ID:       65c42d7e-8d9c-42d9-b810-d93fc5c7f4cb
:END:

#+begin_src elisp
;;; https://systemcrafters.net/build-a-second-brain-in-emacs/5-org-roam-hacks/
;;; Bind this to C-c n I
(defun org-roam-node-insert-immediate (arg &rest args)
  (interactive "P")
  (let ((args (cons arg args))
        (org-roam-capture-templates (list (append (car org-roam-capture-templates)
                                                  '(:immediate-finish t)))))
    (apply #'org-roam-node-insert args)))
#+end_src

#+begin_src elisp
(use-package org-roam
  :init
  (setq org-roam-v2-ack t)
  :custom
  (org-roam-directory (concat org-directory "/brain"))
  :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)
         ("C-c n I" . org-roam-node-insert-immediate))
  :config
  (org-roam-setup))
#+end_src

#+begin_src elisp
(use-package org-roam-ui
  :delight
  :after org-roam
  :config
  (setq org-roam-ui-sync-theme t)
  (setq org-roam-ui-follow nil)
  (setq org-roam-ui-update-on-save t)
  (setq org-roam-ui-open-on-start nil))
#+end_src

**** Diary and Org Agenda Extras
:PROPERTIES:
:ID:       9e4a8207-5798-4dd8-b7c3-71c8f5db6f33
:END:

https://orgmode.org/worg/org-hacks.html#org790bd5a
https://orgmode.org/worg/org-hacks.html#orgf1fe951

#+begin_src elisp
(require 'cl-lib)
(require 'lunar)
(require 'solar)

(autoload 'solar-sunrise-sunset "solar.el")
(autoload 'solar-time-string "solar.el")

(setq lunar-phase-names
      '("๐ŸŒ‘ New Moon"
        "๐ŸŒ“ First Quarter Moon"
        "๐ŸŒ• Full Moon"
        "๐ŸŒ— Last Quarter Moon"))

(with-suppressed-warnings ((lexical date))
  (defvar date))
(defun kb/diary-lunar-phases ()
  "Show lunar phase in Agenda Buffer."
  (let* ((phase-list (lunar-phase-list (nth 0 date) (nth 2 date)))
         (phase (cl-find-if (lambda (phase) (equal (car phase) date))
                            phase-list)))
    (when phase
      (concat (lunar-phase-name (nth 2 phase)) " "
              (substring (nth 1 phase) 0 5)))))

(defun kb/diary-solar-sunrise ()
  "Show sunrise in Agenda Buffer."
  (let ((sunrise (car (car (solar-sunrise-sunset date)))))
    (concat "Sunrise " (solar-time-string sunrise nil))))

(defun kb/diary-solar-sunset ()
  "Show sunset in agenda buffer."
  (let ((sunset (car (cadr (solar-sunrise-sunset date)))))
    (concat "Sunset " (solar-time-string sunset nil))))
#+end_src

**** Daily Prayers
:PROPERTIES:
:ID:       5b7bda68-43f4-4cc9-a89f-b40cda3a622e
:END:

#+begin_src elisp
(use-package awqat
  :config
  (setq awqat-asr-hanafi nil)
  (awqat-set-preset-isna))
#+end_src

*** elgantt
:PROPERTIES:
:ID:       270cff5d-0d98-4bad-819c-629a6fe9d37c
:END:

#+begin_src elisp
(setq elgantt-header-type 'outline)
(setq elgantt-insert-blank-line-between-top-level-header t)
(setq elgantt-startup-folded nil)
(setq elgantt-show-header-depth t)
(setq elgantt-draw-overarching-headers t)
#+end_src

*** Communications and Such
:PROPERTIES:
:ID:       6e80a7ca-bd5e-4b64-8241-1f06f0fbbeb5
:END:

**** Auth Sources
:PROPERTIES:
:ID:       31130462-3eff-40c4-8bdb-d4c2864c5c8a
:END:

#+begin_src elisp
(use-package pass)
#+end_src

#+begin_src elisp :tangle no
(use-package helm-pass
  :after helm)
#+end_src

#+begin_src elisp
(use-package auth-source-pass
  :config
  (auth-source-pass-enable))
#+end_src

**** Org-Contacts
:PROPERTIES:
:ID:       49e301c9-cdaa-4890-a3be-34b17d050b05
:END:

#+begin_src elisp
(use-package org-contacts
  :after org
  :config
  (setq org-contacts-files (list kb/org-contacts)))
#+end_src

**** BBDB
:PROPERTIES:
:ID:       2c9fbc3f-9a6d-478b-b70e-3b21f0084d59
:END:

https://emacs-fu.blogspot.com/2009/08/managing-e-mail-addresses-with-bbdb.html

#+begin_src elisp :tangle no
(use-package bbdb
  :init
  (setq bbdb-file "~/.org/bbdb")
  (setq bbdb-offer-save 1)
  (setq bbdb-use-pop-up t)
  (setq bbdb-electric-p t)
  (setq bbdb-popup-target-lines 1)
  (setq bbdb-dwim-net-address-allow-redundancy t)
  (setq bbdb-quiet-about-name-mismatches t)
  (setq bbdb-always-add-address t)
  (setq bbdb-canonicalize-redundent-nets-p t)
  (setq bbdb-use-alternate-names t)
  (setq bbdb-completion-type nil)
  (setq bbdb-elided-display t)
  (setq bbdb/mail-auto-create-p #'bbdb-ignore-some-messages-hook)
  (setq bbdb-ignore-some-messages-alist
        (quote (("From" . "no.?reply\\|DAEMON\\|daemon\\|")))))
#+end_src

**** Email
:PROPERTIES:
:ID:       9e5814f8-b058-4f64-a6c1-3d2358cab29a
:END:

Configuration borrowed from the tutorial found here:
- https://protesilaos.com/dotemacs/#h:14cf6fea-54eb-4faa-bb16-3739485c929a
- https://github.com/redguardtoo/mastering-emacs-in-one-year-guide/blob/master/gnus-guide-en.org

#+begin_src elisp
(require 'mm-encode)
(setq mm-encrypt-option 'guided)
(setq mm-sign-option 'guided)

(require 'mml-sec)
(setq mml-secure-openpgp-encrypt-to-self t)
(setq mml-secure-openpgp-sign-with-sender nil)
(setq mml-secure-smime-encrypt-to-self t)
(setq mml-secure-smime-sign-with-sender nil)

(require 'message)
(setq mail-user-agent 'message-user-agent)
;; (setq mail-header-separator (purecopy "* * *"))
(setq compose-mail-user-agent-warnings nil)
(setq message-mail-user-agent nil)
(setq mail-signature-file "~/.signature")
(setq message-cite-function #'message-cite-original-without-signature)
(setq message-citation-line-format "On %Y-%m-%d, %R %z, %N wrote:\n")
(setq message-citation-line-function
      #'message-insert-formatted-citation-line)
(setq message-yank-cited-prefix ">")
(setq sendmail-program "msmtp")
(setq mail-specify-envelope-from t)
(setq message-sendmail-f-is-evil nil)
(setq message-sendmail-envelope-from 'header)
(setq message-confirm-send t)
(setq message-kill-buffer-on-exit t)
(setq message-wide-reply-confirm-recipients t)
(setq message-send-mail-function 'message-send-mail-with-sendmail)
(add-to-list 'mm-body-charset-encoding-alist '(utf-8 . base64))
#+end_src

**** mu4e
:PROPERTIES:
:ID:       5a1f2181-6b0f-4b78-a648-54ced20d028b
:END:

Configuration taken from the tutorial found here:
- https://vxlabs.com/2014/06/06/configuring-emacs-mu4e-with-nullmailer-offlineimap-and-multiple-identities/
- https://vxlabs.com/2017/02/07/mu4e-0-9-18-e-mailing-with-emacs-now-even-better/
- http://www.cachestocaches.com/2017/3/complete-guide-email-emacs-using-mu-and-/

#+begin_src elisp
(require 'mu4e)
(require 'mu4e-vars)
(require 'org-mu4e)
#+end_src

#+begin_src elisp :tangle no
(use-package helm-mu
  :after (mu4e helm)
  :bind (:map mu4e-main-mode-map
              ("s" . #'helm-mu)
              :map mu4e-headers-mode-map
              ("s" . #'helm-mu)
              :map mu4e-view-mode-map
              ("s" . #'helm-mu)))
#+end_src

#+begin_src elisp
(setq mu4e-compose-format-flowed nil)
(setq mu4e-use-fancy-chars t)
(setq mu4e-headers-date-format "%Y-%m-%d %H:%M")
(setq message-citation-line-format "On %Y-%m-%d %H:%M %Z, %N wrote:")
(setq message-citation-line-function #'message-insert-formatted-citation-line)
(setq mu4e-view-show-addresses t)
(setq mu4e-get-mail-command "mbsync -a")
(setq mu4e-headers-sort-field :date)
(setq mu4e-headers-sort-direction 'ascending)
(setq message-send-mail-function 'message-send-mail-with-sendmail)
(setq sendmail-program "msmtp")
(setq mail-specifiy-envelope-from t)
(setq message-sendmail-f-is-evil nil)
(setq message-sendmail-envelope-from 'header)
(setq mu4e-change-filenames-when-moving t)
(setq org-mu4e-link-query-in-headers-mode nil)
(setq message-kill-buffer-on-exit t)
(setq mu4e-context-policy 'pick-first)
(setq mu4e-confirm-quit nil)
(setq mu4e-sent-messages-behavior 'sent)
(setq mu4e-completing-read-function 'completing-read)
(setq mu4e-view-use-old nil)
(setq mu4e-headers-include-releated t)
(setq mu4e-headers-skip-duplicates t)
;; without this, "symbol's value as variable is void: mml2014-use" when signing
;; then found http://www.gnu.org/software/emacs/manual/html_node/gnus/Security.html
;; so set to epg and all was good!
;; to sign a mail: M-x mml-secure-sign-pgpmime
(setq mml2014-use 'epg)
#+end_src

#+begin_src elisp
(defun kb/msg-to-devnulllabs-p (msg)
  "Is MSG addressed to personal."
  (when msg
    (mu4e-message-contact-field-matches msg :to "\.*@devnulllabs.io\'")))

(defun kb/devnulllabs-maildir ()
  "Return base maildir for devnulllabs."
  (expand-file-name "~/.mail/devnulllabs.io/"))

(defun kb/msg-to-boisestate-p (msg)
  "Is MSG addressed to BSU account."
  (when msg
    (mu4e-message-contact-field-matches msg :to "kennyballou\.*@(u.)?boisestate.edu\'")))

(defun kb/boisestate-maildir ()
  "Return base maildir for uboisestate."
  (expand-file-name "~/.mail/u.boisestate.edu/"))

(defun kb/smart-folders-fn (folder)
  "Return a function that maps a message into the account appropriate FOLDER."
  (let (folder folder)
    (lambda (msg)
      (cond ((kb/msg-to-devnulllabs-p msg) (concat (kb/devnulllabs-maildir) folder))
            ((kb/msg-to-boisestate-p msg) (concat (kb/boisestate-maildir) folder))
            (t (concat (kb/devnulllabs-maildir) folder))))))

(setq mu4e-refile-folder (kb/smart-folders-fn "archive")
      mu4e-drafts-folder (kb/smart-folders-fn "drafts")
      mu4e-sent-folder (kb/smart-folders-fn "sent")
      mu4e-trash-folder (kb/smart-folders-fn "trash"))

(setq mu4e-user-mail-address-list '("kb@devnulllabs.io"
                                    "kballou@devnulllabs.io"
                                    "kenny@devnulllabs.io"
                                    "kennethmgballou@gmail.com"
                                    "kennyballou@u.boisestate.edu"
                                    "kennyballou@boisestate.edu"))

(setq mu4e-contexts
      `(,(make-mu4e-context
          :name "devnulllabs"
          :match-func (lambda (msg) (kb/msg-to-devnulllabs-p msg))
          :vars `((mu4e-root-maildir . ,(kb/devnulllabs-maildir))
                  (user-mail-address . "kb@devnulllabs.io")
                  (user-full-name . "Kenny Ballou")
                  (my-xpgp-key-uri . "https://kennyballou.com/932F3E8E1C0F4A9895D7B8B8B0CAA28A02958308.txt")
                  (mu4e-compose-signature . ":SIG:!0xB0CAA28A02958308!:\n")
                  (mu4e-maildir-shortcuts . ((:maildir "/devnulllabs.io/INBOX" :key ?i)
                                             (:maildir "/devnulllabs.io/archive" :key ?a)
                                             (:maildir "/devnulllabs.io/trash" :key ?t)
                                             (:maildir "/devnulllabs.io/sent" :key ?s)))
                  (mu4e-trash-folder . "/devnulllabs.io/trash")
                  (mu4e-refile-folder . "/devnulllabs.io/archive")
                  (mu4e-sent-folder . "/devnulllabs.io/sent")
                  (mu4e-drafts-folder . "/devnulllabs.io/drafts")
                  (mu4e-sent-messages-behavior . delete)))
        ,(make-mu4e-context
          :name "bsu"
          :match-func (lambda (msg) (kb/msg-to-boisestate-p msg))
          :vars `((mu4e-root-maildir . ,(kb/boisestate-maildir))
                  (user-mail-address . "kennyballou@u.boisestate.edu")
                  (user-full-name . "Kenny Ballou")
                  (my-xpgp-key-uri . "https://kennyballou.com/932F3E8E1C0F4A9895D7B8B8B0CAA28A02958308.txt")
                  (mu4e-compose-signature . ":SIG:!0xB0CAA28A02958308!:\n")
                  (mu4e-maildir-shortcuts . ((:maildir "/u.boisestate.edu/INBOX" :key ?i)
                                             (:maildir "/u.boisestate.edu/archive" :key ?a)
                                             (:maildir "/u.boisestate.edu/trash" :key ?t)
                                             (:maildir "/u.boisestate.edu/sent" :key ?s)))
                  (mu4e-trash-folder . "/u.boisestate.edu/trash")
                  (mu4e-refile-folder . "/u.boisestate.edu/archive")
                  (mu4e-sent-folder . "/u.boisestate.edu/sent")
                  (mu4e-drafts-folder . "/u.boisestate.edu/drafts")
                  (mu4e-sent-messages-behavior . delete)))
        ))

(setq mu4e-bookmarks
      '((:name "All Inboxes"
         :query "maildir:/devnulllabs.io/INBOX OR maildir:/u.boisestate.edu/INBOX"
         :key ?i)
        (:name "Unread Messages"
         :query "flag:unread AND NOT flag:trashed AND NOT (maildir:/devnulllabs.io/spam OR maildir:/u.boisestate.edu/spam)"
         :key ?u)
        (:name "Today's Messages"
         :query "date:today..now AND NOT flag:trashed and NOT (maildir:/devnulllabs.io/spam OR maildir:/u.boisestate.edu/spam)"
         :key ?t)
        (:name "Last 7 Days"
         :query "date:7d..now AND NOT flag:trashed AND NOT (maildir:/devnulllabs.io/spam OR maildir:/u.boisestate.edu/spam)"
         :hide-unread t
         :key ?w)
        (:name "Last Month"
         :query "date:30d..now AND NOT flag:trashed AND NOT (maildir:/devnulllabs.io/spam OR maildir:/u.boisestate.edu/spam)"
         :hide-unread t
         :key ?m)))

(add-hook 'mu4e-compose-mode-hook
          (lambda ()
            (set-fill-column 72)
            (flyspell-mode)
            (save-excursion
              (message-add-header (format "X-PGP-Key: %s\n"
                                          my-xpgp-key-uri)))))

;; Replace default compose with mu4e
(global-set-key (kbd "C-x m") 'mu4e-compose-new)
;; Add shortcut for _only_ updating the index
(define-key mu4e-main-mode-map (kbd "u") #'mu4e-update-index)
;; http://pragmaticemacs.com/emacs/some-useful-mu4e-shortcuts/
;; Add CC line
(define-key mu4e-compose-mode-map (kbd "C-1 c") #'message-goto-cc)

(setq mu4e-get-mail-command "mbsync -a")
#+end_src

**** gnus -- Disabled
:PROPERTIES:
:ID:       8c291c1d-a6db-41ff-8bb8-860be0afccc0
:END:

Configuration borrowed from the tutorial found here:
- https://protesilaos.com/dotemacs/#h:14cf6fea-54eb-4faa-bb16-3739485c929a
- https://github.com/redguardtoo/mastering-emacs-in-one-year-guide/blob/master/gnus-guide-en.org

#+begin_src elisp :tangle no
(require 'gnus)
(require 'gnus-sum)
(require 'gnus-dired)
(require 'gnus-topic)
(require 'nnir)

;; Override the default GNUS directories
(setq gnus-agent-directory (expand-file-name "~/.mail/gnus/agent"))
(setq gnus-article-save-directory (expand-file-name "~/.mail/gnus/"))
(setq gnus-cache-directory (expand-file-name "~/.cache/gnus/"))
(setq gnus-directory (expand-file-name "~/.mail/gnus/"))
(setq gnus-dribble-directory (expand-file-name "~/.mail/gnus/dribble"))
(setq message-directory (expand-file-name "~/.mail/gnus/mail"))
(setq mail-default-directory (expand-file-name "~/.mail/gnus/"))
(setq nndraft-directory (expand-file-name "~/.mail/gnus/drafts"))
(setq nnfolder-directory (expand-file-name "~/.mail/gnus/archive"))


(setq gnus-select-method '(nnnil ""))
(setq gnus-secondary-select-methods
      '((nnmaildir "devnulllabs" (directory "~/.mail/devnulllabs.io/"))
        ;; (gnus-search-engine gnus-search-notmuch
        ;;                     (remove-prefix "~/.mail/devnulllabs.io")))
        (nnmaildir "uboisestate" (directory "~/.mail/u.boisestate.edu/"))
        ;; (gnus-search-engine gnus-search-notmuch
        ;;                     (remove-prefix "~/.mail/u.boisestate.edu")))

        ))

(setq gnus-fetch-old-headers 'some)
(setq gnus-search-use-parsed-queries t)
(setq gnus-permanently-visible-groups ".*")
(setq gnus-search-use-parsed-queries t)
(setq gnus-gcc-mark-as-read t)
(setq gnus-agent t)
(setq gnus-novice-user nil)
(setq gnus-check-new-newsgroups 'ask-server)
(setq gnus-read-active-file 'some)
(setq gnus-use-dribble-file t)
(setq gnus-always-read-dribble-file t)
(setq gnus-agent-article-alist-save-format 1) ; uncompressed
(setq gnus-agent-cache t)
(setq gnus-agent-confirmation-function 'y-or-n-p)
(setq gnus-agent-consider-all-articles nil)
(setq gnus-agent-directory "~/.mail/gnus/agent/")
(setq gnus-agent-expire-all nil)
(setq gnus-agent-expire-days 30)
(setq gnus-agent-mark-unread-after-downloaded t)
(setq gnus-agent-queue-mail t) ; queue if unplugged
(setq gnus-agent-synchronize-flags nil)
(setq gnus-article-browse-delete-temp 'ask)
(setq gnus-article-over-scroll nil)
(setq gnus-article-show-cursor t)
(setq gnus-article-sort-functions
      '((not gnus-article-sort-by-number)
        (not gnus-article-sort-by-date)))
(setq gnus-article-truncate-lines nil)
(setq gnus-html-frame-width 80)
(setq gnus-html-image-automatic-caching t)
(setq gnus-inhibit-images t)
(setq gnus-max-image-proportion 0.7)
(setq gnus-treat-display-smileys nil)
(setq gnus-article-mode-line-format "%G %S %m")
(setq gnus-visible-headers
      '("^From:"
        "^To"
        "^Cc:"
        "^Subject:"
        "^Newsgroups":
        "^Date:"
        "Followup-To:"
        "Reply-To:"
        "^Organization:"
        "^X-Newsreader:"
        "^X-Mailer:"))
(setq gnus-sorted-header-list gnus-visible-headers)
(setq gnus-asynchronous t)
(setq gnus-use-article-prefetch 15)
(setq gnus-level-subscribed 6)
(setq gnus-level-unsubscribed 7)
(setq gnus-level-zombie 8)
(setq gnus-activate-level 1)
(setq gnus-list-groups-with-ticked-articles nil)
(setq gnus-group-sort-function
      '((gnus-group-sort-by-unread)
        (gnus-group-sort-by-alphabet)
        (gnus-group-sort-by-rank)))
(setq gnus-group-line-format "%M%p%P%5y:%B%(%g%)\n")
(setq gnus-group-mode-line-format "%%b")
(setq gnus-topic-display-empty-topics nil)
(setq gnus-auto-select-first nil)
(setq gnus-summary-ignore-duplicates t)
(setq gnus-suppress-duplicates t)
(setq gnus-save-duplicate-list t)
(setq gnus-summary-goto-unread nil)
(setq gnus-summary-make-false-root 'adopt)
(setq gnus-summary-thread-gathering-function
      'gnus-gather-threads-by-subject)
(setq gnus-summary-gather-subject-limit 'fuzzy)
(setq gnus-thread-sort-functions
      '((not gnus-thread-sort-by-date)
        (not gnus-thread-sort-by-number)))
(setq gnus-thread-hide-subtree nil)
(setq gnus-thread-ignore-subject nil)
(setq gnus-user-date-format-alist
      '(((gnus-second-today) . "Today at %R")
        ((+ (* 60 60 24) (gnus-seconds-today)) . "Yesterday, %R")
        (t . "%Y-%m-%d %R")))
(setq gnus-ignored-from-addresses "Kenny Ballou")
(setq gnus-summary-to-prefix "To: ")
(setq gnus-summary-line-format "%U%R %-18,18&user-date; %4L:%-25,25f %B%s\n")
(setq gnus-summary-mode-line-format "[%U] %p")
(setq gnus-sum-thread-tree-false-root "")
(setq gnus-sum-thread-tree-indent " ")
(setq gnus-sum-thread-tree-single-indent "")
(setq gnus-sum-thread-tree-leaf-with-other "+->")
(setq gnus-sum-thread-tree-root "")
(setq gnus-sum-thread-tree-single-leaf "\\->")
(setq gnus-sum-thread-tree-vertical "|")

(add-hook 'dired-mode-hook #'gnus-dired-mode)
;; (add-hook 'gnus-group-mode-hook #'hl-line-mode)
(add-hook 'gnus-group-mode-hook #'gnus-topic-mode)
;; (add-hook 'gnus-summary-mode-hook #'hl-line-mode)
;; (add-hook 'gnus-browse-mode-hook #'hl-line-mode)
;; (add-hook 'gnus-server-mode-hook #'hl-line-mode)
(add-hook 'gnus-select-group-hook #'gnus-group-set-timestamp)
(let ((map gnus-article-mode-map))
  (define-key map (kbd "i") #'gnus-article-show-images)
  (define-key map (kbd "s") #'gnus-mime-save-part)
  (define-key map (kbd "o") #'gnus-mime-copy-part))
(let ((map gnus-group-mode-map))
  (define-key map (kbd "n") #'gnus-group-next-group)
  (define-key map (kbd "p") #'gnus-group-prev-group)
  (define-key map (kbd "M-n") #'gnus-topic-goto-next-topic)
  (define-key map (kbd "M-p") #'gnus-topic-goto-previous-topic))
(let ((map gnus-summary-mode-map))
  (define-key map (kbd "<delete>") #'gnus-summary-delete-article)
  (define-key map (kbd "n") #'gnus-summary-next-article)
  (define-key map (kbd "p") #'gnus-summary-prev-article)
  (define-key map (kbd "N") #'gnus-summary-next-unread-article)
  (define-key map (kbd "P") #'gnus-summary-prev-unread-article)
  (define-key map (kbd "M-n") #'gnus-summary-next-thread)
  (define-key map (kbd "M-p") #'gnus-summary-prev-thread)
  (define-key map (kbd "C-M-n") #'gnus-summary-next-group)
  (define-key map (kbd "C-M-p") #'gnus-summary-prev-group)
  (define-key map (kbd "C-M-^") #'gnus-summary-refer-thread))

(defun getmail ()
  "Execute getmail in asynchronous buffer."
  (interactive)
  (let ((out-buffer (get-buffer-create "*getmail*"))
        (err-buffer (get-buffer-create "*getmail error*")))
    (async-shell-command "getmail --rcfile ~/.getmail/getmailrc --rcfile ~/.getmail/getmailuboisestate"
                         out-buffer
                         err-buffer)))

;; (setq nnmail-expiry-wait 30)
(setq nnmail-expiry-wait-function
      (lambda (group)
        (cond ((string-match-p "spam" group) 1)
              ((string-match-p "archive" group) 'never)
              (t 30))))
#+end_src
**** ERC
:PROPERTIES:
:ID:       1d2bc479-8dac-46c7-ba69-9a726968ed43
:END:

#+begin_src elisp
(setq erc-server "irc.libera.chat")
(setq erc-nick "kennyballou")
(setq erc-user-full-name "Kenny Ballou")
(setq erc-track-shorten-start 8)
(setq erc-autojoin-channels-alist '(("irc.libera-chat" "#emacs" "#guix")))
(setq erc-kill-buffer-on-part t)
(setq erc-auto-query 'bury)
#+end_src

#+begin_src elisp
(require 'erc-match)
(setq erc-echo-notices-in-minibuffer-flag t)
(setq erc-keywords '("kennyballou"))
#+end_src
**** elfeed
:PROPERTIES:
:ID:       5f76c0d2-17a2-4752-b158-74695b1e0f04
:END:

#+begin_src elisp
(use-package elfeed)

(use-package elfeed-org
  :after elfeed
  :config
  (setq rmh-elfeed-org-files (list "~/.org/elfeed.org"))
  (setq elfeed-search-filter "@12-hours-ago +unread")
  (elfeed-org))
#+end_src
**** World-Clock
:PROPERTIES:
:ID:       8e06ba9b-0911-4691-8ebe-8759197c0ca1
:END:

#+begin_src elisp
(setq zoneinfo-style-world-list
      '(("Etc/UTC" "UTC")
        ("Etc/GMT-12" "AoE")))
#+end_src

*** MultiMedia
:PROPERTIES:
:ID:       ce2d7cd7-a27a-4123-b832-8598bf24cc0a
:END:

**** MPD
:PROPERTIES:
:ID:       0757fb65-c41f-45d9-baf6-a097c5279cd5
:END:

#+begin_src elisp
(use-package mpdel
  :diminish mpdel-mode
  :init
  (setq libmpdel-hostname (format "/run/user/%d/mpd/socket" (user-uid)))
  :config
  (mpdel-mode))

(defhydra kb/hydra/mpdel (:hint nil :exit t)
  "
_SPC_:  Play/Pause                 _n_: next song      _U_: Update Database
_s_:    Stop Playback              _p_: previous song
_r_:    Randomize playback
_dr_:   Disable random playback
_R_:    Repeat placback
_dR_:   Disable repeat
"
  ("q" nil "cancel")
  ("SPC" libmpdel-playback-play-pause)
  ("s" libmpdel-stop)
  ("r" libmpdel-playback-set-random)
  ("dr" libmpdel-playback-unset-random)
  ("R" libmpdel-playback-set-repeat)
  ("dR" libmpdel-playback-unset-repeat)
  ("n" libmpdel-playback-next)
  ("p" libmpdel-playback-previous)
  ("U" libmpdel-database-update))

(define-key global-map (kbd "C-x Z h") #'kb/hydra/mpdel/body)
#+end_src

**** PDF-Tools -- disabled
:PROPERTIES:
:ID:       c61a72a2-01a7-4fae-b6ef-2a723f93aaf8
:END:

#+begin_src elisp :tangle no
(use-package pdf-tools
  :magic ("%PDF" . pdf-view-mdoe))
#+end_src

*** Init Local
:PROPERTIES:
:ID:       3bb4b7cf-7889-4add-bb21-e47ab9ad6df2
:END:

#+begin_src elisp
(require 'init-local nil t)
#+end_src

*** Locales
:PROPERTIES:
:ID:       f1c6d760-19c1-493e-8034-980aadb2aed9
:END:

#+begin_src elisp
;;; https://masteringemacs.org/article/working-coding-systems-unicode-emacs
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; backwards compatibility as default-buffer-file-coding-system
;; is deprecated in 23.2.
(if (boundp 'buffer-file-coding-system)
    (setq-default buffer-file-coding-system 'utf-8)
  (setq default-buffer-file-coding-system 'utf-8))

;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
#+end_src

#+begin_src elisp :tangle no
(use-package unicode-fonts
  :init
  (unicode-fonts-setup))
#+end_src

*** Provide Init
:PROPERTIES:
:ID:       0508985f-3cb2-4394-bc53-489b897012f8
:END:

#+begin_src elisp
(provide 'init)
;;; init.el ends here

;;; Local Variables:
;;; coding: utf-8
;;; no-byte-compile: t
;;; End:

#+end_src


* Local Variables
:PROPERTIES:
:ID:       d02c9b30-8c22-4840-a50c-18cf7bb5506b
:END:

# Local Variables:
# flycheck-disabled-checkers: '(languagetool vale)
# enable-local-eval: t
# eval: (flycheck-disable-checker 'languagetool)
# eval: (flycheck-disable-checker 'vale)
# End: