This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
1644 lines (1415 loc) · 51.5 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
;;; -*- lexical-binding: t -*-
;; NOTE: init.el is now generated from Emacs.org. Please edit that file
;; in Emacs and init.el will be generated automatically!
(setq gc-cons-threshold 200000000)
(setq native-comp-async-report-warnings-errors nil)
(setq warning-minimum-level :error)
(defun me/display-startup-time ()
(message "Emacs loaded in %s with %d garbage collections."
(format "%.2f seconds"
(float-time
(time-subtract after-init-time before-init-time)))
gcs-done))
(add-hook 'emacs-startup-hook #'me/display-startup-time)
(when (fboundp 'horizontal-scroll-bar-mode)
(horizontal-scroll-bar-mode -1))
(when (fboundp 'scroll-bar-mode)
(scroll-bar-mode -1))
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
(when (fboundp 'tooltip-mode)
(tooltip-mode -1))
(when (fboundp 'menu-bar-mode)
(menu-bar-mode -1))
(when (fboundp 'set-fringe-mode)
(set-fringe-mode 10))
(set-frame-parameter (selected-frame) 'fullscreen 'maximized)
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(defconst IS-MAC (eq system-type 'darwin)
"If the host is running MacOS return true")
(defconst IS-LINUX (eq system-type 'gnu/linux)
"If the host is running Linux return true")
(defconst IS-WINDOWS (memq system-type '(cygwin windows-nt ms-dos))
"If the host is running Windows return true")
(defconst IS-BSD (or IS-MAC (eq system-type 'berkeley-unix))
"If the host is running BSD return true")
(setq straight-use-package-by-default t)
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(use-package auto-package-update
:custom
(auto-package-update-interval 7)
(auto-package-update-prompt-before-update nil)
(auto-package-update-hide-results t)
:config
(auto-package-update-maybe)
(auto-package-update-at-time "09:00"))
(use-package no-littering
:demand t
:config
(setq auto-save-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))
(setq custom-file (no-littering-expand-etc-file-name "custom.el")))
(use-package general
:demand t
:config
(progn
(general-evil-setup t)
(general-auto-unbind-keys)
(general-create-definer leader-map
:keymaps 'override
:states '(insert emacs normal hybrid motion visual operator)
:global-prefix "C-c"
:non-normal-prefix "M-SPC"
:prefix "SPC")
(general-create-definer local-leader-map
:keymaps 'override
:states '(insert emacs normal hybrid motion visual operator)
:global-prefix "C-c m"
:non-normal-prefix "M-SPC m"
:prefix "SPC m")))
(use-package emacs
:demand t
:straight nil
:preface
;; Fonts and Text ;;
(defvar me/default-font-size 160)
(defvar me/default-variable-font-size 160)
(defun me/reset-text-size ()
(interactive)
(text-scale-set 0))
;; Transparency ;;
(defvar me/frame-transparency '(95 . 95))
;; Buffers ;;
(defun me/alternate-buffer ()
"Go to previous buffer"
(interactive)
(switch-to-buffer (other-buffer)))
(defun me/set-default-line-length-to (line-length)
"Set the default line length to LINE-LENGTH."
(setq-default fill-column line-length))
;; Saving ;;
(defun me/save-all-unsaved ()
"Save all unsaved files. no ask."
(interactive)
(save-some-buffers t))
;; Utility ;;
(defun me/create-dir-if-not-exists ()
"Offer to create directory when it doesn't exist"
(when buffer-file-name
(let ((dir (file-name-directory buffer-file-name)))
(when (and (not (file-exists-p dir))
(y-or-n-p (format "Directory %s does not exist. Create it?" dir)))
(make-directory dir t)))))
(defun me/open-config ()
"Open configuration file"
(interactive)
(find-file (expand-file-name (concat user-emacs-directory "README.org"))))
(defun me/reload-emacs-config ()
(interactive)
(load-file (expand-file-name (concat user-emacs-directory "init.el"))))
;; Scrolling
(defun me/scroll-half-page (direction)
"Scrolls half page up if `direction' is non-nil, otherwise will scroll half page down."
(let ((opos (cdr (nth 6 (posn-at-point)))))
;; opos = original position line relative to window
(move-to-window-line nil) ;; Move cursor to middle line
(if direction
(recenter-top-bottom -1) ;; Current line becomes last
(recenter-top-bottom 0)) ;; Current line becomes first
(move-to-window-line opos))) ;; Restore cursor/point position
(defun me/scroll-half-page-down ()
"Scrolls exactly half page down keeping cursor/point position."
(interactive)
(me/scroll-half-page nil))
(defun me/scroll-half-page-up ()
"Scrolls exactly half page up keeping cursor/point position."
(interactive)
(me/scroll-half-page t))
(defun me/buffer-to-side-window ()
"Place the current buffer in the side window at the bottom."
(interactive)
(let ((buf (current-buffer)))
(display-buffer-in-side-window
buf '((window-height . 0.25)
(side . bottom)
(slot . -1)
(window-parameters . (no-delete-other-windows . t))))
(delete-window)))
(defun me/quit-window-force ()
(interactive)
(quit-window t))
:config
(progn
;; Startup ;;
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)
;; Bells and Ringers ;;
(setq visible-bell nil)
(setq ring-bell-function 'ignore)
;; History and persistence ;;
(require 'recentf)
(add-to-list 'recentf-exclude no-littering-var-directory)
(add-to-list 'recentf-exclude no-littering-etc-directory)
(setq recentf-max-menu-items 40)
(setq recentf-max-saved-items 250)
(setq save-interprogram-paste-before-kill t)
(setq initial-buffer-choice nil)
;; (require 'desktop)
;; (customize-set-variable 'desktop-save 't)
;; (desktop-save-mode 1)
(recentf-mode 1)
(with-eval-after-load 'no-littering
(add-to-list 'recentf-exclude no-littering-etc-directory)
(add-to-list 'recentf-exclude no-littering-var-directory))
(save-place-mode 1)
(winner-mode 1)
(global-auto-revert-mode t)
;; Completion ;;
(setq read-file-name-completion-ignore-case t
read-buffer-completion-ignore-case t
completion-ignore-case t
completion-cycle-threshold 2
tab-always-indent t
tab-width 4)
(setq-default indent-tabs-mode nil)
(electric-pair-mode t)
;; Use `consult-completion-in-region' if Vertico is enabled.
;; Otherwise use the default `completion--in-region' function.
;; (setq completion-in-region-function
;; (lambda (&rest args)
;; (apply (if vertico-mode
;; #'consult-completion-in-region
;; #'completion--in-region)
;; args)))
;; Emacs 28: Hide commands in M-x which do not work in the current mode.
;; Vertico commands are hidden in normal buffers.
(setq read-extended-command-predicate
#'command-completion-default-include-p)
;; Minibuffer ;;
;; Do not allow the cursor in the minibuffer prompt
(setq minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
(general-def minibuffer-local-map
"C-S-p" 'yank)
;; Enable recursive minibuffers
(setq enable-recursive-minibuffers t)
;; File Encoding ;;
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(set-file-name-coding-system 'utf-8)
(set-clipboard-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)
;; Fonts ;;
(cond (IS-MAC (setq me/default-font-size 200) (setq me/default-variable-font-size 200))
(IS-WINDOWS (setq me/default-font-size 90) (setq me/default-variable-font-size 90)))
(set-face-attribute 'default nil :font "MonoLisa Custom" :height me/default-font-size)
(set-face-attribute 'fixed-pitch nil :font "MonoLisa Custom" :height me/default-font-size)
(set-face-attribute 'variable-pitch nil :font "Cantarell" :height me/default-variable-font-size :weight 'regular)
(global-font-lock-mode t)
;; Transparency ;;
(set-frame-parameter (selected-frame) 'alpha me/frame-transparency)
(add-to-list 'default-frame-alist `(alpha . ,me/frame-transparency))
;; Loading ;;
(setq load-prefer-newer t)
;; Saving ;;
;; Auto save
(setq after-focus-change-function 'me/save-all-unsaved)
(add-hook 'focus-out-hook 'me/save-all-unsaved)
;; Remove whitespace on save
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Make file executable if it's a script on save
(add-hook 'after-save-hook
'executable-make-buffer-file-executable-if-script-p)
;; Create directory if it doesn't exist
(add-hook 'before-save-hook 'me/create-dir-if-not-exists)
;; Version Control ;;
(setq vc-follow-symlinks t)
;; Directories ;;
(setq default-directory "~/")
;; Prog Mode ;;
(add-hook 'prog-mode-hook 'subword-mode)
;; Formatting ;;
(setq sentence-end-double-space nil)
;; (me/set-default-line-length-to 80)
;; Behavior ;;
(setq require-final-newline t)
(setq show-paren-delay 0.0)
(global-set-key [remap quit-window] #'me/quit-window-force)
;; Confirmations
(setq confirm-kill-emacs 'y-or-n-p)
(fset 'yes-or-no-p 'y-or-n-p)
;; Modes
(transient-mark-mode 1)
(delete-selection-mode 1)
(show-paren-mode 1)
(column-number-mode 0)
;; Line Numbers
;; Disable line numbers for some modes
(dolist (mode '(org-mode-hook
term-mode-hook
shell-mode-hook
treemacs-mode-hook
eshell-mode-hook
vterm-mode-hook
dired-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
(global-display-line-numbers-mode 1)
;; Frames
(setq ns-pop-up-frames nil)
;; Windows
;; Attempt to always use the same window size and stop resizing stuff weirdly
(customize-set-variable 'display-buffer-base-action
'((display-buffer-reuse-window display-buffer-same-window)
(reusable-frames . t)))
(customize-set-variable 'even-window-sizes nil)
(setq resize-mini-windows t)
;; Mouse
(setq mouse-yank-at-point t)
;; Apropos
(setq apropos-do-all t)
;; Tab bar ;;
;; (tab-bar-mode t)
;; (customize-set-variable 'tab-bar-new-tab-choice '"*scratch*")
;; (customize-set-variable 'tab-bar-show 't)
;; Mac OS ;;
(when IS-MAC
(setq mac-command-modifier 'control
mac-option-modifier 'meta
mac-control-modifier 'super
mac-right-command-modifier 'control
mac-right-option-modifier 'meta
ns-function-modifier 'hyper))
;; Keybindings ;;
;; Prefixes
(leader-map
"" '(nil :which-key "my lieutenant general prefix")
"b" '(:ignore t :wk "buffers")
"D" '(:ignore t :wk "debug")
"e" '(:ignore t :wk "edit")
"o" '(:ignore t :wk "org")
"f" '(:ignore t :wk "files")
"fe" '(:ignore t :wk "emacs")
"g" '(:ignore t :wk "git")
"s" '(:ignore t :wk "search")
"x" '(:ignore t :wk "execute")
"T" '(:ignore t :wk "toggles"))
(local-leader-map
"" '(nil :which-key "major mode"))
;; Sim Keys
(leader-map
"," (general-simulate-key "C-c")
"C" (general-simulate-key "C-x")
"M" (general-simulate-key "C-c C-x"))
;; Maps
(leader-map
"h" '(:keymap help-map :wk "help"))
;; Base
(leader-map
";" 'execute-extended-command
":" 'eval-expression
"O" 'other-window-prefix
"X" '((lambda () (interactive) (switch-to-buffer "*scratch*")) :wk "scratch")
"br" 'rename-buffer
"bd" 'bury-buffer
"bp" 'me/alternate-buffer
"bk" 'kill-this-buffer
"bK" 'kill-some-buffers
"B" 'ibuffer
"ea" 'align-regexp
"eA" 'align
"er" 'query-replace
"fB" 'bookmark-set
"ff" 'find-file
"fs" 'save-buffer
"fd" 'dired
"fS" 'me/save-all-unsaved
"fee" 'me/open-config
"fer" 'me/reload-emacs-config
"feq" 'save-buffers-kill-emacs
"feQ" 'kill-emacs
"xp" 'check-parens
"xe" 'eval-last-sexp
"xb" 'eval-buffer)
(leader-map "C-h" '(which-key-C-h-dispatch :wk t))
(local-leader-map "C-h" '(which-key-C-h-dispatch :wk t))
(general-def
"C-v" 'me/scroll-half-page-down
"M-v" 'me/scroll-half-page-up)
;; Remaps
(general-def with-editor-mode-map
[remap save-buffer] 'with-editor-finish)
))
(use-package ediff
:straight nil
:config
(progn
(setq ediff-diff-options "")
(setq ediff-custom-diff-options "-u")
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
(setq ediff-split-window-function 'split-window-vertically)))
(use-package smerge-mode
:straight nil
:init (setq smerge-command-prefix "")
:config
(progn
(with-eval-after-load 'hydra
(defhydra hydra/smerge
(:color pink :hint nil :post (smerge-auto-leave))
"
^Move^ ^Keep^ ^Diff^ ^Other^
^^-----------^^-------------------^^---------------------^^-------
_n_ext _b_ase _<_: upper/base _C_ombine
_p_rev _u_pper _=_: upper/lower _r_esolve
^^ _l_ower _>_: base/lower _k_ill current
^^ _a_ll _R_efine
^^ _RET_: current _E_diff
"
("n" smerge-next)
("p" smerge-prev)
("b" smerge-keep-base)
("u" smerge-keep-upper)
("l" smerge-keep-lower)
("a" smerge-keep-all)
("RET" smerge-keep-current)
("\C-m" smerge-keep-current)
("<" smerge-diff-base-upper)
("=" smerge-diff-upper-lower)
(">" smerge-diff-base-lower)
("R" smerge-refine)
("E" smerge-ediff)
("C" smerge-combine-with-next)
("r" smerge-resolve)
("k" smerge-kill-current)
("q" nil "cancel" :color blue))
(with-eval-after-load 'general
(leader-map smerge-mode-map
"gm" 'hydra/smerge/body)))))
(use-package dired
:straight nil
:commands (dired dired-jump)
:preface
:general
(general-def
"C-x C-j" 'dired-jump)
:custom ((dired-listing-switches "-agho --group-directories-first"))
:hook (dired-mode . dired-hide-details-mode)
:config
(general-def '(motion visual normal emacs) dired-mode-map
"l" 'dired-open-file
"L" 'dired-view-file
"h" 'dired-up-directory)
(setq dired-dwim-target t)
(setq dired-kill-when-opening-new-dired-buffer t)
;; MacOS ;;
(when IS-MAC
(setq dired-use-ls-dired t
insert-directory-program "/opt/homebrew/bin/gls"
dired-listing-switches "-aBhl --group-directories-first")))
(use-package dired-single
:commands (dired dired-jump))
(use-package all-the-icons-dired
:after all-the-icons
:hook (dired-mode . all-the-icons-dired-mode))
(use-package dired-open
:commands (dired dired-jump)
:config
(setq dired-open-extensions '(("png" . "feh")
("mkv" . "mpv"))))
(use-package dired-hide-dotfiles
;;:hook (dired-mode . dired-hide-dotfiles-mode)
:config
(with-eval-after-load 'evil-collection
(evil-collection-define-key 'normal 'dired-mode-map
"C-S-h" 'dired-hide-dotfiles-mode)))
(use-package doom-themes
:init
(load-theme 'doom-tokyo-night t)
:config
(progn
(setq doom-themes-enable-bold t
doom-themes-enable-italic t)
(setq doom-themes-treemacs-theme "doom-tokyo-night")
(with-eval-after-load 'treemacs
(doom-themes-treemacs-config))
(with-eval-after-load 'org
(doom-themes-org-config))))
(use-package solaire-mode
:config
(solaire-global-mode))
(use-package exec-path-from-shell
:if IS-MAC
:config
(exec-path-from-shell-initialize))
(use-package dash
:commands (global-dash-fontify-mode)
:init (global-dash-fontify-mode)
:config (dash-register-info-lookup))
(use-package s)
(use-package posframe
:demand t)
(use-package which-key
:init (which-key-mode)
:diminish which-key-mode
:after evil
:demand t
:config
(progn
(setq which-key-allow-evil-operators t)
(setq which-key-sort-order 'which-key-key-order-alpha)
(setq which-key-use-C-h-commands nil)
(setq which-key-idle-delay 0.5)))
(use-package evil
:demand t
:preface
(defun me/evil-record-macro ()
(interactive)
(if buffer-read-only
(quit-window)
(call-interactively 'evil-record-macro)))
(defun me/save-and-kill-this-buffer ()
(interactive)
(save-buffer)
(kill-this-buffer))
:init
(progn
(setq evil-want-integration t
evil-want-keybinding nil
evil-want-C-u-scroll t
evil-want-C-i-jump t
evil-respect-visual-line-mode t
evil-undo-system 'undo-tree))
:config
(progn
(evil-mode 1)
(evil-set-initial-state 'messages-buffer-mode 'normal)
(evil-set-initial-state 'dashboard-mode 'normal)
(with-eval-after-load 'general
(imap "C-n" nil
"C-p" nil)
(nmap "R" 'evil-replace-state
"q" 'me/evil-record-macro
"g ?" 'nil
"gu" 'universal-argument
"gw" 'other-window-prefix)
(imap "C-g" 'evil-normal-state
"C-u" 'universal-argument)
(vmap "gu" 'universal-argument)
(mmap "j" 'evil-next-visual-line
"k" 'evil-previous-visual-line
"L" 'evil-end-of-line-or-visual-line
"H" 'evil-first-non-blank-of-visual-line
"gu" 'universal-argument)
(setq me/window-map (cons 'keymap evil-window-map))
(general-def me/window-map
"u" 'winner-undo
"U" 'winner-redo
"f" 'other-frame)
(leader-map "w" '(:keymap me/window-map :wk "windows"))
(evil-ex-define-cmd "q" #'kill-this-buffer)
(evil-ex-define-cmd "wq" #'me/save-and-kill-this-buffer)
(imap "j"
(general-key-dispatch 'self-insert-command
:timeout 0.15
"k" 'evil-normal-state)))))
(use-package evil-collection
:after evil
:diminish evil-collection-unimpaired-mode
:config
(evil-collection-init)
(with-eval-after-load 'general
(nmap
"go" 'evil-collection-unimpaired-insert-newline-below
"gO" 'evil-collection-unimpaired-insert-newline-above
"gp" 'evil-collection-unimpaired-paste-below
"gP" 'evil-collection-unimpaired-paste-above)))
(use-package evil-org
:after org
:config
(progn
(add-hook 'org-mode-hook 'evil-org-mode)
(add-hook 'evil-org-mode-hook
(lambda () (evil-org-set-key-theme)))))
(use-package evil-commentary
:after evil
:config
(evil-commentary-mode))
(use-package evil-nerd-commenter
:after evil
:config
(evilnc-default-hotkeys nil t))
(use-package evil-matchit
:after evil
:config
(global-evil-matchit-mode 1))
(use-package evil-goggles
:after evil
:config
(progn
(setq evil-goggles-pulse t)
(setq evil-goggles-duration 0.4)
(setq evil-goggles-blocking-duration 0.1)
(evil-goggles-mode)
(evil-goggles-use-diff-faces)))
(use-package evil-surround
:after evil
:config
(global-evil-surround-mode 1))
(use-package evil-owl
:config
(setq evil-owl-display-method 'posframe
evil-owl-extra-posframe-args '(:width 50 :height 20)
evil-owl-max-string-length 50)
(evil-owl-mode))
(use-package evil-mc
:after evil
:config
(progn
(evil-define-local-var evil-mc-custom-paused nil
"Paused functionality when there are multiple cursors active.")
(defun evil-mc-pause-smartchr-for-mode (mode)
"Temporarily disables the smartchr keys for MODE."
(let ((m-mode (if (atom mode) mode (car mode)))
(s-mode (if (atom mode) mode (cdr mode))))
(let ((init (intern (concat "smartchr/init-" (symbol-name s-mode))))
(undo (intern (concat "smartchr/undo-" (symbol-name s-mode)))))
(when (eq major-mode m-mode)
(funcall undo)
(push `(lambda () (,init)) evil-mc-custom-paused)))))
(defun evil-mc-before-cursors-setup-hook ()
"Hook to run before any cursor is created.
Can be used to temporarily disable any functionality that doesn't
play well with `evil-mc'."
(mapc 'evil-mc-pause-smartchr-for-mode
'(web-mode js2-mode java-mode (enh-ruby-mode . ruby-mode) css-mode))
(when (boundp 'whitespace-cleanup-disabled)
(setq whitespace-cleanup-disabled t)
(push (lambda () (setq whitespace-cleanup-disabled nil)) evil-mc-custom-paused)))
(defun evil-mc-after-cursors-teardown-hook ()
"Hook to run after all cursors are deleted."
(dolist (fn evil-mc-custom-paused) (funcall fn))
(setq evil-mc-custom-paused nil))
(add-hook 'evil-mc-before-cursors-created 'evil-mc-before-cursors-setup-hook)
(add-hook 'evil-mc-after-cursors-deleted 'evil-mc-after-cursors-teardown-hook)
(defvar evil-mc-mode-line-prefix "ⓜ"
"Override of the default mode line string for `evil-mc-mode'.")
(global-evil-mc-mode 1)))
(use-package undo-tree
:diminish undo-tree-mode
:init
(global-undo-tree-mode)
:config
(mmap "U" 'undo-tree-visualize))
(use-package projectile
:ensure t
:init
(setq projectile-project-search-path '("~/Code/"))
(projectile-mode +1)
:config
(progn
(leader-map
"p" '(:keymap projectile-command-map :wk "projects"))
(with-eval-after-load 'consult
(general-def projectile-command-map
"b" 'consult-project-buffer))))
(use-package avy
:after evil
:config
(progn
(general-def :states '(normal visual motion)
"gf" 'avy-goto-char-timer
"gF" 'avy-resume)
(general-def :states '(normal visual motion insert emacs)
"C-f" 'avy-goto-char-timer
"C-S-f" 'avy-resume)
(setq avy-timeout-seconds 0.2)))
(use-package all-the-icons)
(use-package all-the-icons-completion
:after (all-the-icons marginalia)
:hook (marginalia-mode . all-the-icons-completion-marginalia-setup)
:init
(all-the-icons-completion-mode))
(use-package all-the-icons-dired
:after all-the-icons)
(use-package vertico
:init (vertico-mode)
:config
(progn
(general-def vertico-map
"C-d" 'vertico-scroll-up
"C-u" 'vertico-scroll-down
"C-v" 'vertico-scroll-up
"M-v" 'vertico-scroll-down
"C-j" 'vertico-next
"C-J" 'vertico-next-group
"C-k" 'vertico-previous
"C-K" 'vertico-previous-group
"M-RET" 'minibuffer-force-complete-and-exit
"M-TAB" 'minibuffer-complete
"C-RET" 'vertico-exit-input
"C-<return>" 'vertico-exit-input)
(advice-add #'vertico--format-candidate :around
(lambda (orig cand prefix suffix index _start)
(setq cand (funcall orig cand prefix suffix index _start))
(concat
(if (= vertico--index index)
(propertize "» " 'face 'vertico-current)
" ")
cand)))))
(use-package vertico-directory
:after vertico
:straight nil
:load-path "straight/repos/vertico/extensions/"
:bind
(:map vertico-map
("RET" . vertico-directory-enter)
("DEL" . vertico-directory-delete-char)
("M-DEL" . vertico-directory-delete-word))
:hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
(use-package vertico-posframe
:disabled t
:config
(setq vertico-posframe-truncate-lines nil)
(setq vertico-posframe-min-width 80)
(setq vertico-posframe-poshandler 'posframe-poshandler-window-top-center)
(vertico-posframe-mode))
(use-package savehist
:init
(savehist-mode))
(use-package consult
:general
(leader-map
"SPC" 'consult-buffer
"so" 'consult-outline
"sm" 'consult-mark
"sl" 'consult-line
"sL" 'consult-line-multi
"sM" 'consult-global-map
"sr" 'consult-ripgrep
"fF" 'consult-recent-file
"fb" 'consult-bookmark
"bb" 'consult-buffer
"bo" 'consult-buffer-other-window
"bf" 'consult-buffer-other-frame
"bm" 'consult-mode-command
"bh" 'consult-history
"xc" 'consult-complex-command
"xk" 'consult-kmacro)
(general-def
"C-x b" 'consult-buffer
"C-x 4 b" 'consult-buffer-other-window
"C-x 5 b" 'consult-buffer-other-frame
"C-x M-:" 'consult-complex-command
"C-x r b" 'consult-bookmark
"C-x p b" 'consult-project-buffer
"M-#" 'consult-register-load
"M-'" 'consult-register-store
"C-M-#" 'consult-register
"M-y" 'consult-yank-pop
"<help> a" 'consult-apropos
"M-g e" 'consult-compile-error
"M-g f" 'consult-flymake
"M-g g" 'consult-goto-line
"M-g M-g" 'consult-goto-line
"M-g o" 'consult-outline
"M-g m" 'consult-mark
"M-g k" 'consult-global-mark
"M-g i" 'consult-imenu
"M-g I" 'consult-imenu-multi
"M-s d" 'consult-find
"M-s D" 'consult-locate
"M-s g" 'consult-grep
"M-s G" 'consult-git-grep
"M-s r" 'consult-ripgrep
"M-s L" 'consult-line-multi
"M-s m" 'consult-multi-occur
"M-s k" 'consult-keep-lines
"M-s u" 'consult-focus-lines
"M-s e" 'consult-isearch-history)
(general-def
"C-s" 'consult-line
"C-S-s" 'consult-line-multi)
(general-def isearch-mode-map
"M-e" 'consult-isearch-history
"M-s e" 'consult-isearch-history
"C-s" 'consult-line
"C-S-s" 'consult-line-multi)
(general-def minibuffer-local-map
"M-s" 'consult-history
"M-r" 'consult-history)
:init
;; Optionally configure the register formatting. This improves the register
;; preview for `consult-register', `consult-register-load',
;; `consult-register-store' and the Emacs built-ins.
(setq register-preview-delay 0.5
register-preview-function #'consult-register-format)
;; Optionally tweak the register preview window.
;; This adds thin lines, sorting and hides the mode line of the window.
(advice-add #'register-preview :override #'consult-register-window)
;; Use Consult to select xref locations with preview
(setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)
:config
(progn
(consult-customize
consult-theme
:preview-key '(:debounce 0.2 any)
consult-ripgrep consult-git-grep consult-grep
consult-bookmark consult-recent-file consult-xref
consult--source-bookmark consult--source-recent-file
consult--source-project-recent-file
:preview-key (kbd "M-."))
(defvar-local consult-toggle-preview-orig nil)
(defun consult-toggle-preview ()
"Command to enable/disable preview."
(interactive)
(if consult-toggle-preview-orig
(setq consult--preview-function consult-toggle-preview-orig
consult-toggle-preview-orig nil)
(setq consult-toggle-preview-orig consult--preview-function
consult--preview-function #'ignore)))
(general-def vertico-map
"M-p" 'consult-toggle-preview)
(setq consult-narrow-key "<")
(setq completion-in-region-function
(lambda (&rest args)
(apply (if vertico-mode
#'consult-completion-in-region
#'completion--in-region)
args)))))
(use-package orderless
:config
(defvar +orderless-dispatch-alist
'((?% . char-fold-to-regexp)
(?! . orderless-without-literal)
(?`. orderless-initialism)
(?= . orderless-literal)
(?~ . orderless-flex)))
;; Recognizes the following patterns:
;; * ~flex flex~
;; * =literal literal=
;; * %char-fold char-fold%
;; * `initialism initialism`
;; * !without-literal without-literal!
;; * .ext (file extension)
;; * regexp$ (regexp matching at end)
(defun +orderless-dispatch (pattern index _total)
(cond
;; Ensure that $ works with Consult commands, which add disambiguation suffixes
((string-suffix-p "$" pattern)
`(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x200000-\x300000]*$")))
;; File extensions
((and
;; Completing filename or eshell
(or minibuffer-completing-file-name
(derived-mode-p 'eshell-mode))
;; File extension
(string-match-p "\\`\\.." pattern))
`(orderless-regexp . ,(concat "\\." (substring pattern 1) "[\x200000-\x300000]*$")))
;; Ignore single !
((string= "!" pattern) `(orderless-literal . ""))
;; Prefix and suffix
((if-let (x (assq (aref pattern 0) +orderless-dispatch-alist))
(cons (cdr x) (substring pattern 1))
(when-let (x (assq (aref pattern (1- (length pattern))) +orderless-dispatch-alist))
(cons (cdr x) (substring pattern 0 -1)))))))
;; Define orderless style with initialism by default
(orderless-define-completion-style +orderless-with-initialism
(orderless-matching-styles '(orderless-initialism orderless-literal orderless-regexp)))
;; You may want to combine the `orderless` style with `substring` and/or `basic`.
;; There are many details to consider, but the following configurations all work well.
;; Personally I (@minad) use option 3 currently. Also note that you may want to configure
;; special styles for special completion categories, e.g., partial-completion for files.
;;
;; 1. (setq completion-styles '(orderless))
;; This configuration results in a very coherent completion experience,
;; since orderless is used always and exclusively. But it may not work
;; in all scenarios. Prefix expansion with TAB is not possible.
;;
;; 2. (setq completion-styles '(substring orderless))
;; By trying substring before orderless, TAB expansion is possible.
;; The downside is that you can observe the switch from substring to orderless
;; during completion, less coherent.
;;
;; 3. (setq completion-styles '(orderless basic))
;; Certain dynamic completion tables (completion-table-dynamic)
;; do not work properly with orderless. One can add basic as a fallback.
;; Basic will only be used when orderless fails, which happens only for
;; these special tables.
;;
;; 4. (setq completion-styles '(substring orderless basic))
;; Combine substring, orderless and basic.
;;
(setq completion-styles '(orderless basic)
completion-category-defaults nil
;;; Enable partial-completion for files.