-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.el
More file actions
3857 lines (3327 loc) · 140 KB
/
init.el
File metadata and controls
3857 lines (3327 loc) · 140 KB
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)
(setq custom-file (concat conf--base-dir "custom.el"))
(load custom-file)
(defun load-if-exists (f)
(if (file-exists-p (expand-file-name f))
(load-file (expand-file-name f))))
;; -------------------
;; base emacs settings
;; -------------------
(when (string-equal system-type "darwin")
(setq mac-command-modifier 'meta
mac-option-modifier nil))
(when (eq system-type 'windows-nt)
(add-to-list 'exec-path "C:/Program Files/Git/usr/bin/"))
(setq ring-bell-function 'ignore)
(require 'cl-lib)
(require 'cl)
(require 'paren)
(show-paren-mode)
;; save minibuffer history
(savehist-mode 1)
(add-to-list 'savehist-additional-variables 'compile-command)
(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 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)
;; Track-pad horizontal scrolling
(setq mouse-wheel-tilt-scroll t)
(setq mouse-wheel-flip-direction t)
(setq save-interprogram-paste-before-kill t)
(cl-defun remove-from-list (list-var element &key key test)
"Remove ELEMENT from the value of LIST-VAR if present.
This can be used as an inverse of `add-to-list'."
(unless key (setq key #'identity))
(unless test (setq test #'equal))
(setf (symbol-value list-var)
(cl-remove element
(symbol-value list-var)
:key key
:test test)))
(use-package project
:straight (:type built-in))
;; Better comint settings
(use-package comint
:straight (:type built-in)
:config
(setq comint-output-filter-functions (remove 'comint-postoutput-scroll-to-bottom comint-output-filter-functions))
(setq-default comint-scroll-to-bottom-on-output nil)
(setq-default comint-scroll-to-bottom-on-input t)
(setq-default comint-scroll-show-maximum-output nil)
(setq-default comint-prompt-read-only t)
(define-key comint-mode-map (kbd "M-p") #'comint-previous-input)
(define-key comint-mode-map (kbd "M-b") #'comint-previous-input)
(define-key comint-mode-map (kbd "M-r") nil)
(define-key comint-mode-map (kbd "C-M-l") nil))
;; 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-horizontally)
(global-set-key (kbd "M-)") 'enlarge-window-horizontally)
(global-set-key (kbd "C-c b") 'pop-tag-mark)
(global-set-key (kbd "C-q") 'kill-current-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)))
(defun conf--scroll-left ()
(interactive)
(scroll-right 10)
(unless (minibufferp)
(move-to-column (+ (window-hscroll) (/ (window-width) 2)))))
(defun conf--scroll-right ()
(interactive)
(scroll-left 10)
(unless (minibufferp)
(move-to-column (+ (window-hscroll) (/ (window-width) 2)))))
(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-s") 'save-buffer)
(global-set-key (kbd "M-N") 'goto-line)
(global-set-key (kbd "M-a") 'recenter-top-bottom)
;; (global-set-key (kbd "M-k") 'compile)
(global-set-key (kbd "C-x C-c") nil)
(global-set-key (kbd "C-M-l") nil)
(global-set-key (kbd "M-l") nil)
(global-set-key (kbd "M-h") nil)
(global-set-key (kbd "M-H") 'conf--scroll-left)
(global-set-key (kbd "M-L") 'conf--scroll-right)
(global-set-key (kbd "M-u") nil)
(global-set-key (kbd "C-S-x C-S-c") 'save-buffers-kill-terminal)
(global-set-key (kbd "C-c e") 'kmacro-end-and-call-macro)
(global-set-key (kbd "M-£") 'shell-command-on-region)
;; remap registers
(define-key global-map (kbd "C-c r") ctl-x-r-map)
;; (global-set-key (kbd "<mouse-3>") 'xref-find-definitions)
;; (global-set-key (kbd "<mouse-4>") 'xref-go-back)
;; Disable mouse highlighting when typing
;; (setq mouse-highlight 1)
(defun conf--disable-keys (map keys)
(dolist (key keys)
(define-key map (kbd key) nil)))
(defun move-up (amount)
(deactivate-mark)
(condition-case nil
(scroll-down amount)
(error nil))
(previous-line amount))
(defun move-down (amount)
(deactivate-mark)
(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)
(with-eval-after-load 'info
(define-key Info-mode-map (kbd "M-,") 'Info-history-back)
(define-key Info-mode-map (kbd "C-M-,") 'Info-history-forward)
(define-key Info-mode-map (kbd "e") nil))
;; fix some coding systems
(define-coding-system-alias 'UTF-8 'utf-8)
(define-coding-system-alias 'utf8 'utf-8)
(defun conf--region-more-than-one-line-p ()
"Return t if the selected region spans more than one line, nil otherwise.
Returns nil if there is no active region."
(when (use-region-p)
(save-excursion
(let* ((begin (region-beginning))
(end (region-end))
(begin-line (progn (goto-char begin) (line-number-at-pos)))
(end-line (progn (goto-char end) (line-number-at-pos))))
(/= begin-line end-line)))))
;; Duplicate region
(defun duplicate-line-or-region (&optional n)
(interactive "*p")
(let ((use-region (and (use-region-p)
(conf--region-more-than-one-line-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)
(define-key c-mode-base-map (kbd "M-e") 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\\*"
"\\*Ediff.*\\*"
"*Shell Command Output*"))
(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-current-buffer-avoid-boring ()
(interactive)
(kill-current-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-current-buffer] 'kill-current-buffer-avoid-boring)
;; better process performance
(setq read-process-output-max (* 1024 1024))
;; Testing this setting, greatly improve the compilation output speed
(setq process-adaptive-read-buffering nil)
(defun conf--backward-delete-word ()
"Delete word backwards, and delete matching pair if at point."
(interactive)
(let ((pt (point)))
(when (electric-pair-mode)
(while (and (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.
;; Do the same thing with embark
(defun conf--undo ()
(interactive)
(if (equal 'select (car-safe (meow--selection-type)))
(let ((undo-fu-allow-undo-in-region nil))
(call-interactively 'undo-fu-only-undo))
(call-interactively 'undo-fu-only-undo)))
(use-package undo-fu
:custom
(undo-fu-ignore-keyboard-quit nil)
(undo-fu-allow-undo-in-region t)
:config
(global-unset-key (kbd "M-z"))
(global-set-key (kbd "M-z") 'conf--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 password-store)
(use-package pass)
(auth-source-pass-enable)
(setq epa-file-select-keys 'silent)
(setq epa-file-encrypt-to '("C37350DE46EE427FC9FA5ADFF63419C720EB67CE"))
(defun conf--toggle-flymake-error-color ()
"Toggle the flymake-error face between its original red underline and no color."
(interactive)
(let ((current-underline (face-attribute 'flymake-error :underline)))
(if (and current-underline
(listp current-underline)
(string= (plist-get current-underline :color) "Red1"))
;; Currently has red color, remove it
(progn
(set-face-attribute 'flymake-error nil :underline nil)
(message "Flymake error color disabled"))
;; Currently has no color or different color, restore original
(progn
(set-face-attribute 'flymake-error nil :underline '(:style wave :color "Red1"))
(message "Flymake error color enabled")))))
(use-package flymake
:straight (:type built-in)
:bind
(("C-c i f" . flymake-mode)
("C-c i t" . conf--toggle-flymake-error-color)
;; ("C-c i r" . conf--toggle-flymake-end-of-line)
:map flymake-mode-map
("C-c i l" . flymake-show-buffer-diagnostics)
("C-c i p" . flymake-goto-prev-error)
("C-c i n" . flymake-goto-next-error))
:custom
(flymake-indicator-type 'fringes)
;; (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)))
(defun conf--org-meta-return-split()
(interactive)
(let ((org-insert-heading-respect-content nil))
(call-interactively 'org-meta-return)))
(use-package org
:straight (:type built-in)
:bind
(:map org-mode-map
("M-." . org-open-at-point)
("M-<return>" . conf--org-open-link-maybe)
("C-M-<return>" . conf--org-meta-return-split)
("M-<up>" . (lambda () (interactive) (move-up 4)))
("M-<down>" . (lambda () (interactive) (move-down 4)))
("M-H" . org-shiftmetaleft)
("M-L" . org-shiftmetaright)
("C-c /" . nil)
("C-c C-u" . nil)
("M-," . org-mark-ring-goto)
("M-h" . nil)
:map org-read-date-minibuffer-local-map
("M-h" . org-calendar-backward-day)
("M-j" . org-calendar-forward-week)
("M-k" . org-calendar-backward-week)
("M-l" . org-calendar-forward-day))
:config
(setq org-startup-folded t)
(setq org-confirm-babel-evaluate nil)
(setq org-support-shift-select t)
(setq org-special-ctrl-a/e t)
(setq org-src-preserve-indentation t)
(setq org-hide-emphasis-markers t)
(setq org-startup-with-inline-images t)
(setq org-image-actual-width nil)
(add-hook 'org-attach-after-change-hook #'(lambda (dir) (run-with-timer 0.1 nil 'org-display-inline-images)))
(setq org-M-RET-may-split-line '((default . nil)))
(setq org-insert-heading-respect-content t)
(setq org-log-done 'time)
(setq org-log-into-drawer t)
(setq org-link-file-path-type 'relative)
;; (setq org-tags-column -90)
(defun conf--org-table-align-after-yank (&rest _args)
"Align org table after yanking if point is in a table."
(when (and (eq major-mode 'org-mode)
(org-at-table-p))
(org-table-align)))
(advice-add 'yank :after #'conf--org-table-align-after-yank)
(advice-add 'yank-pop :after #'conf--org-table-align-after-yank)
;; fold heading when task is done
(defun my/org-fold-done-tasks (plist)
"Fold heading when changed to DONE state."
(when (and (eq (plist-get plist :type) 'todo-state-change)
(member (plist-get plist :to) org-done-keywords))
(save-excursion
(org-back-to-heading t)
(outline-hide-subtree))))
(add-hook 'org-trigger-hook #'my/org-fold-done-tasks)
(modify-syntax-entry ?= "." org-mode-syntax-table)
(org-babel-do-load-languages
'org-babel-load-languages
'((dot . t) (python . t) (sql . t) (shell . t)))
(setq org-babel-default-header-args:sql
'((:engine . "postgresql")))
(setq org-babel-default-header-args:python
'((:results . "output")))
(setq org-babel-default-header-args:elisp
'((:lexical . t)))
(add-to-list 'org-src-lang-modes '("json" . js-json))
(add-to-list 'org-src-lang-modes '("tsx" . tsx-ts))
(add-to-list 'org-src-lang-modes '("jsx" . tsx-ts))
(add-to-list 'org-src-lang-modes '("typescript" . tsx-ts)))
(use-package org-agenda
:straight (:type built-in)
:bind
(("C-c A" . org-agenda)
("C-c Z" . org-capture)
;; :map org-agenda-mode-map
;; ("L" . nil)
)
:config
(setq org-directory "~/Dropbox/denotes/")
(setq org-agenda-files (list org-directory "~/Dropbox/todo.org" "~/Dropbox/archive-todo.org"))
(setq org-default-notes-file "~/Dropbox/todo.org")
(setq org-capture-templates
'(("t" "Tasks" entry
(file "")
"* TODO %?\n%a"))))
(setq org-archive-location "archive-%s::")
(defun org-archive-all-done ()
"Archive all DONE items in the current buffer."
(interactive)
(let ((done-positions '())
(archived-count 0))
;; First pass: collect all DONE item positions
(org-map-entries
(lambda ()
(push (point) done-positions))
"TODO=\"DONE\"")
;; Second pass: archive from bottom to top (so positions stay valid)
(dolist (pos (sort done-positions '>))
(goto-char pos)
(when (org-entry-is-done-p) ; Double-check it's still DONE
(org-archive-subtree)
(setq archived-count (1+ archived-count))))
(message "Archived %d DONE items" archived-count)))
(defun org-archive-all-done-confirm ()
"Archive all DONE items with confirmation."
(interactive)
(let ((done-count (length (org-map-entries t "TODO=\"DONE\""))))
(when (and (> done-count 0)
(y-or-n-p (format "Archive %d DONE items? " done-count)))
(org-archive-all-done))))
(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)
(add-to-list 'electric-pair-pairs '(?` . ?`))
(add-to-list 'insert-pair-alist '(?` ?`))
(use-package vundo
:bind
(("C-x u" . vundo)
("C-x C-u" . vundo)
:map vundo-mode-map
("h" . vundo-backward)
("l" . vundo-forward)
("j" . vundo-next)
("k" . vundo-previous)))
(defun delete-until-slash ()
(interactive)
(let ((start-pos (if (minibufferp)
(minibuffer-prompt-end)
(point-min))))
;; Only delete the character before if it's past the start position
(when (and (memq (char-before) '(?/ ?:))
(> (point) start-pos))
(delete-char -1))
;; Search backwards for separator, but don't go past the start position
(if (re-search-backward "[:/]" start-pos t)
;; Found separator: delete everything after it and reinsert the separator
(let ((separator (buffer-substring (point) (1+ (point)))))
(delete-region (point) (point-max))
(insert separator))
;; No separator found: delete everything until start position
(delete-region start-pos (point-max)))))
(defvar conf--delete-slash-blacklisted-commands '(denote-open-or-create))
(defun delete-until-slash-maybe ()
(interactive)
(if (and (eq 'file (vertico--metadata-get 'category))
(not (memq embark--command conf--delete-slash-blacklisted-commands)))
(delete-until-slash)
(conf--backward-delete-word)))
(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)))
(use-package dumb-jump
:init
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)
:custom
(dumb-jump-force-searcher 'rg))
(use-package symbol-overlay
:bind
([f7] . symbol-overlay-put)
:init
(setq symbol-overlay-inhibit-map t))
(use-package cmake-mode
:if (not (eq system-type 'windows-nt))
:defer t
:bind
(:map cmake-mode-map
;; dump-jump doesn't work on cmake
("M-." . conf--consult-ripgrep))
:config
(setq cmake-tab-width 4))
(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))
(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 phi-search
:config
(setq phi-search-limit 10000))
(setq mc/list-file (expand-file-name "mc-lists.el" (file-name-directory load-file-name)))
(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-n" . mc/skip-to-next-like-this)
("M-N" . mc/unmark-next-like-this) ; not sure about this one
("M-v" . nil))
:config
(add-to-list 'mc/unsupported-minor-modes 'electric-indent-mode)
(add-to-list 'mc/unsupported-minor-modes 'corfu-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)
("C-x v f" . magit-find-file)
("C-x v s" . magit-show-commit)
("C-x v g" . magit-blame-addition)
("C-c G" . magit-dispatch)
:map magit-status-mode-map
("M-p" . nil)
:map magit-diff-mode-map
("M-p" . nil)
:map magit-hunk-section-map
("C-j" . nil))
:custom
(magit-diff-refine-hunk 'all)
(magit-list-refs-sortby "-creatordate")
(magit-diff-visit-avoid-head-blob t)
(magit-auto-revert-immediately t)
(vc-display-status nil)
(magit-diff-visit-prefer-worktree t))
;; This git is faster got some reason
(let ((git-path "/Applications/Xcode.app/Contents/Developer/usr/bin/git"))
(when (file-exists-p git-path)
(setq magit-git-executable git-path)))
(defun my/forget-project-after-worktree-delete (worktree)
"Remove WORKTREE from project.el's known projects after deletion."
(when (require 'project nil t)
(project-forget-project worktree)))
(advice-add 'magit-worktree-delete :after #'my/forget-project-after-worktree-delete)
(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))))
(setq github-token (password-store-get "github-token"))
(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 (kbd "C-c d") #'conf--visit-circle-ci)
(define-key magit-mode-map (kbd "C-c p") #'conf--visit-pull-request-url-github))
(use-package git-timemachine
:straight (git-timemachine :type git :host github :repo "emacsmirror/git-timemachine")
:config
(add-hook 'git-timemachine-mode-hook #'font-lock-ensure)
(add-hook 'git-timemachine-mode-hook #'meow--switch-to-motion))
(use-package magit-delta
:straight (:fork (:host github :repo "Azkae/magit-delta" :branch "fix-magit-log-buffer-file"))
:if (executable-find "delta")
:bind
:custom
(magit-delta-default-dark-theme "Monokai Extended")
(magit-delta-default-light-theme "Github")
(magit-delta-hide-plus-minus-markers nil)
(magit-delta-max-size 200000)
:config
(add-hook 'magit-mode-hook #'(lambda () (magit-delta-mode +1))))
(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
:defer t)
(use-package cython-mode
:defer t)
(use-package glsl-mode
:defer t)
(use-package jinja2-mode
:defer t)
(use-package nhexl-mode)
(define-key hexl-mode-map (kbd "M-X") nil)
(define-key hexl-mode-map (kbd "M-q") nil)
(define-key hexl-mode-map (kbd "C-x C-h") nil)
(define-key hexl-mode-map (kbd "C-x C-j") nil)
(define-key hexl-mode-map (kbd "C-x C-k") nil)
(define-key hexl-mode-map (kbd "C-x C-l") nil)
(define-key hexl-mode-map (kbd "M-f") nil)
(use-package dockerfile-mode)
(require 'project)
(require 'project-local)
(add-hook 'project-find-functions 'conf--project-try-local 90)
(defun conf--xref-find-definitions ()
(interactive)
(let ((this-command 'xref-find-definitions))
(deactivate-mark)
(call-interactively 'xref-find-definitions)))
(defun conf--xref-find-references ()
(interactive)
(let ((this-command 'xref-find-references))
(deactivate-mark)
(call-interactively 'xref-find-references)))
(use-package eglot
:straight (:type built-in)
:bind
(("M-." . conf--xref-find-definitions)
("M-?" . conf--xref-find-references)
:map eglot-mode-map
("<mouse-3>" . 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 python-mode python-ts-mode) . (lambda () (setq-local eglot-ignored-server-capabilities '(:inlayHintProvider :semanticTokensProvider))))
((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)
(eglot-code-action-indicator "h")
:config
(fset #'jsonrpc--log-event #'ignore)
;; (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")))))
(add-to-list 'eglot-server-programs `(python-mode . ,(eglot-alternatives
'(("basedpyright-langserver" "--stdio")
("pyright-langserver" "--stdio")))))
(setq eldoc-echo-area-use-multiline-p nil)
(setq eglot-code-action-indications '(margin))
;; Disable auto indent after '}' on cpp mode, may break a few things..
;; (remove-hook 'post-self-insert-hook 'eglot--post-self-insert-hook t)
(add-to-list 'eglot-stay-out-of 'company-backends)
;; Enable flymake only on save:
;; This allows to trigger flymake only when the sever published diagnostics
(defun conf--eglot-publishDiagnostics (server method &rest args)
(when (eq method 'textDocument/publishDiagnostics)
(let ((uri (plist-get args :uri)))
(when-let ((buffer (find-buffer-visiting (eglot-uri-to-path uri))))
(with-current-buffer buffer
(when (bound-and-true-p sideline-mode)
(sideline--reset)
(sideline-render-this)))))))
(advice-add 'eglot-handle-notification :after #'conf--eglot-publishDiagnostics))
(el-patch-feature eglot)
;; Fix highlighting of eldoc parameters, fixed in emacs31
;; See 04a8faef0948f46b16172855ee337f59819f22a7
(with-eval-after-load 'eglot
(el-patch-defun eglot--sig-info (sig &optional sig-active briefp)
(eglot--dbind ((SignatureInformation)
((:label siglabel))
((:documentation sigdoc)) parameters activeParameter)
sig
(with-temp-buffer
(insert siglabel)
;; Add documentation, indented so we can distinguish multiple signatures
(when-let (doc (and (not briefp) sigdoc (eglot--format-markup sigdoc)))
(goto-char (point-max))
(insert "\n" (replace-regexp-in-string "^" " " doc)))