-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinit.el
executable file
Β·2484 lines (2290 loc) Β· 88.9 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 --- My config -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
;; useful for quickly debugging Emacs
;; (setq debug-on-error t)
(setenv "LSP_USE_PLISTS" "true")
;;; Startup
(add-hook 'emacs-startup-hook
(lambda ()
(message "*** Emacs loaded in %s seconds with %d garbage collections."
(emacs-init-time "%.2f")
gcs-done)))
;; Make it easy to jump between packages
(setopt use-package-enable-imenu-support t)
;; Get clipboard to work when using wsl
(defconst running-in-wsl (executable-find "wslpath"))
(when running-in-wsl
(defun wls-copy (text)
(let ((wls-copy-process (make-process :name "clip.exe"
:buffer nil
:command '("clip.exe")
:connection-type 'pipe)))
(process-send-string wls-copy-process text)
(process-send-eof wls-copy-process)))
(setq interprogram-cut-function 'wls-copy))
(setq initial-scratch-message nil
initial-major-mode 'emacs-lisp-mode
inhibit-startup-screen t)
(defvar file-name-handler-alist-old file-name-handler-alist)
(setq file-name-handler-alist nil
gc-cons-threshold most-positive-fixnum)
;; Lower threshold to speed up garbage collection
(add-hook 'after-init-hook
#'(lambda ()
(setq file-name-handler-alist file-name-handler-alist-old)
(setq gc-cons-threshold (* 2 1000 1000))
(setq gc-cons-percentage 0.1))
t)
;;; Backups
(setq backup-directory-alist `(("." . ,(locate-user-emacs-file "backups")))
vc-make-backup-files t
version-control t
kept-old-versions 0
kept-new-versions 10
delete-old-versions t
backup-by-copying t)
;;; PACKAGE LIST
(setq package-install-upgrade-built-in t)
(setq package-archives
'(("melpa" . "https://melpa.org/packages/")
("elpa" . "https://elpa.gnu.org/packages/")
;; ("gnu-devel" . "https://elpa.gnu.org/devel/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")))
;;; BOOTSTRAP USE-PACKAGE
(package-initialize)
(eval-when-compile (require 'use-package))
(setq use-package-verbose t
native-comp-async-report-warnings-errors nil)
;; Install and load `quelpa-use-package'.
(setq quelpa-update-melpa-p nil)
(package-install 'quelpa-use-package)
(require 'quelpa-use-package)
;; Keep custom-set-variables and friends out of my init.el
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
(load custom-file))
;;; ASYNC
;; Emacs look SIGNIFICANTLY less often which is a good thing.
;; asynchronous bytecode compilation and various other actions makes
(use-package async
:ensure t
:after dired
:init
(dired-async-mode 1))
(use-package savehist
:defer 2
:init
(savehist-mode t)
;; So I can always jump back to wear I left of yesterday
(add-to-list 'savehist-additional-variables 'global-mark-ring))
(use-package repeat
:defer 10
:init
(repeat-mode +1))
;;; MY STUFF
(use-package custom-variables
:ensure nil :no-require t :demand t
:init
(cl-defmacro let-regex ((bindings (string regex)) &body body)
"Macro for creating BINDINGS to captured blocks of REGEX found in a STRING.
BINDINGS: A list of different symbols to be bound to a captured section of the regex
STRING: The string the regex is searching through
REGEX: Regex used to match against the string
If no binding is captured section of regex is found for a BINDING an error is signaled
;; Example usage
(let-regex ((h w) (\"hello world\" \"\\(hello\\) \\(world\\)\"))
(message \"result was %s then %s\" h w))"
(let ((holder (gensym)))
`(let ((,holder (with-temp-buffer
(insert ,string)
(beginning-of-buffer)
(search-forward-regexp ,regex nil nil)
(let ((i 0))
(mapcar (lambda (_a)
(setq i (+ i 1))
(match-string i))
'( ,@bindings))))))
(let ,(mapcar (lambda (binding)
`(,binding (or (pop ,holder)
(error "Failed to find binding for %s"
',binding))))
bindings)
,@body))))
(defvar my/is-termux
(string-suffix-p
"Android" (string-trim (shell-command-to-string "uname -a")))
"Truthy value indicating if Emacs is currently running in termux.")
(defvar my/is-terminal
(not window-system)
"Truthy value indicating if Emacs is currently running in a terminal.")
(defvar my/my-system
(equal "gavinok" (getenv "USER"))
"Non-nil value if this is my system."))
(use-package image-mode
:bind (:map image-mode-map
("&" . my/shell-command-on-file)
("<down-mouse-1>" . (lambda ()
(interactive)
(dnd-begin-file-drag (buffer-file-name)))))
:config
(defun my/dnd-this-file ()
"Begin dragging the current file using drag and drop"
(interactive)
(dnd-begin-file-drag (buffer-file-name))))
(use-package custom-functions
:ensure nil :no-require t
:bind (([remap scroll-up-command] . my/scroll-down)
([remap scroll-down-command]. my/scroll-up)
("C-M-&" . my/shell-command-on-file)
("C-x O" . other-other-window)
("M-f" . sim-vi-w)
("C-x n a" . my/increment-number-at-point)
("C-x n x" . my/decrement-number-at-point)
("C-c d" . my/next-fn)
:repeat-map my/next-fn-map
("d" . my/next-fn)
:repeat-map change-number-repeat-map
("a" . my/increment-number-at-point)
("x" . my/decrement-number-at-point))
:init
(defun my/next-fn (&optional arg)
(interactive "P")
(apply (if arg
#'text-property-search-backward
#'text-property-search-forward)
'face
(cond
((eql major-mode 'haskell-mode) 'haskell-definition-face)
(t 'font-lock-function-name-face))
nil))
(defun my/change-number-at-point (change increment)
(search-forward-regexp (rx digit)) ; Go to the closest number
(let ((number (number-at-point))
(point (point)))
(when number
(progn
(forward-word)
(search-backward (number-to-string number))
(replace-match (number-to-string (funcall change number increment)))
(goto-char (- point 1))))))
(defun my/increment-number-at-point (&optional increment)
"Increment number at point like vim's C-a"
(interactive "p")
(my/change-number-at-point '+ (or increment 2)))
(defun my/decrement-number-at-point (&optional increment)
"Decrement number at point like vim's C-x"
(interactive "p")
(my/change-number-at-point '- (or increment 1)))
(defun my/scroll-down (_arg)
"Move cursor down half a screen ARG times."
(interactive "p")
(let ((dist (/ (window-height) 2)))
(forward-line dist)))
(defun my/scroll-up (_arg)
"Move cursor up half a screen ARG times."
(interactive "p")
(let ((dist (/ (window-height) 2)))
(forward-line (- dist))))
(defun my/shell-command-on-file (command)
"Execute COMMAND asynchronously on the current file."
(interactive (list (read-shell-command
(concat "Async shell command on " (buffer-name) ": "))))
(let ((filename (if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name))))
(async-shell-command (concat command " " filename))))
(defun eqn-to-tex (eqn-expression)
"Takes a eqn expression as a string string EQN-EXPRESSION and
returns the equivalent latex version."
(calc-eval `(,eqn-expression
calc-simplify-mode none
calc-language eqn)
'push)
(calc-eval '(1
calc-simplify-mode none
calc-language latex)
'top))
(defun echo-eqn-to-tex (eqn-expr &optional _arg)
"Takes an eqn expression eqn-expr and prints a message with the
latex version of it."
(interactive "sEnter eqn here: ")
(message (eqn-to-tex eqn-expr)))
(defun eqn-to-tex-region (start end)
"Replaces the active region containing a eqn expression and
replaces it with the Latex equivalent."
(interactive "r")
(let ((converted-expr (eqn-to-tex (filter-buffer-substring start end))))
(kill-region start end)
(insert converted-expr)))
(defun all-history ()
"Command for getting command history from basically every source out
there.
No more \"Where did I call that again?\" going off in your head"
(interactive)
(cl-flet ((file->lines (file-name)
(split-string (with-temp-buffer
(insert-file-contents-literally file-name)
(buffer-substring-no-properties (point-min) (point-max)))
"\n")))
(completing-read
"All History: "
(append shell-command-history
compile-history
(when (boundp 'eshell-history-file-name)
(file->lines eshell-history-file-name))
(file->lines (getenv "HISTFILE"))))))
(defun gist-from-region (BEG END fname desc &optional private)
"Collect the current region creating a github gist with the
filename FNAME and description DESC.
If the optional argument PRIVATE is non-nil then the gist will be
made private. Otherwise the gist will be default to public.
Depends on the `gh' commandline tool"
(interactive (list (mark) (point)
(read-string "File Name: ")
(read-string "Description: ")
current-prefix-arg))
(let* ((extra-args (unless private '("--public")))
(command `("gh" "gist" "create"
"--filename" ,fname
"--desc" ,desc
,@extra-args
"-"))
(proc (make-process :name "Gist Creation"
:buffer "*Gist URL*"
:command command
:sentinel (lambda (process event)
"Listens for process finish and prints the gist's URL"
(unless (process-live-p process )
(if (string-match "finis.*" event)
(let ((select-enable-clipboard t)
(url (with-current-buffer (process-buffer process)
(goto-char (point-max))
(thing-at-point 'line))))
(message "Gist for file %s created at %s (copied to clipboard)"
fname url)
(kill-new url))
(switch-to-buffer "*Gist URL*")))))))
(message "Creating Gist")
(process-send-region proc BEG END)
(process-send-eof proc)
(process-send-eof proc)))
(defun other-other-window (&optional arg)
(interactive)
(if arg
(other-window (- arg))
(other-window -1)))
(defun sim-vi-w (&optional arg)
"Simulate Vi's \"w\" behavior"
(interactive "P")
(forward-word arg)
(search-forward-regexp "[^[:space:]]")
(forward-char -1)))
;;; Defaults
(use-package undo-fu-session ; Persistant undo history
:ensure t
:demand t
:bind (("C-x u" . undo-only)
("C-/" . undo-only)
("C-?" . undo-redo)
("C-z" . undo-only)
("C-S-z" . undo-redo))
:config (global-undo-fu-session-mode))
(use-package emacs
:ensure nil
:demand t
:bind (("C-c w" . fixup-whitespace)
("C-x C-d" . delete-pair)
("M-c" . capitalize-dwim)
("M-u" . upcase-dwim)
("M-l" . downcase-dwim)
("M-z" . zap-up-to-char)
("C-x S" . shell)
("C-x M-t" . transpose-regions)
("C-;" . negative-argument)
("C-M-;" . negative-argument)
("C-g" . my/keyboard-quit-only-if-no-macro)
)
:config
(defun my/keyboard-quit-only-if-no-macro ()
"A workaround to let me accidently hit C-g while recording a macro"
(interactive)
(if (or defining-kbd-macro executing-kbd-macro)
(progn
(if (region-active-p)
(deactivate-mark)
(message "Macro running. Can't quit.")))
(keyboard-quit)))
;; Set the title of the frame to the current file - Emacs
(setq-default frame-title-format '("%b - Emacs"))
;; No delay when deleting pairs
(setopt delete-pair-blink-delay 0)
(blink-cursor-mode -1)
;; change truncation indicators
(define-fringe-bitmap 'right-curly-arrow
[#b10000000 #b10000000 #b01000000
#b01000000 #b00100000 #b00100000
#b00010000 #b00010000 #b00001000
#b00001000 #b00000100 #b00000100])
(define-fringe-bitmap 'left-curly-arrow
[#b00000100 #b00000100 #b00001000
#b00001000 #b00010000 #b00010000
#b00100000 #b00100000 #b01000000
#b01000000 #b10000000 #b10000000])
;;;; Defaults
;; Handle long lines
(setopt bidi-paragraph-direction 'left-to-right)
(setopt bidi-inhibit-bpa t)
(global-so-long-mode 1)
(setopt history-length 1000
use-dialog-box nil
delete-by-moving-to-trash t
create-lockfiles nil
auto-save-default nil
ring-bell-function 'ignore)
;;;; UTF-8
(prefer-coding-system 'utf-8)
;;;; Remove Extra Ui
(setopt use-short-answers t) ; don't ask to spell out "yes"
(setopt show-paren-context-when-offscreen 'overlay) ; Emacs 29
(show-paren-mode 1) ; Highlight parenthesis
;; (if running-in-wsl
;; (setq-default select-enable-primary t) ; use primary as clipboard in emacs
;; (setq select-enable-primary nil))
(setq-default select-enable-primary t)
;; avoid leaving a gap between the frame and the screen
(setq-default frame-resize-pixelwise t)
;; Vim like scrolling
(setq scroll-step 1
scroll-conservatively 10000
next-screen-context-lines 5
;; move by logical lines rather than visual lines (better for macros)
line-move-visual nil)
;;TRAMP
(setq tramp-default-method "ssh"
shell-file-name "bash") ; don't use zsh
;; For using local lsp's with tramp
;; (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
;; recentf
(setopt recentf-make-menu-items 150)
(setopt recentf-make-saved-items 150))
(use-package time
:init
(setopt world-clock-time-format "%a %d %b %I:%M%p %Z")
(setopt zoneinfo-style-world-list
'(("Asia/Hawaii" "Hilo")
("America/Edmonton" "Calgary")
("America/Vancouver" "Vancouver")
("America/New_York" "New York")
("America/Whitehorse" "Whitehorse")
("Europe/London" "London")
("Asia/Tokyo" "Tokyo"))))
(use-package font-setup :ensure nil :no-require t
:demand t
:when my/my-system
:init
;; Fonts
;; The concise one which relies on "implicit fallback values"
(use-package fontaine
:ensure t
:unless my/is-terminal
:config
(setopt fontaine-presets
'((regular
:default-height 140)
(small
:default-height 110)
(large
:default-weight semilight
:default-height 180
:bold-weight extrabold)
(extra-large
:default-weight semilight
:default-height 210
:line-spacing 5
:bold-weight ultrabold)
(t ; our shared fallback properties
:default-family "PragmataPro Mono Liga")))
(fontaine-set-preset 'regular))
;; Load pragmatapro-lig.el
;; (load (locate-user-emacs-file
;; "lisp/pragmatapro-prettify-symbols-v0.829.el"))
;; (add-hook 'prog-mode-hook 'prettify-hook)
;; (require 'pragmatapro-lig)
;; Enable pragmatapro-lig-mode for specific modes
;; (set-fontset-font "fontset-default" 'unicode "Symbola" nil 'prepend)
;; Use twitter emojis cuz I like them
(set-fontset-font "fontset-default" 'emoji "Twemoji" nil 't))
(setq treesit-language-source-alist
'((templ "https://github.com/vrischmann/tree-sitter-templ")
(bash "https://github.com/tree-sitter/tree-sitter-bash")
(cmake "https://github.com/uyha/tree-sitter-cmake")
(css "https://github.com/tree-sitter/tree-sitter-css")
(elisp "https://github.com/Wilfred/tree-sitter-elisp")
(go "https://github.com/tree-sitter/tree-sitter-go")
(gomod "https://github.com/camdencheek/tree-sitter-go-mod")
(html "https://github.com/tree-sitter/tree-sitter-html")
(javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src")
(dockerfile "https://github.com/camdencheek/tree-sitter-dockerfile")
(json "https://github.com/tree-sitter/tree-sitter-json")
(make "https://github.com/alemuller/tree-sitter-make")
(markdown "https://github.com/ikatyang/tree-sitter-markdown")
(python "https://github.com/tree-sitter/tree-sitter-python")
(toml "https://github.com/tree-sitter/tree-sitter-toml")
(tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")
(typescript "https://github.com/tree-sitter/tree-sitter-typescript"
"master" "typescript/src")
(yaml "https://github.com/ikatyang/tree-sitter-yaml")
(haskell "https://github.com/tree-sitter/tree-sitter-haskell")
(typst "https://github.com/uben0/tree-sitter-typst")
(java "https://github.com/tree-sitter/tree-sitter-java")
(ruby "https://github.com/tree-sitter/tree-sitter-ruby")
(rust "https://github.com/tree-sitter/tree-sitter-rust")))
(use-package unified-marks :ensure nil :no-require t
:custom
(global-mark-ring-max 256)
(set-mark-command-repeat-pop 256)
:init
;; Unify Marks
(define-advice push-mark (:after (&optional _location _nomsg _activate)
my/push-mark-global)
"Always push to the global mark when push-mark is called"
(let ((old (nth global-mark-ring-max global-mark-ring))
(history-delete-duplicates nil))
(add-to-history
'global-mark-ring (copy-marker (mark-marker))
global-mark-ring-max t)
(when old
(set-marker old nil)))))
;;; General Key Bindings
(use-package crux
:ensure t
:bind (("C-x w v" . crux-swap-windows)
("C-S-o" . crux-smart-open-line-above)
("C-o" . crux-smart-open-line)
("C-x B" . my/org-scratch)
:map dired-mode-map
("O" . crux-open-with))
:config
(defun my/org-scratch ()
(interactive)
(let ((initial-major-mode 'org-mode))
(crux-create-scratch-buffer))))
(use-package simple
:ensure nil
:bind (("M-SPC" . cycle-spacing)))
;;; TERMINAL SETTINGS
(when my/is-terminal
(progn (set-face-background 'default "undefinded")
(add-to-list 'term-file-aliases
'("st-256color" . "xterm-256color"))
(xterm-mouse-mode t)))
;;; Aligning Text
(use-package align
:ensure nil
:defer t
:bind ("C-x a a" . align-regexp)
:config
;; Align using spaces
(defadvice align-regexp (around align-regexp-with-spaces activate)
(let ((indent-tabs-mode nil))
ad-do-it)))
;;; COMPLETION
(use-package vertico
:ensure t
:init
;; Enable vertico using the vertico-flat-mode
(require 'vertico-directory)
(add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy)
(use-package orderless
:ensure t
:commands (orderless)
:custom (completion-styles '(orderless flex)))
(use-package marginalia
:ensure t
:custom
(marginalia-annotators
'(marginalia-annotators-heavy marginalia-annotators-light nil))
:config
(marginalia-mode))
(vertico-mode t)
:config
;; 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)
;; Enable recursive minibuffers
(setq enable-recursive-minibuffers t)
(minibuffer-depth-indicate-mode 1))
;;;; Extra Completion Functions
(use-package consult
:ensure t
:after vertico
:bind (("C-x b" . consult-buffer)
("C-x C-k C-k" . consult-kmacro)
("M-y" . consult-yank-pop)
("M-g g" . consult-goto-line)
("M-g M-g" . consult-goto-line)
("M-g f" . consult-flymake)
("M-g i" . consult-imenu)
("M-s l" . consult-line)
("M-s L" . consult-line-multi)
("M-s u" . consult-focus-lines)
("M-s g" . consult-ripgrep)
("M-s M-g" . consult-ripgrep)
("M-s f" . consult-find)
("M-s M-f" . consult-find)
("C-x C-SPC" . consult-global-mark)
("C-x M-:" . consult-complex-command)
("C-c n" . consult-org-agenda)
("M-X" . consult-mode-command)
:map minibuffer-local-map
("M-r" . consult-history)
:map Info-mode-map
("M-g i" . consult-info)
:map org-mode-map
("M-g i" . consult-org-heading))
:custom
(completion-in-region-function #'consult-completion-in-region)
:config
(recentf-mode t))
;; (use-package consult-gh
;; :init
;; (unless (package-installed-p 'consult-gh)
;; (package-vc-install
;; '(consult-gh :url "https://github.com/armindarvish/consult-gh")))
;; )
;; (use-package consult-gh
;; :init
;; (unless (package-installed-p 'consult-gh)
;; (package-vc-install
;; '(consult-gh :url "https://github.com/armindarvish/consult-gh.git")))
;; )
;; (use-package consult-gh
;; :ensure nil
;; :quelpa (consult-gh :fetcher github :repo "armindarvish/consult-gh"))
(use-package consult-dir
:ensure t
:bind (("C-x C-j" . consult-dir)
:map vertico-map
("C-x C-j" . consult-dir)))
(use-package consult-recoll
:ensure t
:bind (("M-s r" . consult-recoll))
:init
(setq consult-recoll-inline-snippets t)
:config
(defconst recollindex-buffer "*RECOLLINDEX*")
(defun my/kill-recoll-index ()
(interactive)
(let ((proc (get-buffer-process (get-buffer recollindex-buffer))))
(when (process-live-p proc)
(kill-process proc))))
(defun my/recoll-index (&optional _args)
"Start indexing deamon if there is not one running already.
This way our searches are kept up to date"
(interactive)
(let ((recollindex-buffer "*RECOLLINDEX*"))
(unless (process-live-p (get-buffer-process (get-buffer recollindex-buffer)))
(make-process :name "recollindex"
:buffer recollindex-buffer
:command '("recollindex" "-m" "-D")))))
(eval-after-load 'consult-recoll
(my/recoll-index)))
(use-package embark
:ensure t
:bind
;; pick some comfortable binding
(("C-=" . embark-act)
([remap describe-bindings] . embark-bindings)
:map embark-file-map
("C-d" . dragon-drop)
:map embark-defun-map
("M-t" . chatgpt-gen-tests-for-region)
:map embark-general-map
("M-c" . chatgpt-prompt)
:map embark-region-map
("?" . chatgpt-explain-region)
("M-f" . chatgpt-fix-region)
("M-f" . chatgpt-fix-region))
:custom
(embark-indicators
'(embark-highlight-indicator
embark-isearch-highlight-indicator
embark-minimal-indicator))
:init
;; Optionally replace the key help with a completing-read interface
(setq prefix-help-command #'embark-prefix-help-command)
(setq embark-prompter 'embark-completing-read-prompter)
:config
(defun dragon-drop (file)
(start-process-shell-command "dragon-drop" nil
(concat "dragon-drop " file)))
;; Preview any command with M-.
(keymap-set minibuffer-local-map "M-." 'my-embark-preview)
(defun my-embark-preview ()
"Previews candidate in vertico buffer, unless it's a consult command"
(interactive)
(unless (bound-and-true-p consult--preview-function)
(save-selected-window
(let ((embark-quit-after-action nil))
(embark-dwim))))))
;; Helpful for editing consult-grep
(use-package wgrep :ensure t :after embark)
;; Consult users will also want the embark-consult package.
(use-package embark-consult
:ensure t
:after (:all embark consult)
:demand t
;; if you want to have consult previews as you move around an
;; auto-updating embark collect buffer
:hook
(embark-collect-mode . consult-preview-at-point-mode))
;; For uploading files
(use-package 0x0
:ensure t
:after embark
:bind (
:map embark-file-map
("U" . 0x0-upload-file)
:map embark-region-map
("U" . 0x0-dwim))
:commands (0x0-dwim 0x0-upload-file))
(use-package completion-preview
:demand t
:hook (prog-mode . completion-preview-mode)
:bind (:map completion-preview-active-mode-map
("C-i" . completion-preview-insert)
("M-n" . completion-preview-next-candidate)
("M-p" . completion-preview-prev-candidate))
:custom
(completion-preview-minimum-symbol-length 2)
:init
(load (locate-user-emacs-file "lisp/completion-preview.el")))
;;;; Code Completion
(use-package corfu
:disabled
:ensure t
;; Optional customizations
:custom
(corfu-cycle t) ; Allows cycling through candidates
(corfu-auto t) ; Enable auto completion
(corfu-auto-prefix 2)
(corfu-auto-delay 0.1)
(corfu-popupinfo-delay '(0.5 . 0.2))
(corfu-preview-current 'insert) ; insert previewed candidate
(corfu-preselect 'prompt)
(corfu-on-exact-match nil) ; Don't auto expand tempel snippets
;; Optionally use TAB for cycling, default is `corfu-complete'.
:bind (:map corfu-map
("M-SPC" . corfu-insert-separator)
("TAB" . corfu-next)
([tab] . corfu-next)
("S-TAB" . corfu-previous)
([backtab] . corfu-previous)
("S-<return>" . corfu-insert)
("RET" . nil))
:init
(global-corfu-mode)
(corfu-history-mode)
(corfu-popupinfo-mode)) ; Popup completion info
(use-package cape
:ensure t
:defer 10
:bind ("C-c f" . cape-file)
:init
;; Add `completion-at-point-functions', used by `completion-at-point'.
(defun my/add-shell-completion ()
(interactive)
(add-to-list 'completion-at-point-functions 'cape-history)
(add-to-list 'completion-at-point-functions 'pcomplete-completions-at-point))
(add-hook 'shell-mode-hook #'my/add-shell-completion nil t)
:config
;; Make capfs composable
(advice-add #'eglot-completion-at-point :around #'cape-wrap-nonexclusive)
(advice-add #'comint-completion-at-point :around #'cape-wrap-nonexclusive)
;; Silence then pcomplete capf, no errors or messages!
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-silent)
;; Ensure that pcomplete does not write to the buffer
;; and behaves as a pure `completion-at-point-function'.
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-purify))
(use-package tempel
:ensure t
:hook ((prog-mode . tempel-setup-capf)
(text-mode . tempel-setup-capf))
:bind (("M-+" . tempel-complete) ;; Alternative tempel-expand
("M-*" . tempel-insert)
:map tempel-map
([remap keyboard-escape-quit] . tempel-done)
("TAB" . tempel-next)
("<backtab>" . tempel-previous))
:config
(defun tempel-include (elt)
"Support i as a way to import another template"
(when (eq (car-safe elt) 'i)
(if-let (template (alist-get (cadr elt) (tempel--templates)))
(cons 'l template)
(message "Template %s not found" (cadr elt))
nil)))
(add-to-list 'tempel-user-elements #'tempel-include)
(defun tempel-setup-capf ()
(setq-local completion-at-point-functions
(cons #'tempel-complete
completion-at-point-functions))))
(use-package eglot-tempel
:ensure t
:after (:all eglot tempel)
:config
(eglot-tempel-mode t))
;;; Themeing
(use-package spaceway-theme
:ensure nil
:load-path "lisp/spaceway/"
:config
(global-hl-line-mode t)
(set-frame-parameter nil 'cursor-color "#dc322f")
(add-to-list 'default-frame-alist '(cursor-color . "#dc322f"))
(when my/my-system
(set-frame-parameter nil 'alpha-background 100)
(add-to-list 'default-frame-alist '(alpha-background . 100)))
(load-theme 'spaceway t)
(setenv "SCHEME" "dark"))
(use-package spacious-padding
:ensure t
:hook (after-init . spacious-padding-mode)
:custom
;; make the modeline look minimal
(spacious-padding-subtle-mode-line '( :mode-line-active default
:mode-line-inactive vertical-border)))
;;; WRITING
(use-package writegood-mode
:ensure t
:hook ((markdown-mode nroff-mode org-mode
mail-mode
git-commit-mode)
. writegood-mode)
:config
(writegood-duplicates-turn-off))
(use-package writeroom-mode
:ensure t
:commands (writeroom-mode global-writeroom-mode)
:init
(setq writeroom-width 90))
(use-package jinx
:unless (eq system-type 'android)
:demand t
:ensure t
:bind ("C-c DEL" . jinx-correct)
:init
(global-jinx-mode)
(add-to-list 'ispell-skip-region-alist '("+begin_src" . "+end_src"))
(setopt flyspell-use-meta-tab nil))
;;; ORG
(load (locate-user-emacs-file
"lisp/org-config.el"))
;;; Email
(load (locate-user-emacs-file
"lisp/mu4e-config.el"))
;;; Git
(use-package magit
:bind (("C-x v SPC" . magit-status)
:map project-prefix-map
("m" . project-magit))
:commands (magit project-magit)
:config
(add-to-list 'project-switch-commands
'(project-magit "Magit" m))
(defun project-magit ()
(interactive)
(let ((dir (project-root (project-current t))))
(magit-status dir))))
(use-package forge :ensure t :after magit)
(use-package git-link
:ensure t
:bind (("C-c g l" . git-link)))
;; Lets me store links to a particular git revision
(use-package ol-git-link :after ol)
(use-package ediff
:after (magit vc)
:commands (ediff)
:init
;; multiframe just doesn't make sense to me
(with-eval-after-load 'winner
(add-hook 'ediff-quit-hook 'winner-undo))
(setopt ediff-window-setup-function 'ediff-setup-windows-plain))
(use-package diff-hl
:ensure t
:unless my/is-termux
:defer 5
:hook ((magit-pre-refresh . diff-hl-magit-pre-refresh)
(magit-pre-refresh . diff-hl-magit-post-refresh))
:init (global-diff-hl-mode)
:config (diff-hl-flydiff-mode))
;;; EAT AND ESHELL
(use-package eat
:ensure t
:custom
(eat-enable-auto-line-mode t)
:bind (("C-x E" . eat)
:map project-prefix-map
("t" . eat-project)))
(use-package em-alias
:ensure nil
:after eshell
;; :config
;; (defun my/setup-eshell-aliases ()
;; (eshell/alias "e" "find-file $1")
;; (eshell/alias "ee" "find-file-other-window $1")
;; (eshell/alias "v" "view-file $1")
;; (eshell/alias "o" "crux-open-with $1"))
;; (add-hook 'eshell-mode-hook my/setup-eshell-aliases)
)
(use-package flymake-proselint
:ensure t
:after flymake
:hook ((markdown-mode org-mode text-mode) . flymake-proselint-setup)
)
(use-package em-term
:ensure nil
:after eshell
:config
(add-to-list 'eshell-visual-options '("git" "--help" "--paginate"))
(add-to-list 'eshell-visual-options '("ghcup" "tui"))
(add-to-list 'eshell-visual-commands '("htop" "top" "git" "log" "diff"
"show" "less" "nix")))
(use-package eshell
:commands eshell
:config
(setq eshell-destroy-buffer-when-process-dies t))
;; More accurate color representation than ansi-color.el
(use-package xterm-color
:ensure t
:after esh-mode
:config
(add-hook 'eshell-before-prompt-hook
(lambda ()
(setq xterm-color-preserve-properties t)))
(add-to-list 'eshell-preoutput-filter-functions 'xterm-color-filter)
(setq eshell-output-filter-functions
(remove 'eshell-handle-ansi-color eshell-output-filter-functions))
(setenv "TERM" "xterm-256color"))
;; Interactive opening of files image preview and more from any repl
;; As the built-in project.el support expects to use vc-mode hooks to
;; find the root of projects we need to provide something equivalent
;; for it.
(use-package project
:ensure nil
:demand t
:bind (("M-s M-s" . project-find-file)
:map project-prefix-map
("m" . project-magit)
("d" . project-dired))
:init
(setopt project-switch-commands
'((project-find-file "Find file" ?f)
(project-dired "Dired" ?d)
(project-vc-dir "VC-Dir" ?v)
(project-eshell "Eshell" ?e)
(project-shell "Shell" ?s))
project-compilation-buffer-name-function 'project-prefixed-buffer-name)
:config
;; Optionally configure a function which returns the project root directory.
;; There are multiple reasonable alternatives to chose from.
;; 1. project.el (project-roots)
(setq consult-project-function
(lambda (may-prompt)
(when-let* ((project (project-current))
(project-root (car (project-roots (project-current))))
(is-not-home
(not (string= "/home/gavinok/" (car (project-roots
(project-current)))))))
project-root)))
;; Added in emacs 29
(setopt project-vc-extra-root-markers
'("*.cabal" "pyproject.toml"
"spago.dhall" "CMakeList.txt"
"package.clj" "package.json" "Project.toml" ".project" "Cargo.toml"
"mix.exs" "qlfile" ".git"))
;; Override project.el backends for specific directories
;; (defvar my/overrided-project '("~/test/"))
;; (defun my/known-project (dir)