-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
2724 lines (2441 loc) · 90 KB
/
init.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
;;; init.el --- Emacs customization -*- lexical-binding: t; mode: emacs-lisp;
;;; coding: utf-8; no-byte-compile: t; fill-column: 80 -*-
;; Swarnendu Biswas
;;; Commentary: My configuration is mostly targeted toward GNU Linux.
;;; Code:
(defgroup sb/emacs nil
"Personal configuration for GNU Emacs."
:group 'local)
(defcustom sb/extras-directory (expand-file-name "extras" user-emacs-directory)
"Path for third-party packages and files."
:type 'string
:group 'sb/emacs)
(defcustom sb/op-mode-daemon nil
"Specify the way you expect Emacs to be used."
:type 'boolean
:group 'sb/emacs)
(defcustom sb/debug-init-file nil
"Enable features to debug errors and performance bottlenecks."
:type 'boolean
:group 'sb/emacs)
(defcustom sb/theme 'modus-vivendi
"Specify which Emacs theme to use."
:type
'(radio
(const :tag "doom-nord" doom-nord)
(const :tag "modus-vivendi" modus-vivendi)
(const :tag "catppuccin" catppuccin)
(const :tag "none" none))
:group 'sb/emacs)
(defcustom sb/modeline-theme 'doom-modeline
"Specify the mode-line theme to use."
:type '(radio (const :tag "doom-modeline" doom-modeline) (const :tag "none" none))
:group 'sb/emacs)
;; Large values make reading difficult when the window is split side-by-side,
;; 100 is also a stretch for smaller screens.
(defcustom sb/fill-column 80
"Column beyond which lines should not extend."
:type 'number
:group 'sb/emacs)
;; Helper const variables
(defconst sb/user-home-directory (getenv "HOME")
"User HOME directory.")
(defconst sb/EMACS28+ (> emacs-major-version 27)
"Non-nil if Emacs version is 28 and above.")
(defconst sb/EMACS29+ (> emacs-major-version 28)
"Non-nil if Emacs version is 29 and above.")
(defconst sb/IS-LINUX (eq system-type 'gnu/linux)
"Non-nil if the OS is GNU/Linux.")
(defconst sb/IS-WINDOWS (eq system-type 'windows-nt)
"Non-nil if the OS is Windows.")
;; "straight.el" makes it easy to install packages from arbitrary sources like
;; GitHub.
(setq
straight-build-dir
(format "build/%d%s%d"
emacs-major-version
version-separator
emacs-minor-version)
;; Do not check packages on startup to reduce load time
straight-check-for-modifications '(check-on-save find-when-checking)
straight-use-package-by-default t
;; There is no need to download the whole Git history, and a single branch
;; often suffices.
straight-vc-git-default-clone-depth '(1 single-branch))
(let ((bootstrap-file
(expand-file-name
"straight/repos/straight.el/bootstrap.el"
(or (bound-and-true-p straight-base-dir) user-emacs-directory)))
(bootstrap-version 7))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent
'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;; These variables need to be set before loading `use-package'.
(setq use-package-enable-imenu-support t)
(straight-use-package
'(use-package :source
melpa))
(if (bound-and-true-p sb/op-mode-daemon)
(setq
use-package-always-demand t
use-package-minimum-reported-time 0 ; Show everything
use-package-verbose t)
(setq
use-package-always-defer t
use-package-expand-minimally t))
(when (bound-and-true-p sb/debug-init-file)
(setq
debug-on-error t
debug-on-event 'sigusr2
;; Use "M-x use-package-report" to see results
use-package-compute-statistics t
use-package-verbose t
use-package-minimum-reported-time 0 ; Show everything
use-package-always-demand t))
(with-eval-after-load "bind-key"
(bind-key "C-c d k" #'describe-personal-keybindings))
;; Check "use-package-keywords.org" for a suggested order of `use-package'
;; keywords.
(use-package diminish
:demand t)
(use-package no-littering
:demand t
:custom
(auto-save-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))
(custom-file (no-littering-expand-var-file-name "custom.el")))
(use-package exec-path-from-shell
:when (symbol-value 'sb/IS-LINUX)
:init
(setq
exec-path-from-shell-check-startup-files nil
exec-path-from-shell-variables
'("PATH"
"JAVA_HOME"
"TERM"
"PYTHONPATH"
"LANG"
"LC_CTYPE"
"XAUTHORITY"
"LSP_USE_PLISTS")
exec-path-from-shell-arguments nil)
(exec-path-from-shell-initialize))
(use-package emacs
:hook ((emacs-startup . garbage-collect) (emacs-startup . save-place-mode))
:custom
(ad-redefinition-action 'accept "Turn off warnings due to redefinitions")
(auto-save-no-message t "Do not print frequent autosave messages")
;; Disable autosaving based on number of characters typed
(auto-save-interval 0)
;; Save bookmark after every bookmark edit and also when Emacs is killed
(bookmark-save-flag 1)
;; Autofill comments in modes that define them
(comment-auto-fill-only-comments t)
(create-lockfiles nil)
(custom-safe-themes t)
(delete-by-moving-to-trash t)
(fast-but-imprecise-scrolling t)
(help-window-select t "Makes it easy to close the window")
(history-delete-duplicates t)
(read-process-output-max (* 4 1024 1024))
(remote-file-name-inhibit-locks t)
(ring-bell-function 'ignore "Disable beeping sound")
(save-interprogram-paste-before-kill t)
(select-enable-clipboard t)
(sentence-end-double-space nil)
(shift-select-mode nil)
(sort-fold-case nil "Do not ignore case when sorting")
(standard-indent 2)
(switch-to-buffer-preserve-window-point t)
(use-dialog-box nil "Do not use dialog boxes with mouse commands")
(use-file-dialog nil)
(view-read-only t "View mode for read-only buffers")
(visible-bell nil)
(warning-minimum-level :error)
(window-combination-resize t "Resize windows proportionally")
(x-gtk-use-system-tooltips nil "Do not use system tooltips")
;; Always trigger an immediate resize of the child frame
(x-gtk-resize-child-frames 'resize-mode)
(x-underline-at-descent-line t)
;; Ignore case when reading a buffer name
(read-buffer-completion-ignore-case t)
(kill-do-not-save-duplicates t "Do not save duplicates to kill ring")
(tags-add-tables nil)
(tags-case-fold-search nil "case-sensitive")
(tags-revert-without-query t)
;; Disable the warning "X and Y are the same file" in case of symlinks
(find-file-suppress-same-file-warnings t)
(auto-mode-case-fold nil "Avoid a second pass through `auto-mode-alist'")
(backup-inhibited t "Disable backup for a per-file basis")
(confirm-nonexistent-file-or-buffer t)
(confirm-kill-emacs nil)
;; Prevent 'Active processes exist' when you quit Emacs
(confirm-kill-processes nil)
(make-backup-files nil "Stop making backup `~' files")
(require-final-newline t "Always end a file with a newline")
;; Unlike `auto-save-mode', `auto-save-visited-mode' saves the buffer contents
;; to the visiting file and runs all save-related hooks. We disable
;; `auto-save-mode' and prefer `auto-save-visited-mode' instead.
(auto-save-default nil)
;; Save buffer to file after idling for some time, the default of 5s may be
;; too frequent since it runs all the save-related hooks.
(auto-save-visited-interval 30)
(revert-without-query '("\\.*") "Revert all files without asking")
(max-mini-window-height 0.4)
(pixel-scroll-precision-use-momentum nil)
(scroll-preserve-screen-position t)
(scroll-margin 3)
;; Scroll the window by 1 line whenever the cursor moves off the visible screen
(scroll-step 1)
(scroll-conservatively 10000)
(bidi-inhibit-bpa nil) ; Disabling BPA makes redisplay faster
(auto-window-vscroll nil)
:config
(dolist (exts
'(".directory"
".dll"
".exe"
".fdb_latexmk"
".fls"
".lof"
".nav"
".pyc"
".rel"
".rip"
".snm"
".synctex.gz"
".toc"
".vrb"
"TAGS"
"indent.log"))
(add-to-list 'completion-ignored-extensions exts))
(when sb/EMACS28+
(setq
next-error-message-highlight t
read-minibuffer-restore-windows t
;; Hide commands in "M-x" which do not work in the current mode.
read-extended-command-predicate #'command-completion-default-include-p
use-short-answers t))
(when sb/EMACS29+
(setq
help-window-keep-selected t
find-sibling-rules
'(("\\([^/]+\\)\\.c\\'" "\\1.h")
("\\([^/]+\\)\\.cpp\\'" "\\1.h")
("\\([^/]+\\)\\.h\\'" "\\1.c")
("\\([^/]+\\)\\.hpp\\'" "\\1.cpp"))))
(when sb/IS-WINDOWS
(setq w32-get-true-file-attributes nil))
(tooltip-mode -1)
(auto-encryption-mode -1)
(dolist
(mode
'(
;; Auto-save file-visiting buffers at idle time intervals
auto-save-visited-mode
column-number-mode size-indication-mode
;; Typing with the mark active will overwrite the marked region
delete-selection-mode
;; Use soft wraps, wrap lines without the ugly continuation marks
global-visual-line-mode
;; When you call `find-file', you do not need to clear the existing
;; file path before adding the new one. Just start typing the whole
;; path and Emacs will "shadow" the current one. For example, you are
;; at "~/Documents/notes/file.txt" and you want to go to
;; "~/.emacs.d/init.el", type the latter directly and Emacs will take
;; you there.
file-name-shadow-mode pixel-scroll-precision-mode))
(when (fboundp mode)
(funcall mode 1)))
;; Changing buffer-local variables will only affect a single buffer.
;; `setq-default' changes the buffer-local variable's default value.
(setq-default
cursor-in-non-selected-windows nil ; Hide the cursor in inactive windows
fill-column sb/fill-column
indent-tabs-mode nil ; Spaces instead of tabs
tab-width 4
;; TAB first tries to indent the current line, and if the line was already
;; indented, then try to complete the thing at point.
tab-always-indent 'complete
bidi-display-reordering 'left-to-right
bidi-paragraph-direction 'left-to-right)
;; Not a library/file, so `eval-after-load' does not work
(diminish 'auto-fill-function)
(advice-add 'risky-local-variable-p :override #'ignore)
;; Hide "When done with a buffer, type C-x 5" message
(when (bound-and-true-p server-client-instructions)
(setq server-client-instructions nil))
(when (file-exists-p custom-file)
(load custom-file 'noerror 'nomessage))
;; Mark safe variables
(put 'compilation-read-command 'safe-local-variable #'stringp)
(put 'reftex-default-bibliography 'safe-local-variable #'stringp)
:diminish visual-line-mode)
(use-package autorevert
:straight (:type built-in)
:hook (emacs-startup . global-auto-revert-mode)
:custom
(auto-revert-verbose nil)
(auto-revert-remote-files t)
;; Revert `dired' buffers if the directory contents changes
(global-auto-revert-non-file-buffers t)
:diminish auto-revert-mode)
(use-package savehist
:straight (:type built-in)
:hook (emacs-startup . savehist-mode)
:custom
(savehist-additional-variables
'(savehist-minibuffer-history-variables
bookmark-history
command-history
compile-command
compile-history
extended-command-history
file-name-history
kill-ring
mark-ring
minibuffer-history
search-ring
regexp-search-ring)))
(use-package abbrev
:straight (:type built-in)
:hook (emacs-startup . abbrev-mode)
:custom
(abbrev-file-name (expand-file-name "abbrev-defs" sb/extras-directory))
(save-abbrevs 'silently)
:diminish)
;; This puts the buffer in read-only mode and disables font locking, revert with
;; "C-c C-c".
(use-package so-long
:straight (:type built-in)
:when sb/EMACS28+
:hook (emacs-startup . global-so-long-mode))
(use-package imenu
:straight (:type built-in)
:after (:any makefile-mode markdown-mode org-mode yaml-mode yaml-ts-mode prog-mode)
:custom
(imenu-auto-rescan t)
(imenu-max-items 1000)
(imenu-use-popup-menu nil))
(use-package recentf
:straight (:type built-in)
:hook (emacs-startup . recentf-mode)
:bind ("<f9>" . recentf-open-files)
:custom
(recentf-auto-cleanup 30 "Cleanup after idling for 30s")
(recentf-exclude
'("[/\\]elpa/"
"[/\\]\\.git/"
".*\\.gz\\'"
".*\\.xz\\'"
".*\\.zip\\'"
".*-autoloads.el\\'"
"[/\\]archive-contents\\'"
"[/\\]\\.loaddefs\\.el\\'"
"[/\\]tmp/.*"
".*/recentf\\'"
".*/recentf-save.el\\'"
"~$"
".*/TAGS\\'"
"*.cache"
"*[/\\]straight/repos/"))
;; Keep remote file without testing if they still exist
(recentf-keep '(file-remote-p file-readable-p))
;; Larger values help in lookup but takes more time to check if the files exist
(recentf-max-saved-items 250)
:config
;; Abbreviate the home directory to make it easy to read the actual file name.
(unless sb/EMACS28+
(setq recentf-filename-handlers '(abbreviate-file-name)))
(dolist (exclude
`(,(recentf-expand-file-name no-littering-etc-directory)
,(recentf-expand-file-name no-littering-var-directory)
,(recentf-expand-file-name (straight--emacs-dir "straight"))))
(add-to-list 'recentf-exclude exclude))
;; `recentf-save-list' is called on Emacs exit. In addition, save the recent
;; list periodically after idling for a few seconds.
(run-with-idle-timer 30 t #'recentf-save-list))
(progn
(defun sb/inhibit-message-call-orig-fun (orig-fun &rest args)
"Hide messages appearing in ORIG-FUN, forward ARGS."
(let ((inhibit-message t))
(apply orig-fun args)))
;; Hide the "Wrote to recentf" message
(advice-add 'recentf-save-list :around #'sb/inhibit-message-call-orig-fun)
;; Hide the "Cleaning up the recentf list...done" message
(advice-add 'recentf-cleanup :around #'sb/inhibit-message-call-orig-fun)
;; Hide the "Wrote ..." message
(advice-add 'write-region :around #'sb/inhibit-message-call-orig-fun))
(progn
(defun sb/auto-save-wrapper (save-fn &rest args)
"Hide 'Auto-saving...done' messages by calling the method.
SAVE-FN with non-nil ARGS."
(ignore args)
(apply save-fn '(t)))
(advice-add 'do-auto-save :around #'sb/auto-save-wrapper))
;; Use "Shift + direction" arrows for moving around windows.
(use-package windmove
:straight (:type built-in)
:when (display-graphic-p)
:init (windmove-default-keybindings))
(use-package doc-view
:straight (:type built-in)
:hook
(doc-view-mode
.
(lambda ()
(when (and buffer-file-name (string-suffix-p ".pdf" buffer-file-name))
(auto-revert-mode 1))))
:bind
(:map
doc-view-mode-map
("=" . doc-view-enlarge)
("-" . doc-view-shrink)
("n" . doc-view-next-page)
("p" . doc-view-previous-page)
("0" . doc-view-scale-reset)
("M-<" . doc-view-first-page)
("M->" . doc-view-last-page)
("C-l" . doc-view-goto-page))
:custom
(doc-view-continuous t)
(doc-view-resolution 120))
(use-package ffap
:straight (:type built-in)
:bind ("<f2>" . ffap)
:custom
;; Do not ping things that look like domain names
(ffap-machine-p-known 'reject))
;; Highlight and allow to open http links in strings and comments in buffers.
(use-package goto-addr
:straight (:type built-in)
:hook ((prog-mode . goto-address-prog-mode) (text-mode . goto-address-mode))
:bind ("C-c RET" . goto-address-at-point))
(use-package ediff
:straight (:type built-in)
:hook (ediff-cleanup . (lambda () (ediff-janitor nil nil)))
:custom
;; Put the control panel in the same frame as the diff windows
(ediff-window-setup-function #'ediff-setup-windows-plain)
;; Split diffs side by side
(ediff-split-window-function #'split-window-horizontally)
;; Prompt and kill file variants on quitting an Ediff session
(ediff-keep-variants nil)
:config (ediff-set-diff-options 'ediff-diff-options "-w"))
;; To edit remote files, use "/method:user@host#port:filename".
;; The shortcut "/ssh::" will connect to default "user@host#port".
;; To edit a local file with sudo, use "C-x C-f /sudo::/etc/hosts".
;; To open a remote file with ssh + sudo, use "C-x C-f /ssh:host|sudo:root:/etc/passwd".
;; Multihop syntax: "C-x C-f /ssh:bird@bastion|ssh:you@remotehost:/path"
;; Multihop with sudo: "C-x C-f /ssh:you@remotehost|sudo:remotehost:/path/to/file"
;; Multihop with sudo with custom user: "C-x C-f /ssh:you@remotehost|sudo:them@remotehost:/path/to/file"
;; Sudo over ssh: "emacs -nw /ssh:[email protected]\|sudo:172.16.42.1:/etc/hosts"
;; Connect as non-root user and then use sudo: "C-x C-f /ssh:192.168.249.10|su::/some/file"
(use-package tramp
:straight (:type built-in)
:bind ("C-S-q" . tramp-cleanup-all-buffers)
:custom
;; Remote files are not updated outside of Tramp
(remote-file-name-inhibit-cache nil)
(tramp-verbose 1 "Only errors and warnings")
:config
;; Disable backup
(add-to-list 'backup-directory-alist (cons tramp-file-name-regexp nil))
;; Include this directory in $PATH on remote
(add-to-list
'tramp-remote-path (expand-file-name ".local/bin" (getenv "HOME")))
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
(setenv "SHELL" shell-file-name) ; Recommended to connect with Bash
(setq debug-ignored-errors (cons 'remote-file-error debug-ignored-errors)))
(use-package whitespace
:straight (:type built-in)
:custom (whitespace-line-column sb/fill-column)
:diminish (global-whitespace-mode whitespace-mode whitespace-newline-mode))
(use-package ibuffer
:straight (:type built-in)
:hook (ibuffer . ibuffer-auto-mode)
:bind
(("C-x C-b" . ibuffer-jump)
:map
ibuffer-mode-map
("`" . ibuffer-switch-format))
:custom
(ibuffer-display-summary nil)
(ibuffer-default-sorting-mode 'alphabetic)
(ibuffer-show-empty-filter-groups nil)
(ibuffer-formats
'((mark modified read-only " " (name 24 24 :left :elide) " " filename)))
(ibuffer-never-show-predicates
'("*Messages\\*"
"*Help\\*"
"*Quick Help\\*"
"*Warnings\\*"
"*Calc Trail\\*"
"*Compile-Log\\*"
"*Async-native-compile-log\\*"
"*Native-compile-log\\*"
"*Calculator\\*"
"*Calendar\\*"
"*Warning\\*"
"magit:.*"
"*Org Help\\*"
"*ltex-ls.*"
"*grammarly-ls.*"
"*bash-ls.*"))
:config (require 'ibuf-ext)
;; (add-to-list 'ibuffer-never-show-predicates "^\\*")
(defalias 'list-buffers 'ibuffer))
;; By default buffers are grouped by `project-current' or by `default-directory'.
(use-package ibuffer-project
:hook
(ibuffer
.
(lambda ()
(setq ibuffer-filter-groups (ibuffer-project-generate-filter-groups))
(unless (eq ibuffer-sorting-mode 'project-file-relative)
(ibuffer-do-sort-by-project-file-relative))))
:custom (ibuffer-project-use-cache t)
:config
;; Remote buffers will be grouped by protocol and host
(add-to-list 'ibuffer-project-root-functions '(file-remote-p . "Remote")))
(use-package immortal-scratch
:hook (emacs-startup . immortal-scratch-mode))
(use-package persistent-scratch
:hook
(emacs-startup
.
(lambda ()
(ignore-errors
(persistent-scratch-setup-default))))
:config
(advice-add
'persistent-scratch-setup-default
:around #'sb/inhibit-message-call-orig-fun))
(use-package window
:straight (:type built-in)
:custom
(display-buffer-alist
'(
;; Allow *Help* buffers to use the full frame
("*Help*" (display-buffer-same-window))
("\\`\\*\\(Warnings\\|Compile-Log\\)\\*\\'"
(display-buffer-no-window)
(allow-no-window . t)))))
(use-package popwin
:hook (emacs-startup . popwin-mode)
:config
(push '(helpful-mode :noselect t :position bottom :height 0.5)
popwin:special-display-config))
(use-package avy
:bind
(("C-\\" . avy-goto-word-1)
("C-'" . avy-goto-char-timer)
("C-/" . avy-goto-line)
("C-M-c" . avy-copy-line)
("C-M-m" . avy-move-line)
:map isearch-mode-map
;; Use "C-'" in `isearch-mode-map' to use `avy-isearch' to select one of the
;; many currently visible `isearch' candidates.
("C-'" . avy-isearch)))
(use-package ace-window
:bind (([remap other-window] . ace-window) ("M-o" . ace-window))
:custom (aw-minibuffer-flag t)
:config (ace-window-display-mode 1))
(use-package ace-jump-buffer
:bind ("C-b" . ace-jump-buffer)
:custom (ajb-bs-configuration "files-and-scratch"))
(use-package dired
:preface
(defun sb/dired-go-home ()
(interactive)
(dired sb/user-home-directory))
(defun sb/dired-jump-to-top ()
(interactive)
(goto-char (point-min)) ; Faster than `(beginning-of-buffer)'
(dired-next-line 1))
(defun sb/dired-jump-to-bottom ()
(interactive)
(goto-char (point-max)) ; Faster than `(end-of-buffer)'
(dired-next-line -1))
:straight (:type built-in)
:commands dired
:hook
((dired-mode . auto-revert-mode) ; Auto refresh `dired' when files change
(dired-mode . dired-hide-details-mode) (dired-mode . hl-line-mode))
:bind
(:map
dired-mode-map
("M-<home>" . sb/dired-go-home)
("M-<up>" . sb/dired-jump-to-top)
("M-<down>" . sb/dired-jump-to-bottom)
("i" . find-file)
("_" . dired-create-empty-file))
:custom
;; When there are two `dired' buffer windows in the same frame, Emacs will
;; select the other buffer as the target directory (e.g., for copying or
;; renaming files).
(dired-dwim-target t)
(dired-auto-revert-buffer t)
;; "A" is to avoid listing "." and "..", "B" is to avoid listing backup
;; entries ending with "~", "F" appends indicator to entries, "g" omits the
;; owner, "h" is to print human-readable sizes, "N" prints entry names without
;; quoting, "si" is to use powers of 1000 not 1024, "o" does not print group
;; information, "p" is to append "/" indicator to directories, "v" uses
;; natural sort of (version) numbers within text. Check "ls" for additional
;; options.
(dired-listing-switches
"-aBFghlNopv --group-directories-first --time-style=locale")
(dired-ls-F-marks-symlinks t "-F marks links with @")
(dired-recursive-copies 'always "Single prompt for all n directories")
(dired-recursive-deletes 'always "Single prompt for all n directories")
;; Do not ask whether to kill buffers visiting deleted files
(dired-clean-confirm-killing-deleted-buffers nil)
(dired-hide-details-hide-symlink-targets nil)
:config
(when (boundp 'dired-kill-when-opening-new-dired-buffer)
(setq dired-kill-when-opening-new-dired-buffer t)))
(use-package dired-x
:straight (:type built-in)
:hook
(dired-mode
.
(lambda ()
(require 'dired-x)
(dired-omit-mode)))
:bind ("C-x C-j" . dired-jump)
:custom (dired-omit-verbose nil "Do not show messages when omitting files")
;; Do not ask whether to kill buffers visiting deleted files
(dired-clean-confirm-killing-deleted-buffers nil)
:config
;; Obsolete from Emacs 28+
(unless sb/EMACS28+
(setq dired-bind-jump t))
(setq dired-omit-files
(concat
dired-omit-files
"\\|^\\..*$" ; Hide all dotfiles
"\\|^.DS_Store\\'"
"\\|^.project\\(?:ile\\)?\\'"
"\\|^.\\(svn\\|git\\)\\'"
"\\|^.cache\\'"
"\\|^.ccls-cache\\'"
"\\|^__pycache__\\'"
"\\|^eln-cache\\'"
"\\|\\(?:\\.js\\)?\\.meta\\'"
"\\|\\.\\(?:elc\\|o\\|pyo\\|swp\\|class\\)\\'"))
;; https://github.com/pdcawley/dotemacs/blob/master/initscripts/dired-setup.el
(defadvice dired-omit-startup (after diminish-dired-omit activate)
"Remove 'Omit' from the modeline."
(diminish 'dired-omit-mode)
dired-mode-map))
(use-package dired-narrow
:after dired
:bind (:map dired-mode-map ("/" . dired-narrow)))
(use-package dired-hist
:straight (:host github :repo "karthink/dired-hist")
:hook (dired-mode . dired-hist-mode)
:bind
(:map
dired-mode-map ("l" . dired-hist-go-back) ("r" . dired-hist-go-forward)))
;; In Emacs Lisp mode, `xref-find-definitions' will by default find only
;; functions and variables from Lisp packages which are loaded into the current
;; Emacs session or are auto-loaded.
(use-package xref
:bind
(("M-." . xref-find-definitions)
("M-?" . xref-find-references)
;; Find all identifiers whose name matches pattern
("C-M-." . xref-find-apropos) ("M-," . xref-go-back))
:custom (xref-search-program 'ripgrep))
(use-package project
:bind
(("<f5>" . project-switch-project)
("<f6>" . project-find-file)
:map
project-prefix-map
("f" . project-or-external-find-file)
("b" . project-switch-to-buffer)
("d" . project-dired)
("v" . project-vc-dir)
("c" . project-compile)
("k" . project-kill-buffers)
("g" . project-find-regexp)
("r" . project-query-replace-regexp))
:custom
;; Start `project-find-file' by default
(project-switch-commands 'project-find-file))
(use-package project-x
:straight (:host github :repo "karthink/project-x")
:after project
:demand t
:config (project-x-mode 1))
(use-package vertico
:straight
(vertico
:files (:defaults "extensions/*")
:includes (vertico-directory vertico-repeat vertico-quick))
:hook
((emacs-startup . vertico-mode)
;; Tidy shadowed file names. That is, when using a command for selecting a
;; file in the minibuffer, the following fixes the path so the selected path
;; does not have prepended junk left behind. This works with
;; `file-name-shadow-mode' enabled. When you are in a sub-directory and use,
;; say, `find-file' to go to your home '~/' or root '/' directory, Vertico
;; will clear the old path to keep only your current input.
(rfn-eshadow-update-overlay . vertico-directory-tidy)
(minibuffer-setup . vertico-repeat-save))
:bind
(("C-c r" . vertico-repeat)
("M-r" . vertico-repeat-select)
:map
vertico-map
("M-<" . vertico-first)
("M->" . vertico-last)
("C-M-j" . vertico-exit-input)
("RET" . vertico-directory-enter)
("DEL" . vertico-directory-delete-char)
("M-DEL" . vertico-directory-delete-word)
("C-c q" . vertico-quick-insert)
("C-'" . vertico-quick-jump))
:custom (vertico-cycle t)
:config
(with-eval-after-load "savehist"
(add-to-list 'savehist-additional-variables 'vertico-repeat-history)))
(use-package consult
:after vertico
:commands consult-fd
:bind
( ;; Press "SPC" to show ephemeral buffers, "b SPC" to filter by buffers, "f
;; SPC" to filter by files, "p SPC" to filter by projects. If you press "DEL"
;; afterwards, the full candidate list will be shown again.
([remap switch-to-buffer] . consult-buffer)
("<f3>" . consult-buffer)
([remap project-switch-to-buffer] . consult-project-buffer)
([remap yank-pop] . consult-yank-from-kill-ring)
([remap goto-line] . consult-goto-line)
([remap bookmark-jump] . consult-bookmark)
([remap bookmark-set] . consult-bookmark)
([remap list-bookmarks] . consult-bookmark)
([remap bookmark-bmenu-list] . consult-bookmark)
("M-g o" . consult-outline)
("C-c C-m" . consult-mark)
([remap imenu] . consult-imenu) ; "M-g i"
("C-c C-j" . consult-imenu)
([remap customize] . consult-customize)
([remap load-theme] . consult-theme)
("C-c s f" . consult-find)
([remap locate] . consult-locate)
("C-c s l" . consult-locate)
;; Prefix argument "C-u" allows to specify the directory. You can pass
;; additional grep flags to `consult-grep' with the "--" separator. E.g.:
;; "foo bar -- -A3" to get matches with 3 lines of 'after' context.
([remap rgrep] . consult-grep)
("C-c s g" . consult-grep)
([remap vc-git-grep] . consult-git-grep)
("C-c s G" . consult-git-grep)
;; Filter by file extension with `consult-ripgrep' "... -- -g *.jsx"
("C-c s r" . consult-ripgrep)
("C-c s h" . consult-isearch-history)
("<f4>" . consult-line)
([remap multi-occur] . consult-multi-occur)
("M-s m" . consult-multi-occur)
([remap recentf-open-files] . consult-recent-file)
("M-g r" . consult-register)
:map
isearch-mode-map
("M-s e" . consult-isearch-history))
:custom
(consult-line-start-from-top t "Start search from the beginning")
(xref-show-xrefs-function #'consult-xref)
(xref-show-definitions-function #'consult-xref)
;; Disable preview by default, enable for selected commands
(consult-preview-key nil)
(completion-in-region-function #'consult-completion-in-region "Complete M-:")
;; Having multiple other sources like `recentf' makes it difficult to identify
;; and switch quickly between only buffers, especially while wrapping around.
(consult-buffer-sources '(consult--source-buffer))
(consult-narrow-key "<")
:config
(consult-customize
consult-line
consult-ripgrep
consult-git-grep
consult-grep
consult-recent-file
consult-bookmark
consult-xref
consult-yank-from-kill-ring
:preview-key
'(:debounce 1.5 any)
consult-theme
consult-buffer
:preview-key
"M-."
consult-find
:sort
t
consult-line
consult-ripgrep
consult-grep
;; Initialize search string with the highlighted region
:initial
(when (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end)))))
(use-package embark
:bind
( ;; "C-h b" lists all the bindings available in a buffer
([remap describe-bindings] . embark-bindings)
("C-`" . embark-act)
("C-;" . embark-dwim)
:map
minibuffer-local-map
("C-`" . embark-act)
("C-c C-c" . embark-collect)
("C-c C-e" . embark-export)
:map
minibuffer-local-completion-map
("C-`" . embark-act))
:custom
;; Replace the key help with a completing-read interface
(prefix-help-command #'embark-prefix-help-command)
:config
(with-eval-after-load "vertico"
(bind-keys
:map
vertico-map
("C-`" . embark-act)
("c-;" . embark-dwim)
("C-c C-e" . embark-export))))
;; Supports exporting search results to a `grep-mode' buffer, on which you can
;; use `wgrep'.
(use-package embark-consult
:after (embark consult)
:hook (embark-collect-mode . consult-preview-at-point-mode))
;; Rich annotations in the minibuffer, e.g., documentation strings or file
;; information.
(use-package marginalia
:after vertico
:init (marginalia-mode 1)
:bind (:map minibuffer-local-map ("M-A" . marginalia-cycle))
:config
(setq marginalia-annotator-registry
(assq-delete-all 'file marginalia-annotator-registry))
(add-to-list
'marginalia-annotator-registry '(symbol-help marginalia-annotate-variable))
(add-to-list
'marginalia-annotator-registry
'(project-buffer marginalia-annotate-project-buffer)))
(use-package consult-tramp
:straight (:host github :repo "Ladicle/consult-tramp")
:bind ("C-c d t" . consult-tramp))
(use-package consult-flycheck
:after (consult flycheck)
:bind (:map flycheck-command-map ("!" . consult-flycheck)))
(use-package consult-yasnippet
:bind ("C-M-y" . consult-yasnippet))
(use-package ispell
:straight (:type built-in)
:bind ("M-$" . ispell-word)
:custom
(ispell-dictionary "en_US")
(ispell-local-dictionary "en_US")
(ispell-personal-dictionary (expand-file-name "spell" sb/extras-directory))
(ispell-alternate-dictionary
(expand-file-name "wordlist.5" sb/extras-directory))
;; Save a new word to personal dictionary without asking
(ispell-silently-savep t)
:config
(cond
((executable-find "hunspell")
(progn
(setenv "LANG" "en_US")
(setenv "DICTIONARY" "en_US")
(setenv "DICPATH" `,(concat user-emacs-directory "hunspell"))
(setq
ispell-program-name "hunspell"
ispell-local-dictionary-alist
'(("en_US"
"[[:alpha:]]"
"[^[:alpha:]]"
"[']"
nil
("-d" "en_US")
nil
utf-8))
ispell-hunspell-dictionary-alist ispell-local-dictionary-alist
ispell-hunspell-dict-paths-alist `(("en_US" ,(concat user-emacs-directory "hunspell/en_US.aff"))))))
((executable-find "aspell")
(progn
(setq
ispell-program-name "aspell"
ispell-extra-args '("--sug-mode=ultra" "--lang=en_US" "--run-together" "--size=90")))))
;; Skip regions in `org-mode'
(add-to-list 'ispell-skip-region-alist '("^#\\+BEGIN_SRC" . "^#\\+END_SRC"))
(add-to-list
'ispell-skip-region-alist '("^#\\+BEGIN_EXAMPLE" . "^#\\+END_EXAMPLE"))
(add-to-list 'ispell-skip-region-alist '("~" "~"))
(add-to-list 'ispell-skip-region-alist '("=" "="))
(add-to-list 'ispell-skip-region-alist '("\:PROPERTIES\:$" . "\:END\:$"))
;; Footnotes in org that have http links that are line breaked should not be
;; ispelled
(add-to-list 'ispell-skip-region-alist '("^http" . "\\]"))
(add-to-list 'ispell-skip-region-alist '("`" "`"))
(add-to-list 'ispell-skip-region-alist '("cite:" . "[[:space:]]"))
(add-to-list 'ispell-skip-region-alist '("label:" . "[[:space:]]"))
(add-to-list 'ispell-skip-region-alist '("ref:" . "[[:space:]]"))
(add-to-list
'ispell-skip-region-alist '("\\\\begin{multline}" . "\\\\end{multline}"))
(add-to-list
'ispell-skip-region-alist '("\\\\begin{equation}" . "\\\\end{equation}"))
(add-to-list
'ispell-skip-region-alist '("\\\\begin{align}" . "\\\\end{align}"))
;; Hide the "Starting new Ispell process" message
(advice-add 'ispell-init-process :around #'sb/inhibit-message-call-orig-fun)
(advice-add 'ispell-lookup-words :around #'sb/inhibit-message-call-orig-fun))
;; Silence "Starting 'look' process..." message
(advice-add 'lookup-words :around #'sb/inhibit-message-call-orig-fun)
;; "M-$" triggers correction for the misspelled word before point, "C-u M-$"
;; triggers correction for the entire buffer.
(use-package jinx
:when (symbol-value 'sb/IS-LINUX)
:hook ((text-mode conf-mode prog-mode) . jinx-mode)
:bind (([remap ispell-word] . jinx-correct) ("C-M-$" . jinx-languages))
:custom (jinx-languages "en_US")
:diminish)