-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfig.el
4028 lines (3603 loc) · 156 KB
/
config.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
;;; private/amos/config.el -*- lexical-binding: t; no-byte-compile: t; -*-
(load! "+bindings")
(load! "+lsp")
(load! "+alias")
;; (load! "+flycheck")
(require 'dash)
(require 'evil-multiedit)
(require 's)
(require 'map)
;; (setq tmux-p (getenv "TMUX"))
(setq tmux-p nil)
(setq gui-p (getenv "GUI"))
(advice-add #'breadcrumb-project-crumbs :override #'ignore)
(add-to-list 'consult-preview-allowed-hooks 'global-hl-line-mode-check-buffers)
(add-to-list 'consult-preview-allowed-hooks 'treecrumbs-mode)
;; (add-to-list 'consult-preview-allowed-hooks 'breadcrumb-local-mode)
;; (add-to-list 'consult-preview-allowed-hooks 'global-treesit-auto-mode-check-buffers)
;; (setq consult-preview-variables (assq-delete-all 'delay-mode-hooks consult-preview-variables))
(minibuffer-depth-indicate-mode +1)
(setq resize-mini-windows 'grow-only)
;; (advice-add #'realign-mode :override #'ignore)
;; (advice-add #'realign-windows :override #'ignore)
;; (advice-add #'+vc-gutter-update-h :override #'ignore)
;; (advice-add #'+vc-gutter-init-maybe-h :override #'ignore)
;; Avoid major-mode switching which leads to cursor shape blinking
(setq evil-default-cursor #'ignore)
(add-to-list 'evil-buffer-regexps `(
,(rx (or
" *checkdoc-temp*"
" *eldoc*"
" *string-output*"
" *string-pixel-width*"
" *temp file*"
" *temp*"
" *elisp-flymake-byte-compile*"
"*gcc-flymake*"
;; "*lsp-log*"
"*envrc*"
;; "*Shell Command Output*"
"*Style Warnings*"
"*Native-compile-Log*"
"*org-src"
"*Org Src"
" *org-src"
))
.
nil))
(defun +amos-flymake-diagnostics-a (orig-fun &rest args)
(if (evil-insert-state-p)
nil
(apply orig-fun args)))
(advice-add 'flymake-diagnostics :around #'+amos-flymake-diagnostics-a)
;; (use-package! copilot
;; :hook (prog-mode . copilot-mode)
;; :init
;; ;; (setq copilot-node-executable "/tmp/gentoo/home/amos/.config/lvim/pack/gongfeng/start/vim/resource/bin/copilot-node-server.sh")
;; ;; (setq copilot-install-dir "/tmp/gentoo/home/amos/.config/lvim/pack/gongfeng/start/vim/resource")
;; :bind (:map copilot-completion-map
;; ("<tab>" . 'copilot-accept-completion)
;; ("C-<tab>" . 'copilot-accept-completion-by-word)))
(use-package lsp-booster
:after lsp)
(use-package eglot-booster
:after eglot
:config
(eglot-booster-mode))
(use-package! treesit-auto
:config
(global-treesit-auto-mode))
(use-package! deadgrep)
(use-package! speed-type
:defer
:config
(map!
:map speed-type--completed-keymap
:ni "q" #'kill-this-buffer
:ni "r" #'speed-type--replay
:ni "n" #'speed-type--play-next))
(use-package! quick-peek
:defer)
(use-package! dired-open
:after dired
:config
(defun +amos/dired-open-callgrind ()
"Open callgrind files according to its name."
(interactive)
(let ((file (ignore-errors (dired-get-file-for-visit)))
process)
(when (and file
(not (file-directory-p file)))
(when (string-match-p "$[cachegrind|callgrind].out" file)
(setq process (dired-open--start-process file "kcachegrind"))))
process))
(push #'+amos/dired-open-callgrind dired-open-functions))
(use-package! dired-quick-sort
:after dired
:config
(dired-quick-sort-setup))
(use-package! cc-playground
:init
(put 'cc-exec 'safe-local-variable #'stringp)
(put 'cc-flags 'safe-local-variable #'stringp)
(put 'cc-links 'safe-local-variable #'stringp)
(dolist (x '(cc-playground-exec cc-playground-debug cc-playground-exec-test cc-playground-bench))
(advice-add x :before #'evil-normal-state))
:bind (:map cc-playground-mode-map
("<f8>" . cc-playground-rm) ; terminal
("S-RET" . cc-playground-rm) ; gui
("C-c r" . cc-playground-add-or-modify-tag)
("C-c b" . cc-playground-bench)
("C-c d" . cc-playground-debug)
("C-c t" . cc-playground-debug-test)
("C-c c" . cc-playground-change-compiler)
("C-c o" . cc-playground-switch-optimization-flag)
("C-c f" . cc-playground-add-compilation-flags))
:config
(add-hook! 'cc-playground-mode-hook (rmsbolt-mode +1))
(add-hook! 'cc-playground-rm-hook
(doom-with-advice (y-or-n-p (lambda (&rest _) t)) (ignore-errors (lsp-shutdown-workspace)))))
(use-package! sync-recentf)
(use-package! rainbow-mode
:defer)
(use-package! google-translate
:defer)
;; (use-package! kurecolor
;; :init
;; ;; | color | toggle | meaning |
;; ;; |----------+----------------------------+--------------|
;; ;; | red | | persist |
;; ;; | blue | :exit t | transient |
;; ;; | amaranth | :foreign-keys warn | persist w |
;; ;; | teal | :foreign-keys warn :exit t | transient w |
;; ;; | pink | :foreign-keys run | nested |
;; (defhydra +rgb@kurecolor (:color red :hint nil)
;; "
;; Inc/Dec _w_/_W_ brightness _d_/_D_ saturation _e_/_E_ hue "
;; ("w" kurecolor-decrease-brightness-by-step)
;; ("W" kurecolor-increase-brightness-by-step)
;; ("d" kurecolor-decrease-saturation-by-step)
;; ("D" kurecolor-increase-saturation-by-step)
;; ("e" kurecolor-decrease-hue-by-step)
;; ("E" kurecolor-increase-hue-by-step)
;; ("q" nil "cancel" :color blue))
;; (advice-add #'+rgb@kurecolor/body :before (lambda (&rest _) (rainbow-mode +1)))
;; :defer)
(use-package! thrift-mode
:config
(add-to-list 'auto-mode-alist '("\\.thrift\\'" . thrift-mode))
(add-hook 'thrift-mode-hook 'font-lock-mode))
;; (use-package! go-playground
;; :defer
;; :bind (:map go-playground-mode-map
;; ("<f8>" . go-playground-rm)))
;; (use-package! rust-playground
;; :defer
;; :bind (:map rust-playground-mode-map
;; ("<f8>" . rust-playground-rm)))
;; (use-package! py-playground
;; :defer
;; :config
;; (dolist (x '(py-playground-exec py-playground-debug))
;; (advice-add x :before #'evil-normal-state))
;; :bind (:map py-playground-mode-map
;; ("<f8>" . py-playground-rm) ; terminal
;; ("S-RET" . py-playground-rm) ; gui
;; ("C-c r" . py-playground-add-or-modify-tag)
;; ("C-c d" . py-playground-debug)))
(use-package! gitattributes-mode
:defer)
;; (use-package! page-break-lines
;; :init
;; (global-page-break-lines-mode +1))
(use-package! adoc-mode
:mode "\\.adoc$")
(use-package! hl-line+
:config
(global-hl-line-mode +1))
(use-package! unfill
:config
(global-set-key [remap fill-paragraph] #'unfill-toggle))
(use-package! easy-hugo
:defer
:config
(evil-set-initial-state 'easy-hugo-mode 'emacs)
(add-hook! 'easy-hugo-mode-hook (setq-local amos-browse t)))
(use-package! move-text
:defer)
(use-package! ws-butler
:config
(ws-butler-global-mode +1))
(use-package! syntactic-close
:defer)
(use-package! realign-mode
:config
(defun amos-special-window-p (window)
(let* ((buffer (window-buffer window))
(framename (frame-parameter (window-frame window) 'name))
(buffname (string-trim (buffer-name buffer))))
(or (equal buffname "*doom*")
(frame-parent (window-frame window))
(with-current-buffer buffer server-visit-file)
(equal buffname "*flycheck-posframe-buffer*")
(equal buffname "*Ediff Control Panel*")
(equal (with-current-buffer buffer major-mode) 'mu4e-view-mode)
(equal (with-current-buffer buffer major-mode) 'mu4e-compose-mode)
(equal (with-current-buffer buffer major-mode) 'pdf-view-mode))))
(push #'amos-special-window-p realign-ignore-window-predicates))
(use-package! narrow-reindent
:config
(defun narrow-reindent-mode-maybe ()
(if (not (minibufferp))
(narrow-reindent-mode +1)))
(define-global-minor-mode global-narrow-reindent-mode
narrow-reindent-mode narrow-reindent-mode-maybe
:group 'narrow-reindent)
(global-narrow-reindent-mode +1))
(use-package! git-gutter
:config
(defface +amos:modified
'((t (:foreground "chocolate" :weight bold :inherit default)))
"Face of modified")
(defface +amos:added
'((t (:foreground "ForestGreen" :weight bold :inherit default)))
"Face of added")
(defface +amos:deleted
'((t (:foreground "DarkRed" :weight bold :inherit default)))
"Face of deleted")
(global-git-gutter-mode +1)
(advice-add #'git-gutter:set-window-margin :override #'ignore)
(defun +amos-git-gutter:before-string-a (sign)
(let* ((gutter-sep (concat " " (make-string (- (if (car (window-margins)) (car (window-margins)) 4) 2) ? ) sign))
(face (pcase sign
("=" '+amos:modified)
("+" '+amos:added)
("-" '+amos:deleted)))
(ovstring (propertize gutter-sep 'face face)))
(propertize " " 'display `((margin left-margin) ,ovstring))))
(defun +amos-git-gutter:start-git-diff-process-a (file proc-buf)
(let ((arg (git-gutter:git-diff-arguments file)))
(apply #'start-file-process "git-gutter" proc-buf
"git" "--no-pager" "-c" "diff.autorefreshindex=0"
"diff" "--no-color" "--no-ext-diff" "--relative" "-U0" "--"
arg)))
(advice-add #'git-gutter:put-signs :before (lambda (&rest _) (realign-windows)))
(advice-add #'git-gutter:before-string :override #'+amos-git-gutter:before-string-a)
(advice-add #'git-gutter:start-git-diff-process :override #'+amos-git-gutter:start-git-diff-process-a)
;; (add-hook 'window-configuration-change-hook #'git-gutter:update-all-windows)
)
(use-package! evil-textobj-line
:after evil)
(use-package! chinese-yasdcv
:defer)
(defun +amos/recenter (&rest _)
(interactive)
(ignore-errors
(recenter)
;; (flycheck-inline-hide-errors)
(+nav-flash-blink-cursor-maybe-h)))
(defvar +amos-dir (file-name-directory load-file-name))
(defvar +amos-snippets-dir (expand-file-name "snippets/" +amos-dir))
;; Don't use default snippets, use mine.
(after! yasnippet
(add-hook! 'yas-minor-mode-hook (yas-activate-extra-mode 'fundamental-mode))
(setq yas-snippet-dirs
(append (list '+amos-snippets-dir '+file-templates-dir)
(delq 'yas-installed-snippets-dir yas-snippet-dirs))))
(add-to-list 'auto-mode-alist '("/git/serverconfig/scripts/[!.]+" . sh-mode))
(setq +file-templates-alist
`(;; General
("/git/serverconfig/scripts/[!.]+" :mode sh-mode)
("/git/serverconfig/.config/fish/functions/.+" :trigger "__func" :mode fish-mode)
(gitignore-mode)
(dockerfile-mode)
("/docker-compose\\.yml$" :mode yaml-mode)
("/Makefile$" :mode makefile-gmake-mode)
;; elisp
("/.dir-locals.el$")
("/packages\\.el$" :when +file-templates-in-emacs-dirs-p
:trigger "__doom-packages"
:mode emacs-lisp-mode)
("/doctor\\.el$" :when +file-templates-in-emacs-dirs-p
:trigger "__doom-doctor"
:mode emacs-lisp-mode)
("/test/.+\\.el$" :when +file-templates-in-emacs-dirs-p
:trigger "__doom-test"
:mode emacs-lisp-mode)
("\\.el$" :when +file-templates-in-emacs-dirs-p
:trigger "__doom-module"
:mode emacs-lisp-mode)
("-test\\.el$" :mode emacs-ert-mode)
(emacs-lisp-mode :trigger "__initfile")
(snippet-mode)
;; web-mode
("/normalize\\.scss$" :trigger "__normalize.scss" :mode scss-mode)
("/master\\.scss$" :trigger "__master.scss" :mode scss-mode)
("\\.html$" :trigger "__.html" :mode web-mode)
(scss-mode)
;; java
("/main\\.java$" :trigger "__main" :mode java-mode)
("/build\\.gradle$" :trigger "__build.gradle" :mode android-mode)
("/src/.+\\.java$" :mode java-mode)
;; javascript
("/package\\.json$" :trigger "__package.json" :mode json-mode)
("/bower\\.json$" :trigger "__bower.json" :mode json-mode)
("/gulpfile\\.js$" :trigger "__gulpfile.js" :mode js-mode)
("/webpack\\.config\\.js$" :trigger "__webpack.config.js" :mode js-mode)
("\\.js\\(?:on\\|hintrc\\)$" :mode json-mode)
;; Lua
("/main\\.lua$" :trigger "__main.lua" :mode love-mode)
("/conf\\.lua$" :trigger "__conf.lua" :mode love-mode)
;; Markdown
(markdown-mode)
;; Org
("/README\\.org$"
:when +file-templates-in-emacs-dirs-p
:trigger "__doom-readme"
:mode org-mode)
("\\.org$" :trigger "__" :mode org-mode)
;; PHP
("\\.class\\.php$" :trigger "__.class.php" :mode php-mode)
(php-mode)
;; Python
;; TODO ("tests?/test_.+\\.py$" :trigger "__" :mode nose-mode)
;; TODO ("/setup\\.py$" :trigger "__setup.py" :mode python-mode)
(python-mode)
;; Ruby
("/lib/.+\\.rb$" :trigger "__module" :mode ruby-mode :project t)
("/spec_helper\\.rb$" :trigger "__helper" :mode rspec-mode :project t)
("_spec\\.rb$" :mode rspec-mode :project t)
("/\\.rspec$" :trigger "__.rspec" :mode rspec-mode :project t)
("\\.gemspec$" :trigger "__.gemspec" :mode ruby-mode :project t)
("/Gemfile$" :trigger "__Gemfile" :mode ruby-mode :project t)
("/Rakefile$" :trigger "__Rakefile" :mode ruby-mode :project t)
(ruby-mode)
;; Rust
("/Cargo.toml$" :trigger "__Cargo.toml" :mode rust-mode)
("/main\\.rs$" :trigger "__main.rs" :mode rust-mode)
;; Slim
("/\\(?:index\\|main\\)\\.slim$" :mode slim-mode)
;; Shell scripts
("\\.zunit$" :trigger "__zunit" :mode sh-mode)
(fish-mode)
(sh-mode)
;; Solidity
(solidity-mode :trigger "__sol")))
(setq epa-file-encrypt-to user-mail-address
c-tab-always-indent t
auth-sources (list (expand-file-name ".authinfo.gpg" +amos-dir)))
(defun +amos-no-authinfo-for-tramp-a (orig-fn &rest args)
"Don't look into .authinfo for local sudo TRAMP buffers."
(let ((auth-sources (if (equal tramp-current-method "sudo") nil auth-sources)))
(apply orig-fn args)))
(advice-add #'tramp-read-passwd :around #'+amos-no-authinfo-for-tramp-a)
(defmacro +amos-make-special-indent-fn! (keyword)
`(let* ((sname (symbol-name ,keyword))
(s (intern (concat "special-indent-fn-" sname))))
(fset s (lambda (pos state)
(save-excursion
(search-backward sname)
(current-column))))
(put ,keyword 'lisp-indent-function s)))
(setq +amos-list-starters
'(:hint
:textDocument
))
(--map (+amos-make-special-indent-fn! it) +amos-list-starters)
(put :color 'lisp-indent-function 'defun)
(put :pre 'lisp-indent-function 'defun)
(put :post 'lisp-indent-function 'defun)
(after! evil-snipe (evil-snipe-mode -1))
(after! evil-multiedit
(setq evil-multiedit-follow-matches t)
(add-hook! 'evil-multiedit-insert-state-entry-hook
(evil-start-undo-step)
(setq evil-in-single-undo t))
(add-hook! 'evil-multiedit-insert-state-exit-hook
(setq evil-in-single-undo nil)
(evil-end-undo-step)))
(defun sp-point-after-same-p (id action _context)
"Return t if point is followed by ID, nil otherwise.
This predicate is only tested on \"insert\" action."
(when (eq action 'insert)
(save-excursion
(backward-char 1) ; go before current inserted quote
(sp--looking-back-p (regexp-quote id)))))
(defun +amos-sp-point-after-bol-p (id action _context)
"Return t if point follows beginning of line and possibly white spaces, nil otherwise.
This predicate is only tested on \"insert\" action."
(when (eq action 'insert)
(save-excursion
(backward-char 1) ; go before current inserted quote
(sp--looking-back-p (concat "^\\s-*" (regexp-quote id))))))
(after! smartparens
;; Auto-close more conservatively
(let ((unless-list '(sp-point-before-word-p
sp-point-after-word-p
sp-point-before-same-p
sp-point-after-same-p)))
(sp-pair "'" nil :unless unless-list)
(sp-pair "\"" nil :unless unless-list))
(sp-pair "{" nil :post-handlers '(("||\n[i]" "RET") ("| " " "))
:unless '(sp-point-before-word-p sp-point-before-same-p))
(sp-pair "(" nil :post-handlers '(("||\n[i]" "RET") ("| " " "))
:unless '(sp-point-before-word-p sp-point-before-same-p))
(sp-pair "[" nil :post-handlers '(("| " " "))
:unless '(sp-point-before-word-p sp-point-before-same-p)))
(after! cus-edit (evil-set-initial-state 'Custom-mode 'normal))
(after! compile (evil-set-initial-state 'compilation-mode 'normal))
(defun +amos|init-frame (&optional frame)
(when (and frame (display-graphic-p frame))
(with-selected-frame frame
(dolist (charset '(kana han cjk-misc bopomofo))
(set-fontset-font t charset
(font-spec :family "WenQuanYi Micro Hei" :size 34)))
(remove-hook! 'after-make-frame-functions #'+amos|init-frame))))
(add-hook! 'after-init-hook
(if initial-window-system
(+amos|init-frame)
(add-hook! 'after-make-frame-functions #'+amos|init-frame)))
(defun selected-root-frame ()
(let ((frame (selected-frame)))
(or (frame-parent frame) frame)))
(defun tty-root-frame-list ()
"Return a list of TTY root frames in reverse order.
These are frames that have a terminal, do not have a parent,
and are not the special daemon frame."
(let (result)
(dolist (f (frame-list))
(when (and (frame-terminal f)
(frame-parameter f 'tty-type)
(not (frame-parent f)))
(push f result)))
result))
(defmacro with-x-environment (&rest body)
`(let ((process-environment
(cons (concat "DISPLAY=" (getenv "DISPLAY" (selected-root-frame)))
process-environment)))
(if (getenv "XAUTHORITY" (selected-root-frame))
(setq process-environment
(cons (concat "XAUTHORITY=" (getenv "XAUTHORITY" (selected-root-frame)))
process-environment)))
,@body))
(defun +amos-x-select-text (text &rest _)
(with-temp-buffer
(insert text)
(with-x-environment
(call-process-region (point-min) (point-max) "xclip")))
text)
(defun +amos-tui-select-text (text &rest _)
(with-temp-buffer
(insert text)
(with-x-environment
(call-process-region (point-min) (point-max) "clipserver")))
text)
(if gui-p
(setq interprogram-cut-function '+amos-x-select-text)
(setq interprogram-cut-function '+amos-tui-select-text))
;; (use-package osc
;; :demand
;; :init
;; (defun +amos/other-window ()
;; (interactive)
;; (if (display-graphic-p)
;; (i3-nav-right)
;; (osc-nav-right)))
;; (if gui-p
;; (setq interprogram-cut-function '+amos-x-select-text)
;; (setq interprogram-cut-function '+amos-tui-select-text))
;; (setq browse-url-browser-function (lambda (url &optional _new-window)
;; (if (display-graphic-p)
;; (if _new-window
;; (browse-url-chrome url)
;; (browse-url-firefox url))
;; (browse-url-osc url _new-window)))))
(defvar server-visit-file nil)
(custom-set-faces!
`(font-lock-number-face :foreground ,(doom-color 'numbers))
'(font-lock-function-call-face
:inherit font-lock-function-name-face
:foreground "hot pink"
:background "black"))
(setq recenter-redisplay nil)
(remove-hook! 'kill-emacs-query-functions #'doom-quit-p)
(remove-hook! 'doom-init-ui-hook #'blink-cursor-mode)
(remove-hook! 'doom-real-buffer-functions #'doom-dired-buffer-p)
;; (remove-hook! 'doom-init-ui-hook #'show-paren-mode)
(add-hook! 'after-init-hook
(defun amos-after-init-h (&rest _)
(realign-mode)
(blink-cursor-mode -1)
(setq-default truncate-lines nil)))
(let ((evil-cursors '(("normal" "#b8860b" box)
("insert" "#66cd00" bar)
("emacs" "#7ec0ee" box)
("replace" "#cd6600" hbar)
("visual" "#808080" hbar)
("motion" "#cd96cd" box)
("lisp" "#ff6eb4" bar)
("sticky" "#B59FEA" box)
("struct" "#8991EF" box)
("iedit" "#ff3030" box)
("multiedit" "#ff3030" box)
("multiedit-insert" "#ff3030" bar)
("iedit-insert" "#ff3030" bar))))
(cl-loop for (state color cursor) in evil-cursors
do (set (intern (format "evil-%s-state-cursor" state)) (list color cursor))))
;; may delete the real hyphens
(defadvice fill-delete-newlines (before *amos+fill-delete-newlines activate)
"Replace -\\n with an empty string when calling `fill-paragraph'."
(when (eq this-command 'unfill-paragraph)
(goto-char (ad-get-arg 0))
(while (search-forward "-\n" (ad-get-arg 1) t)
(replace-match "")
(ad-set-arg 1 (- (ad-get-arg 1) 2)))))
(unless window-system
;; NOTE: Not good
;; (use-package kkp
;; :config
;; ;; (setq kkp-alt-modifier 'alt) ;; use this if you want to map the Alt keyboard modifier to Alt in Emacs (and not to Meta)
;; (global-kkp-mode +1))
(require 'evil-terminal-cursor-changer)
(xterm-mouse-mode +1)
;; enable terminal scroll
(global-set-key (kbd "<mouse-6>")
(lambda ()
(interactive)
(evil-scroll-column-left 3)))
(global-set-key (kbd "<mouse-7>")
(lambda ()
(interactive)
(evil-scroll-column-right 3)))
(global-set-key (kbd "<mouse-4>")
(lambda ()
(interactive)
(evil-scroll-line-up 3)))
(global-set-key (kbd "<mouse-5>")
(lambda ()
(interactive)
(evil-scroll-line-down 3)))
(etcc-on))
(setq +amos-docsets nil)
(defun +amos-set-docsets (mode &rest plist)
(push (cons mode plist) +amos-docsets))
(+amos-set-docsets 'fish-mode :docs '("fish" "Linux_Man_Pages"))
(+amos-set-docsets 'sh-mode :docs '("Bash" "Linux_Man_Pages"))
(+amos-set-docsets 'go-mode :docs "Go")
(+amos-set-docsets 'cmake-mode :docs "CMake")
(+amos-set-docsets 'java-mode :docs "Java")
(+amos-set-docsets 'rust-mode :docs "Rust")
(+amos-set-docsets 'lua-mode :docs '("Lua_5.1" "Lua_5.3"))
(+amos-set-docsets 'c-mode :docs '("C" "Linux_Man_Pages"))
(+amos-set-docsets 'c++-mode :docs '("C" "C++" "Linux_Man_Pages" "Boost"))
(+amos-set-docsets 'python-mode :docs '("Python_3" "Python_2"))
(+amos-set-docsets 'js2-mode :docs "JavaScript")
(+amos-set-docsets 'emacs-lisp-mode :docs "Emacs_Lisp")
(defun +amos-browse-url-a (ofun &rest candidate)
(if (boundp 'amos-browse)
(apply 'browse-url-firefox candidate)
(apply ofun candidate)))
(advice-add 'browse-url :around #'+amos-browse-url-a)
(defadvice run-skewer (around +amos*run-skewer activate)
(setq-local amos-browse t)
ad-do-it)
(defun my-create-newline-and-enter-sexp (&rest _ignored)
"Open a new brace or bracket expression, with relevant newlines and indent."
(newline)
(indent-according-to-mode)
(forward-line -1)
(indent-according-to-mode))
(with-eval-after-load 'smartparens
(sp-local-pair 'c-mode "{" nil :post-handlers
'((my-create-newline-and-enter-sexp "RET")))
(sp-local-pair 'java-mode "{" nil :post-handlers
'((my-create-newline-and-enter-sexp "RET"))))
;; stole from https://emacs.stackexchange.com/a/16495/16662
(defmacro doom-with-advice (args &rest body)
(declare (indent 3))
(let ((fun-name (car args))
(advice (cadr args))
(orig-sym (make-symbol "orig")))
`(cl-letf* ((,orig-sym (symbol-function ',fun-name))
((symbol-function ',fun-name)
(lambda (&rest args)
(apply ,advice ,orig-sym args))))
,@body)))
(defadvice edebug-pop-to-buffer (around +amos*edebug-pop-to-buffer activate)
(doom-with-advice (split-window (lambda (orig-fun window) (funcall orig-fun window nil 'right)))
ad-do-it))
(defadvice hl-line-mode (after +amos*hl-line-mode activate)
(set-face-background hl-line-face "Gray13"))
(defun +amos/evil-undefine ()
(interactive)
(let (evil-mode-map-alist)
(call-interactively (key-binding (this-command-keys)))))
;; recenter buffer when switching windows
(defun +amos-update-window-buffer-list-h ()
(walk-window-tree
(lambda (window)
(let ((old-buffer (window-parameter window 'my-last-buffer))
(new-buffer (window-buffer window)))
(unless (eq old-buffer new-buffer)
;; The buffer of a previously existing window has changed or
;; a new window has been added to this frame.
;; (+amos/recenter)
(setf (window-parameter window 'my-last-buffer) new-buffer))))))
(add-hook! 'window-configuration-change-hook #'+amos-update-window-buffer-list-h)
(defun +amos-goto-error (&optional prev)
(catch 'return
(dolist (walk-windows-window (window-list-1))
(with-selected-window walk-windows-window
(with-current-buffer (window-buffer walk-windows-window)
(when (eq major-mode 'grep-mode)
(let ((inhibit-message t))
(if prev (previous-error)
(next-error)))
(throw 'return nil))))
)
(if prev (windmove-up)
(windmove-down)))
)
(defun +amos/goto-previous-error ()
(interactive)
(+amos-goto-error t)
)
(defun +amos/goto-next-error ()
(interactive)
(+amos-goto-error)
)
(use-package! yapfify
:after python)
;; from spacemacs
(defun +amos/rename-current-buffer-file (&optional arg)
"Rename the current buffer and the file it is visiting.
If the buffer isn't visiting a file, ask if it should
be saved to a file, or just renamed.
If called without a prefix argument, the prompt is
initialized with the current filename."
(interactive "P")
(let* ((name (buffer-name))
(filename (buffer-file-name)))
(if (and filename (file-exists-p filename))
;; the buffer is visiting a file
(let* ((dir (file-name-directory filename))
(new-name (read-file-name "New name: " (if arg dir filename))))
(cond ((get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name))
(t
(let ((dir (file-name-directory new-name)))
(when (and (not (file-exists-p dir))
(yes-or-no-p
(format "Create directory '%s'?" dir)))
(make-directory dir t)))
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(when (fboundp 'recentf-add-file)
(recentf-add-file new-name)
(recentf-remove-if-non-kept filename))
(when (and (featurep 'projectile)
(projectile-project-p))
(call-interactively #'projectile-invalidate-cache))
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name))
(doom-modeline-update-buffer-file-state-icon)
(doom-modeline-update-buffer-file-name)
)))
;; the buffer is not visiting a file
(let ((key))
(while (not (memq key '(?s ?r)))
(setq key (read-key (propertize
(format
(concat "Buffer '%s' is not visiting a file: "
"[s]ave to file or [r]ename buffer?")
name) 'face 'minibuffer-prompt)))
(cond ((eq key ?s) ; save to file
;; this allows for saving a new empty (unmodified) buffer
(unless (buffer-modified-p) (set-buffer-modified-p t))
(save-buffer))
((eq key ?r) ; rename buffer
(let ((new-name (read-string "New buffer name: ")))
(while (get-buffer new-name)
;; ask to rename again, if the new buffer name exists
(if (yes-or-no-p
(format (concat "A buffer named '%s' already exists: "
"Rename again?") new-name))
(setq new-name (read-string "New buffer name: "))
(keyboard-quit)))
(rename-buffer new-name)
(message "Buffer '%s' successfully renamed to '%s'"
name new-name)))
;; ?\a = C-g, ?\e = Esc and C-[
((memq key '(?\a ?\e)) (keyboard-quit))))))))
;; BEGIN align functions
(defun +amos/align-repeat-left (start end regexp)
(interactive "r\nsAlign regexp: ")
(+amos/align-repeat start end regexp))
(defun +amos/align-repeat-right (start end regexp)
(interactive "r\nsAlign regexp: ")
(+amos/align-repeat start end regexp t t))
;; modified function from http://emacswiki.org/emacs/AlignCommands
(defun +amos/align-repeat (start end regexp &optional justify-right after)
"Repeat alignment with respect to the given regular expression.
If JUSTIFY-RIGHT is non nil justify to the right instead of the
left. If AFTER is non-nil, add whitespace to the left instead of
the right."
(let* ((ws-regexp (if (string-empty-p regexp)
"\\(\\s-+\\)"
"\\(\\s-*\\)"))
(complete-regexp (if after
(concat regexp ws-regexp)
(concat ws-regexp regexp)))
(group (if justify-right -1 1)))
(unless (use-region-p)
(save-excursion
(while (and
(string-match-p complete-regexp (thing-at-point 'line))
(= 0 (forward-line -1)))
(setq start (point-at-bol))))
(save-excursion
(while (and
(string-match-p complete-regexp (thing-at-point 'line))
(= 0 (forward-line 1)))
(setq end (point-at-eol)))))
(align-regexp start end complete-regexp group 1 t)))
(defun +amos/dos2unix ()
"Converts the current buffer to UNIX file format."
(interactive)
(set-buffer-file-coding-system 'undecided-unix nil))
(defun +amos/unix2dos ()
"Converts the current buffer to DOS file format."
(interactive)
(set-buffer-file-coding-system 'undecided-dos nil))
;; from https://www.emacswiki.org/emacs/CopyingWholeLines
(defun +amos/duplicate-line-or-region (&optional n)
"Duplicate current line, or region if active.
With argument N, make N copies.
With negative N, comment out original line and use the absolute value."
(interactive "*p")
(let ((use-region (use-region-p)))
(save-excursion
(let ((text (if use-region ; Get region if active, otherwise line
(buffer-substring (region-beginning) (region-end))
(prog1 (thing-at-point 'line)
(end-of-line)
(if (< 0 (forward-line 1)) ; Go to beginning of next line, or make a new one
(newline))))))
(dotimes (i (abs (or n 1))) ; Insert N times, or once if not specified
(insert text))))
(if use-region nil ; Only if we're working with a line (not a region)
(let ((pos (- (point) (line-beginning-position)))) ; Save column
(if (> 0 n) ; Comment out original with negative arg
(comment-region (line-beginning-position) (line-end-position)))
(forward-line 1)
(forward-char pos)))))
(defun +amos/sort-lines-by-column (&optional reverse)
"Sort lines by the selected column,
using a visual block/rectangle selection.
A non-nil argument sorts in REVERSE order."
(interactive "P")
(if (and
;; is there an active selection
(or (region-active-p) (evil-visual-state-p))
;; is it a block or rectangle selection
(or (eq evil-visual-selection 'block) (eq rectangle-mark-mode t))
;; is the selection height 2 or more lines
(>= (1+ (- (line-number-at-pos (region-end))
(line-number-at-pos (region-beginning)))) 2))
(sort-columns reverse (region-beginning) (region-end))
(error "Sorting by column requires a block/rect selection on 2 or more lines.")))
(defun +amos/sort-lines-by-column-reverse ()
"Sort lines by the selected column in reverse order,
using a visual block/rectangle selection."
(interactive)
(+amos/sort-lines-by-column -1))
(after! evil-surround
(setq-default evil-surround-pairs-alist (append '((?` . ("`" . "`")) (?~ . ("~" . "~"))) evil-surround-pairs-alist)))
(evil-define-motion +amos-evil-beginning-of-line-a ()
"Move the cursor to the beginning of the current line."
:type exclusive
(if (bolp)
(back-to-indentation)
(let ((p (point)))
(back-to-indentation)
(if (<= p (point))
(beginning-of-line)))))
(advice-add 'evil-beginning-of-line :override #'+amos-evil-beginning-of-line-a)
(defun +amos/save-buffer-without-dtw ()
(interactive)
(let ((b (current-buffer))) ; memorize the buffer
(with-temp-buffer ; new temp buffer to bind the global value of before-save-hook
(let ((before-save-hook (remove 'ws-butler-before-save before-save-hook)))
(with-current-buffer b ; go back to the current buffer, before-save-hook is now buffer-local
(let ((before-save-hook (remove 'ws-butler-before-save before-save-hook)))
(save-buffer)))))))
(defvar switch-buffer-functions
nil
"A list of functions to be called when the current buffer has been changed.
Each is passed two arguments, the previous buffer and the current buffer.")
(defvar switch-buffer-functions--last-buffer
nil
"The last current buffer.")
(defvar switch-buffer-functions--running-p
nil
"Non-nil if currently inside of run `switch-buffer-functions-run'.")
(defun switch-buffer-functions-run ()
"Run `switch-buffer-functions' if needed.
This function checks the result of `current-buffer', and run
`switch-buffer-functions' when it has been changed from
the last buffer.
This function should be hooked to `buffer-list-update-hook'."
(unless switch-buffer-functions--running-p
(let ((switch-buffer-functions--running-p t)
(current (current-buffer))
(previous switch-buffer-functions--last-buffer))
(unless (eq previous
current)
(run-hook-with-args 'switch-buffer-functions
previous
current)
(setq switch-buffer-functions--last-buffer
(current-buffer))))))
(add-hook! 'buffer-list-update-hook #'switch-buffer-functions-run)
(defun endless/sharp ()
"Insert #' unless in a string or comment."
(interactive)
(call-interactively #'self-insert-command)
(let ((ppss (syntax-ppss)))
(unless (or (elt ppss 3)
(elt ppss 4)
(eq (char-after) ?'))
(insert "'"))))
(add-hook! 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
(defun +amos*reload-envrc ()
"Update all buffers using the same .envrc directory when .envrc is saved."
(when (and buffer-file-name
(string-equal (file-name-nondirectory buffer-file-name) ".envrc"))
(envrc-reload)))
(add-hook! 'after-save-hook #'+amos*reload-envrc)
(defun +amos*evil-transient-mark (&optional arg)
"Toggle Transient Mark mode.
Ensure that the region is properly deactivated.
Enable with positive ARG, disable with negative ARG."
(unless (numberp arg)
(setq arg (if transient-mark-mode -1 1)))
(cond
((< arg 1)
(evil-active-region -1))
(t
(unless transient-mark-mode
(evil-active-region -1)
(transient-mark-mode 1)))))
(advice-add #'evil-transient-mark :override #'+amos*evil-transient-mark)
(evil-define-command ab-char-inc ()
(save-excursion
(let ((chr (1+ (char-after))))
(unless (characterp chr) (error "Cannot increment char by one"))
(delete-char 1)
(insert chr))))
(evil-define-command +amos/replace-last-sexp ()
(let ((value (eval (preceding-sexp))))
(kill-sexp -1)
(insert (format "%S" value))))
(evil-define-command +amos/replace-defun ()
(narrow-to-defun)
(goto-char (point-max))
(let ((value (eval (preceding-sexp))))
(kill-sexp -1)
(insert (format "%s" value)))
(widen)
(backward-char))
(evil-define-command +amos/new-empty-elisp-buffer ()
(let ((buf (generate-new-buffer "*new*")))
(+amos/workspace-new)
(switch-to-buffer buf)
(emacs-lisp-mode)
(evil-insert-state)
(setq buffer-offer-save nil)
buf))
(defun +amos/smart-jumper (&optional f)
(let* ((dir (if f -1 (forward-char) 1))
(c (point))
quote
delim)
(setq quote (if (nth 3 (syntax-ppss))
(let ((b (save-excursion (progn (up-list -1 t t) (point))))