-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.el
1704 lines (1469 loc) · 51.5 KB
/
init.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; init.el --- Load the full configuration -*- lexical-binding: t -*-
;;; Commentary:
;; This file bootstraps the full configuration
;;; Code:
(when (version< emacs-version "29")
(error "必须要使用 Emacs 29 以上的版本"))
;; 判断是否是 MacOS 系统
(defconst *is-mac* (eq system-type 'darwin) "是否是 MacOS 操作系统")
;; 判断是否是 Linux 系统
(defconst *is-linux* (eq system-type 'gnu/linux) "是否是 Linux 操作系统")
;; 判断是否是 Windows 系统
(defconst *is-win* (eq system-type 'windows-nt) "是否是 Windows 操作系统")
;; 是否是 GUI
(defconst *is-gui* (display-graphic-p) "是否是GUI")
;; 是否是 TUI
(defconst *is-tui* (not *is-gui*) "是否是TUI")
;; 是否是 nixos/darwin 模块 使用
(defconst *is-nix-module* (equal (getenv "GRASS_EMACS_ENV") "nix-module") "是否是Nix模块")
;; 是否是nixos
(defconst *is-nixos* (and *is-linux* *is-nix-module*) "是否是 NixOS 操作系统")
;; 计算中国农历的年份,用于org中
(defun grass-emacs/calc-chinese-year (year)
(let* ((cycle (/ (+ year 2637) 60.0))
(year (- (+ year 2637) (* 60 (truncate cycle)))))
(list (+ 1 (floor cycle)) year))
)
;; 从 Bitwarden 中读取密码
(defun grass-emacs/get-bitwarden-password (name)
"根据name从rbw(Bitwarden 非官方 cli 客户端) 中读取密码"
(let (
(out (shell-command-to-string (concat "echo -n `rbw get " name "`")))
)
(if (string-prefix-p "rbw get: couldn't find entry for" out) (error "没找到对应的密码") out)
))
(require 'xdg)
(defun expand-emacs-config (filename)
"expand emacs config files"
(expand-file-name filename
(or (getenv "EMACS_DEBUG_DIR")
(expand-file-name "emacs" (xdg-config-home))
)))
(defun expand-emacs-data (filename)
"expand emacs data files"
(expand-file-name filename
(expand-file-name "emacs" (xdg-data-home))
))
(defun expand-emacs-state (filename)
"expand emacs state files"
(expand-file-name filename
(expand-file-name "emacs" (xdg-state-home))
))
(defun expand-emacs-cache (filename)
"expand emacs cache files"
(expand-file-name filename
(expand-file-name "emacs" (xdg-cache-home))
))
;; 给 eln-cache 目录换个地方
(when (boundp 'native-comp-eln-load-path)
(startup-redirect-eln-cache (expand-emacs-cache "eln-cache")))
;; 定义自定义文件
(defconst custom-file (expand-emacs-data "custom.el") "一些个性化的定义存放之地")
;; 插件默认使用这个目录,如果需要的话,再调整到其它相关目录
(setq user-emacs-directory (expand-emacs-state ""))
;; 更改到缓存目录
(setq package-user-dir (expand-emacs-cache "elpa"))
;; 关闭原生编译警告
(setq native-comp-async-report-warnings-errors nil)
;; 关闭启动画面
(setq inhibit-startup-screen t)
;; 禁用对话框
(setq use-dialog-box nil)
;; 禁用文件对话框
(setq use-file-dialog nil)
;; 允许像素级别调整窗口和窗体大小
(setq-default
window-resize-pixelwise t
frame-resize-pixelwise t)
;; 关闭工具栏
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
;; 关闭文件滑动控件
(when (fboundp 'set-scroll-bar-mode)
(set-scroll-bar-mode nil))
;; 关闭菜单栏
(menu-bar-mode -1)
;; 隐藏内部边框
(let ((no-border '(internal-border-width . 0)))
(add-to-list 'default-frame-alist no-border)
(add-to-list 'initial-frame-alist no-border))
;; 开启像素级滚动
(when (fboundp 'pixel-scroll-precision-mode)
(pixel-scroll-precision-mode))
;; 关闭emacs自带的退出确认
(setq confirm-kill-emacs #'yes-or-no-p)
;; 自动补全括号(关闭,有时候很烦人))
(electric-pair-mode -1)
;; 编程模式下,光标在括号上时高亮另一个括号
(add-hook 'prog-mode-hook #'show-paren-mode)
;; 在 Mode line 上显示列号
(column-number-mode 1)
;; 选中文本后输入文本会替换文本(更符合我们习惯了的其它编辑器的逻辑)
(delete-selection-mode t)
;; 关闭文件自动备份
(setq make-backup-files nil)
;; 编程模式下,可以折叠代码块
(add-hook 'prog-mode-hook #'hs-minor-mode)
;; 如果是nixos关闭内置的包管理工具
(when *is-nix-module*
(setq package-enable-at-startup nil))
;; 设置等宽字体
(set-face-attribute 'default nil :family "Sarasa Term Slab SC" :height 140)
;; 设置后备字体
(set-fontset-font t nil "Sarasa Term SC" nil 'prepend)
(set-fontset-font t nil "Iosevka" nil 'prepend)
(set-fontset-font t nil "Source Han Sans HW" nil 'append)
(set-fontset-font t nil "Unifont" nil 'append)
(set-fontset-font t nil "Symbols Nerd Font" nil 'append)
;; 设置自动折行
(setq truncate-lines nil)
;; 默认查找目录为home目录
(setq command-line-default-directory "~")
(setq nerd-icons-font-names '("SymbolsNerdFontMono-Regular.ttf")) ;
;; 设置2个空格
(setq-default indent-tabs-mode nil)
(setq-default tab-width 2)
(setq-default default-tab-width 2)
(setq-default js-indent-level 2)
;; 使用短的 y-or-n
(setopt use-short-answers t)
;; 禁用外部程序的粘贴板,避免扰乱emacs 内部的 kill-ring
(setq select-enable-clipboard nil)
;; 为外部剪切板增加绑定
(keymap-global-set "C-S-y" 'meow-clipboard-yank)
(keymap-global-set "C-S-s" 'meow-clipboard-save)
(keymap-global-unset "C-h C-f")
(setq bookmark-default-file (expand-emacs-data "bookmarks"))
(setq auto-save-list-file-prefix (expand-emacs-state "auto-save-list/.saves-"))
;; 调大 gc 的阈值
(let ((normal-gc-cons-threshold (* 20 1024 1024))
(init-gc-cons-threshold (* 128 1024 1024)))
(setq gc-cons-threshold init-gc-cons-threshold)
(add-hook 'emacs-startup-hook
(lambda () (setq gc-cons-threshold normal-gc-cons-threshold))))
;; 调大子进程的输出读取缓冲
(setq read-process-output-max (* 4 1024 1024))
;; 关闭对子进程读取输出时的延迟缓冲
(setq process-adaptive-read-buffering nil)
(defvar application-keymap (make-sparse-keymap) "applications")
(defalias 'application-keymap application-keymap)
(defvar project-keymap (make-sparse-keymap) "project commands")
(defalias 'project-keymap project-keymap)
(defvar buffer-keymap (make-sparse-keymap) "buffer operations")
(defalias 'buffer-keymap buffer-keymap)
(defvar file-keymap (make-sparse-keymap) "file operations")
(defalias 'file-keymap file-keymap)
(defvar org-keymap (make-sparse-keymap) "所有gtd相关的全局操作都在这里")
(defalias 'org-keymap org-keymap)
(defvar-keymap grass/jump-map
:doc "My jump keymap"
)
(keymap-set global-map "C-c j" grass/jump-map)
(defvar toggle-keymap (make-sparse-keymap) "一些开关按键")
(defalias 'toggle-keymap toggle-keymap)
(defvar bootstrap-version)
(setq straight-base-dir (expand-emacs-state ""))
(let ((bootstrap-file
(expand-file-name
"straight/repos/straight.el/bootstrap.el"
(or (bound-and-true-p straight-base-dir)
user-emacs-directory)))
(bootstrap-version 7))
(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))
(straight-use-package 'leaf)
(straight-use-package 'leaf-keywords)
(leaf leaf-keywords
:custom
(leaf-expand-ensure-system-package . t)
:config
(leaf-keywords-init)
)
(leaf system-packages
:straight '(system-packages
:type git :host github :repo "running-grass/system-packages")
:custom
(system-packages-use-sudo . nil)
(system-packages-noconfirm . t)
:config
(system-packages-ensure "git")
)
(leaf exec-path-from-shell
:straight t
:config
(exec-path-from-shell-initialize))
(leaf url
:custom
`(url-configuration-directory . ,(expand-emacs-state "url"))
)
;; 保存了上一次打开文件时的光标位置
(leaf saveplace
:global-minor-mode save-place-mode
:custom
`(save-place-file . ,(expand-emacs-state "places"))
)
;; 命令记录
(leaf savehist
:global-minor-mode t
:custom
(savehist-autosave-interval . 60)
`(savehist-file . ,(expand-emacs-state "history"))
)
(leaf 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\\)\\'")))
;; 配置 tramp -- 远程编辑
(leaf tramp
:custom
(tramp-default-method . "ssh")
`(tramp-persistency-file-name . ,(expand-emacs-state "tramp")))
;; 文件被外部程序修改后,重新载入buffer
(leaf autorevert
:global-minor-mode global-auto-revert-mode
)
;; 最近打开的文件
(leaf recentf
:global-minor-mode t
:custom
`(recentf-save-file . ,(expand-emacs-state "recentf"))
(recentf-max-saved-items . 2000)
(recentf-max-menu-items . 150)
)
(defun reload-config ()
"重新加载配置"
(interactive)
(progn
(org-babel-tangle-file (expand-emacs-config "README.org"))
(load-file (expand-emacs-config "init.el"))
)
)
(defun meow-setup ()
(setq meow-cheatsheet-layout meow-cheatsheet-layout-qwerty)
(meow-motion-overwrite-define-key
;; '("j" . meow-next)
;; '("k" . meow-prev)
'("<escape>" . ignore))
(meow-leader-define-key
;; SPC j/k will run the original command in MOTION state.
'("J" . "H-j")
'("K" . "H-k")
;; Use SPC (0-9) for digit arguments.
'("1" . meow-digit-argument)
'("2" . meow-digit-argument)
'("3" . meow-digit-argument)
'("4" . meow-digit-argument)
'("5" . meow-digit-argument)
'("6" . meow-digit-argument)
'("7" . meow-digit-argument)
'("8" . meow-digit-argument)
'("9" . meow-digit-argument)
'("0" . meow-digit-argument)
'("/" . meow-keypad-describe-key)
'("?" . meow-cheatsheet)
'("<SPC>" . consult-mode-command)
'("r" . reload-config)
)
(meow-normal-define-key
'("0" . meow-expand-0)
'("9" . meow-expand-9)
'("8" . meow-expand-8)
'("7" . meow-expand-7)
'("6" . meow-expand-6)
'("5" . meow-expand-5)
'("4" . meow-expand-4)
'("3" . meow-expand-3)
'("2" . meow-expand-2)
'("1" . meow-expand-1)
'("-" . negative-argument)
'(";" . meow-reverse)
'("," . meow-inner-of-thing)
'("." . meow-bounds-of-thing)
'("[" . meow-beginning-of-thing)
'("]" . meow-end-of-thing)
'("a" . meow-append)
'("A" . meow-open-below)
'("b" . meow-back-word)
'("B" . meow-back-symbol)
'("c" . meow-change)
'("d" . meow-delete)
'("D" . meow-backward-delete)
'("e" . meow-next-word)
'("E" . meow-next-symbol)
'("f" . meow-find)
'("g" . meow-cancel-selection)
'("G" . meow-grab)
'("h" . meow-left)
'("H" . meow-left-expand)
'("i" . meow-insert)
'("I" . meow-open-above)
'("j" . meow-next)
'("J" . meow-next-expand)
'("k" . meow-prev)
'("K" . meow-prev-expand)
'("l" . meow-right)
'("L" . meow-right-expand)
'("m" . meow-join)
'("n" . meow-search)
'("o" . meow-block)
'("O" . meow-to-block)
'("p" . meow-yank)
'("P" . consult-yank-from-kill-ring)
'("q" . meow-quit)
'("Q" . meow-goto-line)
'("r" . meow-replace)
'("R" . meow-swap-grab)
'("s" . meow-kill)
'("t" . meow-till)
'("u" . meow-undo)
'("U" . meow-undo-in-selection)
'("v" . meow-visit)
'("w" . meow-mark-word)
'("W" . meow-mark-symbol)
'("x" . meow-line)
'("X" . meow-goto-line)
'("y" . meow-save)
'("Y" . meow-sync-grab)
'("z" . meow-pop-selection)
'("'" . repeat)
'("<escape>" . ignore))
)
(leaf meow
:straight t
:require t
:init
(defvar meow-leaving-insert-mode-hook nil
"Hook to run when leaving meow insert mode.")
(defvar meow-entering-insert-mode-hook nil
"Hook to run when entering meow insert mode.")
:hook
(meow-insert-mode-hook . (lambda ()
(if meow-insert-mode
(run-hooks 'meow-entering-insert-mode-hook)
(run-hooks 'meow-leaving-insert-mode-hook))))
(meow-leaving-insert-mode-hook . sis-set-english)
:config
(meow-setup)
(meow-global-mode 1)
(add-to-list 'meow-mode-state-list '(minibuffer-mode . insert))
)
(leaf sis
:straight t
:when *is-linux*
:hook
(sis-context-hooks . meow-entering-insert-mode-hook)
;; enable the /context/ and /inline region/ mode for specific buffers
;; (((text-mode prog-mode) . sis-context-mode)
;; ((text-mode prog-mode) . sis-inline-mode))
:config
;; For MacOS
(sis-ism-lazyman-config
;; English input source may be: "ABC", "US" or another one.
;; "com.apple.keylayout.ABC"
"1"
;; Other language input source: "rime", "sogou" or another one.
;; "im.rime.inputmethod.Squirrel.Rime"
"2"
'fcitx5
)
;; enable the /cursor color/ mode
(sis-global-cursor-color-mode t)
;; enable the /respect/ mode
(sis-global-respect-mode -1)
;; enable the /context/ mode for all buffers
(sis-global-context-mode 1)
;; enable the /inline english/ mode for all buffers
;; (sis-global-inline-mode t)
;; org title 处切换 Rime,telega 聊天时切换 Rime。
;; 使用模式编辑 meow,需要额外加 meow-insert-mode 条件。
(add-to-list 'sis-context-detectors
(lambda (&rest _)
(when (and meow-insert-mode
(or (derived-mode-p 'org-mode
'telega-chat-mode
)))
'other)))
(defun +meow-focus-change-function ()
(if (frame-focus-state)
(sis-set-english)
(meow-insert-exit)))
(add-function :after after-focus-change-function '+meow-focus-change-function)
)
(leaf ace-window
:straight t
:bind (("C-x o" . ace-window)))
(leaf mwim
:straight t
:bind
("C-a" . mwim-beginning-of-code-or-line)
("C-e" . mwim-end-of-code-or-line))
(leaf doom-modeline
:straight t
:global-minor-mode t
:custom
(doom-modeline-modal-icon . t)
)
(leaf good-scroll
:straight t
:global-minor-mode t
:when *is-gui* ; 在图形化界面时才使用这个插件
)
(leaf which-key
:straight t
:global-minor-mode t
)
(leaf avy
:straight t
:bind
("C-c j j" . avy-goto-char-timer)
("C-c j l" . avy-goto-line)
)
;; Enable rich annotations using the Marginalia package
(leaf marginalia
:straight t
:global-minor-mode t
;; Bind `marginalia-cycle' locally in the minibuffer. To make the binding
;; available in the *Completions* buffer, add it to the
;; `completion-list-mode-map'.
:bind
(:minibuffer-local-map
("M-A" . marginalia-cycle))
)
(defun delete-current-file ()
"Delete the file associated with the current buffer. Delete the current buffer too. If no file is associated, just close buffer without prompt for save."
(interactive)
(let ((currentFile (buffer-file-name)))
(when (yes-or-no-p (concat "Delete file?: " currentFile))
(kill-buffer (current-buffer))
(when currentFile (delete-file currentFile)))))
;; Example configuration for Consult
(leaf consult
:straight t
:ensure-system-package (rg . ripgrep)
:bind
("C-c b b" . consult-buffer)
("C-c p s" . consult-ripgrep)
("C-c f f" . find-file)
("C-c f d" . delete-current-file)
("C-c f e" . consult-recent-file)
("C-c j g" . consult-goto-line) ;; orig. goto-line
("C-c j m" . consult-imenu)
("C-c j s" . consult-line) ;; orig. previous-matching-history-element
;; Enable automatic preview at point in the *Completions* buffer. This is
;; relevant when you use the default completion UI.
:hook
(completion-list-mode-hook . consult-preview-at-point-mode)
;; The :init configuration is always executed (Not lazy)
:custom
;; Optionally configure the register formatting. This improves the register
;; preview for `consult-register', `consult-register-load',
;; `consult-register-store' and the Emacs built-ins.
(register-preview-delay . 0.5)
(register-preview-function . #'consult-register-format)
;; Use Consult to select xref locations with preview
(xref-show-xrefs-function . #'consult-xref)
(xref-show-definitions-function . #'consult-xref)
;; Optionally configure the narrowing key.
;; Both < and C-+ work reasonably well.
(consult-narrow-key . "<") ;; "C-+"
;; Optionally tweak the register preview window.
;; This adds thin lines, sorting and hides the mode line of the window.
:init
(advice-add #'register-preview :override #'consult-register-window)
;; Configure other variables and modes in the :config section,
;; after lazily loading the package.
:config
;; Optionally configure preview. The default value
;; is 'any, such that any key triggers the preview.
;; (setq consult-preview-key 'any)
;; (setq consult-preview-key "M-.")
;; (setq consult-preview-key '("S-<down>" "S-<up>"))
;; For some commands and buffer sources it is useful to configure the
;; :preview-key on a per-command basis using the `consult-customize' macro.
(consult-customize
consult-theme :preview-key '(:debounce 0.2 any)
consult-ripgrep consult-git-grep consult-grep
consult-bookmark consult-recent-file
;; consult-xref
consult--source-bookmark consult--source-file-register
consult--source-recent-file consult--source-project-recent-file
;; :preview-key "M-."
:preview-key '(:debounce 0.4 any))
;; Optionally make narrowing help available in the minibuffer.
;; You may want to use `embark-prefix-help-command' or which-key instead.
;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)
;; By default `consult-project-function' uses `project-root' from project.el.
;; Optionally configure a different project root function.
;;;; 1. project.el (the default)
;; (setq consult-project-function #'consult--default-project-function)
;;;; 2. vc.el (vc-root-dir)
;; (setq consult-project-function (lambda (_) (vc-root-dir)))
;;;; 3. locate-dominating-file
;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
;; 4. projectile.el (projectile-project-root)
(autoload 'projectile-project-root "projectile")
(setq consult-project-function (lambda (_) (projectile-project-root)))
;;;; 5. No project support
;; (setq consult-project-function nil)
)
(leaf vertico
:straight t
:global-minor-mode t
:custom
;; Show more candidates
(vertico-count . 20)
;; Grow and shrink the Vertico minibuffer
(vertico-resize . t)
;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
(vertico-cycle . t)
)
(leaf embark
:straight t
:bind
(("C-." . embark-act) ;; pick some comfortable binding
("C-;" . embark-dwim) ;; good alternative: M-.
("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
:custom
;; Optionally replace the key help with a completing-read interface
(prefix-help-command . #'embark-prefix-help-command)
;; Show the Embark target at point via Eldoc. You may adjust the
;; Eldoc strategy, if you want to see the documentation from
;; multiple providers. Beware that using this can be a little
;; jarring since the message shown in the minibuffer can be more
;; than one line, causing the modeline to move up and down:
;; (add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target)
;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly)
:config
;; Hide the mode line of the Embark live/completions buffers
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none)))))
;; Consult users will also want the embark-consult package.
(leaf embark-consult
:straight t ; only need to install it, embark loads it after consult if found
:after (consult embark)
:hook
(embark-collect-mode-hook . consult-preview-at-point-mode))
(leaf orderless
:straight t
:custom
;; Configure a custom style dispatcher (see the Consult wiki)
;; (setq orderless-style-dispatchers '(+orderless-consult-dispatch orderless-affix-dispatch)
;; orderless-component-separator #'orderless-escapable-split-on-space)
(completion-styles . '(orderless basic))
(completion-category-defaults . nil)
(completion-category-overrides . '((file (styles partial-completion))))
)
;; 括号的多色彩
(leaf rainbow-delimiters
:straight t
:hook
(prog-mode-hook . rainbow-delimiters-mode)
)
(leaf transient
:straight t
:custom
`(transient-levels-file . ,(expand-emacs-state "transient/levels.el"))
`(transient-values-file . ,(expand-emacs-state "transient/values.el"))
`(transient-history-file . ,(expand-emacs-state "transient/history.el"))
)
(leaf mu4e
:when *is-nix-module*
:ensure-system-package mu offlineimap
:custom
(user-full-name . "Leo Liu")
(user-mail-address . "hi@grass.show")
(sendmail-program . "msmtp")
(mail-user-agent . 'mu4e-user-agent)
(send-mail-function . 'smtpmail-send-it)
(message-sendmail-f-is-evil . t)
(message-sendmail-extra-arguments . '("--read-envelope-from"))
(message-send-mail-function . 'message-send-mail-with-sendmail)
(mu4e-attachment-dir . "~/Downloads")
(mu4e-get-mail-command . "offlineimap -o")
(mu4e-update-interval . 300)
(mu4e-notification-support . t)
:init
;; 定时更新索引
(run-with-idle-timer (* 5 60) t 'mu4e-update-index)
:config
;; 默认是motion模式
(add-to-list 'meow-mode-state-list '(mu4e-view-mode . motion))
;; allow for updating mail using 'U' in the main view:
:commands mu4e-update-index
:bind
("C-c a m" . mu4e)
("C-c t m" . mu4e-update-mail-and-index)
)
(leaf elfeed-protocol
:straight t
:ensure-system-package rbw
:custom
(elfeed-use-curl . t)
`(elfeed-db-directory . ,(expand-emacs-cache "elfeed"))
(elfeed-curl-extra-arguments . '("--insecure")) ;necessary for https without a trust certificate
;; (setq elfeed-protocol-fever-update-unread-only nil)
(elfeed-protocol-fever-fetch-category-as-tag . t)
(elfeed-protocol-fever-update-unread-only . t)
;; setup feeds
(elfeed-protocol-feeds .
'(
("fever+https://grass@rss.grass.work:30443"
:api-url "https://grass@rss.grass.work:30443/fever/"
:password (grass-emacs/get-bitwarden-password "miniflux-fever grass"))
))
;; enable elfeed-protocol
(elfeed-protocol-enabled-protocols . '(fever))
(elfeed-curl-timeout . 36000)
:require t
:config
(elfeed-protocol-enable)
:bind
("C-c a r" . elfeed)
)
(leaf pocket-reader
:straight t
:after elfeed
:custom
(pocket-reader-open-url-default-function . #'eww)
:bind
("C-c a p" . pocket-reader)
(:elfeed-search-mode-map
("P" . pocket-reader-elfeed-search-add-link)
)
(:elfeed-show-mode-map
("P" . pocket-reader-elfeed-entry-add-link)
)
)
(leaf eww
)
;; Use Dabbrev with Corfu!
(leaf yasnippet
:straight t
:global-minor-mode yas-global-mode
:custom
`(yas--default-user-snippets-dir . ,(expand-emacs-data "snippets"))
)
(leaf lsp-bridge
:straight '(lsp-bridge :type git :host github :repo "manateelazycat/lsp-bridge"
:files (:defaults "*.el" "*.py" "acm" "core" "langserver" "multiserver" "resources")
:build (:not compile)
)
:leaf-defer nil
:custom
;; ui
(acm-enable-preview . t)
(lsp-bridge-enable-log . nil)
;; 用户级别的lsp-bridge配置
(lsp-bridge-user-langserver-dir . "~/.config/emacs/lsp-bridge-user/langserver")
(lsp-bridge-php-lsp-server . 'phpactor)
;; codeium
(acm-enable-codeium . t)
(lsp-bridge-enable-completion-in-string . t)
;; formatter
(lsp-bridge-enable-auto-format-code . nil)
(lsp-bridge-auto-format-code-idle . nil)
(lsp-bridge-enable-inlay-hint . t)
:hook
(vue-mode-hook . lsp-bridge-mode)
:config
(add-to-list 'meow-mode-state-list '(lsp-bridge-ref-mode . motion))
(global-lsp-bridge-mode)
:bind
("M-." . lsp-bridge-find-def)
("M-," . lsp-bridge-find-def-return)
("C-c t l" . lsp-bridge-mode)
)
(leaf acm-terminal
:when *is-tui*
:straight '(popon :host nil :repo "https://codeberg.org/akib/emacs-popon.git")
:straight '(acm-terminal :host github :repo "twlz0ne/acm-terminal")
)
(defun projectile-run-vterm ()
(interactive)
(let* ((project (projectile-ensure-project (projectile-project-root)))
(buffer "vterm"))
(require 'vterm)
(if (buffer-live-p (get-buffer buffer))
(switch-to-buffer buffer)
(vterm))
(vterm-send-string (concat "cd " project))
(vterm-send-return)))
(leaf vterm
:straight t
:config
(add-to-list 'meow-mode-state-list '(vterm-mode . insert))
:bind
("C-c b t" . vterm)
)
(leaf project
:config
(setq project-list-file (expand-emacs-state "projects"))
:bind
("C-c p f" . project-find-file)
("C-c p d" . project-find-dir)
("C-c p b" . consult-project-buffer)
)
(leaf projectile
:straight t
:global-minor-mode projectile-mode
:custom
;; 关闭启动时的自动项目发现
(projectile-auto-discover . nil)
`(projectile-known-projects-file . ,(expand-emacs-state "projectile-known-projects.eld"))
(projectile-project-search-path . '(
("~/workspace" . 2)
"~/workspace/mugeda"
))
:bind
("C-c p R" . projectile-replace)
("C-c p S" . projectile-save-project-buffers)
)
;; 绑定 consult-projectile
(leaf consult-projectile
:straight t
:bind
("C-c p p" . consult-projectile-switch-project)
("C-c p 4 f" . consult-projectile-find-file-other-window)
)
(leaf magit
:straight t
:bind
("C-c p v" . magit)
)
;; Org模式相关的,和GTD相关的
(leaf org
:ensure-system-package (pandoc zip)
:custom
;; Edit settings
(org-auto-align-tags . t)
(org-tags-column . 0)
(org-catch-invisible-edits . 'show-and-error)
(org-special-ctrl-a/e . t)
(org-insert-heading-respect-content . t)
(org-protocol-deault-template-key . "n")
;; 使org子项目具有先后依赖
(org-enforce-todo-dependencies . t)
;; Org styling, hide markup etc.
(org-hide-emphasis-markers . t)
(org-pretty-entities . t)
(org-directory . "~/org/")
(org-startup-folded . 'nofold)
(org-refile-targets . '(
(nil . (:level . 1)) ;当前文件的level1
(nil . (:tag . "project"))
("~/org/gtd/gtd.org" . (:tag . "inbox"))
))
(org-todo-keywords . '(
(sequence "NEXT(n)" "TODO(t)" "WAITING(w@)" "SOMEDAY(s)" "|" "DONE(d!)" "CANCELLED(c@)")
))
(org-clock-string-limit . 5)
(org-log-refile . 'nil)
(org-log-done . 'time)
(org-log-into-drawer . "LOGBOOK")
(org-clock-stored-history . t)
(org-clock-auto-clockout-timer . 1800)
(org-tag-alist . '(
;; 上下文需求
(:startgroup . nil)
("@home" . ?h)
("@office" . ?o)
("@phone" . ?f)
("@pc" . ?c)
(:endgroup . nil)
;; 类型
("task" . ?t)
("project" . ?p)
("event" . ?e)
))
(org-capture-templates . '(
("T" "带上下文捕获任务" entry (file+headline "~/org/gtd/gtd.org" "Inbox For GTD") "* TODO %?\n:PROPERTIES:\n:CREATED: %U\n:RELATED: %a\n:END:")
("t" "捕获任务" entry (file+headline "~/org/gtd/gtd.org" "Inbox For GTD") "* TODO %?\n")
("n" "摘抄" entry (file "~/org/inbox/emacs.org") "* TODO 摘抄自 %a \n:PROPERTIES:\n:CREATED: %U\n:RELATED: %a\n:END:\n%i\n" :immediate-finish t)
("x" "快速捕获任务" entry (file+headline "~/org/gtd/gtd.org" "Inbox For GTD") "* TODO %l \nSCHEDULED: %t\n" :immediate-finish t)
))
;; 图片显示
(org-startup-with-inline-images . t)
(org-cycle-inline-images-display . t)
:config
(org-clock-auto-clockout-insinuate)
(defun grass-emacs/next-monday ()
(org-read-date nil nil "Mon"))
(defun grass-emacs/current-monday ()
(org-read-date nil nil "-Mon"))
(defun grass-emacs/last-monday ()
(org-read-date nil nil "--1w" nil (date-to-time (grass-emacs/current-monday))))
:bind
("C-c n s" . org-save-all-org-buffers)
("C-c n c" . org-capture)
:hook
(org-capture-after-finalize-hook . org-save-all-org-buffers)
(org-after-tags-change-hook . org-save-all-org-buffers)
(org-after-refile-insert-hook . org-save-all-org-buffers)
(org-after-todo-state-change-hook . org-save-all-org-buffers)
)
(leaf org-contrib
:straight t
)
(leaf org-agenda
:after org
:custom
;; 除了gtd的,还有各种外部收集箱中的未整理的也要显示
(org-agenda-files . '("~/org/gtd/gtd.org" "~/org/inbox" "~/org/roam/project"))
(org-agenda-tags-column . 0)
(org-agenda-include-diary . t)
(org-agenda-show-future-repeats . 'next)
;; 在agenda视图中默认显示实体文本内容,且最多10行
(org-agenda-start-with-entry-text-mode . nil)
(org-agenda-entry-text-maxlines . 3)
(org-agenda-custom-commands . `(
("i" "外部收集箱" tags "+inbox" ((org-agenda-files '("~/org/inbox" "~/org/sync"))))
("j" "所有待细化的项目" tags "inbox"
(
(org-agenda-files '("~/org/gtd/gtd.org"))
(org-agenda-skip-function '(org-agenda-skip-entry-if 'regexp "Inbox For GTD"))
))
("p" "每周项目回顾" tags-tree "+project" )
("r" . "回顾统计")
("rt" "今日完成任务"
tags "+CLOSED>=\"<today>\"|+LAST_REPEAT>=\"<today>\"-habit|+TIMESTAMP>=\"<today>\"+TIMESTAMP<\"<tomorrow>\"-habit"
((org-agenda-overriding-header "今日完成的任务")
(org-agenda-sorting-strategy '(priority-down))
(org-agenda-start-with-entry-text-mode . nil)
)
nil)
("ry" "昨日完成任务"
tags "+CLOSED>=\"<-1d>\"+CLOSED<\"<today>\"|+LAST_REPEAT>=\"<-1d>\"+LAST_REPEAT<\"<today>\"-habit|+TIMESTAMP>=\"<-1d>\"+TIMESTAMP<\"<today>\"-habit"
((org-agenda-overriding-header "昨日完成的任务")
(org-agenda-sorting-strategy '(priority-down))
(org-agenda-start-with-entry-text-mode . nil)
(org-agenda-prefix-format '((todo . " %i %-12:c %s ")))
)
nil)
("rw" "本周完成任务"