-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2805 lines (2431 loc) · 180 KB
/
index.html
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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2024-05-31 Fri 19:01 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>My literate EMACS config</title>
<meta name="author" content="Roman Kolesnev" />
<meta name="generator" content="Org Mode" />
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/readtheorg.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/lib/js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/js/readtheorg.js"></script>
<style>pre.src{background:#2E3440;color:#D8DEE9;} </style>
</head>
<body>
<div id="content" class="content">
<h1 class="title">My literate EMACS config</h1>
<div id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#org393142f">1. Make it a decent configurable editor</a>
<ul>
<li><a href="#orgbe48461">1.1. It should be obvious that <i>generated files</i> must not be edited</a></li>
<li><a href="#orgadf6b23">1.2. Improve <i>native compilation</i> expiriense</a></li>
<li><a href="#org2c3b1a1">1.3. Improve <i>package</i> management experience</a></li>
<li><a href="#orga45689a">1.4. Writing <i>elisp</i> functions should be convinient</a></li>
<li><a href="#org82a51f1">1.5. Optimize default <i>limits</i> for modern hardware</a></li>
<li><a href="#org9d17c07">1.6. <i>Built-in features</i> that should be enabled by default</a></li>
<li><a href="#org7efe911">1.7. Better organization of <i>auxiliary files</i></a></li>
<li><a href="#org80bb1a7">1.8. It should <i>look</i> modern and comfortable</a></li>
<li><a href="#orgc25be85">1.9. Improve keybinding management with focus on <i>VIM</i> editing style</a></li>
<li><a href="#org4d31358">1.10. Adjust keybindings to <i>MacOS</i></a></li>
<li><a href="#org116971b">1.11. Analyze <i>my behaviour</i></a></li>
<li><a href="#org018618b">1.12. Improve integration with <i>clipboard</i></a></li>
<li><a href="#org3e9092b">1.13. Load shell <i>environment</i> variables</a></li>
<li><a href="#orga9519b6">1.14. Improve <i>minibuffer completion</i> experience</a></li>
<li><a href="#org4a4f935">1.15. Improve <i>ediff</i> experience</a></li>
<li><a href="#orge3d1b21">1.16. Improve <i>dired</i> experience</a></li>
<li><a href="#org7c0980a">1.17. Improve <i>ibuffer</i> experience</a></li>
<li><a href="#org9570faf">1.18. Improve <i>internal help</i> system</a></li>
<li><a href="#org6511815">1.19. Fix confusing <i>buffer naming</i> when working with files with the same name</a></li>
<li><a href="#org316b7cc">1.20. Improve <i>buffer killing</i> flow</a></li>
<li><a href="#orgd50fc2e">1.21. Fast jumps between <i>distant places</i> in buffer</a></li>
<li><a href="#org724b1cc">1.22. Improve <i>window splitting</i> behaviour</a></li>
<li><a href="#orgab872aa">1.23. Fast jumping between <i>distant windows</i></a></li>
<li><a href="#orgdcf2269">1.24. Be able to keep multiple <i>window layouts</i> open</a></li>
<li><a href="#orgefa63ea">1.25. Improve <i>text scaling</i> flow</a></li>
<li><a href="#org50dad13">1.26. Relative <i>line numbers</i> by default, absolute on demand</a></li>
<li><a href="#orga4ee63f">1.27. <i>Do not show</i> non-informative minor modes <i>in modeline</i></a></li>
<li><a href="#org049f82e">1.28. Use spaces for <i>identation</i></a></li>
<li><a href="#orgcc1eeef">1.29. Automatically add <i>newline</i> at the end of the file</a></li>
<li><a href="#orgcff44f3">1.30. Handle situation when too many <i>file watches</i> are added</a></li>
<li><a href="#org35af183">1.31. Distiguish between different pairs of <i>delimiters</i></a></li>
<li><a href="#org0bec934">1.32. Deal with <i>pairs</i> smarter</a></li>
<li><a href="#org64f7f99">1.33. Make <i>regular expessions</i> in this config more readable</a></li>
<li><a href="#org04f6f78">1.34. Open files in <i>existing instance</i> of EMACS</a></li>
<li><a href="#org6445ac7">1.35. Define basic leader <i>keybindings</i></a></li>
</ul>
</li>
<li><a href="#orgbed40b4">2. Make it an IDE</a>
<ul>
<li><a href="#org1a4b892">2.1. <i>Project</i> management and search</a></li>
<li><a href="#org3fe51c9">2.2. Saving and loading <i>bookmark</i> lists</a></li>
<li><a href="#orge634cfe">2.3. Fast access to <i>favourite files</i></a></li>
<li><a href="#orgf7370d4">2.4. <i>Git</i> support</a></li>
<li><a href="#orgb4d3c23">2.5. <i>Terminal</i> support</a></li>
<li><a href="#org35d272b">2.6. Enable <i>autocompletion</i></a></li>
<li><a href="#orgf9a783e">2.7. Enable <i>snippets</i></a></li>
<li><a href="#org1727b05">2.8. Enable <i>Language Server</i> support</a></li>
<li><a href="#org5d08180">2.9. Retrieve secrets from <i>passwod manager</i></a></li>
<li><a href="#orgcc3c63c">2.10. Opt-in switch to <i>GitHub Copilot</i> completion</a></li>
<li><a href="#orgbb032a8">2.11. Get assistance from <i>LLMs</i></a></li>
<li><a href="#org827a837">2.12. <i>REST</i> client</a></li>
<li><a href="#org32417fe">2.13. Support <i>direnv</i> environments</a></li>
<li><a href="#orgdbda011">2.14. Open fancy <i>dashboard</i> on startup</a></li>
</ul>
</li>
<li><a href="#org1c608a8">3. Make it work with…</a>
<ul>
<li><a href="#orgb0bdb75">3.1. Nix</a></li>
<li><a href="#org9cd5328">3.2. Elixir</a></li>
<li><a href="#org9a79deb">3.3. EMACS Lisp</a></li>
<li><a href="#orgaccdaf1">3.4. Ruby</a></li>
<li><a href="#orga0c713e">3.5. JSON</a></li>
<li><a href="#org9ca1b04">3.6. YAML</a></li>
<li><a href="#orgf3bba1d">3.7. ORG</a></li>
<li><a href="#org8437b43">3.8. Markdown</a></li>
<li><a href="#org0638372">3.9. Docker</a></li>
<li><a href="#orgae26dc6">3.10. Earthly</a></li>
<li><a href="#org5990396">3.11. Terrafrom</a></li>
<li><a href="#org002a2bc">3.12. Go</a></li>
<li><a href="#org7e758bd">3.13. Python</a></li>
<li><a href="#org39e88c0">3.14. Mastodon</a></li>
<li><a href="#org4a05344">3.15. JS/TS(X)</a></li>
</ul>
</li>
</ul>
</div>
</div>
<p>
Welcome to my detailed literate <a href="https://www.gnu.org/software/emacs/">EMACS</a> (Editor for Middle-Aged Computer
Scientists) configuration!
</p>
<p>
I'm using EMACS for several years now and I have tried multiple
different ways of adopting it. I started with <a href="https://spacemacs.org/">Spacemacs</a>. Then I tried
to write my own configuration framework. Also I had multiple attempts
to write configuration from scratch (like here). I tried to give up
and use VSCode, but it was too late for me and I returned to EMACS. I
used <a href="https://github.com/doomemacs/doomemacs">DOOM EMACS</a> for around a year or more and it is still my favourite
distribution. If you looking for Vim-style EMACS distribution I highly
recommend to try DOOM EMACS. But I found that I want to have more
control over my configuration and it's more rewarding for me to write
it from scratch. So I'm here again. And this time I feel that I
finally discovered the approach that fits me the best. And I'm happy
to share it with you!
</p>
<p>
Composed in <a href="https://orgmode.org/">ORG mode</a>, this document amalgamates both configuration
code and reasoning behind. Most of the code is <a href="https://orgmode.org/manual/Extracting-Source-Code.html">tangled</a> into the
<code>init.el</code> file, with some exceptions (<code>early-init.el</code>, <code>templates.eld</code>
for example). A helpful feature from <a href="https://github.com/yilkalargaw/org-auto-tangle">Org Auto-Tangle</a> automatically
regenerates all files whenever this document is modified and saved.
</p>
<p>
Several essential aspects of my configuration are not Elisp code, but
<a href="https://nixos.org/">Nix</a> code for <a href="https://github.com/nix-community/home-manager">Home Manager</a>. I keep it in <a href="https://github.com/ffloyd/nix">a separate repository</a> and all
EMACS-related configration is stored in <a href="https://github.com/ffloyd/nix/blob/main/hm/emacs.nix">the separate module</a>.
</p>
<p>
The document structure consists of three primary sections, each is a
high-level configuration goal. Relevant configurations are grouped
together under subsections. When possible I name subsections with the
focus on user behaviours and experience rather than technical details.
</p>
<p>
All functions, variables and modes that are defined in this document
are prefixed with <code>my-</code> to avoid conflicts with other packages.
</p>
<p>
I do not use lazy loading in this configuration. Modern machines are
fast enough to load everything at startup. So I decided to avoid all
the complexity that heavy usage of lazy loading introduces.
</p>
<p>
This config primarily focuses on configuring EMACS for MacOS
environment, but from time to time I make it more adjusted for my
NixOS setup.
</p>
<div id="outline-container-org393142f" class="outline-2">
<h2 id="org393142f"><span class="section-number-2">1.</span> Make it a decent configurable editor</h2>
<div class="outline-text-2" id="text-1">
<p>
Vanilla EMACS doesn't act and look like a modern editor out of the
box. This section focuses on making it more user-friendly and visually
appealing. In addition, it includes some configuration helpers to
simplify configuration process in the later sections.
</p>
<p>
The last subsection in this section is dedicated to <i>leader</i>
keybindings. Other keybindings are defined in the corresponding
subsections.
</p>
</div>
<div id="outline-container-orgbe48461" class="outline-3">
<h3 id="orgbe48461"><span class="section-number-3">1.1.</span> It should be obvious that <i>generated files</i> must not be edited</h3>
<div class="outline-text-3" id="text-1-1">
<p>
Disclaimer for <code>early-init.el</code>:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #616e88;">;; </span><span style="color: #616e88;">WARNING!</span>
<span style="color: #616e88;">;;</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">This file is a result of `org-babel-tangle` execution on `.emacs.d/README.org`.</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">Don't change it manually.</span>
</pre>
</div>
<p>
Disclaimer for <code>init.el</code>:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #616e88;">;; </span><span style="color: #616e88;">WARNING!</span>
<span style="color: #616e88;">;;</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">This file is a result of `org-babel-tangle` execution on `.emacs.d/README.org`.</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">Don't change it manually.</span>
</pre>
</div>
<p>
Disclaimer for <code>templates.eld</code>:
</p>
<div class="org-src-container">
<pre class="src src-lisp-data"><span style="color: #616e88;">;; </span><span style="color: #616e88;">WARNING!</span>
<span style="color: #616e88;">;;</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">This file is a result of `org-babel-tangle` execution on `.emacs.d/README.org`.</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">Don't change it manually.</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgadf6b23" class="outline-3">
<h3 id="orgadf6b23"><span class="section-number-3">1.2.</span> Improve <i>native compilation</i> expiriense</h3>
<div class="outline-text-3" id="text-1-2">
<p>
Native compilation can provide a signifiant speedup and enabled by
deafult in modern EMACS versions, but I don't want to see native
compilation warnings because in the most cases it's just distraction:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> native-comp-async-report-warnings-errors nil<span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org2c3b1a1" class="outline-3">
<h3 id="org2c3b1a1"><span class="section-number-3">1.3.</span> Improve <i>package</i> management experience</h3>
<div class="outline-text-3" id="text-1-3">
<p>
This config uses <a href="https://github.com/raxod502/straight.el">straight.el</a> for downloading packages instead of
<code>package.el</code> (which is part of EMACS). <code>straight</code> does git checkouts
instead of archive downloads. It leads to better discoverability,
simplifies patching and contributing to downloaded packages. Also it
allows to use lockfiles that enables reproducible builds.
</p>
<p>
I disable standard packaging system in <code>early-init.el</code>. It is a bit
more natural than disabling it in <code>init.el</code>. Also I instructing EMACS
to load newer files when alternatives exist. It is something that
works better when set early.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> package-enable-at-startup nil<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> load-prefer-newer t<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
To enable <code>straight</code> I need to copy-paste this bootstraping code from
<code>straight</code>'s <a href="https://github.com/radian-software/straight.el?tab=readme-ov-file#bootstrapping-straightel">README</a>:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">defvar</span> <span style="color: #D8DEE9;">bootstrap-version</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">let</span> <span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">(</span>bootstrap-file
<span style="color: #5E81AC;">(</span>expand-file-name <span style="color: #A3BE8C;">"straight/repos/straight.el/bootstrap.el"</span> user-emacs-directory<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>bootstrap-version 5<span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">unless</span> <span style="color: #81A1C1;">(</span>file-exists-p bootstrap-file<span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span><span style="color: #81A1C1;">with-current-buffer</span>
<span style="color: #5E81AC;">(</span>url-retrieve-synchronously
<span style="color: #A3BE8C;">"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"</span>
'silent 'inhibit-cookies<span style="color: #5E81AC;">)</span>
<span style="color: #5E81AC;">(</span>goto-char <span style="color: #D08770;">(</span>point-max<span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span>
<span style="color: #5E81AC;">(</span>eval-print-last-sexp<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span>load bootstrap-file nil 'nomessage<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
I tried different options for package configuration management:
<a href="https://github.com/jwiegley/use-package">use-package</a>, <a href="https://github.com/conao3/leaf.el">leaf</a> and custom helpers. <code>use-package</code> is a standard
configuration macro now, it even became part of EMACS. <code>leaf</code> is its
alternative: cleaner, easier to extend, but adoption in community is
relatively low (to be honest, I'd prefer <code>leaf</code> to be part of EMACS,
not <code>use-package</code>). But both of them hide configuration details and
focus on configuring packages rather than configuring features (one
package can be used to address multiple features, one feature can be
implemented via multiple packages). That's why I decided to use a set
of small custom helpers and avoid <code>use-package</code> or <code>leaf</code>.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #616e88;">;; </span><span style="color: #616e88;">NO HELPERS YET</span>
</pre>
</div>
<p>
<a href="https://orgmode.org/">ORG</a> should be loaded as early as possible to avoid conflicts with
preinstalled ORG:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'org<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">org</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orga45689a" class="outline-3">
<h3 id="orga45689a"><span class="section-number-3">1.4.</span> Writing <i>elisp</i> functions should be convinient</h3>
<div class="outline-text-3" id="text-1-4">
<p>
"Missing parts of the language": libraries that are used by majority
of developers.
</p>
<p>
<a href="https://github.com/magnars/dash.el">List transformations</a>:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'dash<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">dash</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
<a href="https://github.com/rejeep/f.el">File operations</a>:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'f<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">f</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
<a href="https://github.com/magnars/s.el">String manipulations</a>:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 's<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">s</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org82a51f1" class="outline-3">
<h3 id="org82a51f1"><span class="section-number-3">1.5.</span> Optimize default <i>limits</i> for modern hardware</h3>
<div class="outline-text-3" id="text-1-5">
<p>
Default Garbage Collector behaviour and limits are too aggressive for
modern PCs and can lead to freezes. <a href="https://github.com/emacsmirror/gcmh">Garbage Collector Magic Hack</a>
library introduces adaptive approach to GC. It's better to enable it
early.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'gcmh<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">gcmh</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>gcmh-mode 1<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
Some libraries like <code>lsp</code> or <code>eglot</code> have to work with external
processes that produce a lot of output. By default EMACS has a way too
low limit for process output.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> read-process-output-max <span style="color: #88C0D0;">(</span>* 1024 1024<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
Some other default limits in EMACS are also unnecessary low:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> undo-limit <span style="color: #88C0D0;">(</span>* 80 1000 1000<span style="color: #88C0D0;">)</span>
recentf-max-saved-items 1000<span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org9d17c07" class="outline-3">
<h3 id="org9d17c07"><span class="section-number-3">1.6.</span> <i>Built-in features</i> that should be enabled by default</h3>
<div class="outline-text-3" id="text-1-6">
<p>
A lot of really useful EMACS behaviours are disabled by default.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #616e88;">;; </span><span style="color: #616e88;">when you visit a file, point goes to the last place where it was</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">when you previously visited the same file</span>
<span style="color: #8FBCBB;">(</span>save-place-mode 1<span style="color: #8FBCBB;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">saves minibuffer history (use M-p/n in minibuffer)</span>
<span style="color: #8FBCBB;">(</span>savehist-mode 1<span style="color: #8FBCBB;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">visualization of matching parens</span>
<span style="color: #8FBCBB;">(</span>show-paren-mode 1<span style="color: #8FBCBB;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">typing an open parenthesis automatically inserts the corresponding</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">closing parenthesis</span>
<span style="color: #8FBCBB;">(</span>electric-pair-mode 1<span style="color: #8FBCBB;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">allows to '</span><span style="color: #81A1C1;">undo</span><span style="color: #616e88;">' window configuration changes</span>
<span style="color: #8FBCBB;">(</span>winner-mode 1<span style="color: #8FBCBB;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">word-based commands stop inside symbols with mixed uppercase and</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">lowercase letters, e.g. "GtkWidget", "EmacsFrameClass",</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">"NSGraphicsContext".</span>
<span style="color: #8FBCBB;">(</span>global-subword-mode 1<span style="color: #8FBCBB;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">keeping track of opened files</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">recentf</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org7efe911" class="outline-3">
<h3 id="org7efe911"><span class="section-number-3">1.7.</span> Better organization of <i>auxiliary files</i></h3>
<div class="outline-text-3" id="text-1-7">
<p>
<a href="https://github.com/emacscollective/no-littering">no-littering</a> is an awesome package that organizes many "technical"
files into <code>.emacs.d/etc</code> and <code>.emacs.d/var</code> folders. The package
should be loaded as early as possible.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'no-littering<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">no-littering</span><span style="color: #8FBCBB;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">I'm ok with security risks here but before you do this, make sure</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">you understand the risks and read the documentation of</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">no-littering-theme-backups for details</span>
<span style="color: #8FBCBB;">(</span>no-littering-theme-backups<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
I prefer to store local customizations file under <code>etc</code> folder.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> custom-file <span style="color: #88C0D0;">(</span>no-littering-expand-etc-file-name <span style="color: #A3BE8C;">"custom.el"</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
I do not need lockfiles: I never open the same file in multiple EMACS
instances.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> create-lockfiles nil<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
It's a good idea to exclude <code>etc</code> and <code>var</code> folders from <code>recentf</code>
results.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>add-to-list 'recentf-exclude no-littering-etc-directory<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>add-to-list 'recentf-exclude no-littering-var-directory<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
Native compilation cache location can be adjusted in <code>early-init.el</code>.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">when</span> <span style="color: #88C0D0;">(</span>fboundp 'startup-redirect-eln-cache<span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span>startup-redirect-eln-cache
<span style="color: #81A1C1;">(</span>convert-standard-filename
<span style="color: #5E81AC;">(</span>expand-file-name <span style="color: #A3BE8C;">"var/eln-cache/"</span> user-emacs-directory<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org80bb1a7" class="outline-3">
<h3 id="org80bb1a7"><span class="section-number-3">1.8.</span> It should <i>look</i> modern and comfortable</h3>
<div class="outline-text-3" id="text-1-8">
<p>
This subsection should be placed as early as possible to avoid
blinking on startup.
</p>
<p>
Disable UI elements nobody interested in:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>tool-bar-mode -1<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>scroll-bar-mode -1<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>horizontal-scroll-bar-mode -1<span style="color: #8FBCBB;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">disabling menu-bar-mode on MacOS leads to incorrect</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">window maximization behaviour</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">unless</span> <span style="color: #88C0D0;">(</span>eq system-type 'darwin<span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span>menu-bar-mode -1<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
<a href="https://typeof.net/Iosevka/">Iosevka</a> is my favourite font:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">let*</span> <span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">(</span>family <span style="color: #A3BE8C;">"Iosevka SS10"</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>size <span style="color: #5E81AC;">(</span><span style="color: #81A1C1;">if</span> <span style="color: #D08770;">(</span>eq system-type 'darwin<span style="color: #D08770;">)</span>
18 <span style="color: #616e88;">;; </span><span style="color: #616e88;">on MacOS HiDPI scaling works out of the box</span>
26<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span> <span style="color: #616e88;">;; </span><span style="color: #616e88;">in Gnome HiDPI scaling doesn't work properly</span>
<span style="color: #81A1C1;">(</span>spec <span style="color: #5E81AC;">(</span>font-spec <span style="color: #81A1C1;">:family</span> family <span style="color: #81A1C1;">:size</span> size <span style="color: #81A1C1;">:weight</span> 'semi-light<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span>set-face-attribute 'default nil <span style="color: #81A1C1;">:font</span> spec<span style="color: #88C0D0;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">fixed-pitch was set to "Monospace" font by default</span>
<span style="color: #88C0D0;">(</span>set-face-attribute 'fixed-pitch nil <span style="color: #81A1C1;">:family</span> family<span style="color: #88C0D0;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">variable-pitch was is set "non-monospace" font by default</span>
<span style="color: #88C0D0;">(</span>set-face-attribute 'variable-pitch nil <span style="color: #81A1C1;">:family</span> family<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
<a href="https://www.nordtheme.com/">Nord</a> is my favourite theme:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'nord-theme<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">nord-theme</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>load-theme 'nord t<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
But it has some missing parts and some parts are designed in a way I
do not like. Let's fix it! Unfortunately I haven't realized how to use
<code>custom-theme-set-faces</code> here so I merely update global face
settings. While I do not need secondary theme it's good enbough for
me.
</p>
<p>
<a href="https://www.nordtheme.com/docs/colors-and-palettes">Nord palletes</a> are used here for colors when applicable.
</p>
<p>
Related issues:
</p>
<ul class="org-ul">
<li><a href="https://github.com/nordtheme/emacs/issues/105">Missing tab bar colors</a></li>
</ul>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">let</span> <span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">(</span>nord0 <span style="color: #A3BE8C;">"#2E3440"</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>nord1 <span style="color: #A3BE8C;">"#3B4252"</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>nord3 <span style="color: #A3BE8C;">"#4C566A"</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>nord9 <span style="color: #A3BE8C;">"#81A1C1"</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>nord10 <span style="color: #A3BE8C;">"#5E81AC"</span><span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span>custom-set-faces
`<span style="color: #81A1C1;">(</span>tab-bar <span style="color: #5E81AC;">(</span><span style="color: #D08770;">(</span>t <span style="color: #EBCB8B;">(</span><span style="color: #81A1C1;">:background</span> ,nord1<span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
`<span style="color: #81A1C1;">(</span>tab-bar-tab <span style="color: #5E81AC;">(</span><span style="color: #D08770;">(</span>t <span style="color: #EBCB8B;">(</span><span style="color: #81A1C1;">:background</span> ,nord0
<span style="color: #81A1C1;">:weight</span> bold
<span style="color: #81A1C1;">:box</span> <span style="color: #A3BE8C;">(</span><span style="color: #81A1C1;">:line-width</span> -1 <span style="color: #81A1C1;">:style</span> released-button<span style="color: #A3BE8C;">)</span><span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
`<span style="color: #81A1C1;">(</span>tab-bar-tab-inactive <span style="color: #5E81AC;">(</span><span style="color: #D08770;">(</span>t <span style="color: #EBCB8B;">(</span><span style="color: #81A1C1;">:foreground</span> <span style="color: #A3BE8C;">"gray39"</span>
<span style="color: #81A1C1;">:background</span> ,nord1<span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
`<span style="color: #81A1C1;">(</span>org-block <span style="color: #5E81AC;">(</span><span style="color: #D08770;">(</span>t <span style="color: #EBCB8B;">(</span><span style="color: #81A1C1;">:inherit</span> org-block <span style="color: #81A1C1;">:background</span> ,nord1<span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
`<span style="color: #81A1C1;">(</span>org-headline-done <span style="color: #5E81AC;">(</span><span style="color: #D08770;">(</span>t <span style="color: #EBCB8B;">(</span><span style="color: #81A1C1;">:inherit</span> org-headline-done <span style="color: #81A1C1;">:foreground</span> ,nord10<span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
Unfortunately, it's pretty common that some interfaces from 3rd-party
libraries are not styled properly or look ugly. To fix it I need to
know which exact faces look ugly. <code>describe-face</code> is a great tool to
find out what face is used for a particular element, but invoking it
each time is annoying. So I wrote a minor mode that shows face under
current cursor position in the minibuffer.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">defun</span> <span style="color: #88C0D0;">my-what-the-face</span> <span style="color: #88C0D0;">()</span>
<span style="color: #616e88;">"Show face under point in the minibuffer."</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">interactive</span><span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">let</span> <span style="color: #81A1C1;">(</span><span style="color: #5E81AC;">(</span>face <span style="color: #D08770;">(</span>get-char-property <span style="color: #EBCB8B;">(</span>point<span style="color: #EBCB8B;">)</span> 'face<span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span><span style="color: #81A1C1;">if</span> face
<span style="color: #5E81AC;">(</span>message <span style="color: #A3BE8C;">"Face: %s"</span> face<span style="color: #5E81AC;">)</span>
<span style="color: #5E81AC;">(</span>message <span style="color: #A3BE8C;">"No face at point"</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">defvar</span> <span style="color: #D8DEE9;">my-what-the-face-last-point</span> nil
<span style="color: #616e88;">"Last point where face was described."</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">defun</span> <span style="color: #88C0D0;">my-what-the-face-adviced</span> <span style="color: #88C0D0;">()</span>
<span style="color: #616e88;">"Show face under point in the minibuffer. (Only once after point change)"</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">unless</span> <span style="color: #81A1C1;">(</span>equal my-what-the-face-last-point <span style="color: #5E81AC;">(</span>point<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span><span style="color: #81A1C1;">setq</span> my-what-the-face-last-point <span style="color: #5E81AC;">(</span>point<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>my-what-the-face<span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">define-minor-mode</span> <span style="color: #88C0D0;">my-what-the-face-mode</span>
<span style="color: #616e88;">"Minor mode to show face under point when cursor is moved."</span>
<span style="color: #81A1C1;">:global</span> t
<span style="color: #81A1C1;">:lighter</span> <span style="color: #A3BE8C;">" WTFace"</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">if</span> my-what-the-face-mode
<span style="color: #81A1C1;">(</span>add-hook 'post-command-hook #'my-what-the-face-adviced 0 t<span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>remove-hook 'post-command-hook #'my-what-the-face-adviced t<span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
<i>Visible bell</i> is super-distracting and scary (especilly in the
night).
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> visible-bell nil<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
Default <i>modeline</i> looks too simple and distracting at the same
time. I want something lightweight, laconic and fancy. <a href="https://seagle0128.github.io/doom-modeline/">doom-modeline</a>
is a great choice here.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'doom-modeline<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> doom-modeline-minor-modes t
doom-modeline-buffer-encoding nil
doom-modeline-project-detection 'project
doom-modeline-modal-icon nil
doom-modeline-workspace-name nil<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">doom-modeline</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>doom-modeline-mode 1<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
I want to see position like <code>123:13</code> instead of <code>L123</code> in the
modeline.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>column-number-mode 1<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
I want modeline for inactive buffers to be very minimalistic.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">doom-modeline-def-modeline</span> <span style="color: #81A1C1;">'very-minimal</span>
'<span style="color: #88C0D0;">(</span>bar buffer-info-simple<span style="color: #88C0D0;">)</span>
'<span style="color: #88C0D0;">(</span>major-mode<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">defun</span> <span style="color: #88C0D0;">my-set-inactive-buffer-modeline</span> <span style="color: #88C0D0;">()</span>
<span style="color: #88C0D0;">(</span>doom-modeline-set-modeline 'very-minimal<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">defun</span> <span style="color: #88C0D0;">my-set-active-buffer-modeline</span> <span style="color: #88C0D0;">()</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">unless</span> <span style="color: #81A1C1;">(</span>doom-modeline-auto-set-modeline<span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>doom-modeline-set-main-modeline<span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">defun</span> <span style="color: #88C0D0;">my-set-modeline-hook</span> <span style="color: #88C0D0;">()</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">dolist</span> <span style="color: #81A1C1;">(</span>buf <span style="color: #5E81AC;">(</span>buffer-list<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span><span style="color: #81A1C1;">with-current-buffer</span> buf
<span style="color: #5E81AC;">(</span><span style="color: #81A1C1;">if</span> <span style="color: #D08770;">(</span>eq <span style="color: #EBCB8B;">(</span>current-buffer<span style="color: #EBCB8B;">)</span> <span style="color: #EBCB8B;">(</span>window-buffer <span style="color: #A3BE8C;">(</span>selected-window<span style="color: #A3BE8C;">)</span><span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span>
<span style="color: #D08770;">(</span>my-set-active-buffer-modeline<span style="color: #D08770;">)</span>
<span style="color: #D08770;">(</span>my-set-inactive-buffer-modeline<span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">let</span> <span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">(</span>nord9 <span style="color: #A3BE8C;">"#81A1C1"</span><span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span>custom-set-faces
`<span style="color: #81A1C1;">(</span>mode-line-inactive <span style="color: #5E81AC;">(</span><span style="color: #D08770;">(</span>t <span style="color: #EBCB8B;">(</span><span style="color: #81A1C1;">:inherit</span> mode-line-inactive
<span style="color: #81A1C1;">:foreground</span> ,nord9<span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
`<span style="color: #81A1C1;">(</span>doom-modeline-buffer-minor-mode <span style="color: #5E81AC;">(</span><span style="color: #D08770;">(</span>t <span style="color: #EBCB8B;">(</span><span style="color: #81A1C1;">:foreground</span> ,nord9<span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>add-hook 'buffer-list-update-hook #'my-set-modeline-hook<span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgc25be85" class="outline-3">
<h3 id="orgc25be85"><span class="section-number-3">1.9.</span> Improve keybinding management with focus on <i>VIM</i> editing style</h3>
<div class="outline-text-3" id="text-1-9">
<p>
There is a joke that "EMACS is a great operating system, but lacks a
good text editor". I know a fix for that: <a href="https://github.com/emacs-evil/evil">evil</a>. It is a VIM emulation
layer for EMACS. Many folks including me think that it's the best
implementation of VIM that is not VIM.
</p>
<p>
First step is to install <code>evil</code> dependencies.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'undo-tree<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">undo-tree</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>global-undo-tree-mode<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>straight-use-package 'goto-chg<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">goto-chg</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
<a href="https://elpa.gnu.org/packages/undo-tree.html">undo-tree</a> is a great package that provides a more advanced undo and
redo system. It's a must-have for <code>evil</code>. But it has an annoying
behaviour: on each undo history save it shows a message in minibuffer.
Sometimes it shadows important messages. I found solution <a href="https://emacs.stackexchange.com/questions/59942/is-it-possible-suppress-save-message-for-undo-tree">here</a>.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">defun</span> <span style="color: #88C0D0;">my-undo-tree-save-history</span> <span style="color: #88C0D0;">(</span>undo-tree-save-history <span style="color: #8FBCBB;">&rest</span> args<span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">let</span> <span style="color: #81A1C1;">(</span><span style="color: #5E81AC;">(</span>message-log-max nil<span style="color: #5E81AC;">)</span>
<span style="color: #5E81AC;">(</span>inhibit-message t<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>apply undo-tree-save-history args<span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>advice-add 'undo-tree-save-history <span style="color: #81A1C1;">:around</span> 'my-undo-tree-save-history<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
Now everything is ready for <code>evil</code>.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #616e88;">;; </span><span style="color: #616e88;">it's required by evil-collection</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> evil-want-keybinding nil<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>straight-use-package 'evil<span style="color: #8FBCBB;">)</span>
<span style="color: #616e88;">;; </span><span style="color: #616e88;">smaller undo steps</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> evil-want-fine-undo t<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> evil-undo-system 'undo-tree<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">evil</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>evil-mode 1<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
Many EMACS packages do not provide VIM keybindings out of the box. But
<a href="https://github.com/emacs-evil/evil-collection">evil-collection</a> does it for many of them. I prefer not to enable all
of the collections, but only those that I really use. (And closer to
the corresponding configuration sections)
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'evil-collection<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">evil-collection</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>evil-collection-image-setup<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>evil-collection-xref-setup<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>evil-collection-bookmark-setup<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>evil-collection-compile-setup<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
EMAСS has a lot of keybindings. And I'm adding even more! So it's a
good idea to improve keybinding discoverability. And <a href="https://github.com/justbur/emacs-which-key">which-key</a> is the
best tool for that!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> which-key-idle-delay 0.4
which-key-max-description-length 120<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>straight-use-package 'which-key<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">which-key</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>which-key-mode<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
Vanilla EMACS keybindings definition system is not very convenient and
sometimes hard to understand. <code>evil</code> adds concept of modes on top of
it and makes it even more complicated. So here I feel need for a
unified and easy to use keybinding definition solution. <a href="https://github.com/noctuid/general.el">General</a> does
it perfectly by hiding complex parts behind a simple API.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'general<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">general</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
My first EMACS "distribution" was <a href="https://spacemacs.org/">Spacemacs</a> and I really liked its
keybinding system. <code>general</code> allows to create similar keybinding
definitions. And even more - define helpers tailored to my needs!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">general-create-definer</span> my-leader-def <span style="color: #81A1C1;">:states</span>
'<span style="color: #88C0D0;">(</span>normal insert emacs<span style="color: #88C0D0;">)</span>
<span style="color: #81A1C1;">:prefix</span> <span style="color: #A3BE8C;">"SPC"</span> <span style="color: #81A1C1;">:non-normal-prefix</span> <span style="color: #A3BE8C;">"C-s-SPC"</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org4d31358" class="outline-3">
<h3 id="org4d31358"><span class="section-number-3">1.10.</span> Adjust keybindings to <i>MacOS</i></h3>
<div class="outline-text-3" id="text-1-10">
<p>
Even <a href="https://bitbucket.org/mituharu/emacs-mac/src/master/">Mitsuharu Yamamoto's EMACS</a> build for MacOS is not tailored for
keybindings that are common in MacOS GUI apps. Fortunately, it's easy
to fix.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">when</span> <span style="color: #88C0D0;">(</span>eq system-type 'darwin<span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">setq</span> locate-command <span style="color: #A3BE8C;">"mdfind"</span><span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">setq</span> mac-command-modifier 'super
mac-option-modifier 'meta<span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span>general-define-key
<span style="color: #A3BE8C;">"s-c"</span> 'kill-ring-save
<span style="color: #A3BE8C;">"s-v"</span> 'yank
<span style="color: #A3BE8C;">"s-x"</span> 'kill-region
<span style="color: #A3BE8C;">"s-s"</span> 'save-buffer
<span style="color: #A3BE8C;">"s-o"</span> 'find-file
<span style="color: #A3BE8C;">"s-a"</span> 'mark-whole-buffer
<span style="color: #A3BE8C;">"s-z"</span> 'undo
<span style="color: #A3BE8C;">"s-f"</span> 'consult-line
<span style="color: #A3BE8C;">"s-<left>"</span> 'beginning-of-line
<span style="color: #A3BE8C;">"s-<right>"</span> 'end-of-line
<span style="color: #A3BE8C;">"s-<up>"</span> 'beginning-of-buffer
<span style="color: #A3BE8C;">"s-<down>"</span> 'end-of-buffer
<span style="color: #A3BE8C;">"M-<up>"</span> 'backward-paragraph
<span style="color: #A3BE8C;">"M-<down>"</span> 'forward-paragraph
<span style="color: #A3BE8C;">"s-/"</span> 'comment-line
<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org116971b" class="outline-3">
<h3 id="org116971b"><span class="section-number-3">1.11.</span> Analyze <i>my behaviour</i></h3>
<div class="outline-text-3" id="text-1-11">
<p>
In order to make data-driven decisions about configuration, I need
tools to analyze my behaviour. keyfreq is a great package that
provides a simple way to track keybindings usage.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'keyfreq<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> keyfreq-excluded-commands
'<span style="color: #88C0D0;">(</span>mac-mwheel-scroll <span style="color: #616e88;">;; </span><span style="color: #616e88;">mouse movement</span>
evil-forward-char <span style="color: #616e88;">;; </span><span style="color: #616e88;">basic VIM movement</span>
evil-backward-char
evil-forward-word-end
evil-backward-word-begin
evil-next-line
evil-previous-line<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">keyfreq</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>keyfreq-mode 1<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>keyfreq-autosave-mode 1<span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org018618b" class="outline-3">
<h3 id="org018618b"><span class="section-number-3">1.12.</span> Improve integration with <i>clipboard</i></h3>
<div class="outline-text-3" id="text-1-12">
<p>
Let's enable saving existing clipboard text into kill ring before
replacing it.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> save-interprogram-paste-before-kill t<span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org3e9092b" class="outline-3">
<h3 id="org3e9092b"><span class="section-number-3">1.13.</span> Load shell <i>environment</i> variables</h3>
<div class="outline-text-3" id="text-1-13">
<p>
EMAСS GUI for MacOS does not load shell environment variables. It's a
common issue for MacOS users. <a href="https://github.com/purcell/exec-path-from-shell">exec-path-from-shell</a> solves the
problem.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'exec-path-from-shell<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">exec-path-from-shell</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>add-to-list 'exec-path-from-shell-variables <span style="color: #A3BE8C;">"LANG"</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>add-to-list 'exec-path-from-shell-variables <span style="color: #A3BE8C;">"LC_ALL"</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>add-to-list 'exec-path-from-shell-variables <span style="color: #A3BE8C;">"LC_CTYPE"</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>exec-path-from-shell-initialize<span style="color: #8FBCBB;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orga9519b6" class="outline-3">
<h3 id="orga9519b6"><span class="section-number-3">1.14.</span> Improve <i>minibuffer completion</i> experience</h3>
<div class="outline-text-3" id="text-1-14">
<p>
EMACS's default <a href="https://www.emacswiki.org/emacs/MinibufferCompletion">minibuffer completion</a> solutions do their job, but
there are better ones. Personally, I prefer solution based on packages
like <code>vertico</code>: in contrast to some completion frameworks like <code>helm</code>,
<code>vertico</code> (and others) enchance default completion system instead of
replacing it. Resulting in better integration with other EMACS
features.
</p>
<p>
Let's start with <a href="https://github.com/minad/vertico">vertico</a>. It's a minimalistic vertical completion UI
similar to <code>ivy</code> or <code>helm</code>. By reusing the built-in facilities system,
Vertico achieves full compatibility with built-in Emacs completion
commands and completion tables.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'vertico<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> vertico-cycle t<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span>vertico-mode<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
Often I want to focus on commands with particular prefix. For example <code>my-</code> or <code>copilot-</code>.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">defun</span> <span style="color: #88C0D0;">my-vertico-replace-with-common-prefix</span> <span style="color: #88C0D0;">()</span>
<span style="color: #616e88;">"Replaces current vertico input with common prefix query.</span>
<span style="color: #616e88;">Replaces vertico input with '</span><span style="color: #81A1C1;">^str</span><span style="color: #616e88;">' where str is the common prefix</span>
<span style="color: #616e88;">for candidates that starts with the first component of current</span>
<span style="color: #616e88;">vertico input."</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">interactive</span><span style="color: #88C0D0;">)</span>
<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">when-let*</span> <span style="color: #81A1C1;">(</span><span style="color: #5E81AC;">(</span>current-input <span style="color: #D08770;">(</span><span style="color: #81A1C1;">or</span> <span style="color: #EBCB8B;">(</span>car vertico--input<span style="color: #EBCB8B;">)</span> <span style="color: #EBCB8B;">(</span>minibuffer-contents-no-properties<span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span>
<span style="color: #5E81AC;">(</span>prefix-from-input <span style="color: #D08770;">(</span><span style="color: #81A1C1;">->></span> current-input
<span style="color: #EBCB8B;">(</span>s-split <span style="color: #A3BE8C;">" "</span><span style="color: #EBCB8B;">)</span>
<span style="color: #EBCB8B;">(</span>-first-item<span style="color: #EBCB8B;">)</span>
<span style="color: #EBCB8B;">(</span>s-replace <span style="color: #A3BE8C;">"^"</span> <span style="color: #A3BE8C;">""</span><span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span>
<span style="color: #5E81AC;">(</span>common-prefix <span style="color: #D08770;">(</span><span style="color: #81A1C1;">-some->></span> vertico--candidates
<span style="color: #EBCB8B;">(</span><span style="color: #81A1C1;">--select</span> <span style="color: #A3BE8C;">(</span>s-prefix? prefix-from-input it<span style="color: #A3BE8C;">)</span><span style="color: #EBCB8B;">)</span>
<span style="color: #EBCB8B;">(</span><span style="color: #81A1C1;">--reduce</span> <span style="color: #A3BE8C;">(</span>fill-common-string-prefix it acc<span style="color: #A3BE8C;">)</span><span style="color: #EBCB8B;">)</span><span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span>
<span style="color: #5E81AC;">(</span>next-search-query <span style="color: #D08770;">(</span>s-concat <span style="color: #A3BE8C;">"^"</span> common-prefix<span style="color: #D08770;">)</span><span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>delete-minibuffer-contents<span style="color: #81A1C1;">)</span>
<span style="color: #81A1C1;">(</span>insert next-search-query<span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">general-def</span> <span style="color: #81A1C1;">:keymaps</span> 'vertico-map
<span style="color: #88C0D0;">(</span>kbd <span style="color: #A3BE8C;">"C-<tab>"</span><span style="color: #88C0D0;">)</span> #'my-vertico-replace-with-common-prefix<span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
<a href="https://github.com/oantolin/orderless">"Emacs completion style that matches multiple regexps in any
order"</a>. Sounds good!
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'orderless<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">require</span> '<span style="color: #81A1C1;">orderless</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
I want to use orderless exclusively. But for better compatibility with
other packages I need to set completion-styles in the following way
(see <code>orderless</code> <a href="https://github.com/oantolin/orderless">README</a>).
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> completion-styles '<span style="color: #88C0D0;">(</span>orderless basic<span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> completion-category-defaults nil<span style="color: #8FBCBB;">)</span>
<span style="color: #8FBCBB;">(</span><span style="color: #81A1C1;">setq</span> completion-category-overrides '<span style="color: #88C0D0;">(</span><span style="color: #81A1C1;">(</span>file <span style="color: #5E81AC;">(</span>styles basic partial-completion<span style="color: #5E81AC;">)</span><span style="color: #81A1C1;">)</span><span style="color: #88C0D0;">)</span><span style="color: #8FBCBB;">)</span>
</pre>
</div>
<p>
<a href="https://github.com/minad/consult">consult</a> is a great package that provides a lot of useful commands
based on <code>completing-read</code>.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #8FBCBB;">(</span>straight-use-package 'consult<span style="color: #8FBCBB;">)</span>