summary refs log tree commit diff stats
path: root/config.org
blob: 016207b5cbada721afcbca46c2fdefa53e52d722 (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
#+TITLE: Emacs configuration, literate-style
#+AUTHOR: Case Duckworth
#+STARTUP: overview
#+PROPERTY: header-args :results output silent

* About me

#+begin_src emacs-lisp :noweb-ref settings
  (setq user-full-name "Case Duckworth"
        user-mail-address "acdw@acdw.net")
#+end_src

** Where I am

#+begin_src emacs-lisp :noweb-ref settings
  (setq calendar-location-name "Baton Rouge, LA"
        calendar-latitude 30.4
        calendar-longitude -91.1)
#+end_src

** Auth-sources

Here feels like as good a place as any to setup =auth-sources=.  Yes, I
/need/ to use GPG.  I'll get around to it.  Until then, /please/ don't
break into my workplace and steal my secrets.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default auth-sources '("~/.authinfo"))
#+end_src

* Look and feel

** Frames

*** Initial frame setup
:PROPERTIES:
:header-args: :noweb-ref early-init-frame
:END:

I tangle this section to =early-init.el=, since that's evaluated
before GUI set-up.  Which, in turn, means Emacs will skip the "flash
of unstyled content" thing.

**** Tool bar

#+begin_src emacs-lisp
  (add-to-list 'default-frame-alist
               '(tool-bar-lines . 0))

  (tool-bar-mode -1)
#+end_src

**** Menu bar

#+begin_src emacs-lisp
  (add-to-list 'default-frame-alist
               '(menu-bar-lines . 0))

  (menu-bar-mode -1)
#+end_src

**** Scroll bars

#+begin_src emacs-lisp
  (add-to-list 'default-frame-alist
               '(vertical-scroll-bars . nil)
               '(horizontal-scroll-bars . nil))

  (scroll-bar-mode -1)
  (horizontal-scroll-bar-mode -1)
#+end_src

**** Resizing

I don't want the frame to resize when I change fonts and stuff, and I
want it to resize by pixels -- we /are/ using a GUI, after all.

#+begin_src emacs-lisp
  (setq-default frame-inhibit-implied-resize t
                frame-resize-pixelwise t)
#+end_src

**** Don't show default modeline

Wait until my *fancy* modeline is loaded -- from [[https://github.com/KaratasFurkan/.emacs.d#remove-redundant-ui][Furkan Karataş]].

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default mode-line-format nil)
#+end_src

**** Window Dividers

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default window-divider-default-places t ; bottom and right
                window-divider-default-bottom-width 2
                window-divider-default-right-width 2)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (window-divider-mode +1)
#+end_src

*** Frame titles

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default frame-title-format
                (concat invocation-name "@" (system-name)
                        ": %b %+%+ %f"))
#+end_src

*** Fringes
:PROPERTIES:
:header-args: :noweb-ref settings
:END:

I have grown to love Emacs's little fringes on the side of the
windows.  In fact, I love them so much that I really went overboard
and have made a custom fringe bitmap.

**** Indicate empty lines after the end of the buffer

#+begin_src emacs-lisp
  (setq-default indicate-empty-lines t)
#+end_src

**** Indicate the boundaries of the buffer

#+begin_src emacs-lisp
  (setq-default indicate-buffer-boundaries 'right)
#+end_src

**** Indicate continuation lines, but only on the left fringe

#+begin_src emacs-lisp
  (setq-default visual-line-fringe-indicators '(left-curly-arrow nil))
#+end_src

**** Customize fringe bitmaps

***** Curly arrows (continuation lines)

#+begin_src emacs-lisp
  (define-fringe-bitmap 'left-curly-arrow
    [#b11000000
     #b01100000
     #b00110000
     #b00011000])

  (define-fringe-bitmap 'right-curly-arrow
    [#b00011000
     #b00110000
     #b01100000
     #b11000000])
#+end_src

***** Arrows (truncation lines)

#+begin_src emacs-lisp
  (define-fringe-bitmap 'left-arrow
    [#b00000000
     #b01010100
     #b01010100
     #b00000000])

  (define-fringe-bitmap 'right-arrow
    [#b00000000
     #b00101010
     #b00101010
     #b00000000])
#+end_src

*** COMMENT Nyan mode

+Fuck it, let's have some fun.+  COMMENTED out because it messes up my
modeline :(

This obviously needs a lot more research.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'nyan-mode)
#+end_src

I add it to the modeline [[*Simple modeline][below]].

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default nyan-bar-length 20)
#+end_src

But I still have to enable the mode ?!

#+begin_src emacs-lisp :noweb-ref settings
  (nyan-mode +1)
#+end_src

** Windows

*** Splitting windows sensibly

This is extremely fiddly and I'd love another option.
- [[https://www.emacswiki.org/emacs/ToggleWindowSplit][ToggleWindowSplit, EmacsWiki]]

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default split-width-threshold 100
                split-height-threshold 50)
#+end_src

*** Switch to other window or buffer                                   :crux:

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/map (kbd "M-o") #'crux-other-window-or-switch-buffer)
#+end_src

*** The *Help* window

I want to select the *Help* window by default, so I can easily quit it.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default help-window-select t)
#+end_src



** Buffers

*** Uniquify buffers

The default way Emacs makes buffer names unique is really ugly and,
dare I say it, stupid.  Instead, I want them to be uniquified by their
filesystem paths.

#+begin_src emacs-lisp :noweb-ref requires
  (require 'uniquify)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default uniquify-buffer-name-style 'forward
                uniquify-separator "/"
                uniquify-after-kill-buffer-p t
                uniquify-ignore-buffers-re "^\\*")
#+end_src

*** Startup buffers

When Emacs starts up, I want a blank slate: the *scratch* buffer.  I
also want it to show a cute little message to myself.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default inhibit-startup-screen t ; Don't show that splash screen thing.
                initial-buffer-choice t  ; Start on *scratch*
                initial-scratch-message
                (concat ";; Howdy, "
                        (nth 0 (split-string user-full-name)) "!"
                        "  Welcome to Emacs."
                        "\n\n"))
#+end_src

*** Immortal =*scratch*= buffer

I don't want to accidentally kill the *scratch* buffer.  So, I add a
function to the =kill-buffer-query-functions= hook that will return
=nil= if the buffer is *scratch*.

#+begin_src emacs-lisp :noweb-ref functions
  (defun immortal-scratch ()
    (if (not (eq (current-buffer) (get-buffer "*scratch*")))
        t
      (bury-buffer)
      nil))
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'kill-buffer-query-functions #'immortal-scratch)
#+end_src

*** An /even better/ scratch buffer                                   :package:

The aptly-named =scratch= pops open a new scratch buffer /with the same
mode as the file you're currently editing/.  I'm pretty chuffed about
it.

I found it from [[https://old.reddit.com/r/emacs/comments/l4v1ux/one_of_the_most_useful_small_lisp_functions_in_my/][this discussion]], which might also come in handy
someday.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'scratch)
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/leader (kbd "C-x") #'scratch)
#+end_src

*** Kill buffers better

#+begin_src emacs-lisp :noweb-ref functions
  (defun kill-a-buffer (&optional prefix)
    "Kill a buffer and its window, prompting only on unsaved changes.

  `kill-a-buffer' uses the PREFIX argument to determine which buffer(s) to kill:
  0            => Kill current buffer & window
  4 (C-u)      => Kill OTHER buffer & window
  16 (C-u C-u) => Run `kill-buffer' without a prefix arg."
    (interactive "P")
    (pcase (or (car prefix) 0)
      (0 (kill-current-buffer)
         (unless (one-window-p) (delete-window)))
      (4 (other-window 1)
         (kill-current-buffer)
         (unless (one-window-p) (delete-window)))
      (16 (let ((current-prefix-arg nil))
            (kill-buffer)))))
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/map (kbd "C-x k") #'kill-a-buffer)
#+end_src

*** Kill old buffers after a while

Adapted from =midnight-mode=, using suggestions from [[https://old.reddit.com/r/emacs/comments/l6jpxf/how_do_emacs_users_usually_have_multiple_files/gl2249u/][u/ndamee]].

#+begin_src emacs-lisp :noweb-ref packages
  (require 'midnight)
#+end_src

What time I run the clean up is a little tricky for me, since I use
Emacs at work /and/ at home, and all at different times.  However, I
realized that since I close out of Emacs at work pretty much every
day, I don't need to worry about too many buffers there -- so I just
have =clean-buffer-list= run at 8:00 PM.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default acdw/clean-buffer-list-timer
                (run-at-time "20:00" 86400 #'clean-buffer-list)
                clean-buffer-list-delay-general 5
                clean-buffer-list-delay-special (* 7 24 60 60))

  (add-to-list 'clean-buffer-list-kill-buffer-names "*Completions*")
  (add-to-list 'clean-buffer-list-kill-buffer-names "*Calendar*")
#+end_src

** Cursor

*** Cursor shape

I like a vertical bar, but only in the selected window.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default cursor-type 'bar
                cursor-in-non-selected-windows nil)
#+end_src

*** Don't blink the cursor

#+begin_src emacs-lisp :noweb-ref modes
  (blink-cursor-mode -1)
#+end_src

** Tabs

*** Tab bar mode settings

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default tab-bar-show 1 ; show the tab bar when more than 1 tab
                tab-bar-new-tab-choice "*scratch*"
                tab-bar-tab-name-function
                #'tab-bar-tab-name-current-with-count)
#+end_src

*** Tab bar history

#+begin_src emacs-lisp :noweb-ref modes
  (tab-bar-history-mode +1)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default tab-bar-history-limit 25)
#+end_src

** Fonts

On Linux, I have a custom build of Iosevka that I like.

#+begin_src emacs-lisp :noweb-ref linux-specific
  (set-face-attribute 'default nil
                      :family "Iosevka Acdw"
                      :height 105)

  ;; (set-face-attribute 'fixed-pitch nil
  ;;                     :family "Iosevka Acdw"
  ;;                     :height 105)
#+end_src

But on Windows, I use Consolas.

#+begin_src emacs-lisp :noweb-ref windows-specific
  (set-face-attribute 'default nil
                      :family "Consolas"
                      :height 100)

  ;; (set-face-attribute 'fixed-pitch nil
  ;;                     :family "Consolas"
  ;;                     :height 100)
#+end_src

*** Underlines

I like the /fancy/ underlines in newer browsers that skip all the
descenders.  Emacs doesn't /quite/ have that, but it can put the
underline below all the text.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default x-underline-at-descent-line t)
#+end_src

*** Unicode fonts                                                   :package:

=unicode-fonts= pulls in some other packages that still require the
deprecated =cl= library.  So, I've forked those libraries to require
=cl-lib= instead.

**** First: un-fuck =font-utils= and =list-utils= ... and =persistent-soft=

***** List-utils

Since =font-utils= depends on =list-utils=, if I load the former first, it
pulls in the unpatched latter.  /So/ I need to do =list-utils= first.
(=*straight-process*= is your friend, y'all!)

Since =list-utils= requires =cl= in line 259 (see [[https://github.com/rolandwalker/list-utils/issues/6][this issue]], apparently
just changing it breaks many tests, but I'll run with it until Emacs
complains), I need to fork and change that to a =cl-lib=.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(list-utils
                          :host github
                          :repo "rolandwalker/list-utils"
                          :fork (:repo "duckwork/list-utils")))
#+end_src

***** Persistent-soft

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(persistent-soft
                          :host github
                          :repo "rolandwalker/persistent-soft"
                          :fork (:repo "duckwork/persistent-soft")))
#+end_src

***** Font-utils

I was able to actually create a [[https://github.com/rolandwalker/font-utils/pull/2][PR]] for this one, so fingers crossed.
Since the last update on =font-utils= was in 2015, I'm not super hopeful
that my fix will get merged upstream, but I'm using a =:fork= argument
to stay hopeful.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(font-utils
                          :host github
                          :repo "rolandwalker/font-utils"
                          :fork (:repo "duckwork/font-utils")))
#+end_src

***** A function in case it comes up again

I keep googling [[https://github.com/hlissner/doom-emacs/issues/3372][this Doom Emacs issue]], because I keep forgetting what
I need to do to see where =Package cl is deprecated= is coming from.
So... function!

#+begin_src emacs-lisp :noweb-ref functions
  ;; Make the compiler happy
  (autoload 'file-dependents "loadhist")
  (autoload 'feature-file "loadhist")

  (defun acdw/fucking-cl ()
    "Find out where the fuck `cl' is being required from."
    (interactive)
    (require 'loadhist)
    (message "%S" (file-dependents (feature-file 'cl))))
#+end_src

**** Unicode-fonts

/Okay/ ... pull requests in, time to load =unicode-fonts=.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(unicode-fonts
                          :host github
                          :repo "rolandwalker/unicode-fonts"))
  (require 'unicode-fonts)
#+end_src

According to [[https://github.com/rolandwalker/unicode-fonts/issues/3][Issue #3]], there can be problems with =unicode-fonts-setup=
when using a daemon.  Instead of forking this repo and merging [[https://github.com/rolandwalker/unicode-fonts/pull/4][PR #4]]
into my personal fork, I'll use the workaround described in the
issue.

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--unicode-fonts-setup (frame)
    "Run `unicode-fonts-setup', then remove the hook."
    (select-frame frame)
    (unicode-fonts-setup)
    (remove-hook 'after-make-frame-functions #'hook--unicode-fonts-setup))

  (add-hook 'after-make-frame-functions #'hook--unicode-fonts-setup)
#+end_src

*** Draw form-feeds (=^L=) properly                                   :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'form-feed)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (global-form-feed-mode +1)
  (blackout 'form-feed-mode)
#+end_src

** Theming

*** Modus themes                                                    :package:

I want the git version.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(modus-themes
                          :host gitlab
                          :repo "protesilaos/modus-themes"))
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default modus-themes-slanted-constructs t
                modus-themes-bold-constructs t
                modus-themes-region 'bg-only
                modus-themes-org-blocks 'grayscale
                modus-themes-headings '((1 . line)
                                        (t . t))
                modus-themes-scale-headings nil
                modus-themes-mode-line 'borderless-3d)
#+end_src

*** Change themes based on time of day

#+begin_src emacs-lisp :noweb-ref functions
  (defun acdw/run-with-sun (sunrise-command sunset-command)
    "Run commands at sunrise and sunset."
    (let* ((times-regex (rx (* nonl)
                            (: (any ?s ?S) "unrise") " "
                            (group (repeat 1 2 digit) ":"
                                   (repeat 1 2 digit)
                                   (: (any ?a ?A ?p ?P) (any ?m ?M)))
                            (* nonl)
                            (: (any ?s ?S) "unset") " "
                            (group (repeat 1 2 digit) ":"
                                   (repeat 1 2 digit)
                                   (: (any ?a ?A ?p ?P) (any ?m ?M)))
                            (* nonl)))
           (ss (sunrise-sunset))
           (_m (string-match times-regex ss))
           (sunrise-time (match-string 1 ss))
           (sunset-time (match-string 2 ss)))
      (run-at-time sunrise-time (* 60 60 24) sunrise-command)
      (run-at-time sunset-time (* 60 60 24) sunset-command)))
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (acdw/run-with-sun #'modus-themes-load-operandi
                     #'modus-themes-load-vivendi)
#+end_src

*** Mode line

**** Simple modeline                                                :package:

After trying =doom-mode-line= and =smart-mode-line=, I think I've finally
landed on a good one: =simple-modeline=.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'simple-modeline)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default simple-modeline-segments
                '(;; left side
                  (simple-modeline-segment-modified
                   simple-modeline-segment-buffer-name
                   simple-modeline-segment-position)
                  ;; right side
                  (simple-modeline-segment-minor-modes
                   simple-modeline-segment-input-method
                   simple-modeline-segment-vc
                   simple-modeline-segment-misc-info
                   simple-modeline-segment-process
                   simple-modeline-segment-major-mode)))
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (simple-modeline-mode +1)
#+end_src

***** COMMENT Functions to figure out what window is focused

How is this not built into Emacs?  Oh well, I have [[https://github.com/jamesnvc/dotfiles/blob/master/emacs.d/modules/cogent-modeline.el][Cogent]] to thank.

#+begin_src emacs-lisp :noweb-ref variables
  (defvar cogent-line-selected-window (frame-selected-window))
#+end_src

#+begin_src emacs-lisp :noweb-ref functions
  (defun cogent-line-set-selected-window (&rest _args)
    (when (not (minibuffer-window-active-p (frame-selected-window)))
      (setq cogent-line-selected-window (frame-selected-window))
      (force-mode-line-update)))

  (defun cogent-line-unset-selected-window ()
    (setq cogent-line-selected-window nil)
    (force-mode-line-update))

  (defun cogent-line-selected-window-active-p ()
    (eq cogent-line-selected-window (selected-window)))
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'window-configuration-change-hook #'cogent-line-set-selected-window)
  (add-hook 'focus-in-hook #'cogent-line-set-selected-window)
  (add-hook 'focus-out-hook #'cogent-line-unset-selected-window)
  (advice-add 'handle-switch-frame :after #'cogent-line-set-selected-window)
  (advice-add 'select-window :after #'cogent-line-set-selected-window)
#+end_src

**** Blackout some modes                                            :package:

Like =diminish= or =delight=, =blackout= allows me to remove some
minor-modes from the modeline.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(blackout
                          :host github
                          :repo "raxod502/blackout"))
#+end_src

*** Setting faces

It took me a while to find a function that'll let me customize faces
/without/ using *customize*.  Thanks to [[https://www.emacswiki.org/emacs/CustomizingFaces#toc5][Drew Adams]], I've got it!

#+begin_src emacs-lisp :noweb-ref functions
  (defun doremi-face-set (face spec)
    "Tell Customize that FACE has been set to value SPEC.
    SPEC is as for `defface'."
    (put face 'customized-face spec)
    (face-spec-set face spec)
    (message "Customized face %s." (symbol-name face)))
#+end_src

* Interactivity

** Dialogs and alerts

*** Don't use a dialog box

Ask in the modeline instead.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default use-dialog-box nil)
#+end_src

*** Yes or no questions

I just want to type =y= or =n=, okay?

#+begin_src emacs-lisp :noweb-ref functions
  (fset 'yes-or-no-p #'y-or-n-p)
#+end_src

*** The Bell

The only system I /sort of/ like the bell on is my Thinkpad, which
does a little on-board speaker beep.  Until I can figure out how to
let it do its thing, though, I'll just change the bell on all my
systems.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default visible-bell nil
                ring-bell-function #'flash-mode-line)
#+end_src

**** Flash the mode-line

#+begin_src emacs-lisp :noweb-ref functions
  (defun flash-mode-line ()
    (invert-face 'mode-line)
    (run-with-timer 0.2 nil #'invert-face 'mode-line))
#+end_src

** Minibuffer

*** Keep the cursor away from the  minibuffer prompt

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default minibuffer-prompt-properties
                '(read-only t
                  cursor-intangible t
                  face minibuffer-prompt))
#+end_src

*** Enable a recursive minibuffer

#+begin_src emacs-lisp :noweb-ref
  (setq-default enable-recursive-minibuffers t)
#+end_src

*** Show the recursivity of the minibuffer in the mode-line

#+begin_src emacs-lisp :noweb-ref modes
  (minibuffer-depth-indicate-mode +1)
#+end_src

** Completing-read

*** Shadow file names

When typing =~= or =/= in the file-selection dialog, Emacs "pretends"
that you've typed them at the beginning of the line. By default,
however, it only /fades out/ the previous contents of the line. I want
to /hide/ those contents.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default file-name-shadow-properties '(invisible t))
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (file-name-shadow-mode +1)
#+end_src

*** Ignore case

#+begin_src emacs-lisp :noweb-ref
  (setq-default completion-ignore-case t
                read-buffer-completion-ignore-case t
                read-file-name-completion-ignore-case t)
#+end_src

*** Selectrum                                                       :package:

My minibuffer completion system uses =selectrum=, =prescient=, =company=,
and =marginalia=.  At some point, I'd like to take a deep dive in =embark=
(possibly switching out =selectrum=), =ido=, =orderless=, or others,
for now .... I just want to see my completions.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'selectrum)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (selectrum-mode +1)
#+end_src

*** Prescient                                                       :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'prescient)
  (require 'prescient)
#+end_src

Prescient can persist itself too.

#+begin_src emacs-lisp :noweb-ref modes
  (prescient-persist-mode +1)
#+end_src

**** Selectrum integration

Let's have =prescient= and =selectrum= work together.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'selectrum-prescient)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (with-eval-after-load 'selectrum
    (selectrum-prescient-mode +1))
#+end_src

*** Consult                                                         :package:

#+begin_src emacs-lisp :noweb-ref modes
  (straight-use-package 'consult)
  (require 'consult)
#+end_src

Consult has a lot of great bindings that work well with Emacs's
default completion system.  These all come from the [[https://github.com/minad/consult#configuration][example configuration]].

#+begin_src emacs-lisp :noweb-ref bindings
  (with-eval-after-load 'consult
    ;; C-c bindings (`mode-specific-map')
    (define-key acdw/map (kbd "C-c h") #'consult-history)
    (define-key acdw/map (kbd "C-c m") #'consult-mode-command)
    ;; C-x bindings (`ctl-x-map')
    (define-key acdw/map (kbd "C-x M-:") #'consult-complex-command)
    (define-key acdw/map (kbd "C-x b") #'consult-buffer)
    (define-key acdw/map (kbd "C-x 4 b") #'consult-buffer-other-window)
    (define-key acdw/map (kbd "C-x 5 b") #'consult-buffer-other-frame)
    (define-key acdw/map (kbd "C-x r x") #'consult-register)
    (define-key acdw/map (kbd "C-x r b") #'consult-bookmark)
    ;; M-g bindings (`goto-map')
    (define-key acdw/map (kbd "M-g g") #'consult-line)
    (define-key acdw/map (kbd "M-g M-g") #'consult-line)
    (define-key acdw/map (kbd "M-g o") #'consult-outline)
    (define-key acdw/map (kbd "M-g m") #'consult-mark)
    (define-key acdw/map (kbd "M-g k") #'consult-global-mark)
    (define-key acdw/map (kbd "M-g i") #'consult-imenu)
    (define-key acdw/map (kbd "M-g e") #'consult-error)
    ;; M-s bindings (`search-map')
    (define-key acdw/map (kbd "M-s g") #'consult-grep) ; alts:
                                          ; consult-git-grep,
                                          ; consult-ripgrep
    (define-key acdw/map (kbd "M-s f") #'consult-find) ; alts:
                                          ; consult-locate
    (define-key acdw/map (kbd "M-s l") #'consult-line)
    (define-key acdw/map (kbd "M-s m") #'consult-multi-occur)
    (define-key acdw/map (kbd "M-s k") #'consult-keep-lines)
    (define-key acdw/map (kbd "M-s u") #'consult-focus-lines)
    ;; Other bindings
    (define-key acdw/map (kbd "M-y") #'consult-yank-pop)
    (define-key acdw/map (kbd "<f1> a") #'consult-apropos)
    (define-key acdw/map (kbd "C-h a") #'consult-apropos))
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (autoload 'consult-register-preview "consult") ; make the compiler happy
  (setq-default register-preview-delay 0
                register-preview-function #'consult-register-preview)
#+end_src

*** Marginalia                                                      :package:

Finally, =marginalia= provides extra information about completion
candidates.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'marginalia)
  (require 'marginalia)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (marginalia-mode +1)
#+end_src

I like the rich annotations provided by =marginalia=.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default marginalia-annotators
                '(marginalia-annotators-heavy
                  marginalia-annotators-light
                  nil))
#+end_src

**** Integration with Selectrum

#+begin_src emacs-lisp :noweb-ref functions
  (advice-add #'marginalia-cycle :after
              (lambda ()
                (when (bound-and-true-p selectrum-mode)
                  (selectrum-exhibit))))
#+end_src

** Imenu

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default imenu-auto-rescan t)
#+end_src

** Completion

*** Hippie Expand

Before I install any completion framework, I want a good default for
completing.  =hippie-expand= fills that niche.

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/map (kbd "M-/") #'hippie-expand)
#+end_src

** Bindings

*** Acdw Mode

I've decided to set up a custom minor mode for my keybindings, as
suggested in [[https://github.com/larstvei/dot-emacs#key-bindings][Lars Tvei]]'s config, so that I can override all other
modes with my own keybindings.  Plus I can easily turn it off and back
on as I please.

#+begin_src emacs-lisp :noweb-ref acdw-mode
  (defvar acdw/map (make-sparse-keymap)
    "A keymap for my custom bindings.")

  (define-minor-mode acdw/mode
      "A mode for `acdw/map'."
    :init-value t
    :lighter " ⱷ"
    :keymap acdw/map)

  (define-globalized-minor-mode acdw/global-mode acdw/mode acdw/mode)
#+end_src

**** Turn off acdw/mode in the minibuffer

#+begin_src emacs-lisp :noweb-ref acdw-mode
  (defun acdw/mode--disable ()
    "Turn off acdw/mode."
    (acdw/mode -1))

  (add-hook 'minibuffer-setup-hook #'acdw/mode--disable)
#+end_src

**** Custom leader

Since =C-z= is generally pretty useless in Emacs (minimize the window?
really?), I rebind it to be a sort of personal leader key.  I
generally use it as a leader for entering applications.

#+begin_src emacs-lisp :noweb-ref acdw-mode
  (defvar acdw/leader
    (let ((map (make-sparse-keymap))
          (c-z (global-key-binding "\C-z")))
      ;(global-unset-key "\C-z")
      (define-key acdw/map "\C-z" map)
      (define-key map "\C-z" c-z)
      map))

  ;; Just in case I want to run hooks after defining the leader map
  (run-hooks 'acdw/leader-defined-hook)
#+end_src

*** Show keybindings with =which-key=                                 :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'which-key)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (which-key-mode +1)
  (blackout 'which-key-mode)
#+end_src

** Scrolling

According to [[https://github.com/mpereira/.emacs.d#make-cursor-movement-an-order-of-magnitude-faster][Murilo Pereira]], these settings will make Emacs scrolling
"an order of magnitude faster."

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default auto-window-vscroll nil
                fast-but-imprecise-scrolling t)
#+end_src

** Enable commands

I think the /disabled command/ feature of Emacs is stupid, especially
for a program that values freedom so much.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default disabled-command-function nil)
#+end_src

** CRUX                                                        :package:crux:

A collection of generally-useful functions that I don't want to bother
including here myself.  This is kind of an experiment, to be honest.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(crux
                          :host github
                          :repo "bbatsov/crux"))
  (require 'crux)
#+end_src

A note: I /don't/ do the same with [[https://github.com/alphapapa/unpackaged.el][unpackaged]] (see below, specifically
the *Org* sections) because it pulls in =hydra= and =use-package=, et al.

* Persistence

** Minibuffer history

The =savehist= package saves minibuffer history between sessions, as
well as the option for some other variables.  Since storage is cheap,
I keep all of it.

#+begin_src emacs-lisp :noweb-ref requires
  (require 'savehist)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (setq-default savehist-additional-variables
                '(kill-ring
                  search-ring
                  regexp-search-ring)
                history-length t ; Don't truncate
                history-delete-duplicates t
                savehist-autosave-interval 60)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (savehist-mode +1)
#+end_src

** File places

The =saveplace= package saves where I've been in my visited files.

#+begin_src emacs-lisp :noweb-ref requires
  (require 'saveplace)
#+end_src

Since storage is cheap, but I'm impatient -- especially on Windows --
I'm not going to check whether the files =save-place= saves the places
of are readable or not when I'm not at home.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default save-place-forget-unreadable-files
                (memq system-type '(gnu gnu/linux gnu/kfreebsd)))
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (save-place-mode +1)
#+end_src

** Recent files

I also like to keep track of recently-opened files.  =recentf= helps
with that.

#+begin_src emacs-lisp :noweb-ref requires
  (require 'recentf)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default recentf-max-menu-items 100
                recentf-max-saved-items nil
                recentf-auto-cleanup 'never)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (recentf-mode +1)
#+end_src

I also want to ignore the =no-littering-var-directory= and
=no-littering-etc-directory=, since those aren't useful.

#+begin_src emacs-lisp :noweb-ref no-littering
  (add-to-list 'recentf-exclude no-littering-var-directory)
  (add-to-list 'recentf-exclude no-littering-etc-directory)
#+end_src

*** Save the recentf list periodically

#+begin_src emacs-lisp :noweb-ref functions
  (defun maybe-save-recentf ()
    "Save `recentf-file' every five minutes, but only when out of focus."
    (defvar recentf--last-save (time-convert nil 'integer)
      "When we last saved the `recentf-save-list'.")

    (when (> (time-convert (time-since recentf--last-save) 'integer)
             (* 60 5))
      (setq-default recentf--last-save (time-convert nil 'integer))
      (when-unfocused #'recentf-save-list)))
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (add-function :after after-focus-change-function
                #'maybe-save-recentf)
#+end_src

* Responsiveness

Emacs has a slew of well-documented problems with snappiness.
Luckily, there are a number of solutions.

** Only do things when unfocused

Sometimes, we can fake responsiveness by only performing commands when
the user is looking at something else.

#+begin_src emacs-lisp :noweb-ref functions
  (defun when-unfocused (func &rest args)
    "Run FUNC, with ARGS, iff all frames are out of focus."
    (when (seq-every-p #'null (mapcar #'frame-focus-state (frame-list)))
      (apply func args)))
#+end_src

** Garbage collection

*** Garbage Collection Magic Hack                                   :package:

Look, I'm not going to look too deeply into this.  It's /magic/ afer
all.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'gcmh)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (gcmh-mode +1)
  (blackout 'gcmh-mode)
#+end_src

*** Garbage Collect when out of focus

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--gc-when-unfocused ()
    (when-unfocused #'garbage-collect))

  (add-function :after after-focus-change-function
                #'hook--gc-when-unfocused)
#+end_src

* Files

** Encoding

*** UTF-8

It's 2020.  Let's encode files like it is.

#+begin_src emacs-lisp :noweb-ref settings
  (prefer-coding-system 'utf-8)
  (set-default-coding-systems 'utf-8)
  (set-terminal-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8)
  (set-language-environment "UTF-8")

  (setq-default locale-coding-system 'utf-8
                buffer-file-coding-system 'utf-8
                x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
#+end_src

*** UNIX-style line endings

This function is from the [[https://www.emacswiki.org/emacs/EndOfLineTips][Emacs Wiki]].

#+begin_src emacs-lisp :noweb-ref functions
  (defun ewiki/no-junk-please-were-unixish ()
    "Convert line endings to UNIX, dammit."
    (let ((coding-str (symbol-name buffer-file-coding-system)))
      (when (string-match "-\\(?:dos\\|mac\\)$" coding-str)
        (set-buffer-file-coding-system 'unix))))
#+end_src

I add it to both =file-find-hook= /and/ =before-save-hook= because I'm
/that/ over it.  I don't want to ever work with anything other than
UNIX line endings ever again. I just don't care. Even Microsoft
Notepad can handle UNIX line endings, so I don't want to hear it.

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'find-file-hook #'ewiki/no-junk-please-were-unixish)
  (add-hook 'before-save-hook #'ewiki/no-junk-please-were-unixish)
#+end_src

** Keep =~/.emacs.d= clean                                            :package:

#+begin_src emacs-lisp :noweb-ref packages :noweb yes
  (straight-use-package 'no-littering)
  (require 'no-littering)
  (with-eval-after-load 'no-littering
    <<no-littering>>
    ) ; end of no-littering
#+end_src

** Backups

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default backup-by-copying t
                ;; Don't delete old versions
                delete-old-versions -1
                ;; Make numeric backups unconditionally
                version-control t
                ;; Also backup files covered by version control
                vc-make-backup-files t)
#+end_src

#+begin_src emacs-lisp :noweb-ref no-littering
  (let ((dir (no-littering-expand-var-file-name "backup")))
    (make-directory dir :parents)
    (setq-default backup-directory-alist
                  `((".*" . ,dir))))
#+end_src

** Autosaves                                                        :package:

I don't use the =auto-save= system, preferring instead to use
Bozhidar Batsov's [[https://github.com/bbatsov/super-save][super-save]] package.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default auto-save-default nil)

  (setq-default super-save-remote-files nil
                super-save-exclude '(".gpg")
                super-save-auto-save-when-idle t)
#+end_src

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'super-save)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (super-save-mode +1)
  (blackout 'super-save-mode)
#+end_src

** Lockfiles

I don't think these are really necessary as of now.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default create-lockfiles nil)
#+end_src

** Auto-revert files

I like to keep the buffers Emacs has in-memory in sync with the actual
contents of the files the represent on-disk.  Thus, we have
=auto-revert-mode=.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default auto-revert-verbose nil)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (global-auto-revert-mode +1)
#+end_src

* Editing

** Lines

*** Fill-column

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default fill-column 80)
#+end_src

By default, Emacs uses =C-x f= to set the =fill-column=.  I think it's
pretty dumb that such an easy-to-reach binding (for Emacs) is set to a function
that I /literally/ never use.  So I'm going to bind it to =find-file= ... since
that's the only time I accidentally call it, anyway.

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/map (kbd "C-x f") #'find-file)
#+end_src

*** Auto-fill vs. Visual-line

1. Enable =auto-fill-mode= with text modes.

   #+begin_src emacs-lisp :noweb-ref hooks
     (add-hook 'text-mode-hook #'auto-fill-mode)
   #+end_src

2. /Just/ in case ... let's "fix" =visual-line-mode= if we're in =org-mode=.

   #+begin_src emacs-lisp :noweb-ref hooks
     (defun hook--visual-line-fix-org-keys ()
       (when (derived-mode-p 'org-mode)
         (local-set-key (kbd "C-a") #'org-beginning-of-line)
         (local-set-key (kbd "C-e") #'org-end-of-line)
         (local-set-key (kbd "C-k") #'org-kill-line)))

     (add-hook 'visual-line-mode-hook #'hook--visual-line-fix-org-keys)
  
   #+end_src

I think that'll work -- I only care about line aesthetics with text.
Programming modes should be /allowed/ to have long lines, regardless
of how /terrible/ it is to have them.

*** Visual fill column mode

In reading-intensive views, this mode keeps the text from getting too
wide.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'visual-fill-column)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default visual-fill-column-center-text t)
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'visual-fill-column-mode-hook #'visual-line-mode)

  (with-eval-after-load 'visual-fill-column
    (advice-add 'text-scale-adjust :after #'visual-fill-column-adjust))
#+end_src

*** Stay snappy with long-lined files

#+begin_src emacs-lisp :noweb-ref modes
  (when (fboundp 'global-so-long-mode)
    (global-so-long-mode +1))
#+end_src

** Whitespace

*** Whitespace style

The =whitespace-style= defines what kinds of whitespace to clean up on
=whitespace-cleanup=, as well as what to highlight (if that option is
enabled).

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default whitespace-style '(empty ; remove blank lines at buffer edges
                                   indentation ; clean up indentation
                                   ;; fix mixed spaces and tabs
                                   space-before-tab
                                   space-after-tab))
#+end_src

*** Clean up whitespace on save

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'before-save-hook #'whitespace-cleanup)
#+end_src

*** Don't use TABs

I was team TAB for a while, but I find them easier to avoid in Emacs.
It manages my whitespace for me, anyway.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default indent-tabs-mode nil)
#+end_src

** Killing & Yanking

*** Replace the selection when typing

#+begin_src emacs-lisp :noweb-ref modes
  (delete-selection-mode +1)
#+end_src

*** Work better with the system clipboard

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default
   ;; Save existing clipboard text to the kill ring before replacing it.
   save-interprogram-paste-before-kill t
   ;; Update the X selection when rotating the kill ring.
   yank-pop-change-selection t
   ;; Enable clipboards
   x-select-enable-clipboard t
   x-select-enable-primary t
   ;; Copy a region when it's selected with the mouse
   mouse-drag-copy-region t)
#+end_src

*** Don't append the same thing twice to the kill ring

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default kill-do-not-save-duplicates t)
#+end_src

*** Kill the line if there is no region                                :crux:

#+begin_src emacs-lisp :noweb-ref hooks
  (crux-with-region-or-line kill-ring-save)
  (crux-with-region-or-line kill-region)
#+end_src

** Overwrite mode

*** Change the cursor

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--overwrite-mode-change-cursor ()
    (setq cursor-type (if overwrite-mode t 'bar)))

  (add-hook 'overwrite-mode-hook #'hook--overwrite-mode-change-cursor)
#+end_src

** The Mark

*** Repeat popping the mark without repeating the prefix argument

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default set-mark-repeat-command-pop t)
#+end_src

** Undo                                                               :package:

*** Undo Fu

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'undo-fu)
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/map (kbd "C-/") #'undo-fu-only-undo)
  (define-key acdw/map (kbd "C-?") #'undo-fu-only-redo)
#+end_src

*** Undo Fu session

I'm not putting this in [[*Persistence]] because it'd be confusing away
from =undo-fu=.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'undo-fu-session)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default undo-fu-session-incompatible-files
                '("/COMMIT_EDITMSG\\'"
                  "/git-rebase-todo\\'"))
#+end_src

#+begin_src emacs-lisp :noweb-ref no-littering
  (let ((dir (no-littering-expand-var-file-name "undos")))
    (make-directory dir :parents)
    (setq-default undo-fu-session-directory dir))
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (global-undo-fu-session-mode +1)
#+end_src

** Search/Replace                                                     :package:

The /biggest/ thing I miss about my Neovim days is its ease of
search/replace.  It didn't matter where the point was in the buffer;
it could wrap around.  It had a little highlight to show you all the
matching strings, /and/ it could show you what the replacement would
look like.  =anzu= does /most/ of this, except the wrapping around part --
=ctrlf= does the wrapping around okay, but I haven't really tried to get
the two packages to play nice together.  Until then, I'll just use
=anzu= and =isearch=, which is honestly a pretty good search package.

*** Anzu setup

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'anzu)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default anzu-mode-lighter "" ; hide anzu-mode in the modeline
                anzu-replace-to-string-separator " → ")

  ;; Set up anzu in the modeline
  (setq-default anzu-cons-mode-line-p nil)
  (setcar (cdr (assq 'isearch-mode minor-mode-alist))
          '(:eval (concat " " (anzu--update-mode-line))))
#+end_src

*** Regex

I search with regex by default.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default
   ;; Search Regex by default
   search-default-mode t)
#+end_src

I've switched =query-replace= and =query-replace-regexp= with their anzu
versions, because of the regex thing.

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/map [remap query-replace] #'anzu-query-replace-regexp)
  (define-key acdw/map [remap query-replace-regexp] #'anzu-query-replace)

  (define-key isearch-mode-map [remap isearch-query-replace]
    #'anzu-isearch-query-replace)
  (define-key isearch-mode-map [remap isearch-query-replace-regexp]
    #'anzu-isearch-query-replace-regexp)
#+end_src

** Commenting                                                            :crux:

I don't think the default =M-;= (=M-x comment-dwim=) binding makes sense.
I want it to comment out the region or line, or uncomment it if it's
already commented.  That's it.

#+begin_src emacs-lisp :noweb-ref hooks
  (crux-with-region-or-line comment-or-uncomment-region)
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/map (kbd "M-;") #'comment-or-uncomment-region)
#+end_src

* Writing

** COMMENT Word count                                               :package:

I'm just going to comment this out for right now because I honestly
don't know if it's that useful.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'wc-mode)
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--wc-mode-no-keybinds ()
    (wc-mode +1)
    (define-key wc-mode-map (kbd "C-c C-w w") nil)
    (define-key wc-mode-map (kbd "C-c C-w l") nil)
    (define-key wc-mode-map (kbd "C-c C-w a") nil)
    (define-key wc-mode-map (kbd "C-c C-w c") nil))

  (add-hook 'text-mode-hook #'hook--wc-mode-no-keybinds)
#+end_src

** Spell checking

Let's use =hunspell=.

#+begin_src emacs-lisp :noweb-ref packages
  (with-eval-after-load "ispell"
    (setenv "LANG" "en_US")
    (setq-default ispell-program-name "hunspell"
                  ispell-dictionary "en_US")
    (ispell-set-spellchecker-params))

  (setq ispell-personal-dictionary "~/.hunspell_personal")
  (unless (file-exists-p ispell-personal-dictionary)
    (write-region "" nil ispell-personal-dictionary nil 0))
#+end_src

* Programming

** Comments

*** Auto fill comments in programming modes

Okay, so I lied in the [[*Auto-fill vs. Visual-line][Auto-fill vs. Visual-line]] section.  I /do/ want
to auto-fill in programming modes, but /only/ the comments.

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--comment-auto-fill ()
    (setq-local comment-auto-fill-only-comments t)
    (auto-fill-mode +1))

  (add-hook 'prog-mode-hook #'hook--comment-auto-fill)
#+end_src

** Parentheses

*** Show parentheses

#+begin_src emacs-lisp :noweb-ref modes
  (show-paren-mode +1)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default show-paren-delay 0
                ;; Show the matching paren if visible, else the whole expression
                show-paren-style 'mixed)
#+end_src

*** Smart parens                                                    :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'smartparens)
  (require 'smartparens-config)
#+end_src

**** Show parens

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default sp-show-pair-delay 0
                sp-show-pair-from-inside t)
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'prog-mode-hook #'show-smartparens-mode)
#+end_src

**** Hide the =smartparens= lighter

#+begin_src emacs-lisp :noweb-ref modes
  (blackout 'smartparens-mode)
#+end_src

**** Be strict in =prog-mode=

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'prog-mode-hook #'smartparens-strict-mode)
#+end_src

**** Use =paredit= bindings

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default sp-base-keybindings 'paredit)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (with-eval-after-load 'smart-parens
    (sp-use-paredit-bindings))
#+end_src

** Formatting

*** Aggressive indent                                               :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'aggressive-indent)
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (global-aggressive-indent-mode +1)
  (blackout 'aggressive-indent-mode)
#+end_src

Since aggressive indenting takes care of tabs, I can use =<TAB>= to complete
things!

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default tab-always-indent 'complete)
#+end_src

** Typesetting

*** Prettify-mode

I like my pretty =lambda='s -- and maybe one day, I'll add more symbols,
but only in prog-mode.  I want to see what I'm actually typing in
text.

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'prog-mode-hook #'prettify-symbols-mode)
#+end_src

Of course, I want to be able to /see/ the actual text in the buffer if
I'm /in/ the symbols.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default prettify-symbols-unprettify-at-point 'right-edge)
#+end_src

** Executable scripts

This poorly-named function will make a file executable if it looks
like a script (looking at the function definition, it looks like it
checks for a shebang).

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'after-save-hook
            #'executable-make-buffer-file-executable-if-script-p)
#+end_src

** Compilation

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default compilation-ask-about-save nil ; just save
                compilation-always-kill t ; kill the old processes
                compilation-scroll-output 'first-error)
#+end_src

** Language-specific

*** Emacs Lisp

**** Don't limit the length of evaluated expressions

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default eval-expression-print-length nil
                eval-expression-print-level nil)
#+end_src

**** Indent Elisp like Common Lisp

#+begin_src emacs-lisp :noweb-ref requires
  (require 'cl-lib)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default lisp-indent-function #'common-lisp-indent-function)
  (put 'cl-flet 'common-lisp-indent-function
       (get 'flet 'common-lisp-indent-function))
  (put 'cl-labels 'common-lisp-indent-function
       (get 'labels 'common-lisp-indent-function))
  (put 'if 'common-lisp-indent-function 2)
  (put 'dotimes-protect 'common-lisp-indent-function
       (get 'when 'common-lisp-indent-function))
#+end_src

* Applications

Emacs is well-known for its ability to subsume one's entire computing
life.  There are a few /killer apps/ that make Emacs really shine.
Here, I configure them and a few others.

My rubric for what makes a package an application, versus just a
package, is mostly based on the way I feel about it.  Don't expect to
agree with all of my choices.

** Web browsing

*** Browse-url

I like using Firefox.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default browse-url-browser-function 'browse-url-firefox
                browse-url-new-window-flag t
                browse-url-firefox-new-window-is-tab t)
#+end_src

At work, I need to tell Emacs where Firefox is.

#+begin_src emacs-lisp :noweb-ref windows-specific
  (add-to-list 'exec-path "C:/Program Files/Mozilla Firefox")
#+end_src

** Dired

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--dired-mode ()
    (hl-line-mode +1)
    (dired-hide-details-mode +1))

  (add-hook 'dired-mode-hook #'hook--dired-mode)
#+end_src

A note on =dired-listing-switches=: when I'm able to figure out how to
move up a directory with a keybinding, I'll change =-a= to =-A=.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default dired-recursive-copies 'always
                dired-recursive-deletes 'always
                delete-by-moving-to-trash t
                dired-listing-switches "-AFgho --group-directories-first"
                dired-dwim-target t)
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/map (kbd "C-x C-j") #'dired-jump)
#+end_src

*** Expand subtrees                                                 :package:

Instead of opening each folder in its own buffer, =dired-subtree=
enables me to open them in the same buffer, fancily indented.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'dired-subtree)
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (with-eval-after-load 'dired
    (define-key dired-mode-map "i" #'dired-subtree-toggle))
#+end_src

*** Collapse singleton directories                                  :package:

If a directory only has one item in it, =dired-collapse= shows what
that one item is.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'dired-collapse)
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'dired-mode-hook #'dired-collapse-mode)
#+end_src

** Git                                                                :package:

*** Magit

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'magit)
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/leader "g" #'magit-status)
#+end_src

**** Use =~/.authinfo= for passwords

The =auth-info= line should look like this:

#+begin_example
machine git.example.com user acdw password hahayeahrightyamoroniwouldn'tgiveyouthat
#+end_example

#+begin_src emacs-lisp :noweb-ref hooks
  (autoload 'magit-process-password-auth-source "magit")
  (add-hook 'magit-process-find-password-functions
            #'magit-process-password-auth-source)
#+end_src

**** Windows setup

Following the [[https://github.com/magit/magit/wiki/Pushing-with-Magit-from-Windows][wiki page located here]].  Also make sure to run the
following in =cmd.exe= to set =$HOME= correctly:

#+begin_src cmd
  setx HOME C:\Users\aduckworth\Downloads\acdw
#+end_src

/and/ run /this/ command to setup a git credential helper:

#+begin_src sh
  git config --global credential.helper store
#+end_src

Okay, okay, using the =store= credential.helper is /super/ insecure.  But
here's the thing -- the Gits I Git at work (a) aren't my /real/ git, and
(b) they're just tokens!  So any time I think somebody got access, I
just revoke the tokens and bingo bongo, good to go.  If that's not
true, please feel free to hack this repo and change this paragraph.

#+begin_src emacs-lisp :noweb-ref windows-specific
  (setenv "GIT_ASKPASS" "git-gui--askpass")
#+end_src

**** Forge                                                          :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'forge)
  (with-eval-after-load 'magit
    (require 'forge))
#+end_src

*** Git file modes                                                  :package:

#+begin_src emacs-lisp :noweb-ref packages
  (dolist (feat '(gitattributes-mode
                  gitconfig-mode
                  gitignore-mode))
    (straight-use-package feat)
    (require feat))
#+end_src

** Crosswords!                                                        :package:

I love crosswords.  I love Emacs.  There ya go.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(crossword
                          :host github
                          :repo "Boruch-Baum/emacs-crossword"))
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default crossword-empty-position-char "#")
#+end_src

#+begin_src emacs-lisp :noweb-ref no-littering
  (setq-default crossword-save-path
                (no-littering-expand-var-file-name "crosswords/"))
  (unless (file-exists-p crossword-save-path)
    (make-directory crossword-save-path :parents))
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--setup-crossword ()
    (setq cursor-type 'hbar))

  (add-hook 'crossword-mode-hook #'hook--setup-crossword)
#+end_src

The problem with this package is that the default faces are pretty
bad, to be honest.  Let's change em.

#+begin_src emacs-lisp :noweb-ref settings
  (doremi-face-set 'crossword-current-face
                   '((((class color)
                       (background light))
                      (:inherit 'normal :foreground "black"
                       :background "lightgreen"))
                     (((class color)
                       (background dark))
                      (:inherit 'normal :foreground "white"
                       :background "darkgreen"))
                     (t
                      (:inherit 'normal :foreground "black"
                       :background "darkgreen"))))

  (doremi-face-set 'crossword-other-dir-face
                   '((((class color)
                       (background light))
                      (:inherit 'normal :foreground "black"
                       :background "darkgrey"))
                     (((class color)
                       (background dark))
                      (:inherit 'normal :foreground "black"
                       :background "darkgrey"))
                     (t
                      (:inherit 'normal :foreground "black"
                       :background "darkgrey"))))
#+end_src

** TODO Gnus

See [[https://github.com/redguardtoo/mastering-emacs-in-one-year-guide/blob/master/gnus-guide-en.org][this guide]] and try it out.

** RSS Feeds                                                          :package:

*** Elfeed and goodies

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'elfeed)
  (straight-use-package 'elfeed-goodies)
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (with-eval-after-load 'elfeed
    (require 'elfeed-goodies)
    (elfeed-goodies/setup))
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default elfeed-goodies/entry-pane-position 'top
                elfeed-goodies/powerline-default-separator nil
                elfeed-goodies/tag-column-width 16)
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--elfeed-show ()
    (visual-line-mode +1))

  (add-hook 'elfeed-show-mode-hook #'hook--elfeed-show)
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/leader "f" #'elfeed)
#+end_src

*** Elfeed feeds

#+begin_src emacs-lisp :noweb-ref settings
  (setq elfeed-feeds
        `(
          ("https://atthis.link/rss.xml" blags tech)
          ("https://rachelbythebay.com/w/atom.xml" blags tech)
          ("https://notes.neeasade.net/rss_full.xml" blags tech)
          ("https://www.uninformativ.de/blog/feeds/en.atom" blags tech)
          ("http://blog.z3bra.org/rss/feed.xml" blags tech)
          ("https://blog.sanctum.geek.nz/feed/" blags tech)
          ("https://drewdevault.com/blog/index.xml" blags tech)
          ("https://usesthis.com/feed.atom" tech)
          ("https://occasionallycogent.com/feed.xml" blags)
          ("https://www.murilopereira.com/index.xml" blags tech)
          ("https://botanistinthekitchen.blog/feed/" blags food)
          ("https://www.careercenterbr.com/feed/" work)
          ("https://blog.ebrpl.com/feed/"         work)
          (,(concat
             "https://lemmy.ml/feeds/front/" ; long-ass url
             "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9."
             "eyJpZCI6MTY4MjQsImlzcyI6ImxlbW15Lm1sIn0"
             ".yE2zUGjvlEuTZZi3TiF9HR7L7ITM9f_"
             "fQnquyYLgdJ4.xml?sort=Active")
            news)
          ("https://lobste.rs/rss" news tech)
          ("https://feeds.npr.org/1001/rss.xml" news)
          (,(concat ; long-ass url
             "https://tilde.news/rss?token="
             "FvdFj8rQkhrBy9j1yON1t6RYKDdcuG1MoUlyvRICmbgDGCf2JTWAEObDhdgt")
            news tildes tech)
          ("https://www.acdw.net/atom.xml"              fwends)
          ("https://envs.net/~lucidiot/rsrsss/feed.xml" fwends)
          ("https://planet.emacslife.com/atom.xml" emacs)
          ("http://tilde.town/~lucidiot/fridaypostcard.xml" tildes art)
          ("https://quasivoid.net/feed.atom"                tildes)
          ("https://benjaminwil.info/feed.xml"              tildes fwends)
          ("https://benjaminwil.info/antisocial/feed.xml"   tildes)
          ("https://blog.ryliejamesthomas.net/feed/"        tildes)
          ("https://p1k3.com/feed"                          tildes)
          ("https://cosmic.voyage/rss.xml"                  tildes fiction sci-fi)
          ("https://jackreid.xyz/index.xml"                 tildes)
          ("http://lambdacreate.com/static/feed.rss"        tildes fwends)
          ("https://gaffen.co.uk/feed.xml"                  tildes)
          ("https://gmb.21x2.net/rss.xml"                   tildes)
          ("https://www.insom.me.uk/feed.xml"               tildes)
          ("https://invisibleup.com/atom.xml"               tildes)
          ("https://m455.casa/feed.rss"                     tildes fwends)
          ("https://petras.space/index.xml"                 tildes)
          ("https://www.benovermyer.com/post/index.xml"     tildes)
          ("https://tilde.town/~trm/blog/atom.xml"          tildes)
          ("https://tilde.team/feed.rss"                    tildes)
          ("http://ajroach42.com/feed.xml"                  tildes)
          ("http://tilde.town/~mroik/blog/rss.xml"          tildes)
          ("https://hamster.dance/blog/rss/"                tildes)
          ("https://m455.neocities.org/feed.rss"            tildes fwends)
          ("https://eli.li/feed.rss"                        tildes fwends)
          ("https://aiweirdness.com/rss" tech)
          ("https://spwhitton.name/blog/index.rss" blags)
          ))
#+end_src

*** COMMENT Elfeed-protocol

I'm not /the most/ happy with this -- it seems like a lot for not that
much -- but until I figure out a proper syncing solution, it'll do.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'elfeed-protocol)
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default elfeed-protocol-ttrss-maxsize 200
                elfeed-feeds
                '(("ttrss+https://acdw@rss.tildeverse.org"
                   :use-authinfo t)))
#+end_src

#+begin_src emacs-lisp :noweb-ref modes
  (with-eval-after-load 'elfeed
    (elfeed-protocol-enable))
#+end_src

For whatever reason, =G= (=elfeed-search-fetch=) doesn't fetch anything
new from TTRSS.  So I rebind it to ... =elfeed-protocol-ttrss-reinit=
(=elfeed-protocol-ttrss-update= doesn't pull everything for some reason
... this kind of thing is why I'm looking at other elfeed-sync
options).

#+begin_src emacs-lisp :noweb-ref bindings
  (with-eval-after-load 'elfeed-protocol
    (defun acdw-elfeed-protocol-ttrss-update-then-reinit ()
      "Update, then reinit, the first entry in `elfeed-feeds'."
      (interactive)
      (let ((url (caar elfeed-feeds))
            (msg-update "Elfeed Protocol: Updating...")
            (msg-reinit "Elfeed Protocol: Re-initializing..."))
        (message "%s" msg-update)
        (elfeed-protocol-ttrss-update url)
        (message "%s Done." msg-update)

        (message "%s" msg-reinit)
        (elfeed-protocol-ttrss-reinit url)
        (message "%s Done." msg-reinit)))

    (define-key elfeed-search-mode-map "G"
      #'acdw-elfeed-protocol-ttrss-update-then-reinit))
#+end_src

** 0x0 (null pointer)                                                 :package:

An ease-of-life package that lets me upload my shitty code to share it with
others.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(0x0
                          :repo "https://git.sr.ht/~zge/nullpointer-emacs"))
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default 0x0-default-service 'ttm)
#+end_src

** Gemini/gopher

*** Elpher                                                            :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(elpher
                          :repo "git://thelambdalab.xyz/elpher.git"))
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default elpher-ipv4-always t)

  (doremi-face-set 'elpher-gemini-heading1
                   '((t (:inherit (modus-theme-heading-1)))))
  (doremi-face-set 'elpher-gemini-heading2
                   '((t (:inherit (modus-theme-heading-2)))))
  (doremi-face-set 'elpher-gemini-heading3
                   '((t (:inherit (modus-theme-heading-3)))))
#+end_src

#+begin_src emacs-lisp :noweb-ref no-littering
  (setq-default elpher-certificate-directory
                (no-littering-expand-var-file-name
                 "elpher-certificates/"))
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (with-eval-after-load 'elpher
    (define-key elpher-mode-map "n" #'elpher-next-link)
    (define-key elpher-mode-map "p" #'elpher-prev-link)
    (define-key elpher-mode-map "o" #'elpher-follow-current-link)
    (define-key elpher-mode-map "G" #'elpher-go-current))
#+end_src

*** Gemini-mode                                                       :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(gemini-mode
                          :repo "https://git.carcosa.net/jmcbray/gemini.el.git"))
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (add-to-list 'auto-mode-alist
               '("\\.\\(gemini\\|gmi\\)\\'" . gemini-mode))

  (doremi-face-set 'gemini-heading-face-1
                   '((t (:inherit (elpher-gemini-heading1)))))
  (doremi-face-set 'gemini-heading-face2
                   '((t (:inherit (elpher-gemini-heading2)))))
  (doremi-face-set 'gemini-heading-face3
                   '((t (:inherit (elpher-gemini-heading3)))))
#+end_src

*** Gemini-write                                                      :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(gemini-write
                          :repo "https://alexschroeder.ch/cgit/gemini-write"))

  (with-eval-after-load 'elpher
    (require 'gemini-write))
#+end_src

* Org mode                                                            :package:

** Install it with =straight.el=

I want to use the newest version of Org that I can.

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'org)

  (with-eval-after-load 'org
    (require 'org-tempo)
    (require 'ox-md))
#+end_src

** Basic settings

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default
   ;; Where to look for Org files
   org-directory "~/org" ; this is the default
   ;; Fontify stuff
   org-hide-emphasis-markers t
   org-fontify-whole-heading-line t
   org-fontify-done-headline t
   org-fontify-quote-and-verse-blocks t
   org-src-fontify-natively t
   org-ellipsis "…"
   org-pretty-entities t
   org-tags-column (- 0 fill-column -1)
   ;; Source blocks
   org-src-tab-acts-natively t
   org-src-window-setup 'current-window ; the least stupid option
   org-confirm-babel-evaluate nil
   ;; Behavior
   org-adapt-indentation nil ; don't indent things
   org-catch-invisible-edits 'smart ; let's try this
   org-special-ctrl-a/e t
   org-special-ctrl-k t
   org-imenu-depth 8
   ;; Exporting
   org-export-headline-levels 8
   org-export-with-smart-quotes t
   org-export-with-sub-superscripts t)
#+end_src

** Aesthetics

*** Prettify some other symbols

#+begin_src emacs-lisp :noweb-ref functions
  (defun acdw/org-mode-prettify ()
    "Prettify `org-mode'."
    (dolist (cell '(("[ ]" . ?☐) ("[X]" . ?☑) ("[-]" . ?◐)
                    ("#+BEGIN_SRC" . ?✎) ("#+begin_src" . ?✎)
                    ("#+BEGIN_QUOTE" . ?❝) ("#+begin_quote" . ?❝)
                    ("#+END_QUOTE" . ?❞) ("#+end_quote" . ?❞)
                    ("#+END_SRC" . ?■) ("#+end_src" . ?■)))
      (add-to-list 'prettify-symbols-alist cell :append))
    (prettify-symbols-mode +1))
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'org-mode-hook #'acdw/org-mode-prettify)
#+end_src

*** Prettify lists and checkboxes using font-lock

from [[https://github.com/KaratasFurkan/.emacs.d#org-1][Furkan Karataş]].

#+begin_src emacs-lisp :noweb-ref modes
  (with-eval-after-load 'org
    (font-lock-add-keywords 'org-mode
                            '(("^ *\\([-]\\) "
                               (0 (prog1 ()
                                    (compose-region (match-beginning 1) (match-end 1) "•"))))))
    (font-lock-add-keywords 'org-mode
                            '(("^ *\\([+]\\) "
                               (0 (prog1 ()
                                    (compose-region (match-beginning 1) (match-end 1) "◦"))))))
  
    (defface org-checkbox-done-text
        '((t (:inherit 'font-lock-comment-face :slant normal)))
      "Face for the text part of a checked org-mode checkbox."
      :group 'org)

    (font-lock-add-keywords
     'org-mode
     `(("^[ \t]*\\(?:[-+*]\\|[0-9]+[).]\\)[ \t]+\\(\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\(?:X\\|\\([0-9]+\\)/\\2\\)\\][^\n]*\n\\)"
        1 'org-checkbox-done-text prepend))
     'append))
#+end_src

*** Org-appear                                                        :package:

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package '(org-appear
                          :host github
                          :repo "awth13/org-appear"))
#+end_src

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default org-appear-autoemphasis t
                org-appear-autolinks t
                org-appear-autosubmarkers t)
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'org-mode-hook #'org-appear-mode)
#+end_src

** Org templates

#+begin_src emacs-lisp :noweb-ref settings
  (with-eval-after-load 'org-tempo
    (dolist (cell '(("el" . "src emacs-lisp")
                    ("cr" . "src emacs-lisp :noweb-ref requires")
                    ("cf" . "src emacs-lisp :noweb-ref functions")
                    ("cs" . "src emacs-lisp :noweb-ref settings")
                    ("cm" . "src emacs-lisp :noweb-ref modes")
                    ("cl" . "src emacs-lisp :noweb-ref linux-specific")
                    ("cw" . "src emacs-lisp :noweb-ref windows-specific")
                    ("cp" . "src emacs-lisp :noweb-ref packages")
                    ("ch" . "src emacs-lisp :noweb-ref hooks")
                    ("cb" . "src emacs-lisp :noweb-ref bindings")
                    ("cnl" . "src emacs-lisp :noweb-ref no-littering")))
      (add-to-list 'org-structure-template-alist cell)))
#+end_src

** Org Return: DWIM

#+begin_src emacs-lisp :noweb-ref functions
  (defun unpackaged/org-element-descendant-of (type element)
    "Return non-nil if ELEMENT is a descendant of TYPE.
  TYPE should be an element type, like `item' or `paragraph'.
  ELEMENT should be a list like that returned by `org-element-context'."
    ;; MAYBE: Use `org-element-lineage'.
    (when-let* ((parent (org-element-property :parent element)))
      (or (eq type (car parent))
          (unpackaged/org-element-descendant-of type parent))))

  (defun unpackaged/org-return-dwim (&optional default)
    "A helpful replacement for `org-return'.  With prefix, call `org-return'.

  On headings, move point to position after entry content.  In
  lists, insert a new item or end the list, with checkbox if
  appropriate.  In tables, insert a new row or end the table."
    ;; Inspired by John Kitchin:
    ;; http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/
    (interactive "P")
    (if default
        (org-return)
      (cond
        ;; Act depending on context around point.

        ;; NOTE: I prefer RET to not follow links, but by uncommenting
        ;; this block, links will be followed.
        ;; FURTHER NOTE: Ideally, I would follow links unless point
        ;; /appeared/ to be at the end of the line (even if it's still
        ;; inside the link) -- when it would do `org-return'.  That
        ;; would take some /doing/, however.

        ;; ((eq 'link (car (org-element-context)))
        ;;  ;; Link: Open it.
        ;;  (org-open-at-point-global))

        ((org-at-heading-p)
         ;; Heading: Move to position after entry content.
         ;; NOTE: This is probably the most interesting feature of this function.
         (let ((heading-start (org-entry-beginning-position)))
           (goto-char (org-entry-end-position))
           (cond ((and (org-at-heading-p)
                       (= heading-start (org-entry-beginning-position)))
                  ;; Entry ends on its heading; add newline after
                  (end-of-line)
                  (insert "\n\n"))
                 (t
                  ;; Entry ends after its heading; back up
                  (forward-line -1)
                  (end-of-line)
                  (when (org-at-heading-p)
                    ;; At the same heading
                    (forward-line)
                    (insert "\n")
                    (forward-line -1))
                  ;; FIXME: looking-back is supposed to be called with
                  ;; more arguments.
                  (while (not (looking-back (rx
                                             (repeat 3
                                                     (seq (optional blank)
                                                          "\n")))
                                            nil))
                    (insert "\n"))
                  (forward-line -1)))))

        ((org-at-item-checkbox-p)
         ;; Checkbox: Insert new item with checkbox.
         (org-insert-todo-heading nil))

        ((org-in-item-p)
         ;; Plain list.  Yes, this gets a little complicated...
         (let ((context (org-element-context)))
           (if (or (eq 'plain-list (car context))  ; First item in list
                   (and (eq 'item (car context))
                        (not (eq (org-element-property :contents-begin context)
                                 (org-element-property :contents-end context))))
                   ;; Element in list item, e.g. a link
                   (unpackaged/org-element-descendant-of 'item context))
               ;; Non-empty item: Add new item.
               (org-insert-item)
             ;; Empty item: Close the list.
             ;; TODO: Do this with org functions rather than operating
             ;; on the text. Can't seem to find the right function.
             (delete-region (line-beginning-position) (line-end-position))
             (insert "\n"))))

        ((when (fboundp 'org-inlinetask-in-task-p)
           (org-inlinetask-in-task-p))
         ;; Inline task: Don't insert a new heading.
         (org-return))

        ((org-at-table-p)
         (cond ((save-excursion
                  (beginning-of-line)
                  ;; See `org-table-next-field'.
                  (cl-loop with end = (line-end-position)
                     for cell = (org-element-table-cell-parser)
                     always (equal (org-element-property :contents-begin cell)
                                   (org-element-property :contents-end cell))
                     while (re-search-forward "|" end t)))
                ;; Empty row: end the table.
                (delete-region (line-beginning-position) (line-end-position))
                (org-return))
               (t
                ;; Non-empty row: call `org-return'.
                (org-return))))
        (t
         ;; All other cases: call `org-return'.
         (org-return)))))
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (with-eval-after-load 'org
    (define-key org-mode-map (kbd "RET") #'unpackaged/org-return-dwim))
#+end_src

** Insert blank lines around headers

#+begin_src emacs-lisp :noweb-ref functions
  (defun unpackaged/org-fix-blank-lines (&optional prefix)
    "Ensure that blank lines exist between headings and between headings and their contents.
  With prefix, operate on whole buffer. Ensures that blank lines
  exist after each headings's drawers."
    (interactive "P")
    (org-map-entries (lambda ()
                       (org-with-wide-buffer
                        ;; `org-map-entries' narrows the buffer, which prevents us
                        ;; from seeing newlines before the current heading, so we
                        ;; do this part widened.
                        (while (not (looking-back "\n\n" nil))
                          ;; Insert blank lines before heading.
                          (insert "\n")))
                       (let ((end (org-entry-end-position)))
                         ;; Insert blank lines before entry content
                         (forward-line)
                         (while (and (org-at-planning-p)
                                     (< (point) (point-max)))
                           ;; Skip planning lines
                           (forward-line))
                         (while (re-search-forward org-drawer-regexp end t)
                           ;; Skip drawers. You might think that `org-at-drawer-p'
                           ;; would suffice, but for some reason it doesn't work
                           ;; correctly when operating on hidden text.  This
                           ;; works, taken from `org-agenda-get-some-entry-text'.
                           (re-search-forward "^[ \t]*:END:.*\n?" end t)
                           (goto-char (match-end 0)))
                         (unless (or (= (point) (point-max))
                                     (org-at-heading-p)
                                     (looking-at-p "\n"))
                           (insert "\n"))))
                     t (if prefix
                           nil
                         'tree)))
#+end_src

I fix the headline spacing every time I save.

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--org-mode-fix-blank-lines ()
    (when (eq major-mode 'org-mode)
      (let ((current-prefix-arg 4)) ; Emulate C-u
        (call-interactively 'unpackaged/org-fix-blank-lines))))

  (add-hook 'before-save-hook #'hook--org-mode-fix-blank-lines)
#+end_src

** Org Agenda

I'm trying to organize my life.
Inspo:

- [[https://github.com/cadadr/configuration/blob/3e11ef25344188cc55b16f314c3c5358ace8a266/emacs.d/init.el#L4625][Göktuğ Kayaalp]]
- [[https://pages.sachachua.com/.emacs.d/Sacha.html#org1db6fe9][Sacha Chua]]

*** Basic Agenda Settings

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default org-agenda-files ; look for files in ~/org
                (list org-directory)
                ;; agenda
                org-agenda-span 5
                org-agenda-skip-scheduled-if-done t
                org-agenda-skip-deadline-if-done t
                org-deadline-warning-days 2
                ;; logging
                org-log-into-drawer "LOGBOOK"
                org-log-done t)
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/leader (kbd "C-a") #'org-agenda)
#+end_src

*** Agenda hooks

#+begin_src emacs-lisp :noweb-ref hooks
  (defun hook--org-agenda-mode ()
    (hl-line-mode +1))

  (add-hook 'org-agenda-mode-hook #'hook--org-agenda-mode)
#+end_src

*** Refile

#+begin_src emacs-lisp :noweb-ref settings
  (setq org-refile-targets '((org-agenda-files . (:maxlevel . 3))))
#+end_src

*** Calendar settings

I'm not sure where else to put these, to be honest.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default calendar-date-style 'iso) ; YYYY-mm-dd
#+end_src

*** Habits

Org can track habits!  Great stuff.  I need to add it to =org-modules=,
though.

#+begin_src emacs-lisp :noweb-ref settings
  (add-to-list 'org-modules 'org-habit)
#+end_src

Now I just add a =habit= property to a subtree, and BAM!

*** Org Todo Keywords

These need some more thinking -- e.g., the MEETING sequence should
maybe be a type, or maybe I need to include those in something else
altogether.  Hm.

#+begin_src emacs-lisp :noweb-ref settings
  (setq-default org-todo-keywords
                '((sequence
                   "TODO(t)" "STARTED(s)"
                   "WAITING(w@/!)" "SOMEDAY(.)"
                   "|" "DONE(x!)" "CANCELLED(c@/!)")
                  (sequence "RECUR(r)" "|" "DONE(x!)")
                  (sequence "MEETING(m)")))
#+end_src

** Org Capture

#+begin_src emacs-lisp :noweb-ref packages
  (require 'org-capture)
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (with-eval-after-load 'org-capture
    (define-key acdw/leader (kbd "C-c") #'org-capture))
#+end_src

I've still got a lot of thinking to do about what kinds of things I
want to capture, but I guess for now I can start with the basics:
TODO, and Diary.

#+begin_src emacs-lisp :noweb-ref settings
  (defvar acdw/org-inbox-file (expand-file-name "inbox.org" org-directory))
  (defvar acdw/org-diary-file (expand-file-name "diary.org" org-directory))
  (setq-default
   org-capture-templates
   `(;; Todo -- these go to the Inbox for further processing
     ("t" "Quick Task" entry
          (file ,acdw/org-inbox-file)
          "* TODO %^{Task}\n"
          :immediate-finish t)
     ("T" "Task" entry
          (file ,acdw/org-inbox-file)
          "* TODO %^{Task}\n")
     ("." "Today" entry
          (file ,acdw/org-inbox-file)
          "* TODO %^{Task}\nSCHEDULED: %t\n"
          :immediate-finish t)
     ;; Meetings
     ("m" "Meeting" entry
          (file ,acdw/org-inbox-file)
          "* MEETING %^{Meeting}\n%^T\n\n%?")
     ;; Diary -- for the special Diary file
     ("j" "Diary entry" entry
          (file+olp+datetree ,acdw/org-diary-file)
          "* %U\n\n%?"
          :empty-lines 1)
     ;; Books to read
     ("b" "Book to read" entry
          (file "books.org")
          "* TOREAD %^{Title}
  :PROPERTIES:
  :Author: %^{Author}
  :END:\n" :immediate-finish t)))

#+end_src

* Package management                                                  :package:
:PROPERTIES:
:header-args: :noweb-ref early-init-package
:END:

Emacs is the /extensible/ editor, and that means I want to use
third-party packages.  Of course, first I have to /manage/ those
packages.  I use the excellent =straight.el=.

** Update the PATH

PATH handling on Emacs is a little complicated.  There's the regular
environment variable =$PATH=, which we all know and love, and then
Emacs has its own special =exec-path= on /top/ of that.  From my
research, it looks like Emacs uses =exec-path= for itself, and =$PATH=
for any shells or other processes it spawns.  They don't /have/ to be
the same, but luckily for us, Emacs sets =exec-path= from =$PATH= on
initialization, so when I add stuff to =exec-path= to, say, run git, I
can just change =$PATH= right back to the expanded =exec-path= without
any data loss.  Here's what all that looks like.

#+begin_src emacs-lisp
  (let ((win-app-dir "~/Applications"))
    (dolist (path (list
                   ;; Windows
                   (expand-file-name "exe" win-app-dir)
                   (expand-file-name "Git/bin" win-app-dir)
                   (expand-file-name "Git/usr/bin" win-app-dir)
                   (expand-file-name "Git/mingw64/bin" win-app-dir)
                   (expand-file-name "Everything" win-app-dir)
                   (expand-file-name "Win-builds/bin" win-app-dir)
                   ;; Linux
                   (expand-file-name "bin" user-emacs-directory)
                   (expand-file-name "~/bin")
                   (expand-file-name "~/.local/bin")
                   (expand-file-name "~/Scripts")
                   ))
      (when (file-exists-p path)
        (add-to-list 'exec-path path :append))))

  ;; Set $PATH
  (setenv "PATH" (mapconcat #'identity exec-path path-separator))
#+end_src

*** References

- [[https://emacs.stackexchange.com/questions/550/exec-path-and-path][exec-path and $PATH (StackExchange)]]
- [[https://utoi.tistory.com/entry/Difference-Between-Emacss-%E2%80%9Cgetenv-PATH%E2%80%9D-and-%E2%80%9Cexec-path%E2%80%9D][Difference between Emacs's "(getenv PATH)" and "exec-path" (U&I)]]
- GUI Emacs sets the exec-path only from Windows environment variable
  but not from .emacs file [[https://emacs.stackexchange.com/questions/27326/gui-emacs-sets-the-exec-path-only-from-windows-environment-variable-but-not-from][(StackExchange)]]

** Disable =package.el=

#+begin_src emacs-lisp
  (setq package-enable-at-startup nil)
#+end_src

** Bootstrap

The following is straight (heh) from the straight repo, wrapped in a
function so I can call it in another wrapper.

#+begin_src emacs-lisp
  (defun acdw/bootstrap-straight ()
    "Bootstrap straight.el."
    (defvar bootstrap-version)
    (let ((bootstrap-file
           (expand-file-name
            "straight/repos/straight.el/bootstrap.el"
            user-emacs-directory))
          (bootstrap-version 5))
      (unless (file-exists-p bootstrap-file)
        (with-current-buffer
            (url-retrieve-synchronously
             (concat
              "https://raw.githubusercontent.com/"
              "raxod502/straight.el/develop/install.el")
             'silent 'inhibit-cookies)
          (goto-char (point-max))
          (eval-print-last-sexp)))
      (load bootstrap-file nil 'nomessage)))
#+end_src

To actually bootstrap straight, I'll first try running the above
directly.  If it errors (it tends to on Windows), I'll directly clone
the repo using git, /then/ run the bootstrap code.

#+begin_src emacs-lisp
  (when (executable-find "git")
    (unless (ignore-errors (acdw/bootstrap-straight))
      (let ((msg "Straight.el didn't bootstrap correctly.  Cloning directly"))
        (message "%s..." msg)
        (call-process "git" nil
                      (get-buffer-create "*bootstrap-straight-messages*") nil
                      "clone"
                      "https://github.com/raxod502/straight.el"
                      (expand-file-name "straight/repos/straight.el"
                                        user-emacs-directory))
        (message "%s...Done." msg)
        (acdw/bootstrap-straight))))
#+end_src

* System integration

I use both Linux (at home) and Windows (at work).  To make Emacs
easier to use in both systems, I've included various system-specific
settings and written some ancillary scripts.

** All systems

I'll put generic system-integrating code here.

*** Edit with Emacs                                                 :package:

Install the [[https://addons.mozilla.org/en-US/firefox/addon/edit-with-emacs1/][Firefox Addon]] alongside this package to edit web forms in
Emacs (or the [[https://chrome.google.com/webstore/detail/edit-with-emacs/ljobjlafonikaiipfkggjbhkghgicgoh][Chrome one]] if you... /hate/ freedom :P).

#+begin_src emacs-lisp :noweb-ref packages
  (straight-use-package 'edit-server)
#+end_src

#+begin_src emacs-lisp :noweb-ref hooks
  (add-hook 'after-init-hook #'edit-server-start)
#+end_src

*** =git-sync= ~/org

I don't know where else to put this, but it's just a little command to
run =git-sync= in =org-directory=.

#+begin_src emacs-lisp :noweb-ref functions
  (defun acdw/org-sync ()
    "Run git-sync in `org-directory'.

  Requires git-sync."
    (interactive)
    (async-shell-command
     (format "git -C %s sync" (expand-file-name org-directory))))

  (define-key acdw/leader (kbd "C-M-o") #'acdw/org-sync)
#+end_src

** Linux (home)
:PROPERTIES:
:header-args: :noweb-ref linux-specific
:END:

*** Settings

*** Scripts

**** em
:PROPERTIES:
:header-args: :tangle-mode (identity #o755) :mkdirp yes
:END:

Here's a wrapper script that'll start =emacs --daemon= if there isn't
one, and then launch =emacsclient= with the arguments.  Install it to
your =$PATH= somewhere.

#+begin_src sh :shebang "#!/bin/sh" :tangle (if (eq system-type 'gnu/linux) "~/bin/em" "")
  if ! emacsclient -nc "$@"; then
      emacs --daemon
      emacsclient -nc "$@"
  fi
#+end_src

**** emacsclient.desktop
:PROPERTIES:
:header-args: :mkdirp yes
:END:

I haven't really tested this yet, but it should allow me to open other
files and things in Emacs.  From [[https://www.taingram.org/blog/emacs-client.html][taingram]].

#+begin_src conf-desktop :tangle (if (eq system-type 'gnu/linux) "~/.local/share/applications/emacsclient.desktop" "")
  [Desktop Entry]
  Name=Emacs Client
  GenericName=Text Editor
  Comment=Edit text
  MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
  Exec=emacsclient -c %f
  Icon=emacs
  Type=Application
  Terminal=false
  Categories=Utility;TextEditor;
#+end_src

** Windows (work)
:PROPERTIES:
:header-args: :noweb-ref windows-specific
:END:

I use Windows at work, where I /also/ don't have Admin rights.  So I
kind of fly-by-night there.  Many of the ideas and scripts in this
section come from [[https://github.com/termitereform/JunkPile/blob/master/emacs-on-windows.md][termitereform]] on Github.

*** Settings

See also [[https://www.gnu.org/software/emacs/manual/html_mono/efaq-w32.html][the GNU FAQ for Windows]].  At some point I should really dig
into the multiple settings available for w32 systems.

See also [[https://github.com/bbatsov/prelude/blob/master/core/prelude-windows.el][the Prelude Windows configuration]] (modifier keys).

#+begin_src emacs-lisp
  (setq-default w32-allow-system-shell t ; enable cmd.exe as shell
                ;; modifier keys
                w32-pass-lwindow-to-system nil
                w32-lwindow-modifier 'super
                w32-pass-rwindow-to-system nil
                w32-rwindow-modifier 'super
                w32-pass-apps-to-system nil
                w32-apps-modifier 'hyper)
#+end_src

*** Scripts
:PROPERTIES:
:header-args: :noweb yes :mkdirp yes
:END:

**** Common variables

#+begin_src bat :noweb-ref w32-bat-common
  if not exist %HOME% (set HOME=%~dp0..\..)
  set EMACS=%HOME%\Applications\Emacs\bin\runemacs.exe
  set EMACSC=%HOME%\Applications\Emacs\bin\emacsclientw.exe
  set GIT=%HOME%\Applications\Git\bin\git.exe
#+end_src

**** Emacs Autostart

Either run this once at startup, or put a shortcut of it in the
Startup folder: 
=%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup=.

#+begin_src bat :tangle (if (eq system-type 'windows-nt) "~/Applications/cmd/Emacs Autostart.cmd" "")
  <<w32-bat-common>>
  REM git pull the config
  start "git" /wait %GIT% -C %HOME%\.emacs.d pull

  REM start emacs
  chdir %HOME%
  start "emacs-daemon" /wait %EMACS% --daemon
  start "emacs-client" %EMACSC% -n -c -a "" %*
#+end_src

**** Emacs Client

This will try to connect to the daemon above.  If that fails, it'll
run =runemacs.exe=.

*This is the main shortcut for running Emacs.*

#+begin_src bat :tangle (if (eq system-type 'windows-nt) "~/Applications/cmd/Emacs.cmd" "")
<<w32-bat-common>>
start "emacs" "%EMACSC%" -n -c -a "%EMACS%" %*
#+end_src

**** Emacs Daemon

#+begin_src bat :tangle (if (eq system-type 'windows-nt) "~/Applications/cmd/Emacs Daemon.cmd" "")
<<w32-bat-common>>
start "emacs-daemon" %EMACS% --daemon
#+end_src

**** Emacs Safe Start

This runs Emacs with the factory settings.

#+begin_src bat :tangle (if (eq system-type 'windows-nt) "~/Applications/cmd/Emacs Safe Start.cmd" "")
<<w32-bat-common>>
start "emacs-safe" "%EMACS%" -Q %*
#+end_src

**** Emacs Debug

This runs Emacs with the =--debug-init= option enabled.

#+begin_src bat :tangle (if (eq system-type 'windows-nt) "~/Applications/cmd/Emacs Debug.cmd" "")
<<w32-bat-common>>
start "emacs-debug" "%EMACS%" --debug-init %*
#+end_src

* Appendices

** config.el
:PROPERTIES:
:header-args: :tangle config.el :noweb yes
:END:

While =config.el= is written above, I use Noweb references to tangle
them all together in the following block, which enables me to organize
my config here /logically/, while keeping the generated file organized
/programmatically/.

*** Enable lexical binding

#+begin_src emacs-lisp
  ;;; config.el --- personal configuration -*- lexical-binding: t -*-
#+end_src

*** Header & disclaimer
:PROPERTIES:
:header-args: :noweb-ref disclaimer
:END:

#+begin_src emacs-lisp
  ;; Copyright (C) 2020 Case Duckworth

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

  ;; This file is not part of GNU Emacs.

  ;;; Commentary:
  ;; This file is automatically tangled from config.org.
  ;; Hand edits will be overwritten!

#+end_src

*** The rest

#+begin_src emacs-lisp
  <<disclaimer>>
  ;;; Code:

  ;;; REQUIRES
  <<requires>>

  ;;; VARIABLES
  <<variables>>

  ;;; ACDW MODE
  <<acdw-mode>>

  ;;; PACKAGES
  <<packages>>

  ;;; FUNCTIONS
  <<functions>>

  ;;; SETTINGS
  <<settings>>

  ;;; SYSTEM-DEPENDENT SETTINGS
  ;; at home
  (eval-and-compile
    (when (memq system-type '(gnu gnu/linux gnu/kfreebsd))
      <<linux-specific>>
      ))

  ;; at work
  (eval-and-compile
    (when (memq system-type '(ms-dos windows-nt))
      <<windows-specific>>
      ))

  ;;; MODES
  <<modes>>

  ;;; HOOKS
  <<hooks>>

  ;;; BINDINGS
  <<bindings>>
  ;;; config.el ends here
#+end_src

*** Ease of editing
:PROPERTIES:
:header-args: :tangle no
:END:

#+begin_src emacs-lisp :noweb-ref functions
  (defun acdw/find-config ()
    "Find `config.org'."
    (interactive)
    (find-file (locate-user-emacs-file "config.org")))
#+end_src

Bind it to =C-z i= because =C-z C-c= is taken for capture.

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/leader (kbd "i") #'acdw/find-config)
#+end_src

*** Ease of reloading
:PROPERTIES:
:header-args: :tangle no
:END:

#+begin_src emacs-lisp :noweb-ref functions
  (defun acdw/reload ()
    "Tangle and reload Emacs configuration."
    (interactive)
    (let ((config (locate-user-emacs-file "config.org")))
      ;; tangle
      (with-current-buffer (find-file-noselect config)
        (message "Tangling config.org...")
        (let ((prog-mode-hook nil)
              (inhibit-redisplay t)
              (inhibit-message t))
          (add-to-list 'load-path (locate-user-emacs-file
                                   "straight/build/org/"))
          (require 'org)
          (org-babel-tangle)))
      (message "Tangling config.org... Done.")
      ;; load init files
      (load (locate-user-emacs-file "early-init.el"))
      (load (locate-user-emacs-file "init.el"))
      (load (locate-user-emacs-file "config.el"))))
#+end_src

#+begin_src emacs-lisp :noweb-ref bindings
  (define-key acdw/leader (kbd "C-M-r") #'acdw/reload)
#+end_src

** init.el
:PROPERTIES:
:header-args: :tangle init.el :noweb yes
:END:

The classic Emacs initiation file.

*** Header

#+begin_src emacs-lisp
  ;;; init.el -*- lexical-binding: t -*-
  <<disclaimer>>
  ;;; Code:
#+end_src

*** Prefer newer files to older files

#+begin_src emacs-lisp
  (setq-default load-prefer-newer t)
#+end_src

*** Load the config

I keep most of my config in =config.el=, which is tangled directly from
this file.  This init just loads that file, either from lisp 
or directly from Org if it's newer.  /Note/ the longish comment before
the =unless= form -- it was pretty tough for me to wrap my head around
the needed boolean expression to tangle config.org.  Booleans, yall!

#+begin_src emacs-lisp
  (let* (;; Speed up init
         (gc-cons-threshold most-positive-fixnum)
         (file-name-handler-alist nil)
         ;; Config file names
         (config (expand-file-name "config"
                                   user-emacs-directory))
         (config.el (concat config ".el"))
         (config.org (concat config ".org"))
         (straight-org-dir (locate-user-emacs-file "straight/build/org")))
    ;; Okay, let's figure this out.
    ;; `and' evaluates each form, and returns nil on the first that
    ;; returns nil.  `unless' only executes its body if the test
    ;; returns nil.  So.
    ;; 1. Test if config.org is newer than config.el.  If it is (t), we
    ;;    *want* to evaluate the body, so we need to negate that test.
    ;; 2. Try to load the config.  If it errors (nil), it'll bubble that
    ;;    to the `and' and the body will be evaluated.
    (unless (and (not (file-newer-than-file-p config.org config.el))
                 (load config :noerror))
      ;; A plain require here just loads the older `org'
      ;; in Emacs' install dir.  We need to add the newer
      ;; one to the `load-path', hopefully that's all.
      (when (file-exists-p straight-org-dir)
        (add-to-list 'load-path straight-org-dir))
      ;; Load config.org
      (require 'org)
      (org-babel-load-file config.org)))

  ;;; init.el ends here
#+end_src

** early-init.el
:PROPERTIES:
:header-args: :tangle early-init.el :noweb yes
:END:

Beginning with 27.1, Emacs also loads an =early-init.el= file, before
the package manager or the UI code.  The Info says we should put as
little as possible in this file, so I only have what I need.

#+begin_src emacs-lisp
  ;;; early-init.el -*- no-byte-compile: t; -*-
  <<disclaimer>>
  ;;; Code:

  ;; BOOTSTRAP PACKAGE MANAGEMENT
  <<early-init-package>>
  ;; SETUP FRAME
  <<early-init-frame>>

  ;;; early-init.el ends here
#+end_src

** License
:PROPERTIES:
:header-args: :tangle LICENSE
:END:

Copyright © 2020 Case Duckworth <acdw@acdw.net>

This work is free.  You can redistribute it and/or modify it under the
terms of the Do What the Fuck You Want To Public License, Version 2,
as published by Sam Hocevar.  See the =LICENSE= file, tangled from the
following source block, for details.

#+begin_src text
  DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

  Version 2, December 2004

  Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

  Everyone is permitted to copy and distribute verbatim or modified copies of
  this license document, and changing it is allowed as long as the name is changed.

  DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE

  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.
#+end_src

*** Note on the license

It's highly likely that the WTFPL is completely incompatible with the
GPL, for what should be fairly obvious reasons.  To that, I say:

*SUE ME, RMS!*

** Inspiration and further reading

- [[https://github.com/bbatsov/prelude][Emacs Prelude]]
- [[https://github.com/alphapapa/unpackaged.el][Unpackaged]]