-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathinit.el
More file actions
3976 lines (3526 loc) · 164 KB
/
Copy pathinit.el
File metadata and controls
3976 lines (3526 loc) · 164 KB
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
;;; init.el --- Emacs Solo (no external packages) Configuration --- Init -*- lexical-binding: t; byte-compile-warnings: (not free-vars unresolved make-local); -*-
;;
;; Author: Rahul Martim Juliato
;; URL: https://github.com/LionyxML/emacs-solo
;; Package-Requires: ((emacs "30.1"))
;; Keywords: config
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;;; Commentary:
;; Init configuration for Emacs Solo
;;
;;; Welcome to:
;;; ┌─────────────────────────────────────────────────────────────────────────┐
;;; │ ███████╗███╗ ███╗ █████╗ ██████╗███████╗ │
;;; │ ██╔════╝████╗ ████║██╔══██╗██╔════╝██╔════╝ │
;;; │ █████╗ ██╔████╔██║███████║██║ ███████╗ │
;;; │ ██╔══╝ ██║╚██╔╝██║██╔══██║██║ ╚════██║ │
;;; │ ███████╗██║ ╚═╝ ██║██║ ██║╚██████╗███████║ │
;;; │ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚══════╝ │
;;; │ │
;;; │ ███████╗ ██████╗ ██╗ ██████╗ │
;;; │ ██╔════╝██╔═══██╗██║ ██╔═══██╗ │
;;; │ ███████╗██║ ██║██║ ██║ ██║ │
;;; │ ╚════██║██║ ██║██║ ██║ ██║ │
;;; │ ███████║╚██████╔╝███████╗╚██████╔╝ │
;;; │ ╚══════╝ ╚═════╝ ╚══════╝ ╚═════╝ │
;;; └─────────────────────────────────────────────────────────────────────────┘
;;; ┌─────────────────────────────────────────────────────────────────────────┐
;;; │ HELP, WHERE IS MY CONFIG? │
;;; ├─────────────────────────────────────────────────────────────────────────┤
;;; │ If you're opening this file inside Emacs Solo, it's likely collapsed │
;;; │ by default to help you better navigate its structure. Use outline-mode │
;;; │ keybindings to explore sections as needed: │
;;; │ │
;;; │ C-c @ C-a -> Show all sections │
;;; │ C-c @ C-q -> Hide all sections │
;;; │ C-c @ C-c -> Toggle section at point │
;;; │ │
;;; │ If you're viewing this file on a code forge (e.g., GitHub, Codeberg) │
;;; │ or in another editor, you might see it fully expanded. For the best │
;;; │ viewing and navigation experience, use Emacs Solo. │
;;; │ │
;;; │ To disable automatic folding on load, set: │
;;; │ (setq emacs-solo-enable-outline-init nil) │
;;; └─────────────────────────────────────────────────────────────────────────┘
;;; Code:
;;; ┌──────────────────── EMACS SOLO CUSTOM OPTIONS
;;
;; Some features Emacs Solo provides you can turn on/off
(defcustom emacs-solo-enable-outline-init t
"Enable init.el starting all collapsed."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-enable-transparency nil
"Enable `emacs-solo-transparency'."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-icon-modules
'(dired eshell ibuffer)
"List of Emacs Solo icon modules to enable.
Controls which modules display file type icons.
Valid values (combine in a list):
- \\='dired: Show file type icons in Dired buffers
- \\='eshell: Show file type icons in Eshell prompts
- \\='ibuffer: Show buffer type icons in Ibuffer
- \\='nerd: Prefer Nerd Font glyphs over Emojis
- nil: Disable all icons
Default is \\='(dired eshell ibuffer), which uses Emoji icons.
Add \\='nerd to the list to use Nerd Font glyphs instead."
:type '(set :tag "Emacs Solo icon modules"
(const :tag "Use icons on Dired" dired)
(const :tag "Use icons on Eshell" eshell)
(const :tag "Use icons on Ibuffer" ibuffer)
(const :tag "Prefer Nerd Fonts icons over Emojis" nerd))
:group 'emacs-solo)
(defcustom emacs-solo-enable-dired-gutter t
"Enable `emacs-solo-enable-dired-gutter'."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-enable-highlight-keywords t
"Enable `emacs-solo-enable-highlight-keywords'."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-enable-rainbown-delimiters t
"Enable `emacs-solo-enable-rainbown-delimiters'."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-enable-buffer-gutter t
"Enable `emacs-solo-enable-gutter'."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-enable-custom-orderless nil
"Enable `emacs-solo-simple-orderless'."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-enable-eldoc-box t
"Enable `emacs-solo-eldoc-box'."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-use-custom-theme 'crafters
"Select which emacs-solo customization theme to use.
Valid values are:
- \\='catppuccin
- \\='crafters
- \\='gits
- \\='matrix
- nil: Disable custom theme
IMPORTANT NOTE: If you disable this or choose another theme, also check
\\='emacs-solo-avoid-flash-options to ensure compatibility."
:type '(choice
(const :tag "Disabled" nil)
(const :tag "Catppuccin" catppuccin)
(const :tag "Crafters" crafters)
(const :tag "Matrix" matrix)
(const :tag "GITS" gits))
:group 'emacs-solo)
(defcustom emacs-solo-enable-preferred-font t
"Enable `emacs-solo-enable-preferred-font'."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-preferred-font-name "JetBrainsMono Nerd Font"
"The name of the font to be used.
Examples: `Maple Mono NF' or `JetBrainsMono Nerd Font'."
:type 'string
:group 'emacs-solo)
(defcustom emacs-solo-preferred-font-sizes '(130 105)
"List of default font sizes (first for macOS, second for GNU/Linux)."
:type '(repeat integer)
:group 'emacs-solo)
(defcustom emacs-solo-ai-scratch-path nil
"If non-nil, AI commands run from this directory.
This allows using a specific environment or scratch context."
:type '(choice (const :tag "Disabled" nil)
(directory :tag "AI Scratch Directory"))
:group 'emacs-solo)
(defcustom emacs-solo-enable-erc-image t
"Whether to enable inline image support in ERC buffers.
This is enabled by default and allows displaying images directly from
URLs posted in ERC channels."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-enable-auto-formatter t
"Whether to automatically enable format-on-save for files.
Respects the `emacs-solo-formatter-alist'. When non-nil, opening a file whose
extension has a registered formatter will add format-on-save to the
buffer's `after-save-hook'."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-enable-flymake-eslint nil
"Whether to enable Flymake integration using ESLint.
This is disabled by default, since nowadays we tend to use LSP servers
for ESLint."
:type 'boolean
:group 'emacs-solo)
(defcustom emacs-solo-doc-view-invert-default nil
"Whether PDFs in `doc-view-mode' open with all pages color-inverted."
:type 'boolean
:group 'emacs-solo)
;;; ├──────────────────── CACHE PATHS
;;
;; Single source of truth for every path Emacs Solo stores in its
;; cache. `emacs-solo-cache-directory' is the base; each entry in
;; `emacs-solo-cache-paths' maps a key (usually the Emacs variable
;; that should hold the resolved path) to a path relative to that
;; base. A trailing slash means the value is a directory and will be
;; created as-is; otherwise the value is a file and only its parent
;; directory is created.
;;
;; To wire a variable: use (emacs-solo--cache-path 'KEY) inside a
;; use-package :custom block (or wherever the value is needed).
(defcustom emacs-solo-cache-directory
(expand-file-name "cache/" user-emacs-directory)
"Base directory for Emacs Solo cache files.
All entries in `emacs-solo-cache-paths' are resolved relative to this
directory. Choose one of the presets or supply any custom directory path.
Changes take effect after restarting Emacs."
:type `(choice
(const :tag "Inside Emacs config (cache/ in user-emacs-directory)"
,(expand-file-name "cache/" user-emacs-directory))
(const :tag "System temp (/tmp/emacs-cache/)" "/tmp/emacs-cache/")
(directory :tag "Custom directory"))
:group 'emacs-solo)
;; custom-file is already set and loaded in early-init.el, but reload it here
;; so any M-x customize changes saved mid-session before restart also apply
;; to cache paths and other init.el settings.
(load custom-file 'noerror 'nomessage)
(defvar emacs-solo-cache-paths
'(;; Files:
(bookmark-file . "bookmarks")
(ielm-history-file-name . "ielm-history.eld")
(project-list-file . "projects")
(recentf-save-file . "recentf")
(savehist-file . "history")
(save-place-file . "saveplace")
(transient-history-file . "transient/history.el")
(transient-levels-file . "transient/levels.el")
(transient-values-file . "transient/values.el")
(tramp-persistency-file-name . "tramp")
(viper-custom-file-name . "viper")
(nsm-settings-file . "network-security.data")
;; Directories:
(auto-saves . "auto-saves/")
(auto-saves-sessions . "auto-saves/sessions/")
(shared-game-score-directory . "games/")
(multisession-directory . "multisession/")
(url-configuration-directory . "url/")
(rcirc-log-directory . "rcirc/logs/")
(erc-log-channels-directory . "erc/logs/")
(erc-image-cache-directory . "erc/images/")
(image-dired-dir . "image-dired/")
(newsticker-dir . "newsticker/")
(yt-subs . "yt-subs"))
"Alist of (KEY . RELATIVE-PATH) for Emacs Solo cache locations.
RELATIVE-PATH is resolved against `emacs-solo-cache-directory'.
A trailing slash on RELATIVE-PATH marks the entry as a directory.")
(defun emacs-solo--cache-path (key)
"Return the absolute path for KEY in `emacs-solo-cache-paths'."
(let ((rel (cdr (assq key emacs-solo-cache-paths))))
(unless rel
(error "emacs-solo--cache-path: Unknown key %S" key))
(expand-file-name rel emacs-solo-cache-directory)))
(defun emacs-solo--ensure-cache-dirs ()
"Create every directory referenced by `emacs-solo-cache-paths'.
Entries ending in `/' are created directly; other entries have their
parent directory created."
(dolist (entry emacs-solo-cache-paths)
(let* ((abs (emacs-solo--cache-path (car entry)))
(dir (if (directory-name-p abs)
abs
(file-name-directory abs))))
(make-directory dir t))))
(emacs-solo--ensure-cache-dirs)
;;; ├──────────────────── GENERAL EMACS CONFIG
;;; │ EMACS
(use-package emacs
:ensure nil
:bind ; NOTE: M-x describe-personal-bindings (for all use-packge binds)
(("M-o" . other-window)
("M-g r" . recentf)
("M-s g" . grep)
("C-x ;" . comment-line)
("M-s f" . find-name-dired)
("C-x C-b" . ibuffer)
("C-x p l". project-list-buffers)
("C-x w t" . window-layout-transpose) ; EMACS-31
("C-x w r" . window-layout-rotate-clockwise) ; EMACS-31
("C-x w f h" . window-layout-flip-leftright) ; EMACS-31
("C-x w f v" . window-layout-flip-topdown) ; EMACS-31
("C-x 5 l" . select-frame-by-name)
("C-x 5 s" . set-frame-name)
("RET" . newline-and-indent)
("C-z" . nil)
("C-x C-z" . nil)
("C-M-z" . delete-pair)
("C-x C-k RET" . nil)
("M-@" . emacs-solo/copy-whole-word)
("M-J" . duplicate-dwim) ; As suggest on r/emacs by the_cecep:
("M-K" . kill-paragraph) ; Expands M-k for kill-sentence
("M-Z" . zap-up-to-char) ; Expands M-z for zap-to-char
("M-F" . forward-to-word) ; Expands M-f to jump to beginning of next word
("M-B" . backward-to-word) ; Expands M-b to jump to end of previous word
("M-M" . end-of-line) ; Expands M-m to jump to end line, useful for paragraphs
("M-T" . transpose-sentences) ; Expands M-t for transposing words
("C-x M-t" . transpose-paragraphs) ; Expands C-x C-t for transposing lines
([remap capitalize-word] . capitalize-dwim) ; Make M-c work on regions
([remap downcase-word] . downcase-dwim) ; Make M-l work on regions
([remap upcase-word] . upcase-dwim) ; Make M-u work on regions
([remap kill-buffer] . kill-current-buffer) ; C-x k stops prompting for buffer to kill
([remap delete-horizontal-space] . cycle-spacing) ; M-\. Called twice, cycle-spacing has same effect and its default binding (M-SPC) is problematic in macOS
)
:custom
(ad-redefinition-action 'accept)
(auto-save-default t)
(bookmark-file (emacs-solo--cache-path 'bookmark-file))
(shared-game-score-directory (emacs-solo--cache-path 'shared-game-score-directory)) ; FIXME: is this even working?
(calendar-latitude 42.36) ;; These are needed
(calendar-longitude -42.36) ;; for M-x `sunrise-sunset'
(calendar-location-name "Cambridge, MA")
(column-number-mode t)
(line-number-mode t)
(line-spacing nil)
(completion-ignore-case t)
(completions-detailed t)
(delete-by-moving-to-trash t)
(delete-pair-blink-delay 0)
(delete-pair-push-mark t) ; EMACS-31 for easy subsequent C-x C-x
(display-line-numbers-width 4)
(display-line-numbers-widen t)
(display-fill-column-indicator-warning nil) ; EMACS-31
(delete-selection-mode t)
(enable-recursive minibuffers t)
(ffap-machine-p-known 'reject)
(find-ls-option '("-exec ls -ldh {} +" . "-ldh")) ; find-dired results with human readable sizes
(frame-resize-pixelwise t)
(global-goto-address-mode t) ; C-c RET on URLs open in default browser
(browse-url-secondary-browser-function 'eww-browse-url) ; C-u C-c RET on URLs open in EWW
(help-window-select t)
(history-length 300)
(inhibit-startup-message t)
(initial-scratch-message "")
(ibuffer-human-readable-size t) ; EMACS-31
(ielm-history-file-name (emacs-solo--cache-path 'ielm-history-file-name)) ; EMACS-31
(kill-do-not-save-duplicates t)
(kill-region-dwim 'emacs-word) ; EMACS-31
(create-lockfiles nil) ; No lock files
(make-backup-files nil) ; No backup files
(multisession-directory (emacs-solo--cache-path 'multisession-directory))
(nsm-settings-file (emacs-solo--cache-path 'nsm-settings-file))
(native-comp-async-on-battery-power nil) ; No compilations when on battery EMACS-31
(pixel-scroll-precision-mode t)
(pixel-scroll-precision-use-momentum nil)
(project-list-file (emacs-solo--cache-path 'project-list-file))
(project-vc-extra-root-markers '("Cargo.toml" "package.json" "go.mod" "*.asd")) ; Excelent for mono repos with multiple langs, makes Eglot happy
(ring-bell-function 'ignore)
(read-answer-short t)
(read-process-output-max (* 4 1024 1024)) ; 4MB
(redisplay-skip-fontification-on-input t)
(recentf-max-saved-items 300) ; default is 20
(recentf-max-menu-items 15)
(recentf-auto-cleanup (if (daemonp) 300 'never))
(recentf-exclude (list "^/\\(?:ssh\\|su\\|sudo\\)?:"))
(recentf-save-file (emacs-solo--cache-path 'recentf-save-file))
(register-use-preview t)
(remote-file-name-inhibit-delete-by-moving-to-trash t)
(remote-file-name-inhibit-auto-save t)
(remote-file-name-inhibit-locks t)
(remote-file-name-inhibit-auto-save-visited t)
(tramp-copy-size-limit (* 2 1024 1024)) ;; 2MB
(tramp-use-scp-direct-remote-copying t)
(tramp-verbose 2)
(resize-mini-windows 'grow-only)
(scroll-conservatively 8)
(scroll-margin 5)
(save-interprogram-paste-before-kill t)
(savehist-save-minibuffer-history t) ; t is default
(savehist-additional-variables
'(kill-ring ; clipboard
register-alist ; macros
mark-ring global-mark-ring ; marks
search-ring regexp-search-ring)) ; searches
(savehist-file (emacs-solo--cache-path 'savehist-file))
(save-place-file (emacs-solo--cache-path 'save-place-file))
(save-place-limit 600)
(set-mark-command-repeat-pop t) ; So we can use C-u C-SPC C-SPC C-SPC... instead of C-u C-SPC C-u C-SPC...
(split-width-threshold 170) ; So vertical splits are preferred
(split-height-threshold nil)
(shr-use-colors nil)
(switch-to-buffer-obey-display-actions t)
(tab-always-indent 'complete)
(tab-width 4)
(transient-history-file (emacs-solo--cache-path 'transient-history-file))
(transient-levels-file (emacs-solo--cache-path 'transient-levels-file))
(transient-values-file (emacs-solo--cache-path 'transient-values-file))
(treesit-font-lock-level 4)
(treesit-auto-install-grammar t) ; EMACS-31
(treesit-enabled-modes t) ; EMACS-31
(truncate-lines t)
(undo-limit (* 13 160000))
(undo-strong-limit (* 13 240000))
(undo-outer-limit (* 13 24000000))
(url-configuration-directory (emacs-solo--cache-path 'url-configuration-directory))
(use-dialog-box nil)
(use-file-dialog nil)
(use-package-hook-name-suffix nil)
(use-short-answers t)
(visible-bell nil)
(view-lossage-auto-refresh t) ; EMACS-31 auto updates C-h l usefull when teaching/debugging
(window-combination-resize t)
(window-resize-pixelwise nil)
(xref-search-program 'ripgrep)
(zone-all-frames t) ; EMACS-31
(zone-all-windows-in-frame t) ; EMACS-31
(zone-programs '[zone-pgm-rat-race])
(grep-command "rg -nS --no-heading ") ; used by M-x grep
(grep-find-ignored-directories ; used if M-x rgrep uses find (default in grep-find-template)
'("SCCS" "RCS" "CVS" "MCVS" ".src" ".svn" ".jj" ".git" ".hg" ".bzr" "_MTN" "_darcs" "{arch}" "node_modules" "build" "dist"))
(grep-find-template "rg <C> --null -nH -e <R> <D>") ; used by M-x rgrep (dropping find when using rg)
:config
;; Sets outline-mode for the `init.el' file
(defun emacs-solo/outline-init-file ()
(when (and (buffer-file-name)
(string-match-p "init\\.el\\'" (buffer-file-name)))
(outline-minor-mode 1)
(declare-function outline-hide-sublevels "")
(outline-hide-sublevels 1)))
(when emacs-solo-enable-outline-init
(declare-function emacs-solo/outline-init-file "")
(add-hook 'emacs-lisp-mode-hook #'emacs-solo/outline-init-file))
;; Make C-x 5 o repeatable
(defvar-keymap frame-repeat-map
:repeat t
"o" #'other-frame
"n" #'make-frame
"d" #'delete-frame)
(put 'other-frame 'repeat-map 'frame-repeat-map)
;; Makes everything accept utf-8 as default, so buffers with tsx and so
;; won't ask for encoding (because undecided-unix) every single keystroke
(modify-coding-system-alist 'file "" 'utf-8)
;; Setup preferred fonts when present on System
(declare-function emacs-solo/setup-font "")
(defun emacs-solo/setup-font ()
(let* ((emacs-solo-have-default-font (find-font (font-spec :family emacs-solo-preferred-font-name)))
(size (nth (if (eq system-type 'darwin) 0 1)
emacs-solo-preferred-font-sizes)))
(set-face-attribute 'default nil
:family (when emacs-solo-have-default-font
emacs-solo-preferred-font-name)
:height size)
;; macOS specific fine-tuning
(when (and (eq system-type 'darwin) emacs-solo-have-default-font)
;; Glyphs for powerline/icons
(set-fontset-font t '(#xe0b0 . #xe0bF) (font-spec :family emacs-solo-preferred-font-name))
;; Emojis
(set-fontset-font t '(#x1F300 . #x1FAFF)
(font-spec :family "Apple Color Emoji") nil 'prepend)
(add-to-list 'face-font-rescale-alist '("Apple Color Emoji" . 0.8)))))
;; Load Preferred Font Setup
(when emacs-solo-enable-preferred-font
(emacs-solo/setup-font))
;; MacOS specific customizations
(when (eq system-type 'darwin)
(setq insert-directory-program "gls")
(setq mac-command-modifier 'meta))
;; We want auto-save, but no #file# cluterring, so everything goes under our config cache/
;; (Directories are pre-created by `emacs-solo--ensure-cache-dirs'.)
(setq auto-save-list-file-prefix (emacs-solo--cache-path 'auto-saves-sessions)
auto-save-file-name-transforms `((".*" ,(emacs-solo--cache-path 'auto-saves) t)))
;; For OSC 52 compatible terminals support
(defvar xterm-extra-capabilities)
(setq xterm-extra-capabilities '(getSelection setSelection modifyOtherKeys))
;; TERMs should use the entire window space
(declare-function emacs-solo/disable-global-scrolling-in-ansi-term "")
(defun emacs-solo/disable-global-scrolling-in-ansi-term ()
"Disable global scrolling behavior in ansi-term buffers."
(setq-local scroll-conservatively 101)
(setq-local scroll-margin 0)
(setq-local scroll-step 0))
(add-hook 'term-mode-hook #'emacs-solo/disable-global-scrolling-in-ansi-term)
(with-eval-after-load 'term
(define-key term-raw-map (kbd "M-v") 'term-paste)
(define-key term-raw-map (kbd "M-e") (lambda () (interactive) (term-send-raw-string "\e"))))
;; TRAMP specific HACKs
;; See https://coredumped.dev/2025/06/18/making-tramp-go-brrrr./
(connection-local-set-profile-variables
'remote-direct-async-process
'((tramp-direct-async-process . t)))
(connection-local-set-profiles
'(:application tramp :protocol "scp")
'remote-direct-async-process)
(declare-function tramp-compile-disable-ssh-controlmaster-options "")
(with-eval-after-load 'tramp
(with-eval-after-load 'compile
(remove-hook 'compilation-mode-hook #'tramp-compile-disable-ssh-controlmaster-options)))
(setopt tramp-persistency-file-name (emacs-solo--cache-path 'tramp-persistency-file-name))
(setopt viper-custom-file-name (emacs-solo--cache-path 'viper-custom-file-name))
;; Set line-number-mode with relative numbering
(setq display-line-numbers-type 'relative)
(add-hook 'prog-mode-hook #'display-line-numbers-mode)
(add-hook 'text-mode-hook #'display-line-numbers-mode)
;; Starts `completion-preview-mode' automatically in some modes
(add-hook 'prog-mode-hook #'completion-preview-mode)
(add-hook 'text-mode-hook #'completion-preview-mode)
(add-hook 'rcirc-mode-hook #'completion-preview-mode)
(add-hook 'erc-mode-hook #'completion-preview-mode)
;; A Protesilaos life savier HACK
;; Add option "d" to whenever using C-x s or C-x C-c, allowing a quick preview
;; of the diff (if you choose `d') of what you're asked to save.
(add-to-list 'save-some-buffers-action-alist
(list "d"
(lambda (buffer) (diff-buffer-with-file (buffer-file-name buffer)))
"show diff between the buffer and its file"))
;; On Terminal: changes the vertical separator to a full vertical line
;; and truncation symbol to a right arrow
(set-display-table-slot standard-display-table 'vertical-border ?\u2502)
(set-display-table-slot standard-display-table 'truncation ?\u2192)
;; Ibuffer filters
(setq ibuffer-saved-filter-groups
'(("default"
("org" (or
(mode . org-mode)
(name . "^\\*Org Src")
(name . "^\\*Org Agenda\\*$")))
("tramp" (name . "^\\*tramp.*"))
("emacs" (or
(name . "^\\*scratch\\*$")
(name . "^\\*Messages\\*$")
(name . "^\\*Warnings\\*$")
(name . "^\\*Shell Command Output\\*$")
(name . "^\\*Async-native-compile-log\\*$")))
("ediff" (name . "^\\*[Ee]diff.*"))
("vc" (name . "^\\*vc-.*"))
("dired" (mode . dired-mode))
("terminal" (or
(mode . term-mode)
(mode . shell-mode)
(mode . eshell-mode)))
("help" (or
(name . "^\\*Help\\*$")
(name . "^\\*info\\*$")))
("news" (name . "^\\*Newsticker.*"))
("gnus" (or
(mode . message-mode)
(mode . gnus-group-mode)
(mode . gnus-summary-mode)
(mode . gnus-article-mode)
(name . "^\\*Group\\*")
(name . "^\\*Summary\\*")
(name . "^\\*Article\\*")
(name . "^\\*BBDB\\*")))
("chat" (or
(mode . rcirc-mode)
(mode . erc-mode)
(name . "^\\*rcirc.*")
(name . "^\\*ERC.*"))))))
(add-hook 'ibuffer-mode-hook
(lambda ()
(ibuffer-switch-to-saved-filter-groups "default")))
(setq ibuffer-show-empty-filter-groups nil) ; don't show empty groups
(defun emacs-solo/filtered-project-buffer-completer (project files-only)
"A function that filters special buffers and uses `completing-read`."
(let* ((project-buffers (project-buffers project))
(filtered-buffers
(cl-remove-if
(lambda (buffer)
(let* ((name (buffer-name buffer))
(trimmed-name (string-trim name)))
(or
(and (> (length trimmed-name) 1)
(string-prefix-p "*" trimmed-name)
(string-suffix-p "*" trimmed-name))
(and files-only (not (buffer-file-name buffer))))))
project-buffers)))
(if filtered-buffers
(let* ((buffer-names (mapcar #'buffer-name filtered-buffers))
(selection (completing-read "Switch to project buffer: " buffer-names nil t)))
(when selection
(switch-to-buffer selection)))
(message ">>> emacs-solo: No suitable project buffers to switch to."))))
;; Tell project.el filter out *special buffers* on `C-x p C-b'
(setq project-buffers-viewer 'emacs-solo/filtered-project-buffer-completer)
;; So eshell git commands open an instance of THIS config of Emacs
(setenv "GIT_EDITOR" (format "emacs --init-dir=%s " (shell-quote-argument user-emacs-directory)))
(setenv "JJ_EDITOR" (format "emacs --init-dir=%s " (shell-quote-argument user-emacs-directory)))
(setenv "EDITOR" (format "emacs --init-dir=%s " (shell-quote-argument user-emacs-directory)))
(setenv "PAGER" "cat")
;; So rebase from eshell opens with a bit of syntax highlight
(add-to-list 'auto-mode-alist '("/git-rebase-todo\\'" . conf-mode))
;; Mute NPM loglevel so it wont interfer with other issued commands like grep
(setenv "NPM_CONFIG_LOGLEVEL" "silent")
;; EMACS-31 Remove this, since new emacs will come with 'e' for editing xref buffers.
;; Reference: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=80616
;;
;; Makes any xref buffer "exportable" to a grep buffer with "E" so you can edit it with "e".
(defun emacs-solo/xref-to-grep-compilation ()
"Export the current Xref results to a grep-like buffer (Emacs 30+)."
(interactive)
(unless (derived-mode-p 'xref--xref-buffer-mode)
(user-error "Not in an Xref buffer"))
(let* ((items (and (boundp 'xref--fetcher)
(funcall xref--fetcher)))
(buf-name "*xref→grep*")
(grep-buf (get-buffer-create buf-name)))
(unless items
(user-error "No xref items found"))
(with-current-buffer grep-buf
(let ((inhibit-read-only t))
(erase-buffer)
(insert (format "-*- mode: grep; default-directory: %S -*-\n\n"
default-directory))
(dolist (item items)
(let* ((loc (xref-item-location item))
(file (xref-file-location-file loc))
(line (xref-file-location-line loc))
(summary (xref-item-summary item)))
(insert (format "%s:%d:%s\n" file line summary)))))
(grep-mode))
(pop-to-buffer grep-buf)))
(with-eval-after-load 'xref
(define-key xref--xref-buffer-mode-map (kbd "E")
#'emacs-solo/xref-to-grep-compilation))
;; ELISP evaluations show results in an overlay
(defun emacs-solo/eval-last-sexp-overlay (arg)
"Eval last sexp and show result inline as overlay.
With prefix ARG, insert the result inline instead.
Use ⇒ if displayable, otherwise fallback to =>."
(interactive "P")
(let ((arrow (if (char-displayable-p ?⇒) " ; ⇒ " " ; => ")))
(if arg
(let ((value (elisp--eval-last-sexp nil)))
(insert arrow (format "%S" value)))
(let* ((value (elisp--eval-last-sexp nil))
(str (concat arrow (format "%S" value)))
(ov (make-overlay (point) (point))))
(overlay-put ov 'after-string
(propertize str 'face 'font-lock-comment-face))
(run-with-timer
3 nil
(lambda (o) (delete-overlay o))
ov)))))
(global-set-key (kbd "C-x C-e") #'emacs-solo/eval-last-sexp-overlay)
(defun emacs-solo/copy-whole-word ()
"Copy the symbol at point to the kill ring without moving point."
(interactive)
(let ((bounds (bounds-of-thing-at-point 'symbol)))
(when bounds
(kill-ring-save (car bounds) (cdr bounds)))))
;; TODO: move this to an emacs-lisp use-package section
(defun emacs-solo/prefer-spaces ()
"Disable indent-tabs-mode to prefer spaces over tabs."
(interactive)
(setq indent-tabs-mode nil))
;; Only override where necessary
(add-hook 'emacs-lisp-mode-hook #'emacs-solo/prefer-spaces)
;; Colorize the '*Messages*' buffer
(defun emacs-solo/messages-font-lock-setup ()
(unless font-lock-defaults
(setq-local font-lock-defaults '(nil nil nil nil nil)))
(font-lock-add-keywords nil
'(("^Loading .*" 0 'shadow prepend)
("^Package .*" 0 'shadow prepend)
("^line-move.*" 0 'shadow prepend)
("^For information abou.*" 0 'shadow prepend)
("^Importing package-keyring.gpg.*" 0 'shadow prepend)
("^.*[Ee]rror:? .*" 0 'compilation-error prepend)
("\\[.* times\\]" 0 'font-lock-regexp-face prepend)
("done$" 0 'font-lock-regexp-face prepend)
("^>>>.*" 0 'font-lock-function-name-face prepend)))
(font-lock-mode 1)
(font-lock-flush)
(font-lock-ensure))
(add-hook 'messages-buffer-mode-hook #'emacs-solo/messages-font-lock-setup)
(with-current-buffer (messages-buffer)
(emacs-solo/messages-font-lock-setup))
;; Force abbrev-mode off entering message/mail
(add-hook 'message-mode-hook (lambda () (abbrev-mode -1)))
(add-hook 'mail-mode-hook (lambda () (abbrev-mode -1)))
;; Recenter after save-place restore
;; Reference: https://emacsredux.com/blog/2026/04/07/stealing-from-the-best-emacs-configs/
(advice-add 'save-place-find-file-hook :after
(lambda (&rest _)
(when buffer-file-name (ignore-errors (recenter)))))
;; Loads 'private.el' lazily, once Emacs goes idle after startup.
(add-hook 'after-init-hook
(lambda ()
(run-with-idle-timer
0.5 nil
(lambda ()
(let ((private-file (expand-file-name "private.el" user-emacs-directory)))
(when (file-exists-p private-file)
(load private-file)))))))
:init
;; Keep margins from automatic resizing
(defun emacs-solo/set-default-window-margins ()
"Set default left and right margins for all windows.
Unless the buffer uses `emacs-solo/center-document-mode`
or is an ERC buffer."
(interactive)
(dolist (window (window-list))
(with-current-buffer (window-buffer window)
(unless (or (bound-and-true-p emacs-solo/center-document-mode)
(derived-mode-p 'erc-mode))
(set-window-margins window 2 0))))) ;; (LEFT RIGHT)
(add-hook 'window-configuration-change-hook #'emacs-solo/set-default-window-margins)
(when (>= emacs-major-version 31)
(tty-tip-mode nil)) ;; EMACS-31
(tooltip-mode nil)
(select-frame-set-input-focus (selected-frame))
(blink-cursor-mode 0)
(recentf-mode 1)
(repeat-mode 1)
(savehist-mode 1)
(save-place-mode 1)
(winner-mode)
(xterm-mouse-mode 1)
(file-name-shadow-mode 1) ; allows us to type a new path without having to delete the current one
(with-current-buffer (get-buffer-create "*scratch*")
(insert (format ";;
;; ███████╗███╗ ███╗ █████╗ ██████╗███████╗ ███████╗ ██████╗ ██╗ ██████╗
;; ██╔════╝████╗ ████║██╔══██╗██╔════╝██╔════╝ ██╔════╝██╔═══██╗██║ ██╔═══██╗
;; █████╗ ██╔████╔██║███████║██║ ███████╗ ███████╗██║ ██║██║ ██║ ██║
;; ██╔══╝ ██║╚██╔╝██║██╔══██║██║ ╚════██║ ╚════██║██║ ██║██║ ██║ ██║
;; ███████╗██║ ╚═╝ ██║██║ ██║╚██████╗███████║ ███████║╚██████╔╝███████╗╚██████╔╝
;; ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚══════╝ ╚══════╝ ╚═════╝ ╚══════╝ ╚═════╝
;;
;; Loading time : %s
;; Packages : %s
;;
"
(emacs-init-time)
(number-to-string (length package-activated-list)))))
(message ">>> emacs-solo: init time %s" (emacs-init-time)))
;;; │ ABBREV
;;
;; A nice resource about it: https://www.rahuljuliato.com/posts/abbrev-mode
(use-package abbrev
:ensure nil
:custom
(save-abbrevs nil)
:config
(defun emacs-solo/abbrev--replace-placeholders ()
"Replace placeholders ###1###, ###2###, ... with minibuffer input.
If ###@### is found, remove it and place point there at the end."
(let ((cursor-pos nil)) ;; to store where to place point
(save-excursion
(goto-char (point-min))
(let ((loop 0)
(values (make-hash-table :test 'equal)))
(while (re-search-forward "###\\([0-9]+\\|@\\)###" nil t)
(setq loop (1+ loop))
(let* ((index (match-string 1))
(start (match-beginning 0))
(end (match-end 0)))
(cond
((string= index "@")
(setq cursor-pos start)
(delete-region start end))
(t
(let* ((key (format "###%s###" index))
(val (or (gethash key values)
(let ((input (read-string (format "Value for %s: " key))))
(puthash key input values)
input))))
(goto-char start)
(delete-region start end)
(insert val)
(goto-char (+ start (length val))))))))))
(when cursor-pos
(goto-char cursor-pos))))
(define-abbrev-table 'global-abbrev-table
'(;; Arrows
("ra" "→")
("la" "←")
("ua" "↑")
("da" "↓")
;; Emojis for context markers
("todo" "👷 TODO:")
("fixme" "🔥 FIXME:")
("note" "📎 NOTE:")
("hack" "👾 HACK:")
("pinch" "🤌")
("smile" "😄")
("party" "🎉")
("up" "☝️")
("applause" "👏")
("manyapplauses" "👏👏👏👏👏👏👏👏")
("heart" "❤️")
;; NerdFonts
("nerdfolder" " ")
("nerdgit" "")
("nerdemacs" "")
;; HTML
("nb" " ")
("lt" "<") ;; <
("gt" ">") ;; >
("le" "≤") ;; ≤
("ge" "≥") ;; ≥
("ap" "'") ;; '
("laa" "«") ;; «
("raa" "»") ;; »
("co" "©") ;; ©
("tm" "™") ;; ™
("em" "—") ;; —
("en" "–") ;; –
("dq" """) ;; "
("html" "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <title>Document</title>\n</head>\n<body>\n\n</body>\n</html>")
;; Utils
("isodate" ""
(lambda () (insert (format "%s" (format-time-string "%Y-%m-%dT%H:%M:%S")))))
("uuid" ""
(lambda () (insert (org-id-uuid))))
;; Markdown
("cb" "```@\n\n```"
(lambda () (search-backward "@") (delete-char 1)))
;; ORG
("ocb" "#+BEGIN_SRC @\n\n#+END_SRC"
(lambda () (search-backward "@") (delete-char 1)))
("oheader" "#+TITLE: ###1###\n#+AUTHOR: ###2###\n#+EMAIL: ###3###\n#+OPTIONS: toc:nil\n"
emacs-solo/abbrev--replace-placeholders)
;; JS/TS snippets
("imp" "import { ###1### } from '###2###';"
emacs-solo/abbrev--replace-placeholders)
("fn" "function ###1### () {\n ###@### ;\n};"
emacs-solo/abbrev--replace-placeholders)
("clog" "console.log(\">>> LOG:\", { ###@### })"
emacs-solo/abbrev--replace-placeholders)
("cwarn" "console.warn(\">>> WARN:\", { ###@### })"
emacs-solo/abbrev--replace-placeholders)
("cerr" "console.error(\">>> ERR:\", { ###@### })"
emacs-solo/abbrev--replace-placeholders)
("afn" "async function() {\n \n}"
(lambda () (search-backward "}") (forward-line -1) (end-of-line)))
("ife" "(function() {\n \n})();"
(lambda () (search-backward ")();") (forward-line -1) (end-of-line)))
("esdeps" "// eslint-disable-next-line react-hooks/exhaustive-deps"
(lambda () (search-backward ")();") (forward-line -1) (end-of-line)))
("eshooks" "// eslint-disable-next-line react-hooks/rules-of-hooks"
(lambda () (search-backward ")();") (forward-line -1) (end-of-line)))
;; React/JSX
("rfc" "const ###1### = () => {\n return (\n <div>###2###</div>\n );\n};"
emacs-solo/abbrev--replace-placeholders))))
;;; │ AUTH-SOURCE
(use-package auth-source
:ensure nil
:defer t
:config
(setq epg-pinentry-mode 'loopback)
(setq auth-sources
(list (expand-file-name ".authinfo.gpg" user-emacs-directory)))
(setq user-full-name "User Name and Surnames"
user-mail-address "user@mail.com")
;; Use `pass` as an auth-source
(when (file-exists-p "~/.password-store")
(auth-source-pass-enable)))
;;; │ AUTO-REVERT
(use-package autorevert
:ensure nil
:hook (emacs-startup-hook . global-auto-revert-mode)
:custom
(auto-revert-remote-files nil) ;; t makes tramp slow
(auto-revert-verbose t)
(auto-revert-avoid-polling t)
(global-auto-revert-non-file-buffers t))
;;; │ CONF
(use-package conf-mode
:ensure nil
:mode ("\\.env\\..*\\'" "\\.env\\'")
:init
(add-to-list 'auto-mode-alist '("\\.env\\'" . conf-mode)))
;;; │ COMPILATION
(use-package compile
:ensure nil
:custom
(compilation-always-kill t)
(compilation-scroll-output t)
(ansi-color-for-compilation-mode t)
:config
;; Not ideal, but I do not want this poluting the mode-line
(defun emacs-solo/ignore-compilation-status (&rest _)
(setq compilation-in-progress nil))
(advice-add 'compilation-start :after #'emacs-solo/ignore-compilation-status)
(add-hook 'compilation-filter-hook #'ansi-color-compilation-filter))
;;; │ WINDOW
(use-package window
:ensure nil
:custom
(display-buffer-alist
'(("\\*\\(Backtrace\\|Warnings\\|Compile-Log\\|Messages\\|Bookmark List\\|Occur\\|eldoc\\)\\*"
(display-buffer-in-side-window)
(window-height . 0.25)
(side . bottom)
(slot . 0))
("\\*\\([Hh]elp\\)\\*"
(display-buffer-in-side-window)
(window-width . 75)
(side . right)
(slot . 0))
("\\*\\(Ibuffer\\)\\*"
(display-buffer-in-side-window)
(window-width . 100)
(side . right)
(slot . 1))
("\\*\\(claude:\\|opencode:\\).*\\*"
(display-buffer-in-side-window)
(window-width . 100)
(side . right)
(slot . 1))
("\\*\\(Flymake diagnostics\\|Completions\\)"
(display-buffer-in-side-window)
(window-height . 0.25)
(side . bottom)
(slot . 2))
("\\*\\(grep\\|xref\\|find\\)\\*"
(display-buffer-in-side-window)
(window-height . 0.25)
(side . bottom)
(slot . 1))
("\\*inferior.*"
(display-buffer-in-side-window)
(window-height . 0.5)
(side . bottom)
(slot . 1))
("\\*\\(M3U Playlist\\)"
(display-buffer-in-side-window)
(window-height . 0.25)
(side . bottom)
(slot . 3)))))
;;; │ TAB-BAR
(use-package tab-bar
:ensure nil