-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.el
1203 lines (1062 loc) · 47.9 KB
/
config.el
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
;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
;; ____________________________________________________________________________
;;; FRAMES
;; Initial frame placement
(pushnew! initial-frame-alist
'(fullscreen . maximized))
;; Default frame placement
(pushnew! default-frame-alist
'(width . 90)
'(height . 47)
'(left . 940)
'(top . 0))
;; Bring frame to the front
(select-frame-set-input-focus (selected-frame))
;; ____________________________________________________________________________
;;; FONTS
(setq! doom-font
(font-spec :family "Iosevka Dee" :size 16 :weight 'normal)
doom-serif-font
(font-spec :family "Iosevka Dee Slab" :size 16 :weight 'normal)
doom-variable-pitch-font
(font-spec :family "ETBookOT" :size 18 :weight 'normal))
;; ____________________________________________________________________________
;;; THEMES
;; Declarations
(defvar my-theme-light nil "The default light theme.")
(defvar my-theme-dark nil "The default dark theme.")
(defvar my-frame-opacity 100 "The default frame opacity.")
;; My theme settings
(use-package! my-themes)
;; Modus theme settings
(use-package! modus-themes
:config
(setq modus-themes-bold-constructs t
modus-themes-italic-constructs nil
modus-themes-mixed-fonts t)
(setq modus-operandi-tinted-palette-overrides
modus-themes-preset-overrides-warmer)
(setq modus-vivendi-palette-overrides
modus-themes-preset-overrides-warmer)
(setq modus-themes-common-palette-overrides
'((border-mode-line-active unspecified)
(border-mode-line-inactive unspecified))))
;; Do not extend `region' background past the end of the line
(custom-set-faces
'(region ((t :extend nil))))
;;; - Set light/dark theme:
(setq my-theme-light 'modus-operandi-tinted)
(setq my-theme-dark 'modus-vivendi-tinted)
;; Switch between dark/light theme based on the system appearance
;; <https://github.com/d12frosted/homebrew-emacs-plus?tab=readme-ov-file#system-appearance-change>
(defun my-apply-theme (appearance)
"Load theme, taking current system APPEARANCE into consideration."
(mapc #'disable-theme custom-enabled-themes)
(setq doom-theme
(pcase appearance
('light (load-theme my-theme-light t)
;; Global variable will be used as an argument to launch emacsclient frames
(doom/set-frame-opacity (setq my-frame-opacity 100))
;; Eventually return theme name to set `doom-theme'
my-theme-light)
('dark (load-theme my-theme-dark t)
;; Global variable will be used as an argument to launch emacsclient frames
(doom/set-frame-opacity (setq my-frame-opacity 90))
;; Eventually return theme name to set `doom-theme'
my-theme-dark))))
(add-hook! 'ns-system-appearance-change-functions #'my-apply-theme)
;; BUG Fix for https://github.com/doomemacs/doomemacs/issues/6720
(after! diff-hl
(add-hook! 'doom-load-theme-hook
(defun +vc-gutter-make-diff-hl-faces-transparent-h ()
(mapc (doom-rpartial #'set-face-background (face-background 'default))
'(diff-hl-insert
diff-hl-delete
diff-hl-change)))))
;; ____________________________________________________________________________
;;; SHELLS
(defvar my-shell (executable-find "fish"))
(setq! explicit-shell-file-name my-shell)
;; Use a Posix shell under the hood to avoid problems wherever Emacs (or Emacs
;; packages) spawn child processes via shell commands and rely on their output
(setq! shell-file-name (or (executable-find "dash")
(executable-find "bash")
(executable-find "zsh")
(executable-find "sh")))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Eshell
(after! eshell
(setq! eshell-scroll-to-bottom-on-output nil)
(setq eshell-list-files-after-cd t)
(setq! eshell-term-name "xterm-256color")
(set-eshell-alias!
"q" "exit"
"l" "ls $*"
"la" "ls -A $*"
"ll" "ls -lh $*"
"lla" "ls -lhA $*"
"lt" "eza -T --icons $*"
"lat" "eza -AT --icons $*"
"llt" "eza -lT --icons $*"
"llat" "eza -lAT --icons $*"
"up" "eshell-up $1"
"cdp" "cd-to-project"
"mkdir" "mkdir -p $*"
"tm" "trash $*"
;; Emacs commands
"f" "find-file $1"
"fo" "find-file-other-window $1"
"d" "dired $1"
"do" "dired-other-window $1"
"g" "magit-status"
"doomS" "doom sync --gc --aot"
"doomU" "doom upgrade --aot"
"doomR" "doom/restart"
;; Adblocker
"hblock-off" "hblock -S none -D none"
;; Git
"git" "git --no-pager $*"
;; Tar archives
"targ" "tar cfvz $*"
"targx" "tar xfvz $*"
"tarb" "tar cfvj $*"
"tarbx" "tar xfvj $*"
;; Lisp
"lisp" "rlwrap ros -Q run $*"
"lisp-swank" "rlwrap ros -Q run --eval \"(ql:quickload :swank)\" --eval \"(swank:create-server :dont-close t)\""
;; macOS
"app-unblock" "sudo xattr -d com.apple.quarantine $*"
"app-clear" "sudo xattr -crv $*"
"app-sign" "sudo codesign --force --deep --sign - $*"
;; Homebrew
"brewu" "brew update"
"brewup" "brew update && brew upgrade"
;; Apt-get
"pacu" "sudo apt-get update"
"pacup" "sudo apt-get update && sudo apt-get upgrade"
"pacupd" "sudo apt-get dist-upgrade"
"pacs" "apt-cache search $*"
"pacinfo" "apt-cache show $*"
"paci" "sudo apt-get install --no-install-recommends $*"
"pacli" "apt list --installed"
"paclig" "apt list --installed | grep $*"
"pacmark" "sudo apt-mark $*"
"pacr" "sudo apt-get remove --purge $*"
"pacar" "sudo apt-get autoremove --purge $*"
;; Guix
"guixup" "guix pull && guix package -u"
;; Nix
"nixup" "nix-channel --update nixpkgs && nix-env -u '*'"
;; Too small tmp directory
"resizetmp" "sudo mount -o remount,size=8G,noatime /tmp"))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Vterm
(after! vterm
(setq! vterm-shell my-shell))
;; ____________________________________________________________________________
;;; KEYBINDINGS
(setq! doom-leader-key "SPC"
doom-leader-alt-key "M-SPC"
doom-localleader-key ","
doom-localleader-alt-key "M-SPC ,")
(map! :leader
;; doom-leader-map
:desc nil ":" nil ; M-x
:desc nil "<" nil ; Switch buffer
:desc nil "X" nil ; Org capture
:desc nil "`" nil ; Switch to last buffer
:desc nil "~" nil ; Toggle last popup
:desc "Toggle popups" "`" #'+popup/toggle
:desc "Switch buffer" "," #'switch-to-buffer
:desc "Directories" "d" #'consult-dir
:desc "Eshell" "e" #'+eshell/here
:desc "Command" "m" #'execute-extended-command
:desc "Complex command" "M" #'consult-complex-command
:desc "IEx" "r" #'inf-elixir-run
:desc "Horizontal split" "S" #'+evil/window-split-and-follow
:desc "Vertical split" "V" #'+evil/window-vsplit-and-follow
;; doom-leader-buffer-map
:desc "Kill buffer and window" "b D" #'kill-buffer-and-window
;; doom-leader-file-map
:desc nil "f l" nil ; Locate file
;; doom-leader-open-map
:desc "Browse URL" "o w" #'browse-url
:desc "Browse URL external" "o W" #'browse-url-default-macosx-browser
:desc "Browse URL in Webkit" "o C-w" #'xwidget-webkit-browse-url
;; doom-leader-search-map
:desc "Find file at point" "s f" #'ffap
;; evil-window-map
:desc nil "w `" #'+popup/raise
:desc nil "w ~" #'+popup/buffer)
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - MacOS
;; Make the <Command> key on MacOS act as <Ctrl> key: "C- ..."
(setq! mac-command-modifier 'control)
;; Make the <Option> key on MacOS act as <Meta> key for "M- ..."
;; (setq! mac-option-modifier 'meta)
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Swap keys
;; <https://github.com/wbolster/evil-swap-keys>
(use-package! evil-swap-keys
:config
(global-evil-swap-keys-mode 1)
;; Shift number keys in all Evil states for any buffer type
(setq-hook! 'evil-local-mode-hook
evil-swap-keys-text-input-states
'(normal insert visual replace operator motion emacs))
(add-hook! 'evil-local-mode-hook
#'evil-swap-keys-swap-number-row))
;; Shift the number row per default
;; (define-key key-translation-map (kbd "`") (kbd "~"))
;; (define-key key-translation-map (kbd "1") (kbd "!"))
;; (define-key key-translation-map (kbd "2") (kbd "@"))
;; (define-key key-translation-map (kbd "3") (kbd "#"))
;; (define-key key-translation-map (kbd "4") (kbd "$"))
;; (define-key key-translation-map (kbd "5") (kbd "%"))
;; (define-key key-translation-map (kbd "6") (kbd "^"))
;; (define-key key-translation-map (kbd "7") (kbd "&"))
;; (define-key key-translation-map (kbd "8") (kbd "*"))
;; (define-key key-translation-map (kbd "9") (kbd "("))
;; (define-key key-translation-map (kbd "0") (kbd ")"))
;; ... and vice versa
;; (define-key key-translation-map (kbd "~") (kbd "`"))
;; (define-key key-translation-map (kbd "1") (kbd "!"))
;; (define-key key-translation-map (kbd "@") (kbd "2"))
;; (define-key key-translation-map (kbd "#") (kbd "3"))
;; (define-key key-translation-map (kbd "$") (kbd "4"))
;; (define-key key-translation-map (kbd "%") (kbd "5"))
;; (define-key key-translation-map (kbd "^") (kbd "6"))
;; (define-key key-translation-map (kbd "&") (kbd "7"))
;; (define-key key-translation-map (kbd "*") (kbd "8"))
;; (define-key key-translation-map (kbd "(") (kbd "9"))
;; (define-key key-translation-map (kbd ")") (kbd "0"))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Which-key
(after! which-key
(setq! which-key-idle-delay 0.4
which-key-idle-secondary-delay 0.01))
;; ____________________________________________________________________________
;;; OS INTEGRATION
;; Use the MacOS trash instead of freedesktop.org ~/.local/share/Trash
;; <https://github.com/emacsorphanage/osx-trash>
(use-package! osx-trash
:when (eq system-type 'darwin)
:config
(osx-trash-setup))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Utilities
;; Show and manage OS processes
(setq! proced-auto-update-interval 1
proced-auto-update-flag t
proced-enable-color-flag t
proced-descend t)
;; ____________________________________________________________________________
;;; WINDOW MANAGEMENT
;; <https://github.com/dimitri/switch-window>
(after! switch-window
(custom-set-faces '(switch-window-label
((t :height 1.0 :bold t))))
(custom-set-faces '(switch-window-background
((t :inherit 'whitespace-space :background unspecified))))
(setq! switch-window-multiple-frames t
switch-window-threshold 1
switch-window-mvborder-increment 1
switch-window-background t)
;; Vim-like keybindings for window resizing
(setq! switch-window-extra-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "k") #'switch-window-mvborder-up)
(define-key map (kbd "j") #'switch-window-mvborder-down)
(define-key map (kbd "h") #'switch-window-mvborder-left)
(define-key map (kbd "l") #'switch-window-mvborder-right)
(define-key map (kbd "=") #'balance-windows)
(define-key map (kbd "SPC") #'switch-window-resume-auto-resize-window)
map))
(setq! switch-window-minibuffer-shortcut 109) ; "m"
(setq! switch-window-qwerty-shortcuts
'("a" "s" "d" "f" "g"
"q" "w" "e" "r" "t"
"u" "i" "o" "p"
"z" "x" "c" "v"
"b" "n"))
;; Bind `switch-window' commands to regular Emacs keybindings
(map! :leader
"w w" #'switch-window
"w m" #'switch-window-then-maximize
"w s" #'switch-window-then-split-below
"w v" #'switch-window-then-split-right
"w d" #'switch-window-then-delete
"w D" #'switch-window-then-kill-buffer
"w , d" #'switch-window-then-dired
"w , f" #'switch-window-then-find-file
"w , b" #'switch-window-then-display-buffer
"w , s" #'switch-window-then-swap-buffer))
(after! ace-window
(setq! ace-window-display-mode t
aw-display-mode-overlay nil
aw-dispatch-when-more-than 1
aw-scope 'global)
(setq! aw-dispatch-alist
'((?j aw-flip-window)
(?m aw-swap-window "Swap Windows")
(?M aw-move-window "Move Window")
(?b aw-switch-buffer-in-window "Select Buffer")
(?B aw-switch-buffer-other-window "Switch Buffer Other Window")
(?C aw-copy-window "Copy Window")
(?D aw-delete-window "Delete Window")
(?O delete-other-windows "Delete Other Windows")
(?F aw-split-window-fair "Split Fair Window")
(?S aw-split-window-vert "Split Vert Window")
(?V aw-split-window-horz "Split Horz Window")
(?X aw-execute-command-other-window "Execute Command Other Window")
(?T aw-transpose-frame "Transpose Frame")
(?? aw-show-dispatch-help)))
(setq! aw-keys '(?a ?s ?d ?f ?g
?q ?w ?e ?r ?t
?y ?u ?i ?o ?p))
(set-face-attribute 'aw-background-face nil
:inherit 'shadow))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Popup windows
(when (modulep! :ui popup)
;; Adjust defaults
(plist-put +popup-defaults :height 0.33)
;; Make `other-window' work on popup-windows too
(setq! +popup-default-parameters
(remove '(no-other-window . t) +popup-default-parameters))
;; Don't hide mode-line
(after! hide-mode-line
(advice-add #'hide-mode-line-mode :around
(lambda (orig &optional args) nil)))
;; Make Eglot help windows higher
(after! eglot
(set-popup-rule! "^\\*eglot-help" :size 0.33 :quit t :select t)))
;; Popup adjustments for +defaults flag
;; Taken from `(find-file (concat doom-emacs-dir "modules/ui/popup/config.el"))'
(when (modulep! :ui popup +defaults)
(set-popup-rules!
'(("^\\*Completions" :ignore t)
("^\\*Local variables\\*$"
:vslot -1 :slot 1 :size +popup-shrink-to-fit)
("^\\*\\(?:[Cc]ompil\\(?:ation\\|e-Log\\)\\|Messages\\)"
:vslot -2 :size 0.33 :autosave t :quit t :ttl nil)
("^\\*\\(?:doom \\|Pp E\\)" ; transient buffers (no interaction required)
:vslot -3 :size +popup-shrink-to-fit :autosave t :select ignore :quit t :ttl 0)
("^\\*doom:" ; editing buffers (interaction required)
:vslot -4 :size 0.33 :autosave t :select t :modeline t :quit nil :ttl t)
("^\\*doom:\\(?:v?term\\|e?shell\\)-popup" ; editing buffers (interaction required)
:vslot -5 :size 0.33 :select t :modeline nil :quit nil :ttl nil)
("^\\*\\(?:Wo\\)?Man "
:vslot -6 :size 0.33 :select t :quit t :ttl 0)
("^\\*Calc"
:vslot -7 :side bottom :size 0.33 :select t :quit nil :ttl 0)
("^\\*Customize"
:slot 2 :side bottom :size 0.5 :select t :quit nil)
("^ \\*undo-tree\\*"
:slot 2 :side left :size 20 :select t :quit t)
;; `help-mode', `helpful-mode'
("^\\*\\([Hh]elp\\|Apropos\\)"
:slot 2 :vslot -8 :size 0.33 :select t)
("^\\*eww\\*" ; `eww' (and used by dash docsets)
:vslot -11 :size 0.33 :select t)
("^\\*xwidget"
:vslot -11 :size 0.33 :select nil)
("^\\*info\\*$" ; `Info-mode'
:slot 2 :vslot 2 :size 0.33 :select t))
'(("^\\*Warnings" :vslot 99 :size 0.25)
("^\\*Backtrace" :vslot 99 :size 0.33 :quit nil)
("^\\*CPU-Profiler-Report " :side bottom :vslot 100 :slot 1 :height 0.33 :width 0.5 :quit nil)
("^\\*Memory-Profiler-Report " :side bottom :vslot 100 :slot 2 :height 0.33 :width 0.5 :quit nil)
("^\\*Process List\\*" :side bottom :vslot 101 :size 0.25 :select t :quit t)
("^\\*\\(?:Proced\\|timer-list\\|Abbrevs\\|Output\\|Occur\\|unsent mail.*?\\|message\\)\\*" :ignore t))))
;; ____________________________________________________________________________
;;; MINIBUFFER
;; <https://www.gnu.org/software/emacs/manual/html_mono/emacs.html#Minibuffer>
;; Show the depth of recursive minibuffers?
(minibuffer-depth-indicate-mode 1)
;; Delete duplicates from the command history?
(setq! history-delete-duplicates t)
;; Modal editing in the minibuffer?
(setq! evil-collection-setup-minibuffer t)
;; ____________________________________________________________________________
;;; MISC
;; Make height suitable for smaller frames too
(after! vertico
(setq! vertico-cycle nil
vertico-count 10))
;; Not everything is line-oriented, e.g. Lisp code
(after! hl-line
(setq! hl-line-sticky-flag nil)
(setq! global-hl-line-modes '(text-mode
special-mode
org-agenda-mode
dired-mode)))
;; Light-weight mode-line is too high, fix that
(when (modulep! :ui modeline +light)
(setq! +modeline-height 24))
;; Don't ask
(setq! confirm-kill-emacs nil)
;; ____________________________________________________________________________
;;; BUFFER MANAGEMENT
(setq! initial-major-mode #'lisp-interaction-mode)
(after! ibuffer
(add-hook! 'ibuffer-mode-hook #'ibuffer-auto-mode))
;; Kill all buffers at once
(defun my-kill-all-buffers ()
"Really kill all buffers at once."
(interactive)
(save-some-buffers)
(let ((kill-buffer-query-functions '()))
(mapc #'kill-buffer (buffer-list))))
;; ____________________________________________________________________________
;;; ELDOC
;; <https://www.gnu.org/software/emacs/manual/html_mono/emacs.html#Lisp-Doc>
;; <https://www.masteringemacs.org/article/seamlessly-merge-multiple-documentation-sources-eldoc>
(setq! eldoc-minor-mode-string nil
eldoc-documentation-strategy 'eldoc-documentation-compose-eagerly
eldoc-echo-area-display-truncation-message nil
eldoc-echo-area-prefer-doc-buffer nil
eldoc-echo-area-use-multiline-p 'truncate-sym-name-if-fit)
;; ____________________________________________________________________________
;;; RECENT FILES
(after! recentf
;; Exclude certain files
(add-to-list 'recentf-exclude
(expand-file-name
(concat doom-emacs-dir ".local/etc/workspaces/autosave"))))
;; ____________________________________________________________________________
;;; BACKUP
;; <https://www.gnu.org/software/emacs/manual/html_mono/emacs.html#Backup>
;; Make backup before saving files
(setq! make-backup-files t)
;; Specify file name/path patterns and directories ("REGEXP" . "DIRECTORY")
(setq! backup-directory-alist
`(("." . ,(concat (getenv "HOME") "/Documents/backup/emacs/"))))
;; ____________________________________________________________________________
;;; COMINT
(after! comint
(setq! comint-input-ignoredups t
comint-scroll-to-bottom-on-input 'this))
;; ____________________________________________________________________________
;;; DIRED
;; <https://www.gnu.org/software/emacs/manual/html_mono/emacs.html#Dired>
(after! dired
;; Listing columns; Switch arguments with "C-u s" e.g. hide backups with -B
(setq! dired-listing-switches "-lhFA -v --group-directories-first")
(setq! dired-kill-when-opening-new-dired-buffer t)
(add-hook! 'dired-mode-hook
#'dired-hide-details-mode
#'dired-omit-mode
(setq! dired-omit-files "\\`[.]?#\\|\\`[.][.]?\\'\\|^\\."))
(map! :localleader :mode dired-mode
:n "d" #'dired-hide-details-mode)
;; BUG Fix for <https://github.com/doomemacs/doomemacs/issues/8170>
(defun reset-cursor-after-wdired-exit ()
"Restore the evil-normal-state-cursor to \='box' after exiting Editable Dired."
(kill-local-variable 'evil-normal-state-cursor)
(kill-local-variable 'cursor-type)
(setq evil-normal-state-cursor 'box)
(setq cursor-type 'box))
(advice-add 'wdired-finish-edit :after #'reset-cursor-after-wdired-exit) ;; ZZ
(advice-add 'wdired-abort-changes :after #'reset-cursor-after-wdired-exit) ;; ZQ
(advice-add 'evil-force-normal-state :after #'reset-cursor-after-wdired-exit)) ;; ESC
;; ____________________________________________________________________________
;;; CALENDAR
;; <https://www.gnu.org/software/emacs/manual/html_mono/emacs.html#Calendar_002fDiary>
(setq! calendar-date-style 'iso
calendar-week-start-day 1
calendar-weekend-days '(6 0))
;; ____________________________________________________________________________
;;; WEB BROWSERS
;; <https://www.gnu.org/software/emacs/manual/html_mono/eww.html#Top>
(setq! url-privacy-level '(email lastloc cookies))
(url-setup-privacy-info)
(defun my-user-agent (browser-name)
(cond
((equal browser-name 'safari-macos)
(setq! url-user-agent
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/11.0.1 Safari/603.3.8"))
((equal browser-name 'safari-iphone)
(setq! url-user-agent
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Mobile/15E148 Safari/604.1"))
((equal browser-name 'w3m)
(setq! url-user-agent
"w3m/0.5.3+git2020050"))
(t
(setq! url-user-agent
'default))))
;; Set the user agent for the internal web browser
(my-user-agent 'safari-iphone)
;; Default system browser
(setq! browse-url-browser-function #'eww-browse-url)
;; Secondary web browser
(setq! browse-url-secondary-browser-function #'browse-url-default-browser)
;; ____________________________________________________________________________
;;; PDF-TOOLS
(after! pdf-tools
;; Compile without asking
(pdf-tools-install :no-query))
;; ____________________________________________________________________________
;;; ORG
(after! org
(setq! org-directory "~/Documents/org/")
(setq! org-hide-leading-stars nil))
;; <https://github.com/alphapapa/org-sticky-header>
(use-package! org-sticky-header
:after org
:config
(add-hook! 'org-mode-hook #'org-sticky-header-mode))
;; ____________________________________________________________________________
;;; AI TOOLS
;; Provide a list locally installed Ollama models to use in various places
(defun my-ollama-models (prefix)
"List all locally installed Ollama models and add PREFIX to each element.
PREFIX can be either \"nil\", or \"ollama_chat/\" or \"ollama/\" to produce
Aider-compatible model names."
(let* ((output (shell-command-to-string "ollama list"))
(lines (split-string output "\n" t))
models)
(dolist (line (cdr lines))
(when (string-match "^\\([^[:space:]]+\\)" line)
(push (concat prefix (match-string 1 line)) models)))
(nreverse models)))
;; <https://github.com/s-kostyaev/ellama>
(use-package! ellama
:init
(setq! ellama-language "English")
(setq! ellama-sessions-directory "~/Documents/org/ellama-sessions")
(require 'llm-ollama)
(setq! ellama-provider
(make-llm-ollama
:chat-model "huihui_ai/qwen2.5-abliterate:7b-instruct-q8_0"
:embedding-model "nomic-embed-text"
:default-chat-non-standard-params '(("num_ctx" . 65536))
))
(setq! ellama-coding-provider
(make-llm-ollama
:chat-model "qwen2.5-coder:7b-instruct-q5_K_M"
:embedding-model "nomic-embed-text"
:default-chat-non-standard-params '(("num_ctx" . 65536))
))
(setq! ellama-translation-provider
(make-llm-ollama
:chat-model "thinkverse/towerinstruct:7b-v0.2-q4_0"
:embedding-model "nomic-embed-text"
:default-chat-non-standard-params '(("num_ctx" . 65536))
))
(setq! ellama-summarization-provider
(make-llm-ollama
:chat-model "huihui_ai/qwen2.5-abliterate:7b-instruct-q8_0"
:embedding-model "nomic-embed-text"
:default-chat-non-standard-params '(("num_ctx" . 65536))
))
(setq! ellama-extraction-provider
(make-llm-ollama
:chat-model "qwen2.5-coder:7b-instruct-q5_K_M"
:embedding-model "nomic-embed-text"
:default-chat-non-standard-params '(("num_ctx" . 65536))
))
(setq! ellama-naming-provider
(make-llm-ollama
:chat-model "huihui_ai/qwen2.5-abliterate:0.5b-instruct-q4_K_M"
:embedding-model "nomic-embed-text"
:default-chat-non-standard-params '(("stop" . ("\n")))
))
:config
(setq! ellama-chat-display-action-function #'display-buffer-pop-up-window)
(setq! ellama-instant-display-action-function #'display-buffer-pop-up-window))
(use-package! aider
:config
(setq! aider-popular-models (my-ollama-models "ollama_chat/"))
(setq! aider-args '("--model" "ollama_chat/qwen2.5-coder:7b-instruct-q5_K_M"))
(setenv "OLLAMA_API_BASE" "http://127.0.0.1:11434")
;; (after! my-private
;; (setq aider-args '("--model" "r1"))
;; (setenv "DEEPSEEK_API_KEY" my-deepseek-api-key))
(map! :leader
:desc "Menu" "A m" #'aider-transient-menu))
(use-package! gptel
:config
(setq! gptel-default-mode 'org-mode)
(setq! gptel-directives '((default . "")))
(setq! gptel-model 'huihui_ai/qwen2.5-abliterate:7b-instruct-q8_0
gptel-backend (gptel-make-ollama "Ollama"
:host "localhost:11434"
:stream t
:models (my-ollama-models nil))))
;; ____________________________________________________________________________
;;; EDITING / PROGRAMMING
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Tree-Sitter text objects
(map! (:map +tree-sitter-outer-text-objects-map
;; Use 'm' like module" instead
"m" (evil-textobj-tree-sitter-get-textobj "class.outer"))
(:map +tree-sitter-inner-text-objects-map
;; Use 'm' like "module" instead
"m" (evil-textobj-tree-sitter-get-textobj "class.inner")))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Kill-ring, yanking, copy & paste
;; <https://github.com/NicholasBHubbard/clean-kill-ring.el>
(use-package! clean-kill-ring
:config
(clean-kill-ring-mode 1))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Parenthesis
;; Highlight enclosing parens, or whole expressions?
(setq! show-paren-style 'parenthesis)
;; Color-code nested parens
;; <https://github.com/Fanael/rainbow-delimiters>
(add-hook! '(prog-mode-hook conf-mode-hook)
#'rainbow-delimiters-mode)
;; Structural editing: Lispyville
;; <https://oremacs.com/lispy>
;; <https://github.com/abo-abo/lispy>
(after! (lispy lispyville)
(map! :map lispy-mode-map-lispy
;; Unbind individual bracket keys
"[" nil
"]" nil
;; Re-bind commands bound to bracket keys by default
"M-[" #'lispyville-next-opening
"M-{" #'lispyville-previous-opening
"M-]" #'lispyville-next-closing
"M-}" #'lispyville-previous-closing))
;; Structural editing: Smartparens
;; <https://github.com/Fuco1/smartparens>
;; <https://smartparens.readthedocs.io/en/latest/>
(after! smartparens
(setq! show-smartparens-global-mode t)
;; Custom keybinding set, a blend of standard Emacs sexp keybindings
;; and Paredit keybindings
;; (map! :map smartparens-mode-map
;; ;; Navigation
;; "C-M-f" #'sp-forward-sexp
;; "C-M-b" #'sp-backward-sexp
;; "C-M-u" #'sp-backward-up-sexp
;; "C-M-d" #'sp-down-sexp
;; "C-M-p" #'sp-backward-down-sexp
;; "C-M-n" #'sp-up-sexp
;; "C-M-a" #'sp-beginning-of-sexp
;; "C-M-e" #'sp-end-of-sexp
;; ;; Depth-changing commands
;; "C-M-g" #'sp-unwrap-sexp
;; "C-M-s" #'sp-splice-sexp
;; ;; Forward slurp/barf
;; "C-)" #'sp-forward-slurp-sexp
;; "C-}" #'sp-forward-barf-sexp
;; ;; Backward slurp/barf
;; "C-(" #'sp-backward-slurp-sexp
;; "C-{" #'sp-backward-barf-sexp
;; ;; Misc
;; "C-M-k" #'sp-kill-sexp
;; "C-M-<backspace>" #'sp-backward-kill-sexp
;; "C-M-SPC" #'sp-mark-sexp
;; "C-M-w" #'sp-copy-sexp
;; "C-M-t" #'sp-transpose-sexp
;; "M-(" #'sp-wrap-round)
)
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Line numbers
(setq! display-line-numbers-type 'relative)
;; Turn off line numbers
(remove-hook! '(prog-mode-hook text-mode-hook conf-mode-hook)
#'display-line-numbers-mode)
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Indentation
;; Delete the whole indentation instead spaces one-by-one via <backspace>?
;; (Possibly shadowed by 3rd-party packages like 'smartparens-mode'
(setq! backward-delete-char-untabify-method 'all)
;; Keep code always inteted
;; <https://github.com/Malabarba/aggressive-indent-mode>
(use-package! aggressive-indent
:config
(global-aggressive-indent-mode 1))
;; Indentation guides
(after! indent-bars
(setq! indent-bars-no-descend-lists nil
indent-bars-highlight-current-depth '(:face fringe)
indent-bars-display-on-blank-lines t)
(remove-hook! 'text-mode-hook
#'indent-bars-mode))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Searching
;; TODO: Add keybindings for search and replace
;; The 'query-' variant asks with each string. Confirm with "SPC",
;; or omit the current selection via "n"
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Comments
(after! newcomment
(setq! comment-empty-lines t))
;; ____________________________________________________________________________
;;; LISP
(defun my-lisp-src-modes ()
"Generates a non-exhaustive list of loaded Lisp-related modes.
Entries are derived from the smartparens package."
(seq-filter #'fboundp '(clojure-mode
clojurec-mode
clojurescript-mode
clojurex-mode
clojure-ts-mode
clojurescript-ts-mode
clojurec-ts-mode
common-lisp-mode
emacs-lisp-mode
fennel-mode
gerbil-mode
lfe-mode ; addition
lisp-mode
lisp-data-mode ; addition
racket-mode
scheme-mode
stumpwm-mode
)))
(defun my-lisp-repl-modes ()
"Generates a non-exhaustive list of loaded Lisp-related REPLs.
Entries are derived from the smartparens package."
(seq-filter #'fboundp '(cider-repl-mode
eshell-mode
fennel-repl-mode
geiser-repl-mode
inf-clojure-mode
inferior-emacs-lisp-mode
inferior-lfe-mode ; addition
inferior-lisp-mode
inferior-scheme-mode
lisp-interaction-mode
monroe-mode
racket-repl-mode
scheme-interaction-mode
slime-repl-mode
sly-mrepl-mode
)))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Elisp
(when (modulep! :ui indent-guides)
(add-hook! 'emacs-lisp-mode-hook
(indent-bars-mode -1)))
(after! (lispy lispyville)
;; Making sure that the comment with the result is placed after the evaluated
;; expression, not inside it
(advice-add #'lispy-eval-and-comment
:around #'evil-collection-elisp-mode-last-sexp)
(map! :localleader
:map (emacs-lisp-mode-map lisp-interaction-mode-map)
:prefix "e"
:n "c" #'lispy-eval-and-comment))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - Common Lisp
;; <https://www.gnu.org/software/emacs/manual/html_mono/emacs.html#Executing-Lisp>
;; <http://joaotavora.github.io/sly/>
;; <https://github.com/joaotavora/sly>
;; Default Lisp implementation
(setq! inferior-lisp-program "ros -Q run")
(add-to-list '+lisp-quicklisp-paths "~/.roswell/lisp/quicklisp" 'append)
(when (modulep! indent-guides)
(add-hook! '(lisp-mode-hook lisp-data-mode-hook)
(indent-bars-mode -1)))
(after! sly
;; Set Sly Lisp implementations
(setq! sly-lisp-implementations
'((roswell ("ros" "-Q" "run"))
(sbcl ("ros" "-L" "sbcl" "-Q" "run") :coding-system utf-8-unix)
(ccl ("ros" "-L" "ccl-bin" "-Q" "run"))))
(setq! sly-default-lisp 'roswell
sly-command-switch-to-existing-lisp 'always
sly-complete-symbol-function #'sly-flex-completions)
(add-hook! 'sly-mrepl-mode-hook
#'rainbow-delimiters-mode)
(add-hook! 'sly-net-process-close-hooks
;; Switch to normal state when connection is closed
(when (string-match-p "^\\*sly-mrepl.*\\*" (buffer-name))
(evil-normal-state)))
(set-popup-rules!
'(("^\\*sly-mrepl" :vslot 2 :size 0.33 :quit nil :ttl nil)
("^\\*sly-compilation" :vslot 3 :ttl nil)
("^\\*sly-traces" :vslot 4 :ttl nil)
("^\\*sly-description" :vslot 5 :size 0.33 :ttl 0)
;; Do not display debugger or inspector buffers in a popup window. These
;; buffers are meant to be displayed with sufficient vertical space.
("^\\*sly-\\(?:db\\|inspector\\)" :ignore t)))
;; Change some of Doom's default Common Lisp keybindings
(map! (:map sly-db-mode-map
:n "gr" #'sly-db-restart-frame)
(:map sly-inspector-mode-map
:n "gb" #'sly-inspector-pop
:n "gr" #'sly-inspector-reinspect
:n "gR" #'sly-inspector-fetch-all
:n "K" #'sly-inspector-describe-inspectee)
(:map sly-xref-mode-map
:n "gr" #'sly-recompile-xref
:n "gR" #'sly-recompile-all-xrefs)
(:map lisp-mode-map
:n "gb" #'sly-pop-find-definition-stack)
(:localleader
:map lisp-mode-map
:desc "Sly" "'" #'sly
:desc "Sly (ask)" ";" (cmd!! #'sly '-)
:desc "Expand macro" "m" #'macrostep-expand
:desc "Find file in Quicklisp" "f" #'+lisp/find-file-in-quicklisp
:desc "Quickload System" "q" #'sly-quickload
(:prefix "c" ; ("c" . "compile")
:desc "Compile toplevel form" "c" #'sly-compile-defun
:desc "Compile file" "C" nil ; #'sly-compile-file
:desc "Compile file" "f" #'sly-compile-file
:desc "Compile/load file" "F" nil ; #'sly-compile-and-load-file
:desc "Load file" "l" #'sly-load-file
:desc "Compile/load file" "L" #'sly-compile-and-load-file
:desc "Remove notes" "n" #'sly-remove-notes
:desc "Compile region" "r" #'sly-compile-region)
(:prefix "e" ; ("e" . "evaluate")
:desc "Evaluate buffer" "b" #'sly-eval-buffer
:desc "Evaluate defun" "d" #'sly-overlay-eval-defun
:desc "Evaluate last" "e" #'sly-eval-last-expression
:desc "Evaluate/print last" "E" #'sly-eval-print-last-expression
:desc "Evaluate defun (async)" "f" #'sly-eval-defun
:desc "Undefine function" "F" nil ; #'sly-undefine-function
:desc "Evaluate region" "r" #'sly-eval-region)
(:prefix ("u" . "undefine")
:desc "Undefine function" "f" #'sly-undefine-function
:desc "Unintern symbol" "s" #'sly-unintern-symbol)
(:prefix "g" ; ("g" . "goto")
:desc "Go back" "b" #'sly-pop-find-definition-stack
:desc "Go to" "d" #'sly-edit-definition
:desc "Go to (other window)" "D" #'sly-edit-definition-other-window
:desc "Next note" "n" #'sly-next-note
:desc "Previous note" "N" #'sly-previous-note
:desc "Next sticker" "s" #'sly-stickers-next-sticker
:desc "Previous sticker" "S" #'sly-stickers-prev-sticker)
(:prefix "h" ; ("h" . "help")
:desc "Who calls" "<" #'sly-who-calls
:desc "Calls who" ">" #'sly-calls-who
:desc "Lookup format directive" "~" #'hyperspec-lookup-format
:desc "Lookup reader macro" "#" #'hyperspec-lookup-reader-macro
:desc "Apropos" "a" #'sly-apropos
:desc "Who binds" "b" #'sly-who-binds
:desc "Disassemble symbol" "d" #'sly-disassemble-symbol
:desc "Describe symbol" "h" #'sly-describe-symbol
:desc "HyperSpec lookup" "H" #'sly-hyperspec-lookup
:desc "Who macro-expands" "m" #'sly-who-macroexpands
:desc "Apropos package" "p" #'sly-apropos-package
:desc "Who references" "r" #'sly-who-references
:desc "Who specializes" "s" #'sly-who-specializes
:desc "Who sets" "S" #'sly-who-sets)
(:prefix "r" ; ("r" . "repl")
:desc "Clear REPL" "c" #'sly-mrepl-clear-repl
:desc "Load System" "l" #'sly-asdf-load-system
:desc "Quit connection" "q" #'sly-quit-lisp
:desc "Restart connection" "r" #'sly-restart-inferior-lisp
:desc "Reload Project" "R" #'+lisp/reload-project
:desc "Sync REPL" "s" #'sly-mrepl-sync)
(:prefix "s" ; ("s" . "stickers")
:desc "Toggle breaking stickers" "b" #'sly-stickers-toggle-break-on-stickers
:desc "Clear defun stickers" "c" #'sly-stickers-clear-defun-stickers
:desc "Clear buffer stickers" "C" #'sly-stickers-clear-buffer-stickers
:desc "Fetch stickers" "f" #'sly-stickers-fetch
:desc "Replay stickers" "r" #'sly-stickers-replay
:desc "Add/remove sticker" "s" #'sly-stickers-dwim)
(:prefix "t" ; ("t" . "test")
:desc "Test system" "s" #'sly-asdf-test-system)
(:prefix "T" ; ("T" . "trace")
:desc "Toggle" "t" #'sly-toggle-trace-fdefinition
:desc "Toggle (fancy)" "T" #'sly-toggle-fancy-trace
:desc "Untrace all" "u" #'sly-untrace-all))))
;; The hyperspec must be installed first. Adapt the path below:
(after! hyperspec
(setq! common-lisp-hyperspec-root
(concat "file://"
(expand-file-name "~/common-lisp/.hyperspec/HyperSpec/")))
(setq! common-lisp-hyperspec-symbol-table
(concat common-lisp-hyperspec-root "Data/Map_Sym.txt"))
(setq! common-lisp-hyperspec-issuex-table
(concat common-lisp-hyperspec-root "Data/Map_IssX.txt")))
;; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
;;; - SCHEME
;; <https://www.nongnu.org/geiser>
(after! geiser
(set-popup-rules!
'(("^\\*[gG]eiser \\(dbg\\|xref\\|messages\\)\\*$" :slot 1 :vslot -1)
("^\\*Geiser documentation\\*$" :slot 2 :vslot 2 :select t :size 0.33)
("^\\*Geiser .+ REPL" :size 0.33 :quit nil :ttl nil))))