-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
2390 lines (2039 loc) · 82.2 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
;;; emacs-conf --- Summary -*- lexical-binding: t; -*-
;;; Commentary:
;;
;;; Code:
;; ------------------
;; bootstrap straight
;; ------------------
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)
(setq use-package-always-demand t)
(setq package-enable-at-startup nil)
;; set load path
(setq conf--base-dir (file-name-directory (or load-file-name default-directory)))
(add-to-list 'custom-theme-load-path conf--base-dir)
(add-to-list 'load-path conf--base-dir)
(defun load-if-exists (f)
(if (file-exists-p (expand-file-name f))
(load-file (expand-file-name f))))
(load-if-exists "~/.emacs.d/secrets.el")
;; -------------------
;; base emacs settings
;; -------------------
(when (string-equal system-type "darwin")
(setq mac-command-modifier 'meta
mac-option-modifier nil))
(setq ring-bell-function 'ignore)
(require 'cl-lib)
(require 'cl)
(require 'paren)
(show-paren-mode)
;; save minibuffer history
(savehist-mode 1)
(global-auto-revert-mode)
(setq inhibit-startup-message t)
(setq c-toggle-auto-newline t)
(setq make-backup-files nil)
(delete-selection-mode)
(defalias 'yes-or-no-p 'y-or-n-p)
(setq-default indent-tabs-mode nil)
(setq native-comp-async-report-warnings-errors nil)
(global-unset-key (kbd "C-z"))
(normal-erase-is-backspace-mode 1)
;; speedup long lines
(setq bidi-display-reordering nil)
(setq bidi-inhibit-bpa t)
(setq bidi-paragraph-direction 'left-to-right)
(setq auto-window-vscroll nil)
(setq redisplay-skip-fontification-on-input t)
(global-so-long-mode 1)
;; treat camelCase as multiple words for cursor movement
(global-subword-mode)
;; prefer vertical splits
(setq split-width-threshold 140)
;; Don't spawn another window during ediff
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
;; Track-pad horizontal scrolling
(setq mouse-wheel-tilt-scroll t)
(setq mouse-wheel-flip-direction t)
;; TODO: use bind-key: https://melpa.org/#/bind-key
;; basic keybindings
(global-set-key (kbd "C-f") "\C-a\C-a\C-@\C-e")
(global-set-key [C-return] 'newline)
(global-set-key (kbd "C-h") nil)
(global-set-key (kbd "M-$") 'shrink-window)
(global-set-key (kbd "M-*") 'enlarge-window)
(global-set-key (kbd "M-à") 'shrink-window-horizontally)
(global-set-key (kbd "M-)") 'enlarge-window-horizontally)
(global-set-key (kbd "M-i") 'downcase-word)
(global-set-key (kbd "M-u") 'upcase-word)
(global-set-key (kbd "C-c b") 'pop-tag-mark)
(global-set-key (kbd "C-q") 'kill-this-buffer)
(global-set-key [C-backspace] 'delete-backward-char)
;; remove annoying keybindings
(global-set-key (kbd "C-x DEL") 'ignore)
(global-unset-key (kbd "C-x C-d"))
(global-unset-key (kbd "C-t"))
(global-unset-key (kbd "M-t"))
(global-unset-key (kbd "C-o"))
(define-key key-translation-map (kbd "M-g") (kbd "C-g"))
; (define-key crm-local-completion-map (kbd "M-v") nil)
(global-set-key (kbd "C-c p b") 'profiler-start)
(global-set-key (kbd "C-c p r") 'profiler-report)
(global-set-key (kbd "C-c p e") 'profiler-stop)
(global-set-key (kbd "C-x C-o") 'other-window)
;; don't ask confirmation for kill-buffer with process
(setq kill-buffer-query-functions (delq 'process-kill-buffer-query-function kill-buffer-query-functions))
(defun kill-region-maybe()
(interactive)
(if (use-region-p)
(call-interactively 'kill-region)))
(global-set-key (kbd "M-x") 'kill-region-maybe)
(global-set-key (kbd "M-c") 'kill-ring-save)
(global-set-key (kbd "M-v") 'yank)
(global-set-key (kbd "M-d") "\C-a\C-@\C-e")
(global-set-key (kbd "M-s") 'save-buffer)
(global-set-key (kbd "M-N") 'goto-line)
(global-set-key (kbd "M-a") 'recenter)
;; (global-set-key (kbd "M-k") 'compile)
(global-set-key (kbd "C-x C-c") nil)
(global-set-key (kbd "C-S-x C-S-c") 'save-buffers-kill-terminal)
(global-set-key (kbd "<mouse-3>") 'xref-find-definitions)
(global-set-key (kbd "<mouse-4>") 'xref-go-back)
(defun move-up (amount)
(condition-case nil
(scroll-down amount)
(error nil))
(previous-line amount))
(defun move-down (amount)
(condition-case nil
(scroll-up amount)
(error nil))
(next-line amount))
(global-set-key (kbd "M-<up>") (lambda () (interactive) (move-up 4)))
(global-set-key (kbd "M-<down>") (lambda () (interactive) (move-down 4)))
;; Should move this to meow-motion map? -- this would only be used on motion map
(global-set-key (kbd "M-j") (lambda () (interactive) (move-down 4)))
(global-set-key (kbd "M-k") (lambda () (interactive) (move-up 4)))
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1) ((control) . nil)))
(pixel-scroll-precision-mode)
(setq frame-resize-pixelwise t)
(defun copy-file-name-to-clipboard ()
"Copy the current buffer file name to the clipboard."
(interactive)
(let ((filename (if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name))))
(when filename
(kill-new filename)
(message "Copied buffer file name '%s' to the clipboard." filename))))
(global-set-key (kbd "M-q") nil)
(define-key prog-mode-map (kbd "M-q") nil)
(global-set-key (kbd "M-q M-c") 'copy-file-name-to-clipboard)
;; moving windows
(global-set-key (kbd "M-q <left>") 'windmove-left)
(global-set-key (kbd "M-q <right>") 'windmove-right)
(global-set-key (kbd "M-q <up>") 'windmove-up)
(global-set-key (kbd "M-q <down>") 'windmove-down)
(global-set-key (kbd "M-q M-<left>") 'windmove-left)
(global-set-key (kbd "M-q M-<right>") 'windmove-right)
(global-set-key (kbd "M-q M-<up>") 'windmove-up)
(global-set-key (kbd "M-q M-<down>") 'windmove-down)
(global-set-key (kbd "M-q M-h") 'windmove-left)
(global-set-key (kbd "M-q M-j") 'windmove-down)
(global-set-key (kbd "M-q M-k") 'windmove-up)
(global-set-key (kbd "M-q M-l") 'windmove-right)
;; fix some coding systems
(define-coding-system-alias 'UTF-8 'utf-8)
(define-coding-system-alias 'utf8 'utf-8)
;; Duplicate region
(defun duplicate-line-or-region (&optional n)
(interactive "*p")
(let ((use-region (use-region-p)))
(save-excursion
(let ((text (if use-region
(buffer-substring (region-beginning) (region-end))
(prog1 (thing-at-point 'line)
(end-of-line)
(if (< 0 (forward-line 1))
(newline))))))
(dotimes (i (abs (or n 1)))
(insert text))))
(if use-region nil
(let ((pos (- (point) (line-beginning-position))))
(if (> 0 n)
(comment-region (line-beginning-position) (line-end-position)))
(forward-line 1)
(forward-char pos)))))
(defun my-c-mode-common-hook ()
(define-key c-mode-base-map (kbd "C-d") nil))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(add-hook 'delete-selection-mode 'delete-selection-pre-hook)
(global-set-key (kbd "C-d") 'duplicate-line-or-region)
;; better buffer names
(require 'uniquify)
;; setup cc mode
(c-add-style "better-cc-style"
'("stroustrup"
(indent-tabs-mode . nil) ; use spaces rather than tabs
(c-basic-offset . 4) ; indent by four spaces
(tab-width . 4) ; better reading of code written with tabs
(c-offsets-alist . ((inline-open . 0) ; custom indentation rules
(brace-list-open . 0)
(inlambda . 0)
(statement-case-open . +)
(innamespace 0)
(arglist-close 0)))))
(defun --cc-style-setup()
(c-set-style "better-cc-style"))
(add-hook 'c-mode-hook '--cc-style-setup)
(add-hook 'c++-mode-hook '--cc-style-setup)
(defun --set-tab-width()
(setq tab-width 4)
(setq c-basic-offset 4))
(add-hook 'cmake-mode-hook '--set-tab-width)
(add-hook 'objc-mode-hook '--set-tab-width)
(setq-default tab-width 4)
(setq c-default-style "linux")
(add-to-list 'auto-mode-alist '("\\.mm?\\'" . objc-mode))
;; avoid boring buffers
(setq boring-buffers
'("\\*EGLOT .*\\*"
"\\*Warnings\\*"
"\\*straight-.*\\*"
"\\*Async-.*\\*"
"\\*scratch.*\\*"
"\\*Messages.*\\*"
"\\*helm-.*\\*"
"\\*helm .*\\*"
"magit-process:.*"
"\\*Flymake .*\\*"
"\\*apheleia-.*\\*"
"\\*Native-compile-Log\\*"
"\\*help\\*"))
(defun is-buffer-valid (buffer-name)
(not (cl-loop for boring-buffer in boring-buffers
thereis (string-match boring-buffer buffer-name))))
(defun conf--skip-temp-buffers (func)
(interactive)
(let (( bread-crumb (buffer-name) ))
(funcall func)
(while
(and
(not (is-buffer-valid (buffer-name)))
(not (equal bread-crumb (buffer-name))))
(funcall func))))
(defun conf--next-buffer ()
(interactive)
(conf--skip-temp-buffers 'next-buffer))
(defun conf--prev-buffer ()
(interactive)
(conf--skip-temp-buffers 'previous-buffer))
(defun kill-this-buffer-avoid-boring ()
(interactive)
(kill-this-buffer)
(when (not (is-buffer-valid (buffer-name)))
(conf--skip-temp-buffers 'previous-buffer)))
(global-set-key [remap next-buffer] 'conf--next-buffer)
(global-set-key [remap previous-buffer] 'conf--prev-buffer)
(global-set-key [remap kill-this-buffer] 'kill-this-buffer-avoid-boring)
;; better performance
;; (setq gc-cons-threshold 100000000)
(setq read-process-output-max (* 64 1024)) ;; 64k
(defun conf--backward-delete-word ()
"Delete word backwards, and delete matching pair if at point."
(interactive)
(let ((pt (point)))
(when (and (electric-pair-mode)
(char-before)
(char-after)
(or (eq (matching-paren (char-before)) (char-after))
(and (eq (char-before) (char-after))
(eq (char-before) (string-to-char "\"")))))
(delete-char 1)
(delete-char -1))
(delete-region (point) (progn (backward-word 1) (point)))))
(global-set-key (kbd "M-DEL") 'conf--backward-delete-word)
;; Avoid inadvertently changing font size
(global-set-key (kbd "<pinch>") 'ignore)
(global-set-key (kbd "C-<wheel-up>") 'ignore)
(global-set-key (kbd "C-<wheel-down>") 'ignore)
;; --------------
;; setup packages
;; --------------
(use-package el-patch
:custom
(el-patch-use-aggressive-defvar t))
(setq undo-limit 67108864) ; 64mb.
(setq undo-strong-limit 100663296) ; 96mb.
(setq undo-outer-limit 1006632960) ; 960mb.
(use-package undo-fu
:custom
(undo-fu-ignore-keyboard-quit t)
(undo-fu-allow-undo-in-region t)
:config
(global-unset-key (kbd "M-z"))
(global-set-key (kbd "M-z") 'undo-fu-only-undo)
(global-set-key (kbd "M-Z") 'undo-fu-only-redo))
;; (defun conf--toggle-flymake-end-of-line ()
;; (interactive)
;; (if (eq flymake-show-diagnostics-at-end-of-line nil)
;; (progn (message "Enabled end-of-line diagnostics")
;; (setq-local flymake-show-diagnostics-at-end-of-line 'short))
;; (message "Disabled end-of-line diagnostics")
;; (setq-local flymake-show-diagnostics-at-end-of-line nil))
;; (flymake-mode -1)
;; (flymake-mode 1))
(use-package flymake
:bind
(("C-c i f" . flymake-mode)
;; ("C-c i r" . conf--toggle-flymake-end-of-line)
:map flymake-mode-map
("C-c i l" . flymake-show-buffer-diagnostics))
:custom
(flymake-indicator-type 'fringes)
;; (flymake-show-diagnostics-at-end-of-line 'short)
(flymake-no-changes-timeout nil))
(defun conf--org-open-link-maybe()
(interactive)
(if (eq (car (org-element-context)) 'link)
(call-interactively 'org-open-at-point)
(call-interactively 'org-meta-return)))
(use-package org
:bind
(:map org-mode-map
("M-." . org-open-at-point)
("M-<return>" . conf--org-open-link-maybe)
("M-<up>" . (lambda () (interactive) (move-up 4)))
("M-<down>" . (lambda () (interactive) (move-down 4)))
("M-H" . org-shiftmetaleft)
("M-L" . org-shiftmetaright))
:config
(setq org-startup-folded t)
(setq org-confirm-babel-evaluate nil)
(setq org-support-shift-select t)
(modify-syntax-entry ?= "." org-mode-syntax-table)
(org-babel-do-load-languages
'org-babel-load-languages
'((dot . t) (python . t))))
(use-package gcmh
:config
(gcmh-mode 1))
(use-package diminish)
(diminish 'gcmh-mode)
(with-eval-after-load 'eldoc
(diminish 'eldoc-mode))
(diminish 'subword-mode)
(add-hook 'cc-mode-hook (lambda () (abbrev-mode -1)))
(electric-pair-mode)
(electric-indent-mode)
(use-package ws-butler
:diminish ws-butler-mode
:hook (prog-mode . ws-butler-mode))
(use-package vundo
:bind
(("C-x u" . vundo)
("C-x C-u" . vundo)))
(defun delete-slash ()
(search-backward "/")
(delete-region (point) (point-max)))
(defun delete-until-slash ()
(interactive)
(when (eq (char-before) ?/)
(delete-slash))
(delete-slash)
(insert "/"))
(defun delete-until-slash-maybe ()
(interactive)
(if (eq 'file (vertico--metadata-get 'category))
(delete-until-slash)
(conf--backward-delete-word)))
;; ;; performance regression on helm on mac os.
;; ;; run on helm repo:
;; ;; git revert 1ecefa3840aa5bdd8d4959d2c4efd3ea0e433f64 && git reset HEAD~1
;; (use-package helm
;; :diminish helm-mode
;; :bind
;; (("M-f" . helm-occur)
;; ("C-x C-f" . helm-find-files)
;; ("C-x b" . helm-mini)
;; ("C-b" . helm-resume)
;; ("C-p" . helm-buffers-list)
;; ("M-X" . helm-M-x)
;; ("M-o" . helm-find-files)
;; ("M-O" . helm-buffers-list)
;; ("C-x c M-y" . helm-show-kill-ring)
;; :map helm-map
;; ("<right>" . nil)
;; ("<left>" . nil)
;; ("M-v" . yank)
;; ("C-i" . helm-execute-persistent-action) ;tab
;; ("M-z" . helm-select-action) ;tab
;; ([M-backspace] . conf--backward-delete-word)
;; ("<M-down>" . helm-scroll-other-window)
;; ("<M-up>" . helm-scroll-other-window-down)
;; ("DEL" . nil)
;; :map helm-occur-map
;; ("<right>" . nil)
;; ("<left>" . nil)
;; ("<M-down>" . helm-scroll-other-window)
;; ("<M-up>" . helm-scroll-other-window-down)
;; :map helm-find-files-map
;; ("<M-down>" . helm-scroll-other-window)
;; ("<M-up>" . helm-scroll-other-window-down)
;; ("M-e" . helm-config--ff-open-vterm)
;; ("C-x g" . helm-config--ff-open-magit)
;; ("M-E" . helm-config--ff-open-vterm)
;; ("M-r" . helm-ff-run-rename-file)
;; ("DEL" . nil)
;; ([M-backspace] . delete-until-slash)
;; :map helm-read-file-map
;; ([M-backspace] . delete-until-slash)
;; :map helm-grep-map
;; ("<M-down>" . helm-scroll-other-window)
;; ("<M-up>" . helm-scroll-other-window-down)
;; ("<right>" . nil)
;; ("<left>" . nil)
;; ("DEL" . nil))
;; :config
;; (setq
;; helm-buffers-fuzzy-matching t
;; helm-ff-newfile-prompt-p nil
;; helm-split-window-inside-p t
;; helm-echo-input-in-header-line t
;; helm-move-to-line-cycle-in-source nil
;; ;; Disable helm in minibuffer region completion (eval-expression for example)
;; helm-mode-handle-completion-in-region nil
;; helm-scroll-amount 6
;; helm-find-files-ignore-thing-at-point t)
;; (helm-mode))
;; ;; see https://gist.github.com/PaulCapestany/15d6f04077c1a9bc98968a778d60956e to use ripgrep?
;; (use-package helm-ag
;; :straight (helm-ag :type git :host github :repo "emacsorphanage/helm-ag"
;; :fork (:host github :repo "Azkae/emacs-helm-ag"))
;; :bind
;; (("M-R" . helm-do-ag)
;; ("M-F" . helm-do-ag-buffers)
;; :map helm-find-files-map
;; ("M-R" . helm-config--ff-run-helm-ag)
;; :map helm-ag-mode-map
;; ("<right>" . nil)
;; ("<left>" . nil)
;; :map helm-do-ag-map
;; ("<right>" . nil)
;; ("<left>" . nil)
;; :map helm-ag-edit-map
;; ("RET" . helm-ag-mode-jump-other-window))
;; :custom
;; ;; (helm-ag-base-command "rg --vimgrep --no-heading --smart-case")
;; (helm-ag-base-command "ag --nocolor --nogroup")
;; )
;; ;; (defun remove-helm-smartparens ()
;; ;; (smartparens-mode -1))
;; ;; (add-hook 'helm-minibuffer-set-up-hook 'remove-helm-smartparens)
;; ;; (defun remove-helm-electric-pair ()
;; ;; (electric-pair-local-mode -1))
;; ;; (add-hook 'helm-minibuffer-set-up-hook 'remove-helm-electric-pair)
;; (defun helm-config--helm-do-ag-on-file-maybe(basename)
;; (interactive)
;; (let* ((basename (expand-file-name basename))
;; (basename (if (not (file-directory-p basename))
;; (file-name-directory basename)
;; basename)))
;; (helm-do-ag basename)))
(defun conf--vterm-toggle-insert-cd()
(interactive)
(conf--vterm-save-cd)
;; If the helm session was started from a vterm buffer,
;; insert the cd directly inside the vterm buffer
(if (eq major-mode 'vterm-mode)
(progn
(vterm-send-string (concat " cd " (shell-quote-argument default-directory)) t)
(vterm-send-return))
(call-interactively #'vterm-toggle-cd-show)))
;; (defun open-vterm-action(basename)
;; (interactive)
;; (let* ((basename (expand-file-name basename))
;; (basename (if (not (file-directory-p basename))
;; (file-name-directory basename)
;; basename))
;; (default-directory basename))
;; (conf--vterm-toggle-insert-cd)))
;; (defun open-magit-action(basename)
;; (interactive)
;; (let* ((basename (expand-file-name basename))
;; (basename (if (not (file-directory-p basename))
;; (file-name-directory basename)
;; basename))
;; (default-directory basename))
;; (call-interactively #'magit)))
;; (defun helm-config--helm-do-ag-on-project-root(basename)
;; (interactive)
;; (helm-do-ag (projectile-project-root)))
;; (defun open-vterm-on-project-root-action(basename)
;; (interactive)
;; (let* ((default-directory (projectile-project-root)))
;; (conf--vterm-toggle-insert-cd)))
;; (defun helm-config--ff-open-magit()
;; (interactive)
;; (with-helm-alive-p
;; (helm-exit-and-execute-action 'open-magit-action)))
;; (defun helm-config--ff-open-vterm()
;; (interactive)
;; (with-helm-alive-p
;; (helm-exit-and-execute-action 'open-vterm-action)))
;; (defun helm-config--ff-open-vterm-root()
;; (interactive)
;; (with-helm-alive-p
;; (helm-exit-and-execute-action 'open-vterm-on-project-root-action)))
;; (defun helm-config--ff-run-helm-ag()
;; (interactive)
;; (with-helm-alive-p
;; (helm-exit-and-execute-action 'helm-config--helm-do-ag-on-file-maybe)))
;; (defun helm-config--ff-run-helm-ag-root()
;; (interactive)
;; (with-helm-alive-p
;; (helm-exit-and-execute-action 'helm-config--helm-do-ag-on-project-root)))
;; (add-hook
;; 'helm-find-files-after-init-hook
;; (lambda ()
;; (helm-add-action-to-source "Find AG" 'helm-config--helm-do-ag-on-file-maybe helm-source-find-files)
;; (helm-add-action-to-source "Open vterm" 'open-vterm-action helm-source-find-files)
;; (helm-add-action-to-source "Open magit" 'open-magit-action helm-source-find-files)))
;; (with-eval-after-load "helm-projectile"
;; (helm-add-action-to-source "Find AG" 'helm-config--helm-do-ag-on-file-maybe helm-source-projectile-projects)
;; (helm-add-action-to-source "Find AG" 'helm-config--helm-do-ag-on-project-root helm-source-projectile-files-list)
;; (helm-add-action-to-source "Open vterm" 'open-vterm-action helm-source-projectile-projects)
;; (helm-add-action-to-source "Open vterm on project root" 'open-vterm-on-project-root-action helm-source-projectile-files-list)
;; (helm-add-action-to-source "Open vterm" 'open-vterm-action helm-source-projectile-files-list)
;; (helm-add-action-to-source "Open magit" 'open-magit-action helm-source-projectile-files-list)
;; (helm-add-action-to-source "Open magit" 'open-magit-action helm-source-projectile-projects))
;; (defun helm-config--helm-do-ag-projectile-project-symbol ()
;; (interactive)
;; (helm-do-ag (projectile-project-root) nil (symbol-name (symbol-at-point))))
;; (define-key text-mode-map (kbd "M-.") 'helm-config--helm-do-ag-projectile-project-symbol)
;; ;; Waiting for dumb-jump to support xref-find-references: https://github.com/jacktasia/dumb-jump/issues/433
;; (define-key text-mode-map (kbd "M-?") 'helm-config--helm-do-ag-projectile-project-symbol)
;; (define-key prog-mode-map (kbd "M-?") 'helm-config--helm-do-ag-projectile-project-symbol)
(defun projectile-run-compile ()
"Invoke `gdb' in the project's root."
(interactive)
(projectile-with-default-dir (projectile-acquire-root)
(call-interactively 'compile)))
(defun projectile-run-lldb ()
"Invoke `gdb' in the project's root."
(interactive)
(projectile-with-default-dir (projectile-acquire-root)
(call-interactively 'lldb)))
(setq projectile-keymap-prefix (kbd "M-p"))
(use-package projectile
:diminish projectile-mode
:bind
(:map projectile-mode-map
("M-p k" . projectile-run-compile)
("M-p d" . projectile-run-lldb)
("M-p s s" . consult-ripgrep))
:config
(projectile-global-mode)
(setq projectile-enable-caching nil
projectile-svn-command projectile-generic-command
projectile-current-project-on-switch 'keep)
(setq projectile-mode-line "Projectile") ;avoid lag in tramp
(add-hook 'projectile-mode-hook
(lambda ()
(remove-hook 'find-file-hook #'projectile-cache-files-find-file-hook t)
(remove-hook 'find-file-hook #'projectile-visit-project-tags-table t))))
;; (setq helm-projectile-fuzzy-match nil)
;; (use-package helm-projectile
;; :bind
;; (:map helm-projectile-find-file-map
;; ("<right>" . nil)
;; ("<left>" . nil)
;; ([M-backspace] . conf--backward-delete-word)
;; ("M-e" . helm-config--ff-open-vterm)
;; ("M-E" . helm-config--ff-open-vterm-root)
;; ("M-R" . helm-config--ff-run-helm-ag-root)
;; ("M-p" . previous-history-element)
;; ("C-x g" . helm-config--ff-open-magit)
;; :map helm-projectile-projects-map
;; ("M-e" . helm-config--ff-open-vterm)
;; ("M-R" . helm-config--ff-run-helm-ag)
;; ("C-x g" . helm-config--ff-open-magit))
;; :config
;; (setq projectile-completion-system 'helm))
;; (helm-projectile-on)
;; ;; must be binded after (helm-projectile-on) because it remap projectile keybindings
;; (define-key projectile-mode-map [remap projectile-ag] 'helm-do-ag-project-root)
(use-package dumb-jump
:init
;; (define-key prog-mode-map (kbd "M-.") 'xref-find-definitions)
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)
:custom
(dumb-jump-force-searcher 'ag))
(use-package symbol-overlay
:bind
([f7] . symbol-overlay-put)
:init
(setq symbol-overlay-inhibit-map t))
(use-package cmake-mode
:bind
(:map cmake-mode-map
;; dump-jump doesn't work on cmake
("M-." . conf--consult-ripgrep))
:config
(setq cmake-tab-width 4))
;; (use-package powerline
;; :config
;; (powerline-default-theme)
;; (setq powerline-display-buffer-size nil
;; powerline-display-mule-info nil
;; powerline-display-hud nil))
(use-package doom-modeline
:init (doom-modeline-mode 1)
:custom
(doom-modeline-lsp t)
(doom-modeline-vcs-max-length 32)
(doom-modeline-buffer-encoding 'nondefault)
(doom-modeline-buffer-file-name-style 'relative-from-project)
(doom-modeline-env-version nil))
(use-package all-the-icons
:if (display-graphic-p))
(use-package zoom-frm
:bind
(("C-x C-+" . zoom-in)
("C-x C--" . zoom-out)))
(global-set-key (vector (list 'control mouse-wheel-down-event)) 'zoom-in)
(global-set-key (vector (list 'control mouse-wheel-up-event)) 'zoom-out)
;; (use-package git-gutter-fringe+
;; :diminish git-gutter+-mode
;; :config
;; (global-git-gutter+-mode))
;; (use-package git-gutter-fringe
;; :diminish git-gutter-mode
;; :config
;; (global-git-gutter-mode))
(use-package phi-search
:config
(setq phi-search-limit 10000))
(use-package multiple-cursors
:bind
(("M-m" . mc/mark-next-like-this)
;; ("C-M" . newline)
;; ("C-M-m" . newline)
("C-M-<mouse-1>" . mc/add-cursor-on-click)
:map mc/keymap
("<return>" . nil)
("M-v" . nil))
:config
(add-to-list 'mc/unsupported-minor-modes 'electric-indent-mode))
(use-package yasnippet
:diminish yas-minor-mode
:config
(setq yas-snippet-dirs (list (format "%s/snippets" conf--base-dir)))
(yas-global-mode 1))
(use-package magit
:bind
(("C-x g" . magit-status)
("C-x v l" . magit-log-buffer-file))
:custom
(magit-diff-refine-hunk 'all)
(magit-list-refs-sortby "-creatordate")
(magit-diff-visit-avoid-head-blob t)
(magit-auto-revert-immediately t)
(magit-bury-buffer-function (lambda (_) (magit-mode-quit-window t)))
(vc-display-status nil))
(setq smerge-command-prefix "\C-cv")
(use-package request)
(defun conf--create-pull-request-github (repo branch)
"Create a new PR on Github."
(browse-url
(format "https://github.com/%s/pull/new/%s" repo branch)))
(defun conf--show-pull-request-github (repo number)
"Visit the current branch's PR on Github."
(browse-url
(format "https://github.com/%s/pull/%s" repo number)))
(defun conf--get-current-repo ()
(replace-regexp-in-string
"\\`.+github\\.com:\\(.+\\)\\.git\\'" "\\1"
(magit-get "remote"
(magit-get-push-remote)
"url")))
(defun conf--visit-circle-ci ()
(interactive)
(let ((repo (conf--get-current-repo))
(branch (magit-get-current-branch)))
(browse-url (format "https://app.circleci.com/pipelines/github/%s?branch=%s" repo branch))))
(defun conf--visit-pull-request-url-github ()
(interactive)
(lexical-let ((repo (conf--get-current-repo))
(branch (magit-get-current-branch))
(commit (magit-rev-parse
(and magit-copy-revision-abbreviated "--short")
"HEAD")))
(request (format "https://api.github.com/repos/%s/commits/%s/pulls"
repo commit)
:headers `(("Authorization" . ,(concat "Bearer " github-token)))
:parser 'json-read
:error (cl-function (lambda (&rest args &key error-thrown &allow-other-keys)
(message "Got error: %S" error-thrown)))
:success (cl-function
(lambda (&key data &allow-other-keys)
(if (not (equal (length data) 0))
(let* ((id (alist-get 'number (aref data 0))))
(conf--show-pull-request-github repo id))
(conf--create-pull-request-github repo branch)))))))
(defun conf--visit-pull-request-url-gitlab ()
"Visit the current branch's PR on Gitlab."
(interactive)
(browse-url
(format "https://%s/%s/-/merge_requests/new?merge_request%%5Bsource_branch%%5D=%s"
(replace-regexp-in-string
"\\`.+@\\(.+\\):.+\\.git\\'" "\\1"
(magit-get "remote"
(magit-get-push-remote)
"url"))
(replace-regexp-in-string
"\\`.+:\\(.+\\)\\.git\\'" "\\1"
(magit-get "remote"
(magit-get-push-remote)
"url"))
(url-hexify-string (magit-get-current-branch)))))
(with-eval-after-load 'magit
(define-key magit-mode-map "h" #'conf--visit-pull-request-url-github)
(define-key magit-mode-map "H" #'conf--visit-circle-ci)
(define-key magit-mode-map (kbd "C-c i") #'conf--visit-circle-ci)
(define-key magit-mode-map (kbd "C-c p") #'conf--visit-pull-request-url-github))
(straight-use-package '(git-timemachine :type git :host github :repo "emacsmirror/git-timemachine"))
(use-package magit-delta
;; :straight (magit-delta :type git :host github :repo "dandavison/magit-delta"
;; :fork (:host github :repo "jumper047/magit-delta"))
:if (executable-find "delta")
;; :hook (magit-mode . magit-delta-mode)
:bind
(:map magit-mode-map
("," . #'conf--magit-delta-toggle))
:custom
(magit-delta-default-dark-theme "Monokai Extended")
(magit-delta-default-light-theme "Github")
(magit-delta-hide-plus-minus-markers nil)
:config
(defun conf--magit-delta-toggle ()
"Toggle magit-delta-mode and refresh magit."
(interactive)
(progn
(call-interactively 'magit-delta-mode)
(magit-refresh)))
(add-hook 'magit-delta-mode-hook
(lambda ()
(if magit-delta-mode
(progn
;; For some reason (face-attribute 'diff-added :background) does not work if called top-level
(setq magit-delta-delta-args `("--max-line-distance" "0.6" "--true-color" "always" "--color-only"
"--plus-style" ,(format "syntax \"%s\"" (face-attribute 'diff-added :background))
"--plus-emph-style" ,(format "syntax \"%s\"" (face-attribute 'diff-refine-added :background))
"--minus-emph-style" ,(format "syntax \"%s\"" (face-attribute 'diff-refine-removed :background))
"--minus-style" ,(format "normal \"%s\"" (face-attribute 'diff-removed :background))))
(setq
conf--saved-magit-diff-added-highlight (face-attribute 'magit-diff-added-highlight :background)
conf--saved-magit-diff-added (face-attribute 'magit-diff-added :background)
conf--saved-magit-diff-removed-highlight (face-attribute 'magit-diff-removed-highlight :background)
conf--saved-magit-diff-removed (face-attribute 'magit-diff-removed :background))
(set-face-attribute 'magit-diff-added-highlight nil
:background (face-attribute 'diff-added :background))
(set-face-attribute 'magit-diff-added nil
:background (face-attribute 'diff-added :background))
(set-face-attribute 'magit-diff-removed-highlight nil
:background (face-attribute 'diff-removed :background))
(set-face-attribute 'magit-diff-removed nil
:background (face-attribute 'diff-removed :background))
(setq face-remapping-alist
(seq-difference face-remapping-alist
'((magit-diff-removed . default)
(magit-diff-removed-highlight . default)
(magit-diff-added . default)
(magit-diff-added-highlight . default)))))
(set-face-attribute 'magit-diff-added-highlight nil
:background conf--saved-magit-diff-added-highlight)
(set-face-attribute 'magit-diff-added nil
:background conf--saved-magit-diff-added)
(set-face-attribute 'magit-diff-removed-highlight nil
:background conf--saved-magit-diff-removed-highlight)
(set-face-attribute 'magit-diff-removed nil
:background conf--saved-magit-diff-removed))))
)
(use-package quickrun
:bind
(("M-q r" . quickrun))
:config
(setq quickrun-timeout-seconds -1)
(setq quickrun-truncate-lines nil)
(add-hook 'quickrun-after-run-hook
(lambda()
(with-current-buffer quickrun--buffer-name
(read-only-mode -1)
(end-of-buffer)
(insert "\n-- End --")
(read-only-mode +1))))
)
(use-package yaml-mode
:hook
(yaml-mode . toggle-truncate-lines))
(use-package swift-mode)
(use-package cython-mode)
;; (use-package helm-tramp
;; :bind
;; (("C-c s" . helm-tramp))
;; :config
;; (setq tramp-default-method "ssh")
;; (defun package-installed-p (v) nil))
(use-package glsl-mode)
(use-package fill-column-indicator
:config
(defvar-local company-fci-mode-on-p nil)
(defun company-turn-off-fci (&rest ignore)
(when (boundp 'fci-mode)
(setq company-fci-mode-on-p fci-mode)
(when fci-mode (fci-mode -1))))
(defun company-maybe-turn-on-fci (&rest ignore)
(when company-fci-mode-on-p (fci-mode 1)))
(add-hook 'company-completion-started-hook 'company-turn-off-fci)
(add-hook 'company-completion-finished-hook 'company-maybe-turn-on-fci)
(add-hook 'company-completion-cancelled-hook 'company-maybe-turn-on-fci)
(setq fci-rule-column 120))
(use-package jinja2-mode)
(use-package nhexl-mode)
(use-package dockerfile-mode)
(use-package eglot
:straight nil
:bind
(:map eglot-mode-map
("M-." . xref-find-definitions)
("M-?" . xref-find-references)
("<mouse-2>" . eglot-code-actions-at-mouse))
:hook
((c-mode c++-mode c-ts-mode c++-ts-mode) . eglot-ensure)
((c-mode c++-mode c-ts-mode c++-ts-mode) . (lambda () (setq-local eglot-ignored-server-capabilities '(:inlayHintProvider))))
((typescript-ts-mode tsx-ts-mode) . eglot-ensure)
((python-mode python-ts-mode) . eglot-ensure)
(rust-mode . eglot-ensure)
:custom
(eglot-report-progress t)
;; help with perf:
(eglot-events-buffer-size 0)
:config
;; (add-to-list 'eglot-server-programs '(c++-mode . ("clangd" "--completion-style=detailed")))
(add-to-list 'eglot-server-programs '(c++-mode . ("clangd" "--completion-style=detailed" "--header-insertion-decorators=0" "--header-insertion=never")))
(add-to-list 'eglot-server-programs `(web-mode . ,(eglot-alternatives
'(("vscode-html-language-server" "--stdio")
("html-languageserver" "--stdio")))))
(setq eldoc-echo-area-use-multiline-p nil)
;; Disable auto indent after '}' on cpp mode, may break a few things..
;; (remove-hook 'post-self-insert-hook 'eglot--post-self-insert-hook t)
(fset #'jsonrpc--log-event #'ignore)
(add-to-list 'eglot-stay-out-of 'company-backends)