-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
3160 lines (2793 loc) · 104 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 Init -*- lexical-binding: t -*-
;; Author: Ashlin Eldridge <[email protected]>
;; URL: https://github.com/ashlineldridge/.config
;; Version: 1.0.0
;; Package-Requires: ((emacs "30.0"))
;;; Commentary:
;;
;; My bonsai.
;;; Code:
;;;; Bootstrap
(load (expand-file-name "bootstrap.el" user-emacs-directory))
;;;; Appearance
;;;;; Themes
(use-package theme
:ensure nil
:preface
(defvar my/default-theme 'ef-dark)
(defvar my/variable-pitch-headings
'((1 . (variable-pitch semibold 1.2))
(t . (variable-pitch semibold 1.1))))
:no-require
:hook
(elpaca-after-init . (lambda () (load-theme my/default-theme :no-confirm))))
(use-package modus-themes
:custom
(modus-themes-italic-constructs t)
(modus-themes-custom-auto-reload t)
(modus-themes-mixed-fonts t)
(modus-themes-prompts '(bold))
(modus-themes-org-blocks 'gray-background)
(modus-themes-headings my/variable-pitch-headings))
(use-package ef-themes
:custom
(ef-themes-mixed-fonts t)
(ef-themes-variable-pitch-ui t)
(ef-themes-headings my/variable-pitch-headings))
;;;;; Fonts
(use-package fontaine
:preface
(defconst my/fixed-family "Iosevka Comfy")
(defconst my/variable-family "Iosevka Comfy Motion Duo")
(defun my/fontaine-apply-preset ()
"Apply the current (or default) Fontaine preset."
(fontaine-set-preset (or fontaine-current-preset 'regular)))
:bind
("C-c x f" . fontaine-set-preset)
:hook
(elpaca-after-init . my/fontaine-apply-preset)
:custom
(fontaine-presets
`((regular)
(large
:default-family ,my/fixed-family
:default-height 140
:default-weight semibold
:fixed-pitch-weight semibold
:variable-pitch-weight semibold
:mode-line-active-height 130
:mode-line-inactive-height 130
:line-number-height 120)
(t
:default-family ,my/fixed-family
:default-height 130
:default-weight regular
:fixed-pitch-family ,my/fixed-family
:fixed-pitch-height 1.0
:fixed-pitch-weight regular
:variable-pitch-family ,my/variable-family
:variable-pitch-height 1.0
:variable-pitch-weight regular
:mode-line-active-family ,my/fixed-family
:mode-line-inactive-family ,my/fixed-family
:mode-line-active-height 120
:mode-line-inactive-height 120
:line-number-family ,my/fixed-family
:line-number-slant italic
:line-number-height 110
:bold-weight bold
:italic-slant italic))))
(use-package font-lock
:ensure nil
:preface
;; Create face aliases to be used in `consult-imenu-config'.
(put 'my/imenu-constant-face 'face-alias 'font-lock-constant-face)
(put 'my/imenu-enum-face 'face-alias 'font-lock-type-face)
(put 'my/imenu-function-face 'face-alias 'font-lock-function-name-face)
(put 'my/imenu-impl-face 'face-alias 'font-lock-type-face)
(put 'my/imenu-package-face 'face-alias 'font-lock-constant-face)
(put 'my/imenu-macro-face 'face-alias 'font-lock-preprocessor-face)
(put 'my/imenu-method-face 'face-alias 'font-lock-function-name-face)
(put 'my/imenu-module-face 'face-alias 'font-lock-constant-face)
(put 'my/imenu-static-face 'face-alias 'font-lock-constant-face)
(put 'my/imenu-struct-face 'face-alias 'font-lock-type-face)
(put 'my/imenu-trait-face 'face-alias 'font-lock-type-face)
(put 'my/imenu-type-face 'face-alias 'font-lock-type-face)
(put 'my/imenu-variable-face 'face-alias 'font-lock-variable-name-face))
(use-package face-remap
:ensure nil
:config
;; Makes things like breadcrumb look better when scaling text.
(setq-default text-scale-remap-header-line t))
;;;;; Icons
;; Run `nerd-icons-install-fonts' manually to install fonts for the first time.
(use-package nerd-icons)
(use-package nerd-icons-ibuffer
:hook (ibuffer-mode . nerd-icons-ibuffer-mode))
;; Enables Vertico icons.
(use-package nerd-icons-completion
:hook (vertico-mode . nerd-icons-completion-mode))
(use-package nerd-icons-corfu
:after corfu
:defines corfu-margin-formatters
:init
(add-to-list 'corfu-margin-formatters 'nerd-icons-corfu-formatter)
:config
;; Make `tempel-complete' look nice (use `nerd-icons-insert' to see icons).
(add-to-list 'nerd-icons-corfu-mapping
'(snippet :style "oct" :icon "heart" :face font-lock-string-face)))
;;;;; Mode Line
(use-package smol
:if (file-exists-p "~/dev/home/smol")
:load-path "~/dev/home/smol"
:hook
;; Initialize after Ace Window to take over `mode-line-format'.
(ace-window-display-mode . smol-init)
:custom
(smol-string-truncate-length 80))
;;;;; Point/Cursor
(use-package cursory
:commands cursory-set-preset
:hook
(org-mode . (lambda () (cursory-set-preset 'bar :local)))
:init
(cursory-set-preset 'box))
;;;;; Margins/Padding
(use-package spacious-padding
:preface
(defun my/spacious-padding-toggle-subtle-mode-line ()
"Toggle whether the mode line is displayed in the subtle style."
(interactive)
(setq spacious-padding-subtle-mode-line
(not spacious-padding-subtle-mode-line))
(when spacious-padding-mode
(spacious-padding-mode -1)
(spacious-padding-mode 1)))
:hook
(elpaca-after-init . spacious-padding-mode)
:bind
("C-c x _" . my/spacious-padding-toggle-subtle-mode-line)
:custom
(spacious-padding-subtle-mode-line nil)
(spacious-padding-widths
'(:internal-border-width 20
:fringe-width 8
:right-divider-width 20
:mode-line-width 2)))
;;;;; Lines and Columns
(use-package display-line-numbers
:ensure nil
:bind
("<f9>" . display-line-numbers-mode))
(use-package display-fill-column-indicator
:ensure nil
:bind
("C-c x |" . display-fill-column-indicator-mode)
:custom
(fill-column 80))
;;;; Repeating
(use-package repeat
:ensure nil
:hook (elpaca-after-init . repeat-mode)
:custom
(repeat-keep-prefix t)
(repeat-exit-timeout 5)
(repeat-exit-key "RET"))
;;;; Bookmarks
(use-package bookmark
:ensure nil
:custom
;; Save bookmarks immediately.
(bookmark-save-flag 0))
;;;; Registers
(use-package register
:ensure nil
:preface
(defun my/clear-registers ()
"Clear all registers."
(interactive)
(let ((len (length register-alist)))
(setq register-alist nil)
(message "Cleared %d registers" len)))
:bind
("C-x r K" . my/clear-registers)
:custom
(register-preview-delay 1)
:config
;; Make `insert-register' obey `delete-selection-mode'.
(advice-add #'insert-register :before #'my/maybe-delete-selection))
;;;; General History
(use-package savehist
:ensure nil
:hook (elpaca-after-init . savehist-mode)
:custom
(history-length 1000)
(history-delete-duplicates t)
(savehist-save-minibuffer-history t)
;; Variables to persist between sessions.
(savehist-additional-variables
'(kill-ring
search-ring
regexp-search-ring
extended-command-history
;; Not perfect as doesn't persist if contains certain register types.
register-alist)))
;;;; Windows and Frames
(use-package ns-win
:ensure nil
:custom
(mac-command-modifier 'meta)
(mac-option-modifier nil))
;;;;; Window Basics
(use-package window
:ensure nil
:bind
(("M-[" . previous-buffer)
("M-]" . next-buffer)
("M-q" . bury-buffer)
("M-O =" . balance-windows)
("M-O 0" . delete-window)
("M-O 1" . delete-other-windows)
("M-O 2" . split-window-below)
("M-O 3" . split-window-right)
("M-O M-=" . enlarge-window-horizontally)
("M-O M--" . shrink-window-horizontally)
("M-O M-+" . enlarge-window)
("M-O M-_" . shrink-window)
:repeat-map my/window-repeat-map
("M-=" . enlarge-window-horizontally)
("M--" . shrink-window-horizontally)
("M-+" . enlarge-window)
("M-_" . shrink-window))
:custom
(even-window-sizes nil)
;; Prefer splitting by width and only when the window is quite wide.
(split-height-threshold nil)
(split-width-threshold 200)
;; WORK-IN-PROGRESS: Display buffer configuration.
;; See: https://protesilaos.com/codelog/2024-02-08-emacs-window-rules-display-buffer-alist
;; See: https://github.com/ashlineldridge/.config/blob/b92a568ec77f69170bc06523b163020f73962464/emacs/init.el#L534C6-L534C69
;; See: https://github.com/protesilaos/dotfiles/blob/d16ad4d8d54e1d06ec1cbe7a62568d408651847e/emacs/.emacs.d/prot-emacs-modules/prot-emacs-window.el#L66
(display-buffer-alist
`(;; No window.
("\\*Async Shell Command\\*"
;; Note that some buffers additionally require the `allow-no-window'
;; option to be specified. The downside of this is that it breaks other-
;; window commands such as `consult-buffer-other-window'.
(display-buffer-no-window))
;; Below current window in a regular window.
("CAPTURE-.*\\.org"
(display-buffer-below-selected)
(window-height . 10))
;; Below current window in dedicated side window with no mode line.
("\\*\\(Org \\(Select\\|Note\\)\\|Agenda Commands\\)\\*"
(display-buffer-in-side-window)
(dedicated . t)
(side . bottom)
(slot . 0)
(window-parameters . ((mode-line-format . none))))
;; Same window.
("\\(\\*vc-dir\\*\\|magit: \\)"
(display-buffer-same-window)))))
;;;;; Window Movement
(use-package ace-window
:defines (embark-buffer-map embark-file-map embark-bookmark-map)
:preface
(declare-function aw-delete-window "ace-window")
(declare-function aw-switch-to-window "ace-window")
(declare-function aw-window-list "ace-window")
(defun my/ace-window ()
"Custom Ace window command that modifies the cursor during selection."
(interactive)
(blink-cursor-suspend)
(let ((orig (face-attribute 'cursor :background)))
(set-cursor-color "cyan")
(unwind-protect
(aw-select nil #'aw-switch-to-window)
(set-cursor-color orig)
(blink-cursor-check))))
(defun my/ace-delete-window-and-buffer (window)
"Ace window action to delete window and buffer."
(aw-delete-window window t))
(defmacro my/define-ace-embark-action (name map fn)
"Macro to define an Embark action that switches windows and then runs FN."
`(progn
(defun ,name ()
,(format "Embark action to switch windows and then call `%s'." fn)
(interactive)
(my/ace-window)
(call-interactively #',fn))
(with-eval-after-load 'embark
(bind-key "M-o" #',name ,map))))
;; Create additional Embark actions that support Ace Window.
(my/define-ace-embark-action my/ace-embark-buffer embark-buffer-map switch-to-buffer)
(my/define-ace-embark-action my/ace-embark-file embark-file-map find-file)
(my/define-ace-embark-action my/ace-embark-bookmark embark-bookmark-map bookmark-jump)
:hook
;; Run `ace-window-display-mode' so that overlays aren't shown. Smol will
;; recognize this mode and display the window ID in the mode line.
(elpaca-after-init . ace-window-display-mode)
:bind
("M-o" . my/ace-window)
:custom
(aw-scope 'frame)
(aw-background nil)
(aw-display-mode-overlay nil)
(aw-minibuffer-flag nil)
;; Dispatch settings to allow jumping from the minibuffer to a single window.
(aw-dispatch-always nil)
(aw-dispatch-when-more-than 1)
;; Ignore the minibuffer and use `switch-to-minibuffer' instead.
(aw-ignored-buffers '(minibuffer-mode))
:commands aw-select
:config
;; Custom dispatch menu.
(setq aw-dispatch-alist
'((?k aw-delete-window "Kill Window")
(?K my/ace-delete-window-and-buffer "Kill Window and Buffer")
(?. delete-other-windows "Kill Other Windows")
(?s aw-swap-window "Swap Window")
(?m aw-move-window "Move Window")
(?c aw-copy-window "Copy Window")
(?_ aw-split-window-vert "Split Vertically")
(?| aw-split-window-horz "Split Horizontally")
(?? aw-show-dispatch-help)))
;; Advise the `aw-window-list' function to forcibly enable `aw-ignore-on'.
;; See: https://github.com/abo-abo/ace-window/issues/249.
(advice-add #'aw-window-list :around (lambda (fn &rest args)
(let ((aw-ignore-on t))
(apply fn args)))))
;;;;; Window History
(use-package winner
:ensure nil
:bind
("M-O u" . winner-undo)
("M-O r" . winner-redo)
:hook (elpaca-after-init . winner-mode)
:custom
(winner-dont-bind-my-keys t)
:config
;; Need to bind the repeat map after the package is loaded as Winner defines
;; its own repeat map that we need to override.
(bind-keys :package winner
:repeat-map my/window-repeat-map
("u" . winner-undo)
("r" . winner-redo)))
;;;;; Window Scrolling
(use-package pixel-scroll
:ensure nil
:preface
(declare-function pixel-line-height "pixel-scroll")
(declare-function pixel-scroll-precision-interpolate "pixel-scroll")
(defun my/scroll-delta (delta &optional factor)
"Scroll up by DELTA pixels with scale FACTOR (defaults to 1.0)."
(pixel-scroll-precision-interpolate delta nil (or factor 1.0)))
(defun my/scroll-up-page ()
"Scroll up by the page height."
(interactive)
(my/scroll-delta (window-text-height nil t)))
(defun my/scroll-down-page ()
"Scroll down by the page height."
(interactive)
(my/scroll-delta (- (window-text-height nil t))))
(defun my/scroll-up-lines ()
"Scroll up by a line factor."
(interactive)
(my/scroll-delta (pixel-line-height) 2.0))
(defun my/scroll-down-lines ()
"Scroll down by a line factor."
(interactive)
(my/scroll-delta (- (pixel-line-height)) 2.0))
(defun my/scroll-up-page-other-window ()
"Scroll the other window up by the page height."
(interactive)
(with-selected-window (other-window-for-scrolling)
(my/scroll-up-page)))
(defun my/scroll-down-page-other-window ()
"Scroll down by the page height."
(interactive)
(with-selected-window (other-window-for-scrolling)
(my/scroll-down-page)))
(defun my/scroll-up-lines-other-window ()
"Scroll the other window up by a line factor."
(interactive)
(with-selected-window (other-window-for-scrolling)
(my/scroll-up-lines)))
(defun my/scroll-down-lines-other-window ()
"Scroll the other window down by a line factor."
(interactive)
(with-selected-window (other-window-for-scrolling)
(my/scroll-down-lines)))
(defun my/other-window-for-scrolling ()
"Custom window selection for scrolling other window."
;; Prioritize right, then left, then next.
(or (window-in-direction 'right)
(window-in-direction 'left)
(next-window)))
:bind
("M-v" . my/scroll-up-page)
("C-v" . my/scroll-down-page)
("<prior>" . my/scroll-up-page)
("<next>" . my/scroll-down-page)
("M-S-<up>" . my/scroll-up-lines)
("M-S-<down>" . my/scroll-down-lines)
;; Use the `C-M' chorded keybinds for scrolling the other window. This
;; chord is also used for other window keybindings in other packages.
("C-M-<prior>" . my/scroll-up-page-other-window)
("C-M-<next>" . my/scroll-down-page-other-window)
("C-M-<up>" . my/scroll-up-lines-other-window)
("C-M-<down>" . my/scroll-down-lines-other-window)
;; Also replace existing keybinds for scrolling the other window.
("M-<prior>" . my/scroll-up-page-other-window)
("M-<next>" . my/scroll-down-page-other-window)
("C-M-S-v" . my/scroll-up-page-other-window)
("C-M-v" . my/scroll-down-page-other-window)
:hook (elpaca-after-init . pixel-scroll-precision-mode)
:init
;; The default value of 0 causes point to be recentered when it scrolls off
;; screen. A value of 101 (or above) will mean that point is never recentered,
;; though for some commands (e.g. xref navigation) it can cause point to be
;; shown in an awkward position when you want recentering to occur. A value of
;; 1 provides a good balance such that point is prevented from scrolling off
;; screen but it is recentered when moving by one line doesn't bring point on
;; screen again (e.g. during xref navigation).
(setq scroll-conservatively 1))
;;;;; Frame Management
(use-package frame
:ensure nil
:bind
;; Remove silly `suspend-frame' bindings.
("C-z" . nil)
("C-x C-z" . nil)
("M-O M-O" . other-frame)
("M-O M-N" . make-frame-command)
("M-O M-K" . delete-frame)
("M-O M-U" . undelete-frame)
:hook (elpaca-after-init . undelete-frame-mode))
;;;;; Transient
;; Use external transient as some packages require a later version.
(use-package transient)
;;;;; Tab Bar
(use-package tab-bar
:ensure nil
:custom
(tab-bar-show nil))
;;;;; Breadcrumb
(use-package breadcrumb
:hook (elpaca-after-init . breadcrumb-mode)
:custom
;; Imenu integration is slow to update and sometimes incorrect so just show
;; the project breadcrumb and allow it to take up most of the window width.
(breadcrumb-project-max-length 0.75)
:config
(fset 'breadcrumb-imenu-crumbs 'ignore))
;;;; Help System
(use-package help-fns
:ensure nil
:bind
("C-h F" . describe-face))
(use-package helpful
:bind
("C-h c" . helpful-callable)
("C-h ," . helpful-at-point)
;; Replace `describe-*' bindings with Helpful where possible.
([remap describe-function] . helpful-function)
([remap describe-symbol] . helpful-symbol)
([remap describe-variable] . helpful-variable)
([remap describe-command] . helpful-command)
([remap describe-key] . helpful-key)
:custom
;; Don't select the helpful buffer.
(helpful-switch-buffer-function #'display-buffer))
(use-package which-key
:ensure nil
:hook (elpaca-after-init . which-key-mode)
:custom
(echo-keystrokes 0.01)
;; Use Embark for `prefix-help-command' as it is searchable.
(which-key-show-early-on-C-h nil)
(which-key-use-C-h-commands nil)
(which-key-idle-delay 1.0)
(which-key-idle-secondary-delay 0.05)
(which-key-popup-type 'side-window)
(which-key-side-window-location '(bottom right)))
;;;; General Editing
(use-package simple
:ensure nil
:preface
(declare-function called-interactively-p "subr")
(defun my/keyboard-quit-dwim ()
"DWIM version of `keyboard-quit'."
(interactive)
(cond
((region-active-p)
(deactivate-mark))
((> (minibuffer-depth) 0)
(abort-recursive-edit))
((> (recursion-depth) 0)
(exit-recursive-edit))
(t
(keyboard-quit))))
(defun my/kill-ring-save ()
"Copy the current region or line."
(interactive)
(if (region-active-p)
(copy-region-as-kill nil nil t)
(copy-region-as-kill (line-beginning-position) (line-end-position))))
(defun my/kill-line-backward ()
"Kill from point to the beginning of the line."
(interactive)
(kill-line 0))
(defun my/zap-to-char-backward (arg char)
"Backward `zap-to-char' for the ARGth occurrance of CHAR."
(interactive
(list
(prefix-numeric-value current-prefix-arg)
(read-char-from-minibuffer "Zap back to char: " nil 'read-char-history)))
(zap-to-char (- arg) char t))
(defun my/open-line-below ()
"Open line below and indent point without breaking the current line."
(interactive)
(move-end-of-line 1)
(newline-and-indent))
(defun my/open-line-above ()
"Open line below and indent point without breaking the current line."
(interactive)
(move-beginning-of-line 1)
(newline)
(move-beginning-of-line 0)
(indent-according-to-mode))
(defun my/expand-line ()
"Expand/mark the current line from the margin."
(interactive)
(back-to-indentation)
(set-mark (point))
(end-of-line))
(defun my/truncate-lines ()
"Show long lines as truncated in the current buffer."
(setq-local truncate-lines t))
(defun my/minibuffer-history-eol (_)
"Move point to the end of line when called interactively."
(when (called-interactively-p)
(end-of-line)))
:custom
(indent-tabs-mode nil)
;; Allow shift-selection to continue any active region.
(shift-select-mode 'permanent)
;; Kill more, remember more.
(kill-ring-max 1000)
(mark-ring-max 16)
(global-mark-ring-max 16)
(set-mark-command-repeat-pop t)
(shell-command-prompt-show-cwd t)
(async-shell-command-buffer 'rename-buffer)
;; Don't show M-x commands that don't work in the current mode.
(read-extended-command-predicate #'command-completion-default-include-p)
:bind
([remap kill-ring-save] . my/kill-ring-save)
([remap keyboard-quit] . my/keyboard-quit-dwim)
("ESC ESC" . keyboard-escape-quit) ;; 3rd ESC is unnecessary.
("M-*" . my/expand-line)
("M-c" . capitalize-dwim)
("M-l" . downcase-dwim)
("M-u" . upcase-dwim)
("M-k" . my/kill-line-backward)
("M-S-SPC" . cycle-spacing)
;; I prefer `zap-up-to-char' when zapping forward and `zap-to-char' when
;; zapping backward. This also mimics the zapping behavior of Avy. Some of
;; the following commands are from misc.el but bound here for simplicity.
("M-z" . zap-up-to-char)
("M-Z" . my/zap-to-char-backward)
("C-M-<return>" . duplicate-dwim)
("C-<return>" . my/open-line-below)
("C-S-<return>" . my/open-line-above)
("M-S-<left>" . beginning-of-buffer)
("M-S-<right>" . end-of-buffer)
("C-M-<left>" . beginning-of-buffer-other-window)
("C-M-<right>" . end-of-buffer-other-window)
;; Special keybinding to switch to the minibuffer as I have configured
;; Ace Window to ignore the minibuffer window.
("C-M-O" . switch-to-minibuffer)
("C-c x SPC" . delete-trailing-whitespace)
("C-c x l" . toggle-truncate-lines)
:hook
(elpaca-after-init . column-number-mode)
(prog-mode . my/truncate-lines)
:config
;; Don't yank face properties (e.g. prevents pasting colors).
(add-to-list 'yank-excluded-properties 'face)
;; Move point to the end of the line when navigating minibuffer history.
(advice-add #'next-history-element :after #'my/minibuffer-history-eol)
(advice-add #'previous-history-element :after #'my/minibuffer-history-eol))
;;;;; Text
(use-package text-mode
:ensure nil
:custom
;; Otherwise I get spelling auto-completion in Magit commit buffers
;; which I find annoying. Call Jinx manually instead.
(text-mode-ispell-word-completion nil))
(use-package paragraphs
:ensure nil
:no-require
:custom
(sentence-end-double-space nil))
(use-package indent
:ensure nil
:no-require
:custom
(tab-always-indent 'complete))
(use-package delsel
:ensure nil
:preface
(defun my/maybe-delete-selection (&rest _)
"Delete region if `delete-selection-mode' is enabled."
(when (and delete-selection-mode mark-active)
(delete-active-region)))
:hook (elpaca-after-init . delete-selection-mode))
(use-package iso-transl
:ensure nil
:bind
;; Bind some special characters under 'C-x 8'. The [?] character is a zero-
;; width space character that can be used to escape Org mode emphasis markers.
;; See: https://emacs.stackexchange.com/questions/16688/how-can-i-escape-the-in-org-mode-to-prevent-bold-fontification.
(:map iso-transl-ctl-x-8-map
("0" . [?])
("a" . [?α])
("b" . [?β])
("l" . [?λ])
(">" . [?⟶])
("<" . [?⟵])
("s" . [?😊])))
;;;;; Undo/Redo
(use-package vundo
:bind
("C-x u" . vundo)
:custom
(vundo-glyph-alist vundo-unicode-symbols)
:config
(set-face-attribute 'vundo-default nil :family "Iosevka Comfy Fixed"))
;;;;; Region Expansion
(use-package expreg
:bind
("C-=" . expreg-expand)
("C-+" . expreg-contract))
;;;;; Whitespace
(use-package ws-butler
:hook ((text-mode prog-mode) . ws-butler-mode)
:custom
(ws-butler-keep-whitespace-before-point nil))
;;;;; Jumping Around
(use-package avy
:preface
(declare-function avy-action-copy "avy")
(declare-function avy-goto-end-of-line "avy")
(defun my/avy-goto-end-of-line ()
"Same as `avy-goto-end-of-line' but show the overlay as a postfix."
;; Can't use `avy-styles-alist' as `avy-goto-end-of-line' wraps `avy-goto-line'.
(interactive)
(require 'avy)
(let ((avy-style 'post))
(call-interactively #'avy-goto-end-of-line)))
(defun my/avy-action-yank (pt)
"Same as `avy-action-yank' but respects `delete-selection-mode'."
(avy-action-copy pt)
(my/maybe-delete-selection)
(yank))
:bind
(("M-g c" . avy-goto-char-timer)
("M-g l" . avy-goto-line)
("M-g L" . my/avy-goto-end-of-line)
("M-g w" . avy-goto-word-1)
("M-g W" . avy-goto-char-in-line)
:map isearch-mode-map
("M-g" . avy-isearch))
:custom
(avy-all-windows t) ;; Alternatively, use 'all-frames.
(avy-single-candidate-jump nil)
(avy-timeout-seconds 0.3)
(avy-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
(avy-styles-alist '((avy-isearch . post)))
(avy-dispatch-alist
'((?m . avy-action-mark)
(?t . avy-action-teleport)
(?w . avy-action-copy)
(?y . my/avy-action-yank)
(?z . avy-action-zap-to-char)
(?x . avy-action-kill-stay)))
:config
(eldoc-add-command-completions "avy-goto-"))
(use-package link-hint
:bind
("M-g ." . link-hint-open-link)
("M-g M-." . link-hint-copy-link))
;;;;; Highlighting
(use-package hl-line
:ensure nil
:custom
(hl-line-sticky-flag nil))
(use-package hi-lock
:ensure nil
:bind
(("M-s h ." . highlight-symbol-at-point)
("M-s h h" . highlight-regexp)
("M-s h l" . highlight-lines-matching-regexp)
("M-s h u" . unhighlight-regexp)))
(use-package lin
:hook (elpaca-after-init . lin-global-mode)
:bind
("C-c x h" . lin-mode)
:custom
(lin-face 'lin-green))
(use-package pulsar
:preface
(defun my/pulsar-pulse-line (&optional _)
"Line pulsing function intended to be used as after advice."
(pulsar-pulse-line))
:hook (elpaca-after-init . pulsar-global-mode)
;; Some functionality is better accessed via hooks than by registering
;; functions in `pulsar-pulse-functions'.
(minibuffer-setup . pulsar-pulse-line)
(next-error . pulsar-pulse-line-red)
(next-error . pulsar-reveal-entry)
(next-error . pulsar-recenter-center)
:custom
(pulsar-delay 0.05)
(pulsar-iterations 13)
(pulsar-face 'pulsar-cyan)
:config
;; Add extra functions that should trigger Pulsar. I'm not using
;; #'fn syntax here to avoid needing all the forward declarations.
(add-to-list 'pulsar-pulse-functions 'avy-goto-line)
(add-to-list 'pulsar-pulse-functions 'beginning-of-buffer)
(add-to-list 'pulsar-pulse-functions 'beginning-of-defun)
(add-to-list 'pulsar-pulse-functions 'end-of-buffer)
(add-to-list 'pulsar-pulse-functions 'end-of-defun)
(add-to-list 'pulsar-pulse-functions 'eshell-next-prompt)
(add-to-list 'pulsar-pulse-functions 'eshell-previous-prompt)
(add-to-list 'pulsar-pulse-functions 'flymake-goto-next-error)
(add-to-list 'pulsar-pulse-functions 'flymake-goto-prev-error)
(add-to-list 'pulsar-pulse-functions 'isearch-repeat-backward)
(add-to-list 'pulsar-pulse-functions 'isearch-repeat-forward)
(add-to-list 'pulsar-pulse-functions 'magit-section-backward)
(add-to-list 'pulsar-pulse-functions 'magit-section-forward)
(add-to-list 'pulsar-pulse-functions 'my/avy-goto-end-of-line)
(add-to-list 'pulsar-pulse-functions 'other-frame)
(add-to-list 'pulsar-pulse-functions 'pop-global-mark)
(add-to-list 'pulsar-pulse-functions 'treesit-beginning-of-defun)
(add-to-list 'pulsar-pulse-functions 'treesit-end-of-defun)
(add-to-list 'pulsar-pulse-functions 'vterm-next-prompt)
(add-to-list 'pulsar-pulse-functions 'vterm-previous-prompt)
(add-to-list 'pulsar-pulse-functions 'xref-find-definitions)
(add-to-list 'pulsar-pulse-functions 'xref-go-back)
(add-to-list 'pulsar-pulse-functions 'xref-go-forward)
;; Functions called by Embark need to be advised.
(with-eval-after-load 'embark
(advice-add 'embark-next-symbol :after 'my/pulsar-pulse-line)
(advice-add 'embark-previous-symbol :after 'my/pulsar-pulse-line))
;; Pulse line after switching windows with `ace-window'.
(with-eval-after-load 'ace-window
(advice-add 'aw-switch-to-window :after 'my/pulsar-pulse-line)))
(use-package rainbow-mode)
;;;;; Templating
(use-package tempel
:bind
(("M-/" . tempel-complete)
(:map tempel-map
("M-/" . tempel-next)
("M-?" . tempel-previous)
([remap keyboard-quit] . tempel-done))))
;;;; Buffer Management
;; Use `ibuffer' as a replacement for `list-buffers'.
(use-package ibuffer
:ensure nil
:bind
(("C-x C-b" . ibuffer)
:map ibuffer-mode-map
("M-o" . nil)))
(use-package ibuffer-vc
:after ibuffer
:bind
(:map ibuffer-mode-map
;; Take /p for grouping by "project". By default, /p and /P are bound to
;; `ibuffer-pop-filter' and `ibuffer-pop-filter-group' but these commands
;; are also bound to /<up> and /S-<up>.
("/P" . nil)
("/p" . ibuffer-vc-set-filter-groups-by-vc-root)))
;;;; File System
(use-package files
:ensure nil
:preface
(defun my/kill-buffer-maybe-save ()
"Kill the current buffer after saving if required."
(interactive)
(when (and buffer-file-name (buffer-modified-p))
(save-buffer))
(kill-current-buffer))
:bind
;; Shorter save/quit buffer bindings.
("M-'" . save-buffer)
("M-\"" . my/kill-buffer-maybe-save)
("C-x C-r" . restart-emacs)
:hook (elpaca-after-init . auto-save-visited-mode)
:custom
;; Disable `auto-save-mode' which saves buffers to separate files in favor of
;; `auto-save-visited-mode' which saves file-visiting buffers to their files.
(auto-save-default nil)
(auto-save-visited-interval 30)
(confirm-kill-emacs #'yes-or-no-p)
(delete-by-moving-to-trash t)
;; Use GNU ls (used by dired and supports grouping directories first).
(insert-directory-program "gls"))
;;;;; File Browsing
(use-package dired
:ensure nil
:bind
(:map dired-mode-map
("M-s" . nil)
("N" . dired-create-empty-file)
("?" . which-key-show-major-mode)
:map dired-jump-map
;; Allow `dired-goto-file' (via j) straight after jumping with C-x C-j.
;; Without this, repeat mode takes over and j calls `dired-jump' again.
("j" . nil))
:hook
(dired-mode . my/truncate-lines)
:custom
(delete-by-moving-to-trash t)
(dired-free-space nil)
(dired-recursive-copies 'always)
(dired-recursive-deletes 'always)
(dired-hide-details-hide-symlink-targets nil)
(dired-kill-when-opening-new-dired-buffer t)
(dired-listing-switches "-AGFhlv --group-directories-first --time-style=long-iso"))
(use-package dired-aux
:ensure nil
:custom
(dired-create-destination-dirs 'ask)
(dired-create-destination-dirs-on-trailing-dirsep t))
(use-package dired-subtree
:after dired
:bind
(:map dired-mode-map
("i" . dired-subtree-insert)
(";" . dired-subtree-remove)
("<tab>" . dired-subtree-toggle))
:custom
(dired-subtree-use-backgrounds nil))
(use-package diredfl
:hook (dired-mode . diredfl-mode))
;; Provides the super useful `wdired-change-to-wdired-mode' command.
(use-package wdired
:ensure nil
:after dired
:bind
(:map dired-mode-map
;; Use same keybinding as `wgrep-change-to-wgrep-mode'.
("C-c C-w" . wdired-change-to-wdired-mode))
:custom
(wdired-allow-to-change-permissions t)
(wdired-create-parent-directories t))