-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
1744 lines (1542 loc) · 58.7 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
(setq package-archives '(("gnu" . "http://1.15.88.122/gnu/")
("melpa" . "http://1.15.88.122/melpa/")))
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 6))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;; Set up use-package for tidier package configuration/installation
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)
(setq straight-vc-git-default-clone-depth 1)
;; Add diminish, which makes it easier to customize lighters (minor mode display)
(use-package diminish)
;; time date
(defun gcl/insert-standard-date ()
"Inserts standard date time string."
(interactive)
(insert (format-time-string "%Y-%m-%d %T")))
(defun gcl/insert-changelog-date ()
"Insert changelog date, like yyyy/mm/dd."
(interactive)
(insert (format-time-string "%Y/%m/%d")))
(defun gcl/insert-current-time ()
"Insert current time, like hh:mm:ss."
(interactive)
(insert (format-time-string "%T")))
(defun gcl/open-current-directory ()
(interactive)
(consult-file-externally default-directory))
(defun buf-move-up ()
"Swap the current buffer and the buffer above the split.
If there is no split, ie now window above the current one, an
error is signaled."
;; "Switches between the current buffer, and the buffer above the
;; split, if possible."
(interactive)
(let* ((other-win (windmove-find-other-window 'up))
(buf-this-buf (window-buffer (selected-window))))
(if (null other-win)
(error "No window above this one")
;; swap top with this one
(set-window-buffer (selected-window) (window-buffer other-win))
;; move this one to top
(set-window-buffer other-win buf-this-buf)
(select-window other-win))))
(defun buf-move-down ()
"Swap the current buffer and the buffer under the split.
If there is no split, ie now window under the current one, an
error is signaled."
(interactive)
(let* ((other-win (windmove-find-other-window 'down))
(buf-this-buf (window-buffer (selected-window))))
(if (or (null other-win)
(string-match "^ \\*Minibuf" (buffer-name (window-buffer other-win))))
(error "No window under this one")
;; swap top with this one
(set-window-buffer (selected-window) (window-buffer other-win))
;; move this one to top
(set-window-buffer other-win buf-this-buf)
(select-window other-win))))
(defun buf-move-left ()
"Swap the current buffer and the buffer on the left of the split.
If there is no split, ie now window on the left of the current
one, an error is signaled."
(interactive)
(let* ((other-win (windmove-find-other-window 'left))
(buf-this-buf (window-buffer (selected-window))))
(if (null other-win)
(error "No left split")
;; swap top with this one
(set-window-buffer (selected-window) (window-buffer other-win))
;; move this one to top
(set-window-buffer other-win buf-this-buf)
(select-window other-win))))
(defun buf-move-right ()
"Swap the current buffer and the buffer on the right of the split.
If there is no split, ie now window on the right of the current
one, an error is signaled."
(interactive)
(let* ((other-win (windmove-find-other-window 'right))
(buf-this-buf (window-buffer (selected-window))))
(if (null other-win)
(error "No right split")
;; swap top with this one
(set-window-buffer (selected-window) (window-buffer other-win))
;; move this one to top
(set-window-buffer other-win buf-this-buf)
(select-window other-win))))
(defun kill-other-window-buffer ()
"Kill the buffer in other window."
(interactive)
(other-window +1)
(kill-this-buffer)
(other-window -1))
(defun gcl/get-frame->selected-window ()
"Returns a list of pairs of (frame selected-window)"
(let* ((original-frame (window-frame))
(result (->> (visible-frame-list)
(-map (lambda (f)
(select-frame f t)
(list f (selected-window)))))))
(select-frame original-frame t)
result))
(eval-when-compile
(require 'cl))
(defun gcl/preserve-selected-window (f)
"Runs the given function and then restores focus to the original window. Useful when you want to invoke
a function (like showing documentation) but desire to keep your current window focused."
;; Note that we must preserve the selected window of every frame, because the function being executed may
;; change the focused frame, even if the current frame is in focus.
(lexical-let* ((original-frame (selected-frame))
(frames->windows (gcl/get-frame->selected-window))
(result (funcall f)))
(-each frames->windows (lambda (x)
(select-frame (first x) t)
(select-window (second x) t)))
(select-frame-set-input-focus original-frame t)
result))
(defun reload-init-file ()
"Reload init file with <f5>."
(interactive)
(load-file "~/.emacs.d/init.el"))
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(and (file-readable-p custom-file) (load custom-file))
(defun gcl/open-init-file()
(interactive)
(find-file (expand-file-name "config.org" user-emacs-directory)))
(global-set-key (kbd "<f5>") 'reload-init-file)
(global-set-key (kbd "<f1>") 'gcl/open-init-file)
(global-set-key (kbd "<f2>") 'restart-emacs)
;; 保存文件时自动生成配置到 init.el
(use-package org-auto-tangle
:hook (org-mode . org-auto-tangle-mode))
(use-package auto-save
:straight (:host github :repo "manateelazycat/auto-save")
:config
(auto-save-enable)
(setq auto-save-silent t)
(setq auto-save-delete-trailing-whitespace t)
;; 不想自动保存的文件后缀
(setq auto-save-disable-predicates
'((lambda ()
(string-suffix-p
"gpg"
(file-name-extension (buffer-name)) t))))
)
(setq blog-admin-dir "~/github/mine/blog.cheng92.com/")
(setq user-full-name "Lee ZhiCheng"
user-mail-address "gccll.love@gmail.com"
user-blog-url "https://blog.cheng92.com"
user-github-dir "~/github/mine/"
user-web-dir "~/github/mine/gcl-web-system/"
user-blog-dir (concat user-web-dir "apps/blog/")
user-blog-public-dir (concat user-blog-dir "public/")
user-blog-posts (concat user-blog-dir "/public/posts/")
user-dot-dir "~/.gclrc/"
user-dot-bin-dir "~/.gclrc/bin/"
)
;; 启动全屏
(set-frame-parameter (selected-frame) 'fullscreen 'maximized)
;; 选中粘贴时能覆盖选中的内容
(delete-selection-mode 1)
;; 高亮当前行
(global-hl-line-mode 1)
;; 指针不闪动。
(blink-cursor-mode -1)
;; 有些功能需要用到,比如:折叠等等
(add-hook 'prog-mode-hook #'hs-minor-mode)
;; 选择是或否是用 y/n
(fset 'yes-or-no-p 'y-or-n-p)
;; 默认显示 80 列就换行
(setq default-fill-column 80)
;; 用一个很大的 kill ring. 这样防止我不小心删掉重要的东西
(setq kill-ring-max 1024)
;; 设置的 mark ring 容量
(setq mark-ring-max 1024)
;; 设置执行表达式的长度没有限制
(setq eval-expression-print-length nil)
;; 设置执行表达式的深度没有限制
(setq eval-expression-print-level nil)
;; 设置最大的全局标记容量
(setq global-mark-ring-max 1024)
;; minibuffer 递归调用命令
(setq enable-recursive-minibuffers t)
;; 删除minibuffer的重复历史
(setq history-delete-duplicates t)
;; 显示消息超时的时间
(setq minibuffer-message-timeout 1)
;; 自动更新 buffer
(setq auto-revert-mode 1)
;; 括号匹配显示但不是烦人的跳到另一个括号。
(setq show-paren-style 'parentheses)
;; 当插入右括号时显示匹配的左括号
(setq blink-matching-paren t)
;; 不自动添加换行符到末尾, 有些情况会出现错误
(setq require-final-newline nil)
;; 比较窗口设置在同一个 frame 里
(setq ediff-window-setup-function (quote ediff-setup-windows-plain))
;; 设置传送文件默认的方法
(setq tramp-default-method "ssh")
;; 禁止显示鼠标指针
(setq void-text-area-pointer nil)
;; 当出现异常时弹出三角警告
(setq visible-bell t)
;; 显示行尾空格
(setq show-trailing-whitespace t)
(setq create-lockfiles nil)
;; --- 关闭启动消息。
(setq inhibit-startup-screen t)
(setq inhibit-startup-message t)
(setq inhibit-startup-echo-area-message t)
(setq initial-scratch-message nil)
;; 改变 *scratch* buffer 的模式
(setq initial-major-mode 'emacs-lisp-mode)
(setq initial-buffer-choice t)
;; *scratch* buffer 初始显示的内容
(setq initial-scratch-message "\
;; This buffer is for notes you don't want to save, and for Ruby code.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.")
(defun max-gc-limit ()
(setq gc-cons-threshold most-positive-fixnum))
(defun reset-gc-limit ()
(setq gc-cons-threshold 800000))
;; 设置垃圾回收限制
(add-hook 'minibuffer-setup-hook #'max-gc-limit)
(add-hook 'minibuffer-exit-hook #'reset-gc-limit)
(setq-default bidi-display-reordering nil)
;; 加速启动
(setq auto-mode-case-fold nil)
;; 加快快捷键提示的速度
(setq echo-keystrokes 0.1)
;; 提升 IO 性能。
(setq process-adaptive-read-buffering nil)
;; 增加单次读取进程输出的数据量(缺省 4KB) 。
(setq read-process-output-max (* 1024 1024))
;; 缩短 fontify 时间。
(setq jit-lock-defer-time nil)
(setq jit-lock-context-time 0.1)
;; 更积极的 fontify 。
(setq fast-but-imprecise-scrolling nil)
(setq redisplay-skip-fontification-on-input nil)
;; 缩短更新 screen 的时间。
(setq idle-update-delay 0.1)
;; 使用字体缓存,避免卡顿。
(setq inhibit-compacting-font-caches t)
;; 使用更瘦字体。
(setq ns-use-thin-smoothing t)
;; 一次滚动一行,避免窗口跳动。
(setq mouse-wheel-scroll-amount '(1 ((shift) . hscroll)))
(setq mouse-wheel-scroll-amount-horizontal 1)
(setq mouse-wheel-follow-mouse t)
(setq mouse-wheel-progressive-speed nil)
(defconst 1mb 1048576)
(defconst 20mb 20971520)
(defconst 30mb 31457280)
(defconst 50mb 52428800)
;; lsp-mode's performance suggest
(setq read-process-output-max (* 3 1mb))
(use-package so-long
:straight (:host github :repo "hlissner/emacs-so-long")
:config
(add-hook 'after-init-hook #'global-so-long-mode)
(setq so-long-threshold 40000))
(set-face-attribute 'default nil :height 140 :family "WenQuanYi Micro Hei Mono")
(use-package font-lock+
:straight (:host github :repo "emacsmirror/font-lock-plus"))
(use-package all-the-icons)
(use-package all-the-icons-dired
:hook ((dired-mode . all-the-icons-dired-mode)))
;; -- header line
(set-face-attribute 'header-line nil
:foreground (face-attribute 'mode-line :foreground)
:background (face-attribute 'mode-line :background)
;; height of mode-line is also unspecified, so we set it directly.
:height 150
:box (face-attribute 'mode-line :box))
;; -- awesome tray
(use-package awesome-tray
:straight (awesome-tray :type git :host github :repo "manateelazycat/awesome-tray")
:config
(setq awesome-tray-mode-line-height 0.1)
;; (setq-default awesome-tray-mode-line-default-height 0.1)
(setq awesome-tray-mode-line-active-color "#EC4899")
(setq awesome-tray-mode-line-inactive-color "#959eb1")
(setq awesome-tray-active-modules '(
;; "location"
"pdf-view-page"
"date"
"file-path"
"buffer-name"
"mode-name"
"battery"
"git"
"input-method"
"evil"
;; "flymake"
"belong"
"anzu"
;; "github"
))
(setq awesome-tray-date-format "%d/%H:%M:%S")
(awesome-tray-mode 1))
;; -- highlight-parentheses
(use-package highlight-parentheses
:hook (prog-mode . highlight-parentheses-mode)
:config
(add-hook 'minibuffer-setup-hook #'highlight-parentheses-minibuffer-setup)
)
;; -- 丰富括号
(use-package rainbow-delimiters
:hook (prog-mode-hook . rainbow-delimiters-mode))
(use-package marginalia
:custom
(marginalia-max-relative-age 0)
(marginalia-align 'right)
:init
(marginalia-mode))
(use-package all-the-icons-completion
:after (marginalia all-the-icons)
:hook (marginalia-mode . all-the-icons-completion-marginalia-setup)
:init
(all-the-icons-completion-mode))
(use-package vertico
;; Special recipe to load extensions conveniently
:straight (vertico :files (:defaults "extensions/*")
:includes (vertico-indexed
vertico-flat
vertico-grid
vertico-mouse
vertico-quick
vertico-buffer
vertico-repeat
vertico-reverse
vertico-directory
vertico-multiform
vertico-unobtrusive
))
;; Make sure vertico state is saved for `vertico-repeat'
:hook (minibuffer-setup . vertico-repeat-save)
:custom
(vertico-count 13) ; Number of candidates to display
(vertico-resize t)
(vertico-cycle nil) ; Go from last to first candidate and first to last (cycle)?
:config
(vertico-mode))
(use-package which-key
:hook (after-init . which-key-mode)
:ensure t
:init
(setq which-key-side-window-location 'bottom)
(setq which-key-show-early-on-C-h t)
(setq which-key-idle-delay 0.1)
;;(setq which-key-idle-secondary-delay 0.05)
(which-key-mode)
)
(use-package evil
:ensure t
:init
(evil-mode)
:config
;; 退出编辑模式后光标留在原地
(setq evil-move-cursor-back nil)
;; 让回车,TAB,空格键保持原来的功能
(with-eval-after-load 'evil-maps
(define-key evil-motion-state-map (kbd "RET") nil)
(define-key evil-motion-state-map (kbd "TAB") nil)
(define-key evil-motion-state-map (kbd "SPC") nil))
(progn
(setcdr evil-insert-state-map nil)
(define-key evil-insert-state-map [escape] 'evil-normal-state)
;; --- 解绑一些按键
(evil-global-set-key 'normal (kbd "c") nil)
(setcdr evil-insert-state-map nil)
(define-key evil-insert-state-map [escape] 'evil-normal-state)
(setq-default evil-ex-search-persistent-highlight nil)
(define-key evil-motion-state-map (kbd "0") 'evil-end-of-line)
(evil-global-set-key 'normal "f" 'evil-avy-goto-char)
(evil-global-set-key 'normal "w" 'evil-avy-goto-word-1)
(evil-global-set-key 'motion "-" 'org-decrease-number-at-point)
(evil-global-set-key 'motion "+" 'org-increase-number-at-point)
(evil-global-set-key 'normal (kbd "gd") 'xref-find-definitions)
(evil-global-set-key 'normal (kbd "gb") 'xref-pop-marker-stack)
(evil-global-set-key 'normal (kbd "gc") 'show-commit-and-preserve-window)
(evil-global-set-key 'normal (kbd "cc") 'evilnc-copy-and-comment-lines)
)
)
(use-package evil-nerd-commenter
:ensure t)
;; (evil-set-initial-state 'color-rg-mode 'emacs)
;; (evil-set-initial-state 'multi-vterm-mode 'emacs)
;; (evil-set-initial-state 'vterm-mode 'emacs)
;; (evil-set-initial-state 'magit-mode 'emacs)
;; (evil-set-initial-state 'dired-mode 'emacs)
;; (evil-set-initial-state 'magit-branch-manager-mode 'emacs)
(use-package general)
(general-define-key
;; "<f2>" 'restart-emacs
)
(general-create-definer global-leader
:keymaps 'override
:states '(emacs normal hybrid motion visual operator)
:prefix ","
"" '(:ignore t :which-key (lambda (arg) `(,(cadr (split-string (car arg) " ")) . ,(replace-regexp-in-string "-mode$" "" (symbol-name major-mode))))))
(global-leader
;; "c" 'blamer-show-posframe-commit-info
)
(general-create-definer global-definer
:keymaps 'override
:states '(insert emacs normal hybrid motion visual operator)
:prefix "SPC"
:non-normal-prefix "C-SPC")
(global-definer
"TAB" 'projectile-persp-switch-project
"SPC" 'execute-extended-command
"0" 'select-window-0
"1" 'select-window-1
"2" 'select-window-2
"3" 'select-window-3
"," 'delete-window
"." 'kill-this-buffer
";" 'kill-other-window-buffer
"x" 'switch-to-scratch-buffer
"`" 'multi-vterm-project
)
;; 可以定制 SPC <key1> <key2> ...
(defmacro +general-global-menu! (name infix-key &rest body)
"Create a definer named +general-global-NAME wrapping global-definer.
Create prefix map: +general-global-NAME. Prefix bindings in BODY with INFIX-KEY."
(declare (indent 2))
`(progn
(general-create-definer ,(intern (concat "+general-global-" name))
:wrapping global-definer
:prefix-map ',(intern (concat "+general-global-" name "-map"))
:infix ,infix-key
:wk-full-keys nil
"" '(:ignore t :which-key ,name))
(,(intern (concat "+general-global-" name))
,@body)))
(+general-global-menu! "apps" "a"
"a" 'org-agenda
"c" 'agenda)
(+general-global-menu! "buffer" "b"
"b" 'consult-buffer
"o" 'consult-buffer-other-window
"p" 'previous-buffer
"n" 'next-buffer
"k" 'kill-buffer
"d" 'kill-current-buffer
"i" 'ibuffer
"r" 'crux-rename-buffer-and-file
"x" 'crux-kill-other-buffers
"f" 'gcl/open-current-directory
)
(+general-global-menu! "files" "f"
"o" 'crux-open-with
"p" 'consult-find
"f" 'find-file
"d" 'crux-delete-file-and-buffer
"r" 'crux-rename-file-and-buffer
)
(+general-global-menu! "load&link" "l"
;; test: https://blog.cheng92.com
;; "o" 'link-hint-open-link
;; "c" 'link-hint-copy-link
)
(+general-global-menu! "projects" "p"
;; "p" 'consult-projectile-switch-project
;; "f" 'consult-projectile-find-file
;; "d" 'consult-projectile-find-dir
;; "b" 'consult-projectile-switch-to-buffer
;; "B" 'consult-project-buffer
)
(+general-global-menu! "query" "q"
;; "r" 'restart-emacs
)
(+general-global-menu! "search" "s"
;; "p" 'consult-ripgrep
;; "i" 'color-rg-search-input
;; "I" 'color-rg-search-input-in-project
;; "s" 'color-rg-search-symbol
;; "S" 'color-rg-search-symbol-in-project
)
(+general-global-menu! "window" "w"
"," 'delete-window
"-" 'split-window-below
"v" 'split-window-right
"m" 'delete-other-windows
"h" 'evil-window-left
"l" 'evil-window-right
"j" 'evil-window-down
"k" 'evil-window-up)
(general-define-key
;; "C-;" 'embark-act
"C-=" 'er/expand-region
;; "C-a" 'crux-move-beginning-of-line
"C-r" 'crux-rename-buffer-and-file
"C-j" 'emmet-expand-yas
"C-s" 'consult-line
"C-'" 'toggle-quotes-plus
"C-`" 'vterm-toggle
"C-w" 'evil-delete-backward-word
"C-p" 'previous-line
"C-S-h" 'buf-move-left
"C-S-l" 'buf-move-right
"C-S-j" 'buf-move-down
"C-S-k" 'buf-move-up
"C-S-o" 'duplicate-line-or-region-above
"C-S-n" 'duplicate-line-or-region-below
;; C-c
;; 1 + 2 + 3
;; C-c f -> hydra-lsp/body
"C-c b" 'consult-bookmark
"C-c h" 'consult-history
"C-c o" 'consult-outline
"C-c y" 'fanyi-dwim2
"C-c t" 'gcl/insert-current-time
"C-c d" 'gcl/insert-standard-date
;; "C-c c" 'copy-buffer-file-name-as-kill
"C-c i" 'org-mac-link-get-link
"C-c e" 'consult-flycheck
"C-c r" 'vr/replace
"C-c q" 'vr/query-replace
"C-c m" 'vr/mc-mark
"C-c u" 'uuidgen
)
(general-define-key
"<s-backspace>" 'crux-kill-line-backwards
"<s-left>" 'windmove-left
"<s-right>" 'windmove-right
"<s-down>" 'windmove-down
"<s-up>" 'windmove-up
"s-," 'bury-buffer
"s-." 'unbury-buffer
"s-<" 'watch-other-window-up-line
"s->" 'watch-other-window-down-line
;; "s-0" 'sp-splice-sexp
"s-p" 'move-text-up
"s-n" 'move-text-down
"s-m" 'toggle-input-method
"s-o" 'toggle-one-window
"s-R" 're-builder
;; "s-i" 'gcl/string-inflection-cycle-auto
"s-d" 'consult-dir
"s-F" 'format-all-buffer
;; "s-h" 'gcl/urls/body
;; "s-`" 'vterm-toggle
"s-'" 'vertico-repeat
;; s-g
"s-g" nil
"s-g o" 'consult-outline
"s-g m" 'consult-mark
"s-g k" 'consult-global-mark
"s-g i" 'consult-yasnippet
)
(general-define-key
;; M, Option/Alt
"M-s" 'symbol-overlay-put
"M-n" 'symbol-overlay-switch-forward
"M-p" 'symbol-overlay-switch-backward
"M-c" 'symbol-overlay-remove-all
;; "M-*" 'tempel-insert
;; "M-+" 'tempel-complete
"M-'" 'consult-register-store
"M-#" 'consult-register-load
"M-;" 'evilnc-comment-or-uncomment-lines
;; "M-e" 'emojify-insert-emoji
;; "M-d" 'dash-at-point
;; "M-j" 'rime-inline-ascii
"M-i" 'consult-imenu
;; "M-m" 'blamer-show-posframe-commit-info
)
(setq save-abbrevs nil)
(setq-default abbrev-mode t)
(define-abbrev-table
'global-abbrev-table '(
;; signature
("8zc" "lizhicheng")
("8zj" "李志诚")
("8lp" "范婷婷")
;; Microsoft
("8ms" "Microsoft")
("8em" "gccll.love@gmail.com")
("8bl" "https://blog.cheng92.com")
))
(use-package dabbrev
;; Swap M-/ and C-M-/
:bind (("M-/" . dabbrev-completion)
("C-M-/" . dabbrev-expand))
;; Other useful Dabbrev configurations.
:custom
(dabbrev-ignored-buffer-regexps '("\\.\\(?:pdf\\|jpe?g\\|png\\)\\'")))
(use-package fancy-dabbrev
:ensure t
:config
(global-fancy-dabbrev-mode)
;; Bind fancy-dabbrev-expand and fancy-dabbrev-backward to your keys of
;; choice, here "TAB" and "Shift+TAB":
(global-set-key (kbd "M-/") 'fancy-dabbrev-expand)
(global-set-key (kbd "M-?") 'fancy-dabbrev-backward)
;; If you want TAB to indent the line like it usually does when the cursor
;; is not next to an expandable word, use 'fancy-dabbrev-expand-or-indent
;; instead of `fancy-dabbrev-expand`:
;; (global-set-key (kbd "TAB") 'fancy-dabbrev-expand-or-indent)
;; (global-set-key (kbd "<backtab>") 'fancy-dabbrev-backward)
;; Let dabbrev searches ignore case and expansions preserve case:
(setq dabbrev-case-distinction nil)
(setq dabbrev-case-fold-search t)
(setq dabbrev-case-replace nil)
)
;; 有变化时自动保存
(setq bookmark-save-flag 1)
(use-package expand-region)
(use-package smartparens
:diminish smartparens-mode
:bind
(:map smartparens-mode-map
("C-M-f" . sp-forward-sexp)
("C-M-b" . sp-backward-sexp)
("C-M-k" . sp-kill-sexp)
("C-M-w" . sp-copy-sexp)
:map smartparens-strict-mode-map
("C-M-<backspace>" . sp-backward-unwrap-sexp)
("C-M-d" . sp-unwrap-sexp))
:hook
((prog-mode . smartparens-mode)
;; (smartparens-mode . smartparens-strict-mode)
)
:config (require 'smartparens-config))
(use-package autorevert
:diminish
:hook (after-init . global-auto-revert-mode))
(use-package hungry-delete
:diminish
:hook (after-init . global-hungry-delete-mode)
:config (setq-default hungry-delete-chars-to-skip " \t\f\v"))
(use-package symbol-overlay)
(use-package move-text)
(use-package editorconfig
:config
(editorconfig-mode 1))
(use-package toggle-quotes-plus
:straight (:host github :repo "jcs-elpa/toggle-quotes-plus")
:config
(setq toggle-quotes-plus-chars '("\""
"'"
"`")))
(use-package hydra)
(use-package crux)
(use-package fanyi
:config
(custom-set-variables
'(fanyi-providers '(fanyi-haici-provider
fanyi-youdao-thesaurus-provider
fanyi-etymon-provider
fanyi-longman-provider
fanyi-libre-provider)))
;; 还要自动选择翻译内容 buffer
(setq fanyi-auto-select nil))
(use-package link-hint
:ensure t
:bind
("C-c l o" . link-hint-open-link)
("C-c l c" . link-hint-copy-link))
(use-package math-at-point
:straight (:host github :repo "shankar2k/math-at-point"))
(use-package uuidgen)
(require 'dired)
(setq dired-recursive-deletes 'always)
(setq dired-recursive-copies 'always)
(setq delete-by-moving-to-trash t)
(setq dired-dwim-target t)
(setq dired-listing-switches "-alh")
(setq dired-guess-shell-alist-user
'(("\\.pdf\\'" "open")
("\\.docx\\'" "open")
("\\.\\(?:djvu\\|eps\\)\\'" "open")
("\\.\\(?:jpg\\|jpeg\\|png\\|gif\\|xpm\\)\\'" "open")
("\\.\\(?:xcf\\)\\'" "open")
("\\.csv\\'" "open")
("\\.tex\\'" "open")
("\\.\\(?:mp4\\|mkv\\|avi\\|flv\\|ogv\\)\\(?:\\.part\\)?\\'"
"open")
("\\.\\(?:mp3\\|flac\\)\\'" "open")
("\\.html?\\'" "open")
("\\.md\\'" "open")))
(use-package diredfl
:hook ((dired-mode . diredfl-mode)))
(setenv "NODE_PATH" "/usr/local/lib/node_modules")
(use-package editorconfig
:config
(editorconfig-mode 1))
;; Optionally use the `orderless' completion style.
(use-package orderless
:init
;; Configure a custom style dispatcher (see the Consult wiki)
;; (setq orderless-style-dispatchers '(+orderless-dispatch)
;; orderless-component-separator #'orderless-escapable-split-on-space)
(setq completion-styles '(orderless-fast)
completion-category-defaults nil
completion-category-overrides '((file (styles . (partial-completion)))))
:config
(defun orderless-fast-dispatch (word index total)
(and (= index 0) (= total 1) (length< word 4)
`(orderless-regexp . ,(concat "^" (regexp-quote word)))))
(orderless-define-completion-style orderless-fast
(orderless-style-dispatchers '(orderless-fast-dispatch))
(orderless-matching-styles '(orderless-literal orderless-regexp)))
)
(use-package corfu
:after orderless
;; Optional customizations
:custom
(corfu-cycle t) ;; Enable cycling for `corfu-next/previous'
(corfu-auto t) ;; Enable auto completion
(corfu-quit-at-boundary nil) ;; Automatically quit at word boundary
(corfu-quit-no-match t) ;; Automatically quit if there is no match
(corfu-auto-delay 0)
;; 输入两个字符开始实例
(corfu-auto-prefix 2)
;; (corfu-separator ?\s) ;; Orderless field separator
(corfu-preview-current nil) ;; Disable current candidate preview
(corfu-preselect-first t) ;; Enable candidate preselection
;; (corfu-on-exact-match nil) ;; Configure handling of exact matches
;; (corfu-echo-documentation nil) ;; Disable documentation in the echo area
;; (corfu-scroll-margin 5) ;; Use scroll margin
;; (corfu-min-width 80)
(corfu-max-width 80)
:bind
(:map corfu-map
("C-j" . corfu-next)
("C-k" . corfu-previous)
("<escape>" . corfu-quit)
;; ("M-l" . corfu-show-location)
;; ("M-d" . corfu-show-documentation)
)
:init
(global-corfu-mode)
:config
(defun corfu-enable-always-in-minibuffer ()
"Enable Corfu in the minibuffer if Vertico/Mct are not active."
(unless (or (bound-and-true-p mct--active)
(bound-and-true-p vertico--input))
;; (setq-local corfu-auto nil) Enable/disable auto completion
(corfu-mode 1)))
(add-hook 'minibuffer-setup-hook #'corfu-enable-always-in-minibuffer 1)
)
(use-package kind-icon
:after corfu
:custom
(kind-icon-use-icons t)
(kind-icon-default-face 'corfu-default) ; Have background color be the same as `corfu' face background
(kind-icon-blend-background nil) ; Use midpoint color between foreground and background colors ("blended")?
(kind-icon-blend-frac 0.08)
:config
(add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter) ; Enable `kind-icon'
)
(use-package corfu-doc
;; NOTE 2022-02-05: At the time of writing, `corfu-doc' is not yet on melpa
:straight (corfu-doc :type git :host github :repo "galeo/corfu-doc")
:after corfu
:hook (corfu-mode . corfu-doc-mode)
:bind
(:map corfu-map
("M-n" . corfu-doc-scroll-up)
("M-p" . corfu-doc-scroll-down))
:custom
(corfu-doc-delay 0.5)
(corfu-doc-max-width 70)
(corfu-doc-max-height 20)
;; NOTE 2022-02-05: I've also set this in the `corfu' use-package to be
;; extra-safe that this is set when corfu-doc is loaded. I do not want
;; documentation shown in both the echo area and in the `corfu-doc' popup.
(corfu-echo-documentation nil))
;; A few more useful configurations...
(use-package emacs
:init
(setq completion-cycle-threshold 2)
(setq tab-always-indent 'complete))
(use-package lsp-mode
:init
;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
(setq lsp-keymap-prefix "C-c l")
:hook ((js2-mode . lsp)
(web-mode . lsp)
(typescript-mode . lsp)
(c-mode . lsp)
(c++-mode . lsp)
(python-mode . lsp)
(css-mode . lsp)
(lua-mode . lsp)
(shell-mode . lsp)
;; if you want which-key integration
(lsp-mode . lsp-enable-which-key-integration))
:custom
(lsp-completion-provider :none)
:commands lsp
:config
(setq lsp-disabled-clients '(vls))
;; (setq lsp-enabled-clients '(lsp-volar))
)
(use-package lsp-ui :commands lsp-ui-mode)
(use-package lsp-treemacs :commands lsp-treemacs-errors-list)
(use-package lsp-tailwindcss
:init
(setq lsp-tailwindcss-add-on-mode t)
(setq lsp-tailwindcss-major-modes
'(svelte-mode html-mode sgml-mode mhtml-mode web-mode css-mode js-mode))
(add-hook 'before-save-hook 'lsp-tailwindcss-rustywind-before-save)
)
(use-package lsp-volar
:straight (:host github :repo "jadestrong/lsp-volar"))
(global-set-key (kbd "C-c l s") 'lsp-tailwindcss-rustywind)
(global-set-key (kbd "C-c l i") 'lsp-ui-imenu)
(global-set-key (kbd "C-c l d") 'lsp-ui-peek-find-definitions)
(global-set-key (kbd "C-c l r") 'lsp-ui-peek-find-references)
(global-set-key (kbd "C-c l a") 'lsp-organize-imports)
(use-package dap-mode
:hook ((lsp-mode . dap-mode)
(lsp-mode . dap-ui-mode))
:bind (:map dap-mode-map
("C-c d d" . dap-debug)
("C-c d h" . dap-hydra)
("C-c d b" . dap-ui-breakpoints)
("C-c d l" . dap-ui-locals)
("C-c d r" . dap-ui-repl)))
(defun my/setup-js-mode ()
(require 'dap-chrome)
(setq tab-width 2)
;; 由于 lsp 已经提供了 diagnose 功能,故关闭 js2 自带的错误检查,防止干扰。
(setq js2-mode-show-strict-warnings nil)
(setq js2-mode-show-parse-errors nil))
(use-package js2-mode
:ensure t
:after (lsp-mode dap-mode)
:mode "\\.js\\'"
:hook ((js2-mode . my/setup-js-mode)))
(use-package typescript-mode
:ensure t
:after (lsp-mode dap-mode)
:mode ("\\.ts\\'" "\\.tsx\\'")
:hook ((typescript-mode . my/setup-js-mode)))
(use-package json-mode
:ensure t
:mode "\\.json\\'")
(use-package css-mode)
(use-package scss-mode)
(use-package emmet-mode
:hook ((sgml-mode html-mode css-mode web-mode) . emmet-mode)
:config
(add-hook 'emmet-mode-hook (lambda () (setq emmet-indentation 2))) ;; indent 2 spaces.
)
(use-package web-mode
:mode
(
".twig$"
".html?$"
".hbs$"
".vue$"
".blade.php$"
)
:config
(setq
web-mode-markup-indent-offset 2
web-mode-css-indent-offset 2
web-mode-code-indent-offset 2
web-mode-style-padding 0
web-mode-script-padding 0
web-mode-enable-auto-closing t
web-mode-enable-auto-opening t
web-mode-enable-auto-pairing nil