-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
4666 lines (4262 loc) · 149 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 --- Modus Operandi Emacs Configuration -*- lexical-binding: t -*-
;; Author: Yoav Orot
;; Created: 2021
;; Homepage: https://github.com/manzaltu/modus-emacs
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Modus Operandi Emacs development environment configuration file
;;; Code:
(require 'cl-lib)
;; Set a directory path to be used for cache files
(defvar mo-cache-dir (expand-file-name ".cache" user-emacs-directory))
(defun mo-cache-path (filename)
"Return a valid file path for FILENAME under the cache directory."
(concat (file-name-as-directory mo-cache-dir) filename))
(defvar straight-base-dir mo-cache-dir)
(defvar straight-repository-branch "develop")
;; Init straight.el for package management
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name ".cache/straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 6))
(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))
;; Show calls to use-package in imenu
(customize-set-variable 'use-package-enable-imenu-support t)
;; Enable package hooks
(defvar use-package-inject-hooks t)
;; Init straight for package management
(use-package straight
:custom
;; Packages should be installed by default using straight
( straight-use-package-by-default t))
;; Optionally, load personal settings
(load (concat (file-name-directory load-file-name) "personal.el") t)
(defvar mo-font "PragmataPro Mono Liga-14"
"Font to use.")
;; Add general.el key mapper
(use-package general
:demand t
:defines
( mo-quick-menu-definer
mo--quick-menu-definer-evil
mo--quick-menu-definer-non-evil)
:functions ( general-create-definer mo-quick-menu-definer)
:config
;; Create a definer and a leader for quick menu when in evil-mode
(general-create-definer mo--quick-menu-definer-evil
:states '( normal visual motion emacs)
:prefix ",")
;; Create a definer and a leader for quick menu when not in evil-mode
(general-create-definer mo--quick-menu-definer-non-evil
:keymaps 'override
:prefix "M-<insert>")
(defmacro mo-quick-menu-definer (&rest args)
"Define bindings for both the evil and the non-evil leaders."
(declare (indent defun))
`(progn
(mo--quick-menu-definer-evil
,@args)
(mo--quick-menu-definer-non-evil
,@args)))
(mo-quick-menu-definer
:prefix-map 'mo-quick-menu-map
:which-key "Quick menu prefix key"
"a" '( :which-key "Action")
"b" '( :which-key "Buffer")
"<insert>" '( :which-key Bookmark)
"f" '( :which-key "File")
"v" '( :which-key "View")
"w" '( :which-key "Window")
"x" '( :which-key "Utils")
"z" '( :which-key "Repeat")
"t" '( :which-key "Tab")
"h" '( :which-key "Help")
"DEL" '( :which-key "Project")
"c" '( :which-key "Code")
"d" '( :which-key "Debug")
"l" '( :which-key "Emacs Lisp")
"s" '( :which-key "Lisp")
"g" '( :which-key "Git")
"m" '( :which-key "Merge")
"r" '( :which-key "Multiple Cursors")
"n" '( :which-key "Notes")))
;; Init evil mode for Vim emulation in Emacs
(use-package evil
:demand t
:general
( :keymaps 'mo-quick-menu-map
:prefix "w"
"H" #'evil-window-move-far-left
"J" #'evil-window-move-very-bottom
"K" #'evil-window-move-very-top
"L" #'evil-window-move-far-right
"v" #'evil-window-vsplit
"V" #'mo-evil-vsplit-left
"s" #'evil-window-split
"S" #'mo-evil-split-above
"c" #'evil-window-delete
"+" #'evil-window-increase-height
"-" #'evil-window-decrease-height
">" #'evil-window-increase-width
"<" #'evil-window-decrease-width)
( :keymaps 'mo-quick-menu-map
:prefix "b"
"ESC" #'evil-ex-nohighlight)
;; We want C-f for moving forward a word
( :keymaps 'evil-ex-completion-map
"C-f" nil
"C-b" nil
"C-a" nil
"C-." #'evil-ex-command-window)
( :keymaps 'evil-command-line-map
"C-f" nil
"C-b" nil
"C-a" nil
"M-r" #'evil-paste-from-register)
( :states 'motion
;; We want C-<num> for jumping between tabs
"C-6" nil
"C-S-d" #'evil-scroll-up
"C-}" #'mo-evil-forward-paragraph-recenter
"C-{" #'mo-evil-backward-paragraph-recenter)
( :states 'insert
;; Evil, for historical reasons, binds the <delete> key to delete-char.
;; Today this is unnecessary, and may override other modes keybindings.
"<delete>" nil)
( :keymaps 'global
"C-M-o" #'evil-window-mru)
:hook
;; Recenter after jump
( evil-jumps-post-jump . recenter)
:init
;; Needed for evil-collection
(setq evil-want-keybinding nil)
;; Enable in minibuffer
(setq evil-want-minibuffer t)
;; Undo
(setq evil-undo-system 'undo-redo)
(setq evil-want-fine-undo t)
;; Enable Emacs native bindings in insert mode
(setq evil-disable-insert-state-bindings t)
(setq evil-want-C-u-delete nil)
(setq evil-want-C-w-delete nil)
;; Yanking
(setq evil-want-Y-yank-to-eol t)
;; Use evil search instead of the native search module
(setq evil-search-module 'evil-search)
;; Set word search to look for symbol boundaries
(setq evil-symbol-word-search t)
;; Do not keep highlighting after search
(setq evil-ex-search-persistent-highlight nil)
;; Set end of line selection to not include the newline character
(setq evil-want-visual-char-semi-exclusive t)
;; Don't kill text when pasting over it
(setq-default evil-kill-on-visual-paste nil)
;; Respect visual line mode
(setq evil-respect-visual-line-mode t)
;; Create split windows below
(setq evil-split-window-below t)
;; Create vertical split windows to the right
(setq evil-vsplit-window-right t)
;; Cursor can move beyond eol to support Emacs sexp movement
(setq evil-move-beyond-eol t)
:config
(defun mo-evil-split-above ()
"Split and create a new window above."
(interactive)
(let ((evil-split-window-below nil))
(call-interactively #'evil-window-split)))
(defun mo-evil-vsplit-left ()
"Vertically split and create a new window to the left."
(interactive)
(let ((evil-vsplit-window-right nil))
(call-interactively #'evil-window-vsplit)))
(defun mo-evil-correct-last-sexp (command &rest args)
"In normal-state or motion-state, last sexp ends at point."
;; A false evil-move-beyond-eol is covered by evil-collection
(if (and evil-move-beyond-eol
(or (evil-normal-state-p) (evil-motion-state-p)))
(save-excursion
(unless (or (eobp) (eolp)) (forward-char))
(apply command args))
(apply command args)))
(defun mo-evil-forward-paragraph-recenter ()
"Move to the end of the next paragraph and recenter.
Briefly highlight previous location."
(interactive)
(pulse-momentary-highlight-one-line)
(call-interactively #'evil-forward-paragraph)
(recenter))
(defun mo-evil-backward-paragraph-recenter ()
"Move to the beginning of the previous paragraph and recenter.
Briefly highlight previous location."
(interactive)
(pulse-momentary-highlight-one-line)
(call-interactively #'evil-backward-paragraph)
(recenter))
;; Set word movement to operate on symbol boundaries
(defalias #'forward-evil-word #'forward-evil-symbol)
;; Start with Emacs mode in rustic-popup-mode buffers
(evil-set-initial-state 'rustic-popup-mode 'emacs)
(evil-mode 1))
;; Init Emacs core settings
(use-package emacs
:straight nil
:general
( :keymaps 'mo-quick-menu-map
:prefix "b"
"n w" #'widen
"n f" #'narrow-to-defun
"n r" #'narrow-to-region)
( :keymaps 'mo-quick-menu-map
:prefix "a"
"k" #'kill-process
"s" #'modify-syntax-entry
"r" #'abort-recursive-edit)
( :keymaps 'mo-quick-menu-map
:prefix "l"
"b" #'mo-toggle-lexical-binding)
( :keymaps 'emacs-lisp-mode-map
"C-M-s-r" #'eval-region)
:config
(defun mo-toggle-lexical-binding ()
"Toggle lexical binding in the current buffer."
(interactive)
(message "Lexical binding is %s."
(if (setq lexical-binding (not lexical-binding)) "on" "off")))
;; Inhibit the splash screen
(setq inhibit-splash-screen t)
;; Set the default initial frame size
(add-to-list 'default-frame-alist '( height . 55))
(add-to-list 'default-frame-alist '( width . 210))
;; Don't display startup screen
(setq inhibit-startup-screen t)
;; Scroll incrementally
(setq scroll-step 1)
;; Don't automatically recenter after scrolling
(setq scroll-conservatively 101)
;; Don't create lock files
(setq create-lockfiles nil)
;; Configure auto-save-list
(setq auto-save-list-file-prefix (mo-cache-path "auto-save-list/.saves-"))
;; Disable bell audio
(setq ring-bell-function 'ignore)
;; Use short answers e.g. y or n
(setq use-short-answers t)
;; Truncate lines by default
(setq truncate-lines t)
;; Disable double space at sentence end
(setq sentence-end-double-space nil)
;; Draw the underline at the descent line
(setq x-underline-at-descent-line t)
;; Enable recursive minibuffer
(setq enable-recursive-minibuffers t)
;; Set tab width
(setq-default tab-width 4)
;; Enable indentation and completion using the TAB key
(setq tab-always-indent 'complete)
;; Do not ignore extensions
(setq completion-ignored-extensions nil)
;; Increase saved history size
(setq history-length 1000)
;; Cap command history
(put 'command-history 'history-length 100)
;; Increase undo limits
(setq undo-limit 33554432)
(setq undo-strong-limit 50331648)
(setq undo-outer-limit 134217728)
;; Enable scrolling left
(put 'scroll-left 'disabled nil)
;; Remove vc info from modeline
(setq-default mode-line-format (remove '(vc-mode vc-mode) (default-value 'mode-line-format))))
;; Init files for file related functionality
(use-package files
:demand t
:straight nil
:general
( :keymaps 'mo-quick-menu-map
;; Quick save key binding
"SPC" #'save-buffer)
( :keymaps 'mo-quick-menu-map
"_" #'mo-open-init-file)
( :keymaps 'mo-quick-menu-map
:prefix "f"
"f" #'find-file
"F" #'find-file-literally
"w" #'write-file
"r" #'recover-this-file)
( :keymaps 'mo-quick-menu-map
:prefix "l"
"l" #'load-file)
( :keymaps 'emacs-lisp-mode-map
"C-M-s-b" #'eval-buffer)
( :keymaps 'mo-quick-menu-map
:prefix "b"
"r" #'revert-buffer-quick
"R" #'mo-reload-dir-locals-current-buffer)
( :keymaps 'mo-quick-menu-map
"q" #'save-buffers-kill-terminal)
:config
(defun mo-open-init-file ()
"Open the user's init file."
(interactive)
(find-file user-init-file))
(defun mo-reload-dir-locals-current-buffer ()
"Reload dir-locals for the current buffer."
(interactive)
(hack-dir-local-variables-non-file-buffer))
;; Do not prevent remembering "risky" local variables
(advice-add 'risky-local-variable-p :override #'ignore)
;; Configure backup and auto-saves
(setq backup-directory-alist `( ( "." . ,(mo-cache-path "backups"))))
(setq backup-by-copying t)
(setq delete-old-versions t)
(setq version-control t)
(setq kept-new-versions 6)
(setq kept-old-versions 2)
(setq auto-save-file-name-transforms `( ( ".*" ,(mo-cache-path "backups/") t)))
(setq auto-save-include-big-deletions t)
(setq auto-save-no-message t)
;; Ask for confirmation before exiting emacs
(setq confirm-kill-emacs #'y-or-n-p))
;; Init frame for managing frames
(use-package frame
:demand t
:straight nil
:general
( :keymaps 'mo-quick-menu-map
:prefix "v"
"f" #'make-frame-command
"c" #'delete-frame)
:config
;; Disable cursor blink
(blink-cursor-mode 0)
;; Set font
(set-frame-font mo-font nil t))
;; Init window for managing windows
(use-package window
:demand t
:straight nil
:general
( :keymaps 'override
"C-S-o" #'other-window-prefix
"C-M->" #'mo-current-window-prefix)
( :keymaps 'mo-quick-menu-map
:prefix "w"
"=" #'balance-windows
"C" #'delete-other-windows
"q" #'quit-window
"x" #'mo-quit-other-window)
( :keymaps 'mo-quick-menu-map
:prefix "b"
"q" #'mo-quit-window-kill-buffer
"[" #'previous-buffer
"]" #'next-buffer)
:config
(defun mo-quit-other-window ()
"Quit the other window."
(interactive)
(quit-window nil (previous-window)))
(defun mo-quit-window-kill-buffer ()
"Quit and kill window."
(interactive)
(quit-window t))
(defun mo-current-window-prefix ()
"Display the buffer of the next command in the current window."
(interactive)
(let ((window (selected-window)))
(display-buffer-override-next-command
(lambda (buffer alist)
(cons window 'reuse))
nil "[current-window]")
(message "Display next command buffer in the current window...")))
;; Don't split windows vertically by default
(setq split-height-threshold nil)
;; A fast key binding for showing the next command's result in another window.
;; Make sure it also works when the command is using 'switch-to-buffer'.
(setq switch-to-buffer-obey-display-actions t))
;; Init windmove for directional window selection
(use-package windmove
:straight nil
:general
( :keymaps 'override
"M-<right>" #'windmove-right
"M-<left>" #'windmove-left
"M-<up>" #'windmove-up
"M-<down>" #'windmove-down))
;; Init simple for basic and general Emacs commands
(use-package simple
:demand t
:straight nil
:general
( :keymaps 'override
"C-<f12>" #'mo-toggle-scratch-buffer)
( :keymaps 'mo-quick-menu-map
:prefix "b"
"t" #'toggle-truncate-lines
"v" #'visual-line-mode
"f" #'auto-fill-mode
"F" #'set-fill-column
"I" #'clone-indirect-buffer
"k" #'kill-current-buffer)
( :keymaps 'mo-quick-menu-map
;; Universal argument key binding
"u" #'universal-argument)
( :keymaps 'mo-quick-menu-map
:prefix "x"
;; List all sub processes
"P" #'list-processes
"x" #'async-shell-command)
( :keymaps 'mo-quick-menu-map
:prefix "l"
"e" #'eval-expression)
( :keymaps 'mo-quick-menu-map
:prefix "c"
"RET" #'mo-async-run-code)
( :states 'motion
"g \"" #'end-of-buffer)
( :states 'motion
"g '" #'beginning-of-buffer)
:config
(defvar-local mo-run-code-command nil
"A local var that stores the run code command.
To be used with `mo-async-run-code'.")
(put 'mo-run-code-command 'safe-local-variable 'stringp)
(defun mo-async-run-code ()
"Run code by asynchronously executing `mo-run-code-command'.
When running with a prefix argument, or if `mo-run-code-command' is null, prompt
the user to input the run command."
(interactive)
(setq-local mo-run-code-command
(if (and (not current-prefix-arg)
(and (boundp 'mo-run-code-command) mo-run-code-command))
mo-run-code-command
(read-string "Run code command: ")))
(let ((default-directory (project-root (project-current t))))
(async-shell-command mo-run-code-command "*Run Code Command*")))
(defun mo-toggle-scratch-buffer ()
"Toggle the scratch buffer."
(interactive)
(let ((window (get-buffer-window "*scratch*")))
(if window
(quit-window nil window)
(scratch-buffer))))
;; Set a wide enough default fill-column
(setq-default fill-column 100)
;; Disable default tab indentation
(setq-default indent-tabs-mode nil)
;; Disable blinking matching paren as we use show-paren-mode instead
(setq blink-matching-paren nil)
;; Show cursor's column number
(setq column-number-mode t)
;; Create a new buffer if async shell buffer already in use
(setq async-shell-command-buffer 'new-buffer))
;; Init comp for native compilation settings
(use-package comp
:straight nil
:config
(setq native-comp-async-report-warnings-errors 'silent))
;; Init custom for declaring and initializing user options
(use-package custom
:straight nil
:config
(defvar after-enable-theme-hook nil
"Hook run after a theme is enabled using `enable-theme'.")
(defadvice enable-theme (after run-after-enable-theme-hook activate)
"Run `after-enable-theme-hook'."
(run-hooks 'after-enable-theme-hook)))
;; Init cus-edit for creating and editing customize buffers
(use-package cus-edit
:straight nil
:config
;; Set customization file path
(setq custom-file (expand-file-name "custom.el" user-emacs-directory)))
;; Init minibuffer for minibuffer support
(use-package minibuffer
:straight nil
:config
;; Ignore case on file name completions
(setq read-file-name-completion-ignore-case t))
;; Init imenu for imenu support
(use-package imenu
:straight nil
:config
(setq imenu-max-item-length nil))
;; Init ibuffer for editing buffer lists
(use-package ibuffer
:straight nil
:general
( :keymaps 'mo-quick-menu-map
:prefix "b"
"i" #'ibuffer))
;; Init bufler for an improved ibuffer
(use-package bufler
:general
( :keymaps 'mo-quick-menu-map
:prefix "b"
"RET" #'bufler
"SPC" #'bufler-switch-buffer))
;; Init repeat for repeating previous commands
(use-package repeat
:straight nil
:general
( :keymaps 'mo-quick-menu-map
:prefix "z"
"z" #'repeat))
;; Init kmacro for keyboard macros
(use-package kmacro
:straight nil
:general
( :keymaps 'mo-quick-menu-map
:prefix "k"
"k" #'kmacro-start-macro-or-insert-counter
"c" #'kmacro-end-or-call-macro
"e" #'kmacro-edit-macro
"E" #'kmacro-step-edit-macro
"s" #'kmacro-set-counter
"f" #'kmacro-set-format
"r" #'kmacro-edit-lossage
"v" #'kmacro-view-macro
"d" #'kmacro-delete-ring-head
"n" #'kmacro-cycle-ring-next
"p" #'kmacro-cycle-ring-previous)
;; Unbind global macro bindings
( :keymaps 'global
"<f3>" nil
"<f4>" nil))
;; Init macros for controlling macros
(use-package macros
:straight nil
:general
( :keymaps 'mo-quick-menu-map
:prefix "k"
"q" #'kbd-macro-query))
;; Init env for manipulating environment variables
(use-package env
:straight nil
:general
( :keymaps 'mo-quick-menu-map
:prefix "a"
"e" #'setenv))
;; Init modus-operandi-emacs for non-package related functionality
(use-package modus-operandi-emacs
:after ( simple project tab-bar vertico consult)
:straight nil
:no-require t ; Not a package
:demand t
:general
( :keymaps 'mo-quick-menu-map
:prefix "b"
"p" #'mo-copy-file-path)
( :keymaps 'mo-quick-menu-map
:prefix "DEL"
"DEL" #'mo-open-project-with-tab
"ESC" #'mo-close-project-with-tab
"RET" #'mo-execute-predefined-command)
( :keymaps 'vertico-map
"C-<return>" #'mo-minibuffer-insert-file-pattern
"C-<escape>" #'mo-minibuffer-insert-file-excl-pattern)
:preface
(defun mo-copy-file-path ()
"Copy the full path of the current buffer's file."
(interactive)
(let ((filepath (if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name))))
(when filepath
(kill-new filepath)
(message "%s" filepath))))
(defun mo-open-project-with-tab ()
"Open project with new tab.
Tab is named after the project's name."
(interactive)
(tab-bar-new-tab)
(condition-case err
(progn
(call-interactively #'project-switch-project)
(let ((project-dir (directory-file-name (project-root (project-current))))
(tab-name nil))
(cl-loop for path-part in (reverse (file-name-split project-dir))
do (setq tab-name (file-name-concat path-part tab-name))
while (tab-bar--tab-index-by-name tab-name))
(tab-bar-rename-tab tab-name)))
(quit
(tab-bar-close-tab))))
(defun mo-close-project-with-tab ()
"Kill project buffers and close tab.
Tab is named after the project's name."
(interactive)
(call-interactively #'project-kill-buffers)
(tab-bar-close-tab))
(defvar-local mo-predefined-commands nil
"An alist containing command names and their respective command lines.")
(put 'mo-predefined-commands 'safe-local-variable #'listp)
(defun mo-execute-predefined-command ()
"Select and execute a predefined command."
(interactive)
(let ((project-dir (project-root (project-current t)))
(command (cdr
(assoc
(completing-read
"Execute Command: "
mo-predefined-commands
nil
t)
mo-predefined-commands))))
(let ((default-directory project-dir))
(async-shell-command command))))
(defun mo-show-modified-buffer-changes ()
"If a buffer is different from its file, show the changes."
(let ((buffer buffer-file-name))
(when (and buffer (file-exists-p buffer) (buffer-modified-p))
(let ((diff-window (diff-buffer-with-file)))
(add-hook 'kill-buffer-hook
(lambda ()
(quit-window nil diff-window))
nil t))))
t)
(defun mo-show-welcome-screen ()
"Show welcome screen."
(with-current-buffer (get-buffer-create "*Welcome*")
(setq truncate-lines t)
(let* ((buffer-read-only)
(image-path (expand-file-name "emacs.png" user-emacs-directory))
(image (create-image image-path))
(size (image-size image))
(height (cdr size))
(width (car size))
(top-margin (floor (/ (- (window-height) height) 2)))
(left-margin (floor (/ (- (window-width) width) 2)))
(title "Welcome to Modus Operandi Emacs!")
(subtitle "In Absentia Lucis, Tenebrae Vincunt."))
(setq mode-line-format nil)
(goto-char (point-min))
(insert (make-string top-margin ?\n ))
(insert (make-string left-margin ?\ ))
(insert-image image)
(insert "\n\n\n")
(insert (make-string (floor (/ (- (window-width) (string-width title)) 2)) ?\ ))
(insert (propertize title 'face 'bold))
(insert "\n")
(insert (make-string (floor (/ (- (window-width) (string-width subtitle)) 2)) ?\ ))
(insert (propertize subtitle 'face 'font-lock-comment-face))
(goto-char (point-min)))
(switch-to-buffer (current-buffer))
(read-only-mode +1)))
(defun mo-show-welcome-screen-graphic-mode ()
"Show welcome screen only on graphic mode."
(when (display-graphic-p)
(mo-show-welcome-screen)))
(defvar mo-minibuffer-file-excl-pattern '( ".*?" . ".*?:[[:digit:]]+:")
"Minibuffer file exclusion pattern.")
(defun mo-minibuffer-insert-file-excl-pattern ()
"Insert a file exclusion pattern to the minibuffer filter."
(interactive)
(mo-minibuffer-insert-file-pattern t))
(defun mo-minibuffer-insert-file-pattern (&optional arg)
"Insert a file pattern to the minibuffer filter.
If universal ARG is set, exclude the pattern."
(interactive "P")
(when (minibufferp)
(let* ((consult-asyncp (member consult-async-map (current-local-map)))
(consult-async-style (and consult-asyncp consult-async-split-style))
(consult-async-delimiter ?`)
(prompt-end (minibuffer-prompt-end)))
(if consult-async-style
(progn
(unless (eq consult-async-style 'perl)
(user-error "Only 'perl' consult async split style is supported"))
;; Ensure initial consult async delimiter
(goto-char prompt-end)
(unless (eq (char-after) consult-async-delimiter)
(insert consult-async-delimiter))
;; Ensure the second async delimiter
(goto-char (point-max))
(if (> (how-many (char-to-string consult-async-delimiter) prompt-end) 1)
(insert " ")
(insert consult-async-delimiter)))
(goto-char (point-max))
(unless (eq (minibuffer-prompt-end) (point))
(insert " ")))
;; Insert negation operator, if excluding
(when arg
(insert "!"))
;; Insert file pattern
(dolist (pattern (list (car mo-minibuffer-file-excl-pattern)
(cdr mo-minibuffer-file-excl-pattern)))
(insert (propertize pattern 'display (propertize (make-string 1 ?:) 'face 'shadow))))
(backward-char (length (cdr mo-minibuffer-file-excl-pattern))))))
;; Modeline configuration
(defvar-local mo-lsp-mode-mode-line nil
"Holds the modeline list for lsp-mode.")
;; Needed for displaying in `mode-line-format'
(put 'mo-lsp-mode-mode-line 'risky-local-variable t)
;; Add lsp modeline string to modeline format
(setq-default mode-line-format (append
(butlast (default-value 'mode-line-format) 2)
(list 'mo-lsp-mode-mode-line)
(last (default-value 'mode-line-format) 2)))
:config
(when (< (length command-line-args) 2)
(add-hook 'emacs-startup-hook #'mo-show-welcome-screen-graphic-mode))
;; When killing a modified buffer, show the changes
(add-to-list 'kill-buffer-query-functions #'mo-show-modified-buffer-changes t))
;; Add evil key bindings to other, non-default, modes
(use-package evil-collection
:after ( general evil xref magit sly)
:commands ( general-define-key
evil-collection-init)
:defines ( evil-collection-want-find-usages-bindings
evil-collection-want-unimpaired-p)
:demand t
:init
(defvar forge-add-default-bindings nil)
:config
(defun mo-evil-collection-remove-quick-menu-prefix (_mode keymaps &rest _rest)
"Remove bindings conflicting with the quick menu prefix key from KEYMAPS."
(dolist (keymap keymaps)
(when (and (boundp keymap) (symbol-value keymap))
(general-define-key :keymaps keymap :states 'normal "," nil))))
;; We have our own find references key binding. Remove evil-collection's one.
;; evil-collection's find usages overrides evil-mc key bindings.
(setq evil-collection-want-find-usages-bindings nil)
(setq evil-collection-want-unimpaired-p nil)
(evil-collection-init)
;; Init dired+ for additional dired functionality
;; Init the package after evil-collection is both loaded and configured, so directory
;; reusing will be configured correctly.
(use-package dired+
:functions diredp-toggle-find-file-reuse-dir
:custom
( diredp-hide-details-initially-flag nil)
:config
(setq diredp-ignore-compressed-flag nil)
(diredp-toggle-find-file-reuse-dir 1)
;; These hooks seem to degrade performance on some scenarios
(remove-hook 'dired-after-readin-hook 'diredp-nb-marked-in-mode-name)
(remove-hook 'dired-mode-hook 'diredp-nb-marked-in-mode-name))
:hook
( evil-collection-setup . mo-evil-collection-remove-quick-menu-prefix))
;; Init evil-org for supporting evil key bindings in org-mode
(use-package evil-org
:after org
:functions evil-org-agenda-set-keys
:general
( :definer 'minor-mode
:keymaps 'evil-org-mode
:states 'normal
;; Remove evil org insert heading bindings
"C-<return>" nil
"C-S-<return>" nil)
:hook
( org-mode . evil-org-mode)
( org-agenda-mode . evil-org-mode)
:config
(require 'evil-org-agenda)
(evil-org-agenda-set-keys))
;; Init evil-mc for supporting multiple cursors in evil mode
(use-package evil-mc
:demand t
:general
( :keymaps 'mo-quick-menu-map
:prefix "r"
"RET" #'evil-mc-make-cursor-here
"a" #'evil-mc-make-all-cursors
"A" #'evil-mc-make-cursor-in-visual-selection-end
"I" #'evil-mc-make-cursor-in-visual-selection-beg
"o" #'evil-mc-make-cursor-move-next-line
"O" #'evil-mc-make-cursor-move-prev-line
"p" #'evil-mc-pause-cursors
"r" #'evil-mc-resume-cursors
"n" #'evil-mc-make-and-goto-next-match
"N" #'evil-mc-make-and-goto-prev-match
"s" #'evil-mc-skip-and-goto-next-match
"S" #'evil-mc-skip-and-goto-prev-match
"j" #'evil-mc-make-and-goto-next-cursor
"J" #'evil-mc-skip-and-goto-next-cursor
"k" #'evil-mc-make-and-goto-prev-cursor
"K" #'evil-mc-skip-and-goto-prev-cursor
"^" #'evil-mc-make-and-goto-first-cursor
"$" #'evil-mc-make-and-goto-last-cursor
"u" #'evil-mc-undo-last-added-cursor
"ESC" #'evil-mc-undo-all-cursors)
:config
(global-evil-mc-mode))
;; Init evil-surround for quickly adding paired surrounding characters
(use-package evil-surround
:demand t
:general
( :states 'visual
"s" #'evil-surround-region)
:config
(global-evil-surround-mode 1))
;; Init anzu for showing additional search match info
(use-package anzu
:functions global-anzu-mode
:config
(global-anzu-mode +1))
;; Init evil-anzu for anzu integration with evil search
(use-package evil-anzu
:after evil)
;; Init avy for text zapping using free text and a timeout
(use-package avy
:demand t
:hook
( after-enable-theme . mo-avy-configure-theme)
:config
:general
( :keymaps 'override
"C-;" #'avy-goto-char-timer)
:config
(defun mo-avy-configure-theme ()
"Set avy theme configuration."
;; Better highlight the leading characters
(set-face-attribute 'avy-lead-face nil :background "gold2")
(set-face-attribute 'avy-lead-face-0 nil :background "gold3")
(set-face-attribute 'avy-lead-face-1 nil :background "gold4")
(set-face-attribute 'avy-lead-face-2 nil :background "DarkGoldenrod4"))
(setq avy-single-candidate-jump nil)
(setq avy-all-windows 'all-frames)
(setq avy-timeout-seconds 0.2))
;; Init evil-easymotion for using avy with evil motions
(use-package evil-easymotion
:functions evilem-default-keybindings
:config
(evilem-default-keybindings ";"))
;; Init link-hint for quick link selection
(use-package link-hint
:general
( :keymaps 'override
"C-\"" #'link-hint-open-link))
;; Init evil-snipe for an improved 1 char evil search experience
(use-package evil-snipe
:functions evil-snipe-override-mode
:custom
( evil-snipe-override-evil-repeat-keys nil)
:config
(evil-snipe-override-mode 1))
;; Init expand-region for expanding the selected region by semantic units
(use-package expand-region
:general
( :keymaps 'override
"C-M-<return>" #'er/expand-region
"C-M-<escape>" #'er/contract-region))
;; Init evil-numbers for increasing/decreasing number at point
(use-package evil-numbers
:general
( :states '( normal visual)
"z i" #'evil-numbers/inc-at-pt
"z d" #'evil-numbers/dec-at-pt))
;; Init two-column for editing two-column texts
(use-package two-column
:straight nil
:general
;; Unbind global menu shortcut binding
( :keymaps 'global
"<f2>" nil))
;; Init paredit for parenthetical editing in Emacs
(use-package paredit
:general
( :keymaps 'paredit-mode-map
"C-{" #'paredit-forward-barf-sexp
"C-}" #'paredit-forward-slurp-sexp
"M-{" #'paredit-backward-slurp-sexp
"M-}" #'paredit-backward-barf-sexp
"C-M-{" #'paredit-splice-sexp-killing-backward
"C-M-}" #'paredit-splice-sexp-killing-forward
"M-(" #'mo-paredit-wrap-round-with-space
"C-M-(" #'paredit-wrap-round)
( :keymaps 'paredit-mode-map
:states 'motion
"[" nil
"]" nil)
( :keymaps 'paredit-mode-map
:states 'normal
"[" #'paredit-splice-sexp-killing-backward
"]" #'paredit-splice-sexp-killing-forward)
:config
(defun mo-paredit-wrap-round-with-space ()
"Wrap the following S-expression and insert a space."
(interactive)
(paredit-wrap-round)
(save-excursion
(insert " ")))
:hook
(lisp-data-mode . enable-paredit-mode)
(sly-mrepl . enable-paredit-mode))
;; Init evil-cleverparens for lisp modal editing
(use-package evil-cleverparens
:general
( :keymaps 'evil-cleverparens-mode-map
:states 'normal
"M-k" #'evil-cp-drag-backward
"M-j" #'evil-cp-drag-forward
"M-a" #'evil-cp-insert-at-end-of-form
"M-i" #'evil-cp-insert-at-beginning-of-form
"M-w" #' evil-cp-copy-paste-form)
:custom
( evil-cleverparens-use-additional-bindings nil)
( evil-cleverparens-use-additional-movement-keys nil)
( evil-cleverparens-use-s-and-S nil)
( evil-cleverparens-use-regular-insert t)