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
|
#+title: Emacs configuration
#+author: Oreodave
#+description: My new Emacs configuration
#+property: header-args:emacs-lisp :tangle config.el :comment link
#+options: toc:nil
#+begin_center
My configuration for vanilla Emacs
#+end_center
#+latex: \clearpage
#+toc: headlines
#+latex: \clearpage
* Initial
Let's setup some basics.
Firstly, set full name and mail address for use in a variety of
applications, including encryption.
#+begin_src emacs-lisp
(setq user-full-name "Aryadev Chavali"
user-mail-address "aryadev@aryadevchavali.com")
#+end_src
Let's set all yes or no questions to single letter responses.
#+begin_src emacs-lisp
(fset 'yes-or-no-p 'y-or-n-p)
#+end_src
** No littering
Setup no-littering, which cleans up many of the default directories in
Emacs.
#+begin_src emacs-lisp
(straight-use-package 'no-littering)
(setq no-littering-etc-directory (expand-file-name ".config/" user-emacs-directory)
no-littering-var-directory (expand-file-name ".local/" user-emacs-directory))
(require 'no-littering)
#+end_src
** File saves and custom file
Now let's setup file saving and auto-revert-mode. Along with that,
setup the custom-file to exist in the var-directory
#+begin_src emacs-lisp
(use-package emacs
:straight nil
:init
(setq backup-directory-alist `(("." . ,(no-littering-expand-var-file-name "saves/")))
global-auto-revert-non-file-buffers nil
auto-revert-verbose nil)
(setq custom-file (no-littering-expand-etc-file-name "custom.el"))
:config
(global-auto-revert-mode 1))
#+end_src
** Hide-show mode
Turn on hs minor mode for all prog-mode.
#+begin_src emacs-lisp
(use-package hideshow
:straight nil
:hook (prog-mode-hook . hs-minor-mode))
#+end_src
** Aesthetics
Load my custom "personal-theme" theme (look at [[file:personal-theme.el][this file]]).
#+begin_src emacs-lisp
(use-package custom
:defer 5
:straight nil
:config
(load-theme 'monokai t))
#+end_src
Set font size to 125 if no monitor is plugged in.
#+begin_src emacs-lisp
(use-package faces
:straight nil
:config
(set-face-attribute 'default nil :height 115))
#+end_src
Turn off the startup buffer because I don't particularly care for it,
and write into the scratch buffer some nice information about Emacs.
#+begin_src emacs-lisp
(use-package startup
:straight nil
:defer t
:init
(setq inhibit-startup-screen t
initial-scratch-message (format ";; Emacs v%s\n" emacs-version)
ring-bell-function 'ignore)
(add-hook 'emacs-startup-hook
#'(lambda () (with-current-buffer "*scratch*"
(insert (format ";; Loaded in %s\n" (emacs-init-time)))))))
#+end_src
* Emacs Mode-line
Firstly, declare a variable for the separator between each module
#+begin_src emacs-lisp
(defconst +modeline/separator " " "Separator between modules.")
#+end_src
Then declare a variable for the number of separators between each
module in the modeline.
#+begin_src emacs-lisp
(defconst +modeline/sep-count 4 "Number of +modline/separator instances separating modules.")
#+end_src
Then, declare a list of reserved characters for which the previously
declared seperator won't be applied when placed at the end of a module
string.
#+begin_src emacs-lisp
(defconst +modeline/reserved-chars (list "[" "(")
"Characters that, when at the end of a module string, won't have the separator applied to them.")
#+end_src
Now declare a function that applies the separator with respect to the
reserved characters to any one string.
#+begin_src emacs-lisp
(defun +modeline/handle-string (STR)
(condition-case nil
(progn
(string-blank-p STR)
(cond ((cl-member (car (last (split-string STR "" t))) +modeline/reserved-chars :test #'string=) STR)
(t (concat STR (cl-reduce #'concat (cl-loop for i from 1 to +modeline/sep-count collect +modeline/separator))))))
(error STR)))
#+end_src
Finally, set the mode-line-format.
#+begin_src emacs-lisp
(setq-default
mode-line-format
(mapcar #'+modeline/handle-string
(list "%l:%c"
"%p["
'(:eval (upcase
(substring
(format "%s" (if (bound-and-true-p evil-state) evil-state ""))
0 1)))
"]"
"%+%b("
'(:eval (format "%s" major-mode))
")"
"%I"
vc-mode
mode-line-end-spaces)))
#+end_src
* Custom Functions
These are custom functions I have defined
** New line function
Vim bindings don't have a nice way of adding new lines before or after
the current line while staying in normal mode. You can use =o/O= to
enter insert mode at a new line, but this isn't the same as being able
to stay in normal mode while opening newlines and only adds extra
keypresses if your only purpose was to open up some lines.
As this is Emacs I can extend it as I wish, so I decided to define a
new line function that won't remove me from normal state.
The logic is pretty simple:
- Record current location as =old=
- Use the predefined vim functions for opening new lines above and
below with insert mode
- Return to =old=
- Enter normal state
#+begin_src emacs-lisp
(with-eval-after-load "evil"
(defun dx:newline (&optional BACKWARD)
(interactive)
(save-excursion
(cond ((and BACKWARD (= BACKWARD 1)) (evil-open-below 1))
(t (evil-open-above 1))))
(evil-normal-state)))
#+end_src
** Toggle buffer
*** Toggle buffer preamble
There are many cases where 'toggling' a buffer is very useful. For
example, toggling a shell to access it quickly and hide it away with
little annoyance.
This is negligible with a bit of Emacs lisp. However, as stated
earlier, there are /many/ cases where this is useful. Following the
DRY principle means a more abstract function would be better to use
here.
One may use higher order functions to create an abstract form that
handles toggling, and then the caller can wrap this call in a new
function if they wish to use it in a keybinding. This format or
construct is kinda common (using a higher order function and wrapping
it in an interactive function for use in a binding), so I created a
macro that further wraps this functionality, creating a custom
function for you.
The macro asks for a function name, a buffer name and the function
necessary to create that function. It then generates a function with
the given name that holds the necessary logic to 'toggle' buffers.
*** Code
#+begin_src emacs-lisp
(defmacro +dx/create-toggle-function (func-name buf-name buf-create)
"Generate a function named func-name that toggles
the buffer with name buf-name and creation function buf-create."
`(defun ,func-name ()
(interactive)
(let* ((buffer (or (get-buffer ,buf-name) (,buf-create)))
(displayed (get-buffer-window buffer)))
(cond (displayed
(select-window displayed)
(delete-window))
(t
(display-buffer buffer)
(select-window (get-buffer-window buffer)))))))
#+end_src
** Power function
Basic, tail recursive algorithm for calculating powers
#+begin_src emacs-lisp
(defun pow (a n &optional initial)
"Raise a to the nth power. Use init to set the initial value."
(let ((init (if initial
initial
1)))
(if (= n 0)
init
(pow a (- n 1) (* a init)))))
#+end_src
** Define procedure
=lambda= provides a function with possible arguments. A procedure is
something I define as essentially a function without arguments. This
macro returns an anonymous function with no arguments with all the
forms provided. It returns it in 'backquoted' form as that is the most
common use of this macro.
#+begin_src emacs-lisp
(defmacro proc (&rest CDR)
"For a given list of forms CDR, return a quoted non-argument lambda."
`(quote (lambda () ,@CDR)))
#+end_src
* Core packages
** General
Setup general, a good package for defining keys. In this case, I
generate a new definer for the "LEADER" keys. Leader is bound to SPC
and it's functionally equivalent the doom/spacemacs leader.
#+begin_src emacs-lisp
(use-package general
:demand t
:config
(general-def
:states 'normal
"SPC" nil
"M-V" #'dx:newline
"M-v" (proc (interactive) (dx:newline 1)))
(general-create-definer leader
:states 'normal
:keymaps 'override
:prefix "SPC")
(leader
:infix "b"
"d" #'kill-this-buffer))
#+end_src
*** Some default binds in Emacs
With a ton of use-package declarations (to defer until the last
moment), bind to general some basic binds.
#+begin_src emacs-lisp
(use-package face-remap
:straight nil
:general
(general-def
:states 'normal
"C--" #'text-scale-decrease
"C-=" #'text-scale-increase))
(use-package frame
:straight nil
:general
(general-def
:states 'normal
"C-x d" #'delete-frame))
(use-package simple
:straight nil
:general
(leader
"SPC" #'execute-extended-command
"u" #'universal-argument
";" #'eval-expression))
(use-package files
:straight nil
:general
(leader
"q" #'save-buffers-kill-terminal
"cF" (proc (interactive) (find-file "~/Code/")))
(leader
:infix "f"
"f" #'find-file
"s" #'save-buffer
"p" (proc (interactive) (find-file (concat user-emacs-directory "config.org")))))
(use-package compile
:straight nil
:general
(leader
"cc" #'compile))
(use-package imenu
:straight nil
:general
(leader
"si" #'imenu))
(use-package help
:straight nil
:general
(leader
"h" #'help-command))
(use-package async
:straight nil
:general
(leader
"!" #'async-shell-command))
#+end_src
** Evil
*** Evil Preamble
Evil (Emacs VI Layer) is a package that provides the Vi experience to
Emacs. Packaged with it alone are:
- Modal system
- EX
- Vi mapping functions
This provides a lot of stuff for the vim user moving to
Emacs. However there are many other packages surrounding evil that
provide even greater functionality from vi to Emacs. Surround,
commenting, multiple cursors and further support to other packages are
configured here.
*** Evil Core
Setup the evil package, with some basic keybinds.
#+begin_src emacs-lisp
(use-package evil
:hook (after-init-hook . evil-mode)
:general
(general-def
:states 'normal
[remap evil-window-vsplit] #'make-frame
"TAB" #'evil-jump-item
"r" #'evil-replace-state)
(general-def
:states 'visual
:keymaps 'emacs-lisp-mode-map
"gr" #'eval-region)
(leader
"w" #'evil-window-map
"wd" #'delete-frame)
:init
(setq evil-want-keybinding nil
evil-split-window-below t
evil-vsplit-window-right t
evil-want-abbrev-expand-on-insert-exit t)
:config
(evil-mode))
#+end_src
*** Evil surround
#+begin_src emacs-lisp
(use-package evil-surround
:after evil
:config
(global-evil-surround-mode))
#+end_src
*** Evil commentary
#+begin_src emacs-lisp
(use-package evil-commentary
:after evil
:config
(evil-commentary-mode))
#+end_src
*** Evil mc
Setup for multicursors in Evil mode. Don't let evil-mc setup it's own
keymap because it uses 'gr' as its prefix, which I don't like.
Instead, bind some useful functions to my personal =dx:evil-mc-map=
which is bound to 'gz'. Furthermore, define a function
=dx:evil-mc-cursor-here= which pauses cursors upon placing a cursor at
the current position.
#+begin_src emacs-lisp
(use-package evil-mc
:after evil
:bind (("M-p" . evil-mc-skip-and-goto-prev-cursor)
:map dx:evil-mc-map
("q" . evil-mc-undo-all-cursors)
("d" . evil-mc-make-and-goto-next-match)
("j" . evil-mc-make-cursor-move-next-line)
("k" . evil-mc-make-cursor-move-prev-line)
("j" . evil-mc-make-cursor-move-next-line)
("m" . evil-mc-make-all-cursors)
("z" . dx:evil-mc-cursor-here)
("r" . evil-mc-resume-cursors)
("s" . evil-mc-pause-cursors))
:init
(setq evil-mc-key-map nil)
(define-prefix-command 'dx:evil-mc-map)
(bind-key "gz" dx:evil-mc-map evil-normal-state-map)
:config
(global-evil-mc-mode +1)
(defun dx:evil-mc-cursor-here ()
(interactive)
(evil-mc-make-cursor-here)
(evil-mc-pause-cursors)))
#+end_src
*** Evil lion
Evil lion provides alignment operators. Alignment operators allow you
to, on some given text, align it via a symbol.
For example it can transform the following
#+begin_example
(James . 19)
(Arthur . 22)
#+end_example
to
#+begin_example
(James . 19)
(Arthur . 22)
#+end_example
which would be done via =gl<object><symbol>= (in this case =glip.=)
#+begin_src emacs-lisp
(use-package evil-lion
:after evil
:config
(evil-lion-mode))
#+end_src
*** Evil collection
Setup evil collection, but don't turn on the mode. Instead, I'll turn
on setups for specific modes I think benefit from it.
#+begin_src emacs-lisp
(use-package evil-collection
:after evil
:config
(evil-collection-require 'dired)
(evil-collection-require 'proced))
#+end_src
** Completion
*** Completion Preamble
Emacs is a text based interface. As a text based interface it heavily
leverages searches and user filters to manage input and provide
functionality. Though the standard model of completion may be
desirable to some, it can be advanced through the use of 'completion
frameworks'.
These frameworks handle the input from the user for common commands
and provide a differing interface to the one Emacs comes with. Most of
these completion frameworks provide a text based menu that is actively
filtered as more input is provided. Along with these frameworks come
added functionality and applications to integrate into the Emacs
environment further.
One may say that when using a completion framework there is no point
in using any other framework as they encompasses so much of the
default functionality. However I'd argue that with a bit of management
and Emacs lisp it's totally possible to pick and mix your options. For
small number selections (like finding files) use something like Ido
and for something larger like searching buffers use ivy.
Along with frameworks, there is a configuration for the
completions-list, which is actually the original and default method of
completion within Emacs. When you first install Emacs without a
config, any 'completing-read' function leverages the completions-list when
=TAB= is used.
Though I believe Ido is a better completion system than the
completions-list, it still has it's place and can be used in tandem
with ido.
*** Ido
Ido is a very old completion package that still works great to this
day. Though it is limited in its scope (and may thus be called a
completion add-on rather than a full on framework), it is still a very
powerful package. With the use of ido-completing-read+, it may be used
to as a fully fledged completion framework.
#+begin_src emacs-lisp
(use-package ido
:general
(general-def
:keymaps '(ido-buffer-completion-map
ido-file-completion-map
ido-file-dir-completion-map
ido-common-completion-map)
(kbd "M-j") #'ido-next-match
(kbd "M-k") #'ido-prev-match
(kbd "C-x o") #'evil-window-up)
:init
(setq ido-separator "\n")
(setq-default ido-enable-flex-matching t
ido-enable-dot-prefix t
ido-enable-regexp nil)
:config
(ido-mode)
(ido-everywhere))
#+end_src
**** Ido-completing-read+
Ido completing-read+ is a package that extends the ido package to work
with more text based functions.
#+begin_src emacs-lisp
(use-package ido-completing-read+
:after ido
:config
(ido-ubiquitous-mode +1))
#+end_src
**** Amx
Amx is a fork of Smex that works to enhance the
execute-extended-command interface. It also provides support for ido
or ivy (though I'm likely to use ido here) and allows you to switch
between them.
It provides a lot of niceties such as presenting the keybind when
looking for a command.
#+begin_src emacs-lisp
(use-package amx
:after ido
:config
(amx-mode))
#+end_src
*** Completions-list
#+begin_src emacs-lisp
(use-package simple
:straight nil
:general
(general-def
:keymaps 'completion-list-mode-map
:states 'normal
"l" #'next-completion
"h" #'previous-completion
"ESC" #'delete-completion-window
"q" #'quit-window
"RET" #'choose-completion)
:config
(with-eval-after-load "evil"
(setq evil-emacs-state-modes (cl-remove-if
#'(lambda (x) (eq 'completions-list-mode x))
evil-emacs-state-modes))
(add-to-list 'evil-normal-state-modes 'completions-list-mode)))
#+end_src
*** Ivy
Ivy is a completion framework for Emacs, and my preferred (sometimes
second favourite) one. It has a great set of features with little to
no pain with setting up.
**** Counsel
Setup for counsel. Load after ivy and helpful.
Along with that, set the help function and variable functions to their
helpful counterparts.
#+begin_src emacs-lisp
(use-package counsel
:general
(leader
"ss" #'counsel-grep-or-swiper
"sr" #'counsel-rg)
:init
(general-def
[remap describe-bindings] #'counsel-descbinds
[remap load-theme] #'counsel-load-theme)
:config
(setq ivy-initial-inputs-alist nil))
#+end_src
**** Ivy Core
Setup for ivy, in preparation for counsel. Turn on ivy-mode just
after init.
Setup vim-like bindings for the minibuffer ("C-(j|k)" for down|up the
selection list). Also setup evil-collection for ivy.
#+begin_src emacs-lisp
(use-package ivy
:defer 0.5
:general
(general-def
:keymaps 'ivy-minibuffer-map
"M-j" #'ivy-next-line-or-history
"M-k" #'ivy-previous-line-or-history
"C-c C-e" #'ivy-occur)
(general-def
:keymaps 'ivy-switch-buffer-map
"M-j" #'ivy-next-line-or-history
"M-k" #'ivy-previous-line-or-history)
:config
(require 'counsel nil t)
(setq ivy-height 10
ivy-wrap t
ivy-fixed-height-minibuffer t
ivy-use-virtual-buffers nil
ivy-virtual-abbreviate 'full
ivy-on-del-error-function #'ignore
ivy-use-selectable-prompt t))
#+end_src
**** Counsel etags
Counsel etags allows me to search generated tag files for tags. I
already have a function defined to generate the tags, so it's just
searching them which I find to be a bit of a hassle, and where this
package comes in.
#+begin_src emacs-lisp
(use-package counsel-etags
:after counsel
:general
(leader "st" #'counsel-etags-find-tag))
#+end_src
**** Prompt buffer switch
Essentially add advice to the window split functions or frame creation
functions so that they run ivy-switch-buffer once they're finished.
#+begin_src emacs-lisp
(with-eval-after-load "ivy"
(with-eval-after-load "evil"
(advice-add #'evil-window-vsplit :after #'ivy-switch-buffer)
(advice-add #'evil-window-split :after #'ivy-switch-buffer)))
#+end_src
*** Company
Company is the auto complete system I use. I don't like having heavy
setups for company as it only makes it slower to use. In this case,
just setup some evil binds for company.
#+begin_src emacs-lisp
(use-package company
:hook
(prog-mode-hook . company-mode)
(eshell-mode-hook . company-mode)
:general
(general-def
:states 'insert
(kbd "C-SPC") #'company-complete)
(general-def
:states '(normal insert)
"M-j" #'company-select-next
"M-k" #'company-select-previous))
#+end_src
** Pretty symbols
Prettify symbols mode allows for users to declare 'symbols' that
replace text within certain modes. For example, you may replace the
'for' word in c-mode in trade of '∀'. Though this may seem like
useless eye candy, it actually increases my speed of recognition
(recognising symbols is easier than words for many, including
me).
Now here I provide a macro +pretty/set-alist. This macro works pretty
simply: given a mode hook, as well as a list of pairs typed (text to
substitute, symbol to replace with). Then I add a hook to the given
mode, setting the prettify-symbols-alist to the symbols given.
I've declared it pretty high up into my config so that the rest of my
packages can leverage it.
#+begin_src emacs-lisp
(use-package prog-mode
:straight nil
:init
(setq prettify-symbols-unprettify-at-point t)
:config
(defmacro +pretty/set-alist (mode &rest symbols)
`(add-hook
',mode
(lambda ()
(setq prettify-symbols-alist ',symbols)
(prettify-symbols-mode))))
(defun +pretty/set-alist-f (mode symbols)
`(+pretty/set-alist mode ,@symbols)))
#+end_src
Here's a collection of symbols I have currently that may be used
later.
#+begin_example
("null" . "∅")
("list" . "ℓ")
("string" . "𝕊")
("true" . "⊤")
("false" . "⊥")
("char" . "ℂ")
("int" . "ℤ")
("float" . "ℝ")
("!" . "¬")
("&&" . "∧")
("||" . "∨")
("for" . "∀")
("return" . "⟼")
("print" . "ℙ")
("lambda" . "λ")
#+end_example
** Window management
Window management is really important. I find the default window
handling of Emacs incredibly annoying: sometimes consuming my windows,
sometimes creating new ones. So, as Emacs is the ultimate editor, I
want to configure and fine tune the window management of Emacs.
As I am a man who requires only the highest of optimisations, I always
am looking for ways to make my system faster. The buffer management
commands are defined in the window library, so I bind them in general
here as well via a wrapping use-package declaration.
#+begin_src emacs-lisp
(use-package window
:straight nil
:general
(leader
:infix "b"
"b" #'switch-to-buffer
"K" #'kill-buffer
"j" #'next-buffer
"k" #'previous-buffer)
:init
(setq
display-buffer-alist
'(("\\*Org Src.*"
(display-buffer-same-window))
("\\*e?shell\\*"
(display-buffer-at-bottom)
(window-height . 0.25))
("\\*[Hh]elp.*"
(display-buffer-at-bottom)
(inhibit-duplicate-buffer . t)
(window-height . 0.25))
("\\*\\(Wo\\)?Man.*"
(display-buffer-at-bottom)
(window-height . 0.25))
("\\*Proced\\*"
(display-buffer-at-bottom)
(window-height . 0.25))
("\\*Process List\\*"
(display-buffer-at-bottom)
(window-height . 0.25))
("magit:.*"
(display-buffer-same-window)
(inhibit-duplicate-buffer . t))
("magit-diff:.*"
(display-buffer-below-selected))
("magit-log:.*"
(display-buffer-same-window))
("\\*compilation\\*"
(display-buffer-at-bottom)
(window-height . 0.25))
("\\*\\(Ido \\)?Completions\\*"
(display-buffer-in-side-window)
(window-height . 0.25)
(side . bottom))
("\\*Flycheck.*"
(display-buffer-at-bottom)
(window-height . 0.25))
("grep\\*"
(display-buffer-at-bottom)
(window-height . 0.25))
("\\*Python\\*"
(display-buffer-at-bottom)
(window-height . 0.25))
("\\*Org Export.*"
(display-buffer-at-bottom)
(window-height . 0.25))
("\\*Async Shell Command\\*"
(display-buffer-at-bottom)
(window-height . 0.25))
("\\*haskell\\*"
(display-buffer-at-bottom)
(window-height . 0.25))
)))
#+end_src
** Auto typing
*** Auto typing Preamble
Snippets are a system by which pieces of code can be inserted via
prefixes. For example, an 'if' snippet would work by first inserting
the word 'if' then pressing some _expansion key_ such as TAB. This
will insert a set of text that may be have some components that need
to be further filled by the user.
The popular solution is Yasnippet. Yasnippet is a great package for
snippets, which I use heavily in programming and org-mode. I setup
here the global mode for yasnippet and a collection of snippets for
ease of use.
However, Emacs provides its own 'auto typing' facilities. Abbrevs and
skeletons make up the popular solution within Emacs default. Abbrevs
are for simple expressions wherein there is only one user input (say,
getting today's time which only requires you asking for it). They
provide a lot of inbuilt functionality and are quite useful.
Skeletons, on the other hand, are for higher level insertions
*** Abbrevs
Just define a few abbrevs for various date-time operations. Also
define a macro that will assume a function for the expansion, helping
with abstracting a few things away.
#+begin_src emacs-lisp
(use-package abbrev
:straight nil
:hook
(prog-mode-hook . abbrev-mode)
(text-mode-hook . abbrev-mode)
:init
(defmacro +snippets/deff-abbrev (ABBREV-TABLE ABBREV EXPANSION)
"Wraps around define-abbrev to fill in some repeated stuff
when expansion is a function."
`(define-abbrev
,ABBREV-TABLE
,ABBREV
""
(proc (insert ,EXPANSION))))
:config
(+snippets/deff-abbrev
global-abbrev-table
"sdate"
(format-time-string "%Y-%m-%d" (current-time)))
(+snippets/deff-abbrev
global-abbrev-table
"stime"
(format-time-string "%H:%M:%S" (current-time)))
(+snippets/deff-abbrev
text-mode-abbrev-table
"sday"
(format-time-string "%A" (current-time)))
(+snippets/deff-abbrev
text-mode-abbrev-table
"smonth"
(format-time-string "%B" (current-time))))
#+end_src
*** Skeletons
Defining some basic skeletons
#+begin_src emacs-lisp
(use-package skeleton
:straight nil
:after abbrev
:config
(defmacro +snippets/gen-skeleton-abbrev (mode abbrev &rest skeleton)
(let* ((table (intern (concat (symbol-name mode) "-abbrev-table")))
(skeleton-name (intern (concat "+" "skeleton/" (symbol-name mode) "/" abbrev))))
`(progn
(define-skeleton
,skeleton-name
""
,@skeleton)
(define-abbrev ,table
,abbrev-name
""
',skeleton-name)))))
#+end_src
*** Yasnippet default
:PROPERTIES:
:header-args:emacs-lisp: :tangle no
:END:
Setup global mode after evil mode has been loaded
#+begin_src emacs-lisp
(use-package yasnippet
:after evil
:hook
(prog-mode-hook . yas-minor-mode)
(text-mode-hook . yas-minor-mode)
:general
(leader
"i" #'yas-insert-snippet)
:config
(yas-load-directory (no-littering-expand-etc-file-name "yasnippet/snippets")))
#+end_src
*** Yasnippet snippets
:PROPERTIES:
:header-args:emacs-lisp: :tangle no
:END:
Collection of snippets, activate after yasnippet has been loaded.
#+begin_src emacs-lisp
(use-package yasnippet-snippets
:after yasnippet)
#+end_src
* Small packages
** Display line numbers
I don't like using this mode by default, but I'd like to configure it
if possible.
#+begin_src emacs-lisp
(use-package display-line-numbers
:straight nil
:defer t
:commands display-line-numbers-mode
:init
(setq display-line-numbers t))
#+end_src
** Projectile
Setup projectile, along with the tags command. Also bind "C-c C-p" to
the projectile command map for quick access.
#+begin_src emacs-lisp
(use-package projectile
:after evil
:hook (prog-mode-hook . projectile-mode)
:general
(leader "p" #'projectile-command-map)
:init
(setq projectile-tags-command "ctags -Re -f \"%s\" %s \"%s\"")
:config
(projectile-global-mode))
#+end_src
*** Counsel projectile
Counsel projectile provides the ivy interface to projectile commands, which is really useful.
#+begin_src emacs-lisp :tangle no
(use-package counsel-projectile
:after (projectile counsel)
:config
(counsel-projectile-mode +1))
#+end_src
** Hydra
Use hydras for stuff that I use often, currently buffer manipulation
#+begin_src emacs-lisp
(use-package hydra
:defer nil
:after evil
:init
(defun dx:kill-defun ()
"Mark defun then kill it."
(interactive)
(mark-defun)
(delete-active-region t))
(defun dx:paste-section ()
"Paste the current kill-region content above section."
(interactive)
(open-line 1)
(yank))
:config
(defhydra hydra-buffer (evil-normal-state-map "SPC b")
"buffer-hydra"
("l" next-buffer)
("h" previous-buffer)
("c" kill-this-buffer))
(defhydra hydra-goto-chg (evil-normal-state-map "g;")
"goto-chg"
(";" goto-last-change "goto-last-change")
("," goto-last-change-reverse "goto-last-change-reverse"))
(defhydra hydra-code-manipulator (global-map "C-x c")
"code-manip"
("j" evil-forward-section-begin)
("k" evil-backward-section-begin)
("m" mark-defun)
("d" dx:kill-defun)
("p" dx:paste-section)
("TAB" evil-toggle-fold)))
#+end_src
** Avy
Setup avy with leader. As I use =avy-goto-char-timer= a lot, use the
=M-s= bind.
#+begin_src emacs-lisp
(use-package avy
:after evil
:general
(leader
:infix "s"
"l" #'avy-goto-line)
(general-def
:states 'normal
(kbd "M-s") #'avy-goto-char-timer))
#+end_src
** Ace window
Though evil provides a great many features in terms of window
management, much greater than what's easily available in Emacs, ace
window can provide some nicer chords for higher management of windows
(closing, switching, etc).
#+begin_src emacs-lisp
(use-package ace-window
:after evil
:custom
(aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
:general
(general-def
:states 'normal
[remap evil-window-next] #'ace-window))
#+end_src
** Helpful
Basic setup, will be fully integrated in counsel.
#+begin_src emacs-lisp
(use-package helpful
:general
(general-def
[remap describe-function] #'helpful-callable
[remap describe-variable] #'helpful-variable
[remap describe-key] #'helpful-key)
:config
(evil-define-key 'normal helpful-mode-map "q" #'quit-window))
#+end_src
** Which-key
Pretty simple, just activate after init.
#+begin_src emacs-lisp
(use-package which-key
:defer nil
:config
(which-key-mode))
#+end_src
** Keychord
Keychord is only really here for this one chord I wish to define: "jk"
for exiting insert state. Otherwise, I don't really need it.
#+begin_src emacs-lisp
(use-package key-chord
:after evil
:config
(key-chord-define evil-insert-state-map "jk" #'evil-normal-state)
(key-chord-mode +1))
#+end_src
** (Rip)grep
*** Grep Preamble
Grep is a historical artefact. It is a searching utility that allows
one to search files for certain regex patterns. The fact that there
have been so many attempts to replace grep (with some success) only
goes to show how important a tool it is.
Ripgrep is a grep-like utility written in Rust. It subsumes not only
the ability to search a given file but also to search multiple files
within a directory (which is usually only found by composing the
program find with grep to search multiple files). Being incredibly
fast through its regex optimisations, it also uses ignore files such
as =.gitignore= to remove files from its searches.
Grep has default Emacs utilities that use a =compilation= style buffer
to search a variety of differing data sets. =grep= searches files,
=rgrep= searches in a directory using the =find= binary and =zgrep=
searches archives. This is a great solution for most environments as
most of them will have grep and find installed. Even when you =ssh=
into a remote machine, they're likely to have these tools.
The ripgrep package provides utilities to ripgrep projects and files
for strings via the rg binary. Though [[*Ivy][ivy]] comes with =counsel-rg=
using it makes me dependent on the ivy framework, and this
configuration is intentionally built to be modular and switchable. Of
course, this requires installing the rg binary which is available in
most common repositories nowadays. In terms of general speed, this is
better.
*** Grep
#+begin_src emacs-lisp
(use-package grep
:straight nil
:general
(leader
"sd" #'rgrep))
#+end_src
*** rg
#+begin_src emacs-lisp
(use-package rg
:general
(leader "sr" #'rg)
(:keymaps 'rg-mode-map
"]]" #'rg-next-file
"[[" #'rg-prev-file
"q" #'quit-window)
:init
(setq rg-group-result t
rg-hide-command t
rg-show-columns nil
rg-show-header t
rg-custom-type-aliases nil
rg-default-alias-fallback "all"
rg-buffer-name "*ripgrep*"))
#+end_src
* Applications
** Mail
*** Mail Preamble
Mail is a funny thing; most people use it just for business or
advertising and it's come out of use in terms of personal
communication in the west for the most part (largely due to "social"
media applications). However, this isn't true for the open source and
free software movement who heavily use mail for communication.
Integrating mail into Emacs helps as I can send source code and
integrate it into my workflow just a bit better.
*** Notmuch
#+begin_src emacs-lisp
(defconst +mail/signature "---------------\nAryadev Chavali")
(defconst +mail/local-dir (concat user-emacs-directory ".mail/"))
(use-package notmuch
:commands notmuch
:general
(leader "am" #'notmuch)
:init
(defun +mail/sync-mail ()
"Sync mail via mbsync."
(interactive)
(start-process-shell-command "" nil "mbsync -a"))
:custom
(notmuch-show-logo nil)
(notmuch-hello-sections '(notmuch-hello-insert-saved-searches notmuch-hello-insert-alltags))
(mail-signature +mail/signature)
(mail-default-directory +mail/local-dir)
(mail-source-directory +mail/local-dir)
(message-signature +mail/signature)
(message-auto-save-directory +mail/local-dir)
(message-directory +mail/local-dir)
:config
;; sync mail after refresh
(advice-add #'notmuch-poll-and-refresh-this-buffer :before
#'+mail/sync-mail)
(evil-collection-notmuch-setup))
#+end_src
*** Smtpmail
#+begin_src emacs-lisp
(use-package smtpmail
:after notmuch
:commands mail-send
:custom
(smtpmail-smtp-server "mail.aryadevchavali.com")
(smtpmail-smtp-user "aryadev")
(smtpmail-smtp-service 587)
(smtpmail-stream-type 'starttls)
:init
(setq send-mail-function #'smtpmail-send-it
message-send-mail-function #'smtpmail-send-it))
#+end_src
*** Org message
Org message allows for the use of org mode when composing mails,
generating HTML multipart emails. This integrates the WYSIWYG
experience into mail in Emacs while also providing powerful text
features with basically no learning curve (as long as you've already
learnt the basics of org).
#+begin_src emacs-lisp
(use-package org-msg
:hook
(message-mode-hook . org-msg-mode)
:config
(setq org-msg-options "html-postamble:nil H:5 num:nil ^:{} toc:nil author:nil email:nil \\n:t tex:dvipng"
org-msg-greeting-fmt "Dear %s,\n"
org-msg-greeting-name-limit 3
org-msg-text-plain-alternative t)
(add-to-list 'org-msg-enforce-css
'(img latex-fragment-inline
((transform . ,(format "translateY(-1px) scale(%.3f)"
(/ 1.0 (if (boundp 'preview-scale)
preview-scale 1.4))))
(margin . "0 -0.35em")))))
#+end_src
** Dired
Setup for dired. Make dired-hide-details-mode the default mode when
using dired-mode, as it removes the clutter. Setup evil collection
for dired (even though dired doesn't really conflict with evil, there
are some corners I'd like to adjust).
#+begin_src emacs-lisp
(use-package dired
:straight nil
:hook (dired-mode-hook . dired-hide-details-mode)
:general
(leader
:infix "d"
"f" #'find-dired
"D" #'dired-other-frame
"d" #'dired-jump)
:config
(with-eval-after-load "evil-collection"
(evil-collection-dired-setup)))
#+end_src
** Xwidget
*** Xwidget Preamble
Xwidget is a package (must be compiled at source) which allows for the
insertion of arbitrary xwidgets into Emacs through buffers. One of its
premier uses is in navigating the web which it provides through the
function =xwidget-webkit-browse-url=. This renders a fully functional
web browser within Emacs.
Though I am not to keen on using Emacs to browse the web /via/ xwidget
(EWW does a good job on its own), I am very interested in its
capability to render full fledged web pages which include JavaScript,
as it may come of use when doing web development. I can see the
results of work very quickly without switching windows or workspaces.
*** Xwidget Core
Define a function =+xwidget/render-file= that reads a file name and
presents it in an xwidget. If the current file is an HTML file, ask if
user wants to open current file. Bind it to =aU= in the leader.
#+begin_src emacs-lisp
(use-package xwidget
:commands +xwidget/render-file
:straight nil
:general
(leader "au" #'xwidget-webkit-browse-url
"aU" #'+xwidget/render-file)
(general-def
:states 'normal
:keymaps 'xwidget-webkit-mode-map
"q" #'quit-window
"h" #'xwidget-webkit-scroll-backward
"j" #'xwidget-webkit-scroll-up
"k" #'xwidget-webkit-scroll-down
"l" #'xwidget-webkit-scroll-forward
(kbd "C-f") #'xwidget-webkit-scroll-up
(kbd "C-b") #'xwidget-webkit-scroll-down
"H" #'xwidget-webkit-back
"L" #'xwidget-webkit-forward
"gu" #'xwidget-webkit-browse-url
"gr" #'xwidget-webkit-reload
"gg" #'xwidget-webkit-scroll-top
"G" #'xwidget-webkit-scroll-bottom)
:config
(defun +xwidget/render-file (&optional FORCE)
"Find file (or use current file) and render in xwidget."
(interactive)
(cond
((and (not FORCE) (or (string= (replace-regexp-in-string ".*.html"
"html" (buffer-name)) "html")
(eq major-mode 'web-mode)
(eq major-mode 'html-mode))) ; If in html file
(if (y-or-n-p "Open current file?: ") ; Maybe they want to open a separate file
(xwidget-webkit-browse-url (format "file://%s" (buffer-file-name)))
(+xwidget/render-file t))) ; recurse and open file via prompt
(t
(xwidget-webkit-browse-url
(format "file://%s" (read-file-name "Enter file to open: ")))))))
#+end_src
** Eshell
*** Eshell Preamble
Eshell is the integrated shell environment for Emacs. Though it isn't
necessarily *the best* shell, it really suits the 'integrated
computing environment' moniker that Emacs gets.
It may be argued that Emacs integrates within itself many of the
functionalities that one would use within a shell or terminal. Stuff
like compilation, file management, large scale text manipulation could
be done through Emacs' own tools (=compile=, =dired= and =occur= come
to mind). However, I'd argue that eshell's greatest ability comes from
it's separation (or perhaps better phrased, *integration*) of two
'parsers': the Lisp parser and the Shell parser. With these parsers
you can mix and match at will for use in the shell, which grants
greater power than many shells I know of.
*** Eshell Core
Setup a function that /toggles/ the eshell window rather than
just opening it via =+dx/toggle-buffer=.
Along with that setup the prompt so it looks a bit nicer and add
pretty symbols to eshell.
#+begin_src emacs-lisp
(use-package eshell
:commands +shell/toggle-shell
:general
(leader
"tt" #'+shell/toggle-eshell)
:init
(with-eval-after-load "prog-mode"
(+pretty/set-alist
eshell-mode-hook
("lambda" . "λ")
("numberp" . "ℤ")
("t" . "𝕋")
("nil" . "∅")))
(add-hook
'eshell-mode-hook
(proc
(interactive)
(general-def
:states '(insert normal)
:keymaps 'eshell-mode-map
"C-l" #'eshell/clear-scrollback
"C-j" #'eshell-next-matching-input-from-input
"C-k" #'eshell-previous-matching-input-from-input)))
:config
(setq eshell-cmpl-ignore-case t
eshell-cd-on-directory t
eshell-prompt-function
(proc
(concat
(format "[%s]\n" (abbreviate-file-name (eshell/pwd)))
"λ "))
eshell-prompt-regexp "^λ ")
(+dx/create-toggle-function
+shell/toggle-eshell
"*eshell*"
eshell))
#+end_src
** Elfeed
Elfeed is the perfect RSS feed reader, integrated into Emacs
perfectly. I've got a set of feeds that I use for a large variety of
stuff, mostly media and entertainment. I've also bound "<leader> ar"
to elfeed for loading the system.
#+begin_src emacs-lisp
(use-package elfeed
:general
(leader "ar" #'elfeed)
(general-def
:states 'normal
:keymaps 'elfeed-search-mode-map
"gr" #'elfeed-update
"s" #'elfeed-search-live-filter
"<return>" #'elfeed-search-show-entry)
:init
(setq elfeed-db-directory (no-littering-expand-var-file-name "elfeed/"))
(setq +rss/feed-urls
'(("Arch Linux"
"https://www.archlinux.org/feeds/news/"
Linux)
("LEMMiNO"
"https://www.youtube.com/feeds/videos.xml?channel_id=UCRcgy6GzDeccI7dkbbBna3Q"
YouTube Stories)
("Dark Sominium"
"https://www.youtube.com/feeds/videos.xml?channel_id=UC_e39rWdkQqo5-LbiLiU10g"
YouTube Stories)
("Dark Sominium Music"
"https://www.youtube.com/feeds/videos.xml?channel_id=UCkLiZ_zLynyNd5fd62hg1Kw"
YouTube Music)
("Nexpo"
"https://www.youtube.com/feeds/videos.xml?channel_id=UCpFFItkfZz1qz5PpHpqzYBw"
YouTube)
("Techquickie"
"https://www.youtube.com/feeds/videos.xml?channel_id=UC0vBXGSyV14uvJ4hECDOl0Q"
YouTube)
("Captain Sinbad"
"https://www.youtube.com/feeds/videos.xml?channel_id=UC8XKyvQ5Ne_bvYbgv8LaIeg"
YouTube)
("3B1B"
"https://www.youtube.com/feeds/videos.xml?channel_id=UCYO_jab_esuFRV4b17AJtAw"
YouTube)
("Fredrik Knusden"
"https://www.youtube.com/feeds/videos.xml?channel_id=UCbWcXB0PoqOsAvAdfzWMf0w"
YouTube Stories)
("Barely Sociable"
"https://www.youtube.com/feeds/videos.xml?channel_id=UC9PIn6-XuRKZ5HmYeu46AIw"
YouTube Stories)
("Atrocity Guide"
"https://www.youtube.com/feeds/videos.xml?channel_id=UCn8OYopT9e8tng-CGEWzfmw"
YouTube Stories)
("Philip Defranco"
"https://www.youtube.com/feeds/videos.xml?channel_id=UClFSU9_bUb4Rc6OYfTt5SPw"
YouTube News)
("Hacker News"
"http://morss.aryadevchavali.com/news.ycombinator.com/rss"
Social)
("Hacker Factor"
"https://www.hackerfactor.com/blog/index.php?/feeds/index.rss2"
Social)
("BBC Top News"
"http://morss.aryadevchavali.com/feeds.bbci.co.uk/news/rss.xml"
News)
("BBC Tech News"
"http://morss.aryadevchavali.com/feeds.bbci.co.uk/news/technology/rss.xml"
News)))
:config
(with-eval-after-load "evil-collection"
(evil-collection-elfeed-setup))
(setq elfeed-feeds (cl-map 'list #'(lambda (item)
(append (list (nth 1 item)) (cdr (cdr item))))
+rss/feed-urls)))
#+end_src
** Magit
Magit is *the* git porcelain for Emacs, which perfectly encapsulates
the git cli. In this case, I just need to setup the bindings for it.
As magit will definitely load after evil (as it must be run by a
binding, and evil will load after init), I can use evil-collection
freely.
#+begin_src emacs-lisp
(use-package magit
:general
(leader "g" #'magit-status)
:init
(setq magit-completing-read-function 'magit-ido-completing-read
vc-follow-symlinks t))
(use-package evil-magit
:after magit
:config
(evil-magit-init))
#+end_src
** IBuffer
#+begin_src emacs-lisp
(use-package ibuffer
:after evil
:general
(leader
"bi" #'ibuffer)
:config
(with-eval-after-load "evil-collection"
(evil-collection-ibuffer-setup)))
#+end_src
** Calculator
Surprise, surprise Emacs comes with a calculator. At this point there
is little that surprises me in terms of Emacs' amazing capabilities.
=calc-mode= is a calculator system within Emacs that provides an
incredible array of mathematical operations. It uses reverse polish
notation to do calculations (though there is a standard infix
algebraic notation mode) and provides incredible utilities.
#+begin_src emacs-lisp
(use-package calc
:straight nil
:general
(leader
"ac" #'calc)
:init
(setq calc-algebraic-mode t)
:config
(with-eval-after-load "evil-collection"
(evil-collection-calc-setup)))
#+end_src
*** Calctex
=calc-mode= also has a 3rd party package called =calctex=. It renders
mathematical expressions within calc as if they were rendered in TeX.
You can also copy the expressions in their TeX forms, which is pretty
useful when writing a paper. I've set a very specific lock on this
repository as it's got quite a messy work-tree and this commit seems to
work for me given the various TeX utilities installed via Arch.
#+begin_src emacs-lisp
(use-package calctex
:after calc
:straight (calctex :type git :host github :repo "johnbcoughlin/calctex")
:hook (calc-mode-hook . calctex-mode))
#+end_src
* Major modes, programming and text
Setups for common major modes and languages.
** General Text Configuration
Standard packages and configurations for the text-mode. These
configurations are usually further placed on
*** Flyspell
Flyspell allows me to quickly spell check text documents. I use
flyspell primarily in org mode, as that is my preferred prose writing
software, but I also need it in commit messages and so on. So
flyspell-mode should be hooked to text-mode.
#+begin_src emacs-lisp
(use-package flyspell
:hook (text-mode-hook . flyspell-mode)
:general
(general-def
:states 'normal
:keymaps 'text-mode-map
(kbd "M-a") #'flyspell-correct-word-before-point
(kbd "M-A") #'flyspell-auto-correct-word))
#+end_src
*** White space
Deleting whitespace, highlighting when going beyond the 80th character
limit, all good stuff.
I don't want to highlight whitespace for general mode categories
(Emacs lisp shouldn't really have an 80 character limit; it's a bit of
a wild gun), so set it for specific modes I find need the help.
#+begin_src emacs-lisp
(use-package whitespace
:straight nil
:general
(general-def
:states 'normal
"M--" #'whitespace-cleanup)
:hook
(before-save-hook . whitespace-cleanup)
(c-mode-hook . whitespace-mode)
(c++-mode-hook . whitespace-mode)
(haskell-mode-hook . whitespace-mode)
(python-mode-hook . whitespace-mode)
:init
(setq whitespace-style '(face lines-tail tabs tab-mark trailing newline)
whitespace-line-column 80))
#+end_src
*** Set auto-fill-mode for all text-modes
Auto fill mode is nice for most text modes, 80 char limit is great.
#+begin_src emacs-lisp
(add-hook 'text-mode-hook #'auto-fill-mode)
#+end_src
*** Delete a sentence in auto fill
In long lines via truncate lines, deleting till the end of the
sentence was easy via vim motions. However, the same action is
difficult with auto-fill-mode where sentences are separated through
(potentially several) newlines which makes vim motions
difficult. Thus, I propose some form of functionality which allows you
to:
- Find the next closest period denoting the end of the sentence
- Delete the region between the point of invocation and the found period
This essentially does the same task as vim motion based deletion, but
can handle the newlines. To not trample on the toes of any package,
I'll set it to "M-d" (kill-word), the most inoffensive binding
possible which is still mnemonic.
First, the function. I'll use search-forward (from zap* lib) to find
the period. Then auto-fill to make it look nice.
#+begin_src emacs-lisp
(defun +text/delete-till-sentence ()
"Delete all text from current point to the next closest period."
(interactive)
(set-mark-command nil)
(search-forward ". ")
(kill-region (region-beginning) (region-end))
(fill-paragraph))
#+end_src
Now, the binding
#+begin_src emacs-lisp
(general-def
:states '(normal insert)
(kbd "M-d") #'+text/delete-till-sentence)
#+end_src
*** Smartparens
Smartparens is a smarter electric-parens, it's much more aware of
stuff and easier to use.
#+begin_src emacs-lisp
(use-package smartparens
:hook
(prog-mode-hook . smartparens-mode)
(text-mode-hook . smartparens-mode)
:after evil
:config
(setq sp-highlight-pair-overlay nil
sp-highlight-wrap-overlay t
sp-highlight-wrap-tag-overlay t)
(let ((unless-list '(sp-point-before-word-p
sp-point-after-word-p
sp-point-before-same-p)))
(sp-pair "'" nil :unless unless-list)
(sp-pair "\"" nil :unless unless-list))
(sp-local-pair sp-lisp-modes "(" ")" :unless '(:rem sp-point-before-same-p))
(require 'smartparens-config))
#+end_src
*** Show-paren-mode
Show parenthesis for Emacs
#+begin_src emacs-lisp
(add-hook 'prog-mode-hook #'show-paren-mode)
#+end_src
** General Programming Configuration
*** Eldoc
Eldoc presents documentation to the user upon placing ones cursor upon
any symbol. This is very useful when programming as it:
- presents the arguments of functions while writing calls for them
- presents typing and documentation of variables
#+begin_src emacs-lisp
(use-package eldoc
:straight nil
:hook (prog-mode-hook . eldoc-mode)
:init
(global-eldoc-mode 1))
(use-package eldoc-box
:hook (eldoc-mode-hook . eldoc-box-hover-mode)
:init
(setq eldoc-box-position-function #'eldoc-box--default-upper-corner-position-function
eldoc-box-clear-with-C-g t))
#+end_src
*** Eglot
Eglot is a library of packages to communicate with LSP servers for
better programming capabilities. Interactions with a server provide
results to the client, done through JSON.
#+begin_src emacs-lisp
(use-package eglot
:hook
(c++-mode-hook . eglot-ensure)
(c-mode-hook . eglot-ensure)
(python-mode-hook . eglot-ensure)
:general
(leader
:keymaps 'eglot-mode-map
:infix "c"
"f" #'eglot-format
"a" #'eglot-code-actions
"r" #'eglot-rename
"R" #'eglot-reconnect)
:init
(setq eglot-stay-out-of '(flymake))
(defun project-root (PROJECT)
"Return the single root of a project."
(car (project-roots PROJECT))))
#+end_src
*** Flycheck
Flycheck is the checking system for Emacs. I don't necessarily like
having all my code checked all the time, so I haven't added a hook to
prog-mode as it would be better for me to decide when I want checking
and when I don't.
#+begin_src emacs-lisp
(use-package flycheck
:commands (flycheck-mode flycheck-list-errors)
:general
(leader
"tf" #'flycheck-mode
"cx" #'flycheck-list-errors)
:config
(with-eval-after-load "evil-collection"
(evil-collection-flycheck-setup)))
#+end_src
*** Tabs and spaces
By default, turn off tabs and set the tab width to two.
#+begin_src emacs-lisp
(setq-default indent-tabs-mode nil
tab-width 2)
#+end_src
However, if necessary later, define a function that may activate tabs locally.
#+begin_src emacs-lisp
(defun dx:activate-tabs ()
(interactive)
(setq-local indent-tabs-mode t))
#+end_src
*** Colourising compilation
Colourising the compilation buffer so ansi color codes get computed.
#+begin_src emacs-lisp
(use-package compilation
:defer t
:straight nil
:config
(defun +compile/colourise ()
"Colourise the emacs compilation buffer."
(let ((inhibit-read-only t))
(ansi-color-apply-on-region (point-min) (point-max))))
(add-hook 'compilation-filter-hook #'+compile/colourise))
#+end_src
** PDF
*** PDF Preamble
PDFs are a great format for (somewhat) immutable text and reports with
great formatting options. Though Emacs isn't really the premier
solution for viewing PDFs (I highly recommend [[https://pwmt.org/projects/zathura/][Zathura]]), similar to
most things with Emacs, having a PDF viewer builtin can be a very
useful asset.
For example if I were editing an org document which I was eventually
compiling into a PDF, my workflow would be much smoother with a PDF
viewer within Emacs that I can open on another pane.
Furthermore many governmental studies and essays use the PDF
format. If I were to be analysing them in a study or project (for
example, programming a tool using data from them), which I will most
definitely be using Emacs for, having a PDF pane open for occasional
viewing can be very useful.
*** PDF Tools
=pdf-tools= provides the necessary functionality for viewing
PDFs. There is no PDF viewing without this package. =evil-collection=
provides a setup for this mode, so use that.
#+begin_src emacs-lisp
(use-package pdf-tools
:mode ("\\.[pP][dD][fF]" . pdf-view-mode)
:config
(with-eval-after-load "evil-collection"
(evil-collection-pdf-setup)))
#+end_src
*** PDF grep
PDF grep is a Linux tool that allows for searches against PDFs similar
to standard grep (but for PDFs!). It's a bit badly configured (why not
use the current buffer?) but it works out.
#+begin_src emacs-lisp
(use-package pdfgrep
:after pdf-tools
:hook (pdf-view-mode-hook . pdfgrep-mode)
:general
(general-def
:states 'normal
:keymaps 'pdf-view-mode-map
"M-g" #'pdfgrep))
#+end_src
** Org
*** Org Core Configuration
Hooks, prettify-symbols and my =+org/swiper-goto= to replace the
vanilla =org-goto=
#+begin_src emacs-lisp
(use-package org
:hook
(org-mode-hook . prettify-symbols-mode)
:init
(with-eval-after-load "prog-mode"
(+pretty/set-alist
org-mode-hook
("#+begin_src" . "≫")
("#+end_src" . "≪")))
:config
(with-eval-after-load "swiper"
(defun +org/swiper-goto ()
(interactive)
(swiper "^\\* "))
(general-def
[remap org-goto] #'+org/swiper-goto)))
#+end_src
*** Org Core Bindings
Some bindings for org mode.
#+begin_src emacs-lisp
(use-package org
:general
(general-def
:states 'normal
:keymaps 'org-mode-map
"C-c ;" #'org-property-action))
#+end_src
*** Org Core Variables
Tons of variables for org-mode, including a ton of latex ones.
#+begin_src emacs-lisp
(use-package org
:custom
(org-edit-src-content-indentation 0)
(org-goto-interface 'outline)
(org-src-window-setup 'current-window)
(org-indirect-buffer-display 'current-window)
(org-eldoc-breadcrumb-separator " → ")
(org-enforce-todo-dependencies t)
(org-fontify-quote-and-verse-blocks t)
(org-fontify-whole-heading-line t)
(org-footnote-auto-label 'plain)
(org-hide-leading-stars t)
(org-hide-emphasis-markers nil)
(org-image-actual-width nil)
(org-priority-faces '((?A . error) (?B . warning) (?C . success)))
(org-startup-indented t)
(org-tags-column 0)
(org-todo-keywords
'((sequence "TODO" "WAIT" "DONE")
(sequence "PROJ" "WAIT" "COMPLETE")))
(org-use-sub-superscripts '{})
(org-latex-listings 'minted)
(org-babel-load-languages '((emacs-lisp . t)
(C . t)))
(org-latex-packages-alist '(("" "minted")))
(org-latex-pdf-process
'("%latex -interaction nonstopmode -shell-escape -output-directory %o %f"
"%latex -interaction nonstopmode -shell-escape -output-directory %o %f"
"%latex -interaction nonstopmode -shell-escape -output-directory %o %f"))
(org-latex-minted-options '(("style" "xcode")
("linenos")
("frame" "single")
("mathescape")
("fontfamily" "courier")
("samepage" "false")
("breaklines" "true")
("breakanywhere" "true")
)))
#+end_src
*** Evil Org
Evil org for some nice bindings.
#+begin_src emacs-lisp
(use-package evil-org
:hook (org-mode-hook . evil-org-mode))
#+end_src
*** Org fragtog
Toggle latex fragments in org mode so you get fancy maths symbols. I
use latex a bit in org mode as it is the premier way of getting
mathematical symbols and text rendered and compiled, but org mode >
latex.
As Org mode has the ability to accept arbitrary inputs of Latex
(through escaped (square) brackets), allowing me to observe how they
look is nice to have.
#+begin_src emacs-lisp
(use-package org-fragtog
:hook (org-mode-hook . org-fragtog-mode))
#+end_src
*** Org pretty tables
Make the default ASCII tables of org mode pretty with
#+begin_src emacs-lisp
(use-package org-pretty-table-mode
:straight (org-pretty-table-mode :type git :host github :repo "Fuco1/org-pretty-table")
:hook org-mode-hook)
#+end_src
*** Org pretty tags
#+begin_src emacs-lisp
(use-package org-pretty-tags
:hook (org-mode-hook . org-pretty-tags-mode))
#+end_src
*** Org superstar
Org superstar adds cute little unicode symbols for headers, much
better than the default asterisks.
#+begin_src emacs-lisp
(use-package org-superstar
:hook (org-mode-hook . org-superstar-mode))
#+end_src
** C/C++
Setup for C and C++ modes via the cc-mode package.
*** C/C++ Preamble
C and C++ are great languages for general purpose programming. Though
lisp is more aesthetically and mentally pleasing, they get the job
done. Furthermore, they provide speed and finer control in trade of
aesthetics and security-based abstractions.
When writing C/C++ code, I use folds and section manipulation quite a
bit so observing folds is quite important for me when considering a
codebase. Thus, I observed the two main styles of brace placement and
how they do folds.
#+begin_src c :tangle no
if (cond) {...}
#+end_src
vs
#+begin_src c :tangle no
if (cond)
{....}
#+end_src
I don't print my code, nor am I absolutely pressed for screen real
estate in terms of height (such that newlines matter). Width matters
to me as I do use Emacs multiplexing capabilities often. Thus, with
these in mind the open brace style is a better option than the
opposing style.
Also, with large code bases consistency is important. I personally use
tabs as they are more accessible: anyone can set their tab width such
that it best suits them. Furthermore, tabs produce smaller source
files. However, this isn't set in stone and I will return to no tabs
when needed in projects. Also auto fill mode makes splitting my window
bearable; all text can fit on the screen.
*** Configuration
#+begin_src emacs-lisp
(use-package cc-mode
:hook
(c-mode-hook . auto-fill-mode)
(c++-mode-hook . auto-fill-mode)
:init
(setq-default c-basic-offset 2)
(setq c-default-style '((java-mode . "java")
(awk-mode . "awk")
(other . "user")))
(with-eval-after-load "prog-mode"
(+pretty/set-alist
c-mode-hook
("puts" . "ℙ")
("fputs" . "ϕ")
("printf" . "ω")
("fprintf" . "Ω")
("->" . "→")
("NULL" . "∅")
("true" . "⊤")
("false" . "⊥")
("char" . "ℂ")
("int" . "ℤ")
("float" . "ℝ")
("!" . "¬")
("&&" . "∧")
("||" . "∨")
("for" . "∀")
("return" . "⟼"))
(+pretty/set-alist
c++-mode-hook
("nullptr" . "∅")
("std::string" . "𝕊")
("string" . "𝕊")
("vector" . "ℓ")
("puts" . "ℙ")
("fputs" . "ϕ")
("printf" . "ω")
("fprintf" . "Ω")
("->" . "→")
("NULL" . "∅")
("true" . "⊤")
("false" . "⊥")
("char" . "ℂ")
("int" . "ℤ")
("float" . "ℝ")
("!" . "¬")
("&&" . "∧")
("||" . "∨")
("for" . "∀")
("return" . "⟼")))
:config
(c-add-style
"user"
'((c-basic-offset . 2)
(c-comment-only-line-offset . 0)
(c-hanging-braces-alist (brace-list-open)
(brace-entry-open)
(substatement-open after)
(block-close . c-snug-do-while)
(arglist-cont-nonempty))
(c-cleanup-list brace-else-brace)
(c-offsets-alist
(statement-block-intro . +)
(knr-argdecl-intro . 0)
(substatement-open . 0)
(substatement-label . 0)
(access-label . -)
(inline-open . 0)
(label . 0)
(statement-cont . +)))))
#+end_src
*** Clang format
Clang format for when:
- eglot isn't working/I'm not running it
- eglot format is bad
#+begin_src emacs-lisp
(use-package clang-format
:after cc-mode
:config
(bind-key "C-c '" #'clang-format-region c-mode-map)
(bind-key "C-c '" #'clang-format-region c++-mode-map))
#+end_src
** Haskell
Haskell is a static lazy functional programming language (what a
mouthful). It's quite a beautiful language and really learning it will
change the way you think about programming.
Here I configure the REPL for Haskell via the
=interactive-haskell-mode= as well.
#+begin_src emacs-lisp
(use-package haskell-mode
:hook
(haskell-mode-hook . haskell-indentation-mode)
(haskell-mode-hook . interactive-haskell-mode)
:general
(leader
"th" #'+shell/toggle-haskell-repl)
:config
(+dx/create-toggle-function
+shell/toggle-haskell-repl
"*haskell*"
haskell-process-start))
#+end_src
** Python
Basic, haven't used python in this configuration yet.
#+begin_src emacs-lisp
(use-package python
:straight nil
:init
(setq python-indent-offset 4)
:config
(+pretty/set-alist
python-mode-hook
("None" . "∅")
("list" . "ℓ")
("List" . "ℓ")
("str" . "𝕊")
("True" . "⊤")
("False" . "⊥")
("int" . "ℤ")
("float" . "ℝ")
("not" . "¬")
("and" . "∧")
("or" . "∨")
("for" . "∀")
("print" . "ℙ")
("lambda" . "λ")
("return" . "⟼")
("yield" . "⟻")))
#+end_src
*** Python shell
Setup for python shell, including a toggle option
#+begin_src emacs-lisp
(use-package python
:straight nil
:after eshell
:commands +python/toggle-repl
:general
(leader
"tp" #'+python/toggle-repl)
:config
(+dx/create-toggle-function +python/toggle-repl
"*Python*"
run-python))
#+end_src
** HTML/CSS/JS
Firstly, web mode for consistent colouring of syntax.
#+begin_src emacs-lisp
(use-package web-mode
:mode ("\\.html" . web-mode)
:mode ("\\.js" . web-mode)
:mode ("\\.css" . web-mode)
:custom
((web-mode-markup-indent-offset 2)
(web-mode-css-indent-offset 2)))
#+end_src
Then emmet for super speed
#+begin_src emacs-lisp
(use-package emmet-mode
:hook (web-mode-hook . emmet-mode)
:general
(general-def
:states 'insert
:keymaps 'emmet-mode-keymap
"TAB" #'emmet-expand-line
"M-j" #'emmet-next-edit-point
"M-k" #'emmet-prev-edit-point))
#+end_src
** Emacs lisp
Add a new lisp indent function which indents newline lists more
appropriately.
#+begin_src emacs-lisp
(use-package lisp-mode
:straight nil
:init
(with-eval-after-load "prog-mode"
(+pretty/set-alist
emacs-lisp-mode-hook
("lambda" . "λ")
("numberp" . "ℤ")
("t" . "𝕋")
("nil" . "∅")
("and" . "∧")
("or" . "∨")
("defun" . "ƒ")
("for" . "∀")
("mapc" . "∀")
("mapcar" . "∀")))
:config
(defun +modded/lisp-indent-function (indent-point state)
"This function is the normal value of the variable `lisp-indent-function'.
The function `calculate-lisp-indent' calls this to determine
if the arguments of a Lisp function call should be indented specially.
INDENT-POINT is the position at which the line being indented begins.
Point is located at the point to indent under (for default indentation);
STATE is the `parse-partial-sexp' state for that position.
If the current line is in a call to a Lisp function that has a non-nil
property `lisp-indent-function' (or the deprecated `lisp-indent-hook'),
it specifies how to indent. The property value can be:
,* `defun', meaning indent `defun'-style
\(this is also the case if there is no property and the function
has a name that begins with \"def\", and three or more arguments);
,* an integer N, meaning indent the first N arguments specially
(like ordinary function arguments), and then indent any further
arguments like a body;
,* a function to call that returns the indentation (or nil).
`lisp-indent-function' calls this function with the same two arguments
that it itself received.
This function returns either the indentation to use, or nil if the
Lisp function does not specify a special indentation."
(let ((normal-indent (current-column))
(orig-point (point)))
(goto-char (1+ (elt state 1)))
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
(cond
;; car of form doesn't seem to be a symbol, or is a keyword
((and (elt state 2)
(or (not (looking-at "\\sw\\|\\s_"))
(looking-at ":")))
(if (not (> (save-excursion (forward-line 1) (point))
calculate-lisp-indent-last-sexp))
(progn (goto-char calculate-lisp-indent-last-sexp)
(beginning-of-line)
(parse-partial-sexp (point)
calculate-lisp-indent-last-sexp 0 t)))
;; Indent under the list or under the first sexp on the same
;; line as calculate-lisp-indent-last-sexp. Note that first
;; thing on that line has to be complete sexp since we are
;; inside the innermost containing sexp.
(backward-prefix-chars)
(current-column))
((and (save-excursion
(goto-char indent-point)
(skip-syntax-forward " ")
(not (looking-at ":")))
(save-excursion
(goto-char orig-point)
(looking-at ":")))
(save-excursion
(goto-char (+ 2 (elt state 1)))
(current-column)))
(t
(let ((function (buffer-substring (point)
(progn (forward-sexp 1) (point))))
method)
(setq method (or (function-get (intern-soft function)
'lisp-indent-function)
(get (intern-soft function) 'lisp-indent-hook)))
(cond ((or (eq method 'defun)
(and (null method)
(> (length function) 3)
(string-match "\\`def" function)))
(lisp-indent-defform state indent-point))
((integerp method)
(lisp-indent-specform method state
indent-point normal-indent))
(method
(funcall method indent-point state))))))))
(add-hook 'emacs-lisp-mode-hook (proc (interactive) (setq-local lisp-indent-function #'+modded/lisp-indent-function))))
#+end_src
|