refactor(config): Tidy Emacs config across modules

This commit is contained in:
2026-06-09 03:17:54 +08:00
parent 75fff1e3a7
commit 83fb3d783c
15 changed files with 92 additions and 77 deletions

View File

@@ -15,7 +15,7 @@
(if (or (display-graphic-p) *is-android*) (if (or (display-graphic-p) *is-android*)
(progn (progn
(load "init-proxy" t) (require 'init-proxy nil t)
(require 'init-startup) (require 'init-startup)
(require 'init-elpa) (require 'init-elpa)
(require 'init-base) (require 'init-base)
@@ -32,10 +32,10 @@
(require 'init-kbd-func) (require 'init-kbd-func)
(require 'init-kbd) (require 'init-kbd)
(require 'init-segmentation) (require 'init-segmentation)
(load "init-local" t)) (require 'init-local nil t))
(progn (progn
(require 'init-terminal-startup) (require 'init-terminal-startup)
(load "init-proxy" t) (require 'init-proxy nil t)
(require 'init-elpa) (require 'init-elpa)
(require 'init-terminal-package) (require 'init-terminal-package)
(require 'init-terminal-ui) (require 'init-terminal-ui)

View File

@@ -35,9 +35,10 @@
;; server-mode ;; server-mode
(use-package server (use-package server
:demand t
:hook :hook
(emacs-startup . (lambda () (emacs-startup . (lambda ()
(unless server-mode (unless (server-running-p)
(server-mode 1))))) (server-mode 1)))))
;; recentf最近打开的文件 ;; recentf最近打开的文件
@@ -52,7 +53,9 @@
(if *is-android* (if *is-android*
(add-to-list 'recentf-exclude "~/storage/shared/my-org-note/journal/.*\\.org\\'") (add-to-list 'recentf-exclude "~/storage/shared/my-org-note/journal/.*\\.org\\'")
(add-to-list 'recentf-exclude "~/org/my-org-note/journal/.*\\.org\\'") (add-to-list 'recentf-exclude "~/org/my-org-note/journal/.*\\.org\\'")
(add-to-list 'recentf-exclude "~/org/my-org-note/20260509T232442==agenda--all-my-todos__org\\.org"))) (add-to-list 'recentf-exclude "~/org/my-org-note/20260509T232442==agenda--all-my-todos__org\\.org"))
(add-to-list 'recentf-exclude "~/.emacs.d/emms/history")
(add-to-list 'recentf-exclude "~/.emacs.d/bookmarks"))
;; savehist保存命令顺序 ;; savehist保存命令顺序
(use-package savehist (use-package savehist

View File

@@ -154,6 +154,10 @@ targets."
:config :config
;;Quit completion before saving ;;Quit completion before saving
(add-hook 'before-save-hook #'corfu-quit) (add-hook 'before-save-hook #'corfu-quit)
(add-hook 'eshell-mode-hook
(lambda ()
(setq-local corfu-auto nil)
(local-set-key (kbd "TAB") 'completion-at-point)))
:bind :bind
(:map corfu-map (:map corfu-map
("RET" . nil))) ("RET" . nil)))
@@ -164,12 +168,6 @@ targets."
:hook :hook
(after-init . corfu-terminal-mode)) (after-init . corfu-terminal-mode))
;; 在eshell中使用tab打开补全
(add-hook 'eshell-mode-hook
(lambda ()
(setq-local corfu-auto nil)
(local-set-key (kbd "TAB") 'completion-at-point)))
(use-package emacs (use-package emacs
:custom :custom
(tab-always-indent 'complete) (tab-always-indent 'complete)

View File

@@ -18,36 +18,34 @@
dired-mouse-drag-files t dired-mouse-drag-files t
mouse-drag-and-drop-region-cross-program t mouse-drag-and-drop-region-cross-program t
dired-compress-file-default-suffix ".zip" dired-compress-file-default-suffix ".zip"
dired-kill-when-opening-new-buffer t dired-kill-when-opening-new-dired-buffer nil
dired-kill-when-opening-new-dired-buffer t) dired-auto-revert-buffer t)
(put 'dired-find-alternate-file 'disabled nil)) (put 'dired-find-alternate-file 'disabled nil))
;; dirvish ;; dirvish
(use-package dirvish (use-package dirvish
:hook :straight
(dired-mode-hook . denote-dired-mode) '(dirvish :fork (:host github :repo "latiagertrutis/dirvish"))
:init :init
(dirvish-override-dired-mode) (dirvish-override-dired-mode)
:config :config
(require 'vc) (require 'vc)
(if *is-windows* (require 'fix-dirvish-preview)) (if *is-windows* (require 'fix-dirvish-preview))
(if (or *is-mac* *is-android*) (if (or *is-mac* *is-android*)
(setq dirvish-hide-details t) (setq dirvish-hide-details t)
(setq dirvish-hide-details '(dirvish-side))) (setq dirvish-hide-details '(dirvish-side)))
(setq dirvish-use-mode-line t)
(unless *is-windows*
(setq dirvish-attributes '(file-time file-size)))
(if *is-android* (if *is-android*
(setq dirvish-default-layout '(1 0.6)) (setq dirvish-default-layout '(1 0.6))
(setq dirvish-default-layout nil (setq dirvish-default-layout nil
dirvish-layout-recipes '((1 0.15 0.45)))) dirvish-layout-recipes '((1 0.15 0.45))))
(with-eval-after-load 'dirvish (setq dirvish-use-mode-line t
(add-hook 'dired-mode-hook #'dired-hide-details-mode)) dirvish-mode-line-format '(:left (sort omit symlink) :right (free-space index))
dirvish-attributes '(file-time file-size)
dirvish-yank-sources 'session)
:custom :custom
(dirvish-quick-access-entries (dirvish-quick-access-entries
@@ -78,6 +76,7 @@
("v" "~/视频/" "Videos") ("v" "~/视频/" "Videos")
("n" "~/org/my-org-note/" "Notes") ("n" "~/org/my-org-note/" "Notes")
("g" "~/gptel/" "gptel sessions"))) ("g" "~/gptel/" "gptel sessions")))
(*is-android* (*is-android*
'(("h" "~/" "Home") '(("h" "~/" "Home")
("e" "~/.emacs.d" "Emacs") ("e" "~/.emacs.d" "Emacs")

View File

@@ -1,4 +1,4 @@
;;; init-elpa.el --- elpa config -*- lexical-binding: t -*- ;;; init-elpa.el --- package manager -*- lexical-binding: t -*-
;;; Commentary: ;;; Commentary:

View File

@@ -119,12 +119,9 @@ from the last 1500 characters of the buffer."
(use-package gptel-magit (use-package gptel-magit
:straight :straight
(gptel-magit :type git '(gptel-magit :fork (:host github :repo "ArthurHeymans/gptel-magit"))
:host github
:repo "ArthurHeymans/gptel-magit")
:hook :hook
(magit-mode . gptel-magit-install) (magit-mode . gptel-magit-install)
:init :init
(with-eval-after-load 'gptel (with-eval-after-load 'gptel
(gptel-make-openai "gptel-Kimi-Code-magit" (gptel-make-openai "gptel-Kimi-Code-magit"

View File

@@ -188,6 +188,11 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog
(interactive) (interactive)
(load-file (expand-file-name "~/.emacs.d/lisp/fix-theme-colors.el"))) (load-file (expand-file-name "~/.emacs.d/lisp/fix-theme-colors.el")))
(defun my-note-push ()
"Git add/commit/push notes in `~/org/my-org-note/', generate commit message."
(interactive)
(my-blog-publish "~/org/my-org-note/"))
(when *is-linux* (when *is-linux*
(defun reboot () (defun reboot ()
"Execute loginctl reboot command." "Execute loginctl reboot command."

View File

@@ -29,7 +29,7 @@
"o" 'gptel "o" 'gptel
"m" 'gptel-menu "m" 'gptel-menu
"s" 'gptel-send "s" 'gptel-send
"a" 'gptel-agent-project "a" 'gptel-agent
"t" 'gptel-tools) "t" 'gptel-tools)
(general-def gptel-mode-map (general-def gptel-mode-map
@@ -47,7 +47,8 @@
"c" 'my-color-picker "c" 'my-color-picker
"f" 'describe-face "f" 'describe-face
"r" 'rainbow-delimiters-mode "r" 'rainbow-delimiters-mode
"k" 'keycast-header-line-mode) "k" 'keycast-header-line-mode
"w" 'global-whitespace-mode)
;; f for find and consult command ;; f for find and consult command
(general-def (general-def
@@ -73,7 +74,8 @@
"r" 'consult-ripgrep-project "r" 'consult-ripgrep-project
"R" 'project-query-replace-regexp "R" 'project-query-replace-regexp
"v" 'magit-project-status "v" 'magit-project-status
"V" 'project-vc-dir) "V" 'project-vc-dir
"a" 'gptel-agent-project)
;; t for modes toggle ;; t for modes toggle
(general-def (general-def
@@ -90,7 +92,8 @@
"g" 'consult-notes-search-in-all-notes "g" 'consult-notes-search-in-all-notes
"C" 'calendar "C" 'calendar
"c" 'org-capture "c" 'org-capture
"p" 'my-blog-publish "P" 'my-blog-publish
"p" 'my-note-push
"v" 'my-blog-preview "v" 'my-blog-preview
"d" 'denote "d" 'denote
"r" 'denote-rename-file) "r" 'denote-rename-file)
@@ -151,6 +154,7 @@
"<right>" 'dired-find-file "<right>" 'dired-find-file
"<left>" 'dired-up-directory "<left>" 'dired-up-directory
"C-f" 'dired-find-file "C-f" 'dired-find-file
"C-/" 'dired-undo
"<SPC>" 'my-dirvish-layout-toggle "<SPC>" 'my-dirvish-layout-toggle
"C-s" 'consult-line "C-s" 'consult-line
"C-r" 'consult-line) "C-r" 'consult-line)

View File

@@ -6,17 +6,21 @@
(use-package org (use-package org
:hook :hook
(org-mode . (lambda () (org-mode . org-indent-mode)
(org-indent-mode) (org-mode . visual-line-mode)
(visual-line-mode) (org-mode . jinx-mode)
(jinx-mode) (org-mode . my-org-electric-pair-fix)
(electric-pair-local-mode) (org-mode . electric-pair-local-mode)
:config
(require 'org-tempo) (require 'org-tempo)
(defun my-org-electric-pair-fix ()
(setq-local electric-pair-inhibit-predicate (setq-local electric-pair-inhibit-predicate
(lambda (char) (lambda (char)
(or (eq char ?<) (or (eq char ?<)
(electric-pair-default-inhibit char)))))) (electric-pair-default-inhibit char)))))
:config
;; log默认放入drawer中 ;; log默认放入drawer中
(setq org-log-done t (setq org-log-done t
org-log-into-drawer t) org-log-into-drawer t)
@@ -60,6 +64,7 @@
(use-package denote (use-package denote
:hook :hook
(after-init . denote-rename-buffer-mode) (after-init . denote-rename-buffer-mode)
(dired-mode . denote-dired-mode)
:config :config
(if *is-android* (if *is-android*
(setq denote-directory "~/storage/shared/my-org-note/") (setq denote-directory "~/storage/shared/my-org-note/")
@@ -238,12 +243,13 @@ See `org-capture-templates' for more information."
(function org-hugo-new-subtree-post-capture-template))))) (function org-hugo-new-subtree-post-capture-template)))))
;; 快速部署 ;; 快速部署
(defun my-blog-publish () (defun my-blog-publish (&optional directory)
"Publish blog , git add/commit/push , generate commit message." "Publish blog , git add/commit/push , generate commit message."
(interactive) (interactive)
(let* ((blog-dir (if *is-windows* (let* ((blog-dir (or directory
(if *is-windows*
"h:/emacs/hugo/this-is-my-blog/" "h:/emacs/hugo/this-is-my-blog/"
"~/org/hugo/this-is-my-blog/")) "~/org/hugo/this-is-my-blog/")))
(timestamp (format-time-string "%Y-%m-%d %H:%M:%S")) (timestamp (format-time-string "%Y-%m-%d %H:%M:%S"))
(default-directory blog-dir)) (default-directory blog-dir))
;; save buffer ;; save buffer

View File

@@ -160,6 +160,12 @@
("C-x K" . helpful-kill-buffers) ("C-x K" . helpful-kill-buffers)
("r" . remove-hook-at-point))) ("r" . remove-hook-at-point)))
;; typit打字游戏
(use-package typit)
;; power-mode
(use-package power-mode)
(provide 'init-package) (provide 'init-package)
;;; init-package.el ends here ;;; init-package.el ends here

View File

@@ -1,4 +1,4 @@
;;; init-segmentation.el --- Chinese segmentation config -*- lexical-binding: t -*- ;;; init-segmentation.el --- Chinese word segmentation -*- lexical-binding: t -*-
;;; Commentary: ;;; Commentary:
@@ -7,14 +7,10 @@
;; emacs-chinese-word-segmentation ;; emacs-chinese-word-segmentation
(cond (cond
(*is-windows* (*is-windows*
(add-to-list 'load-path "h:/emacs/emacs-chinese-word-segmentation/") (add-to-list 'load-path "h:/emacs/emacs-chinese-word-segmentation/") ;设置为进程调用方式
;; 设置为进程调用方式 (setq cns-process-type 'shell) ;设置可执行文件路径
(setq cns-process-type 'shell) (setq cns-prog "h:/emacs/emacs-chinese-word-segmentation/cnws.exe") ;设置字典目录
;; 设置可执行文件路径 (setq cns-dict-directory "h:/emacs/emacs-chinese-word-segmentation/cppjieba/dict") ;直接设置进程命令,绕过 Windows shell 检测
(setq cns-prog "h:/emacs/emacs-chinese-word-segmentation/cnws.exe")
;; 设置字典目录
(setq cns-dict-directory "h:/emacs/emacs-chinese-word-segmentation/cppjieba/dict")
;; 直接设置进程命令,绕过 Windows shell 检测
(setq cns-process-shell-command (setq cns-process-shell-command
(format "%s %s %s %s %s %s" (format "%s %s %s %s %s %s"
cns-prog cns-prog
@@ -26,11 +22,8 @@
(t (t
(add-to-list 'load-path "~/emacs-stuff/emacs-chinese-word-segmentation/") (add-to-list 'load-path "~/emacs-stuff/emacs-chinese-word-segmentation/")
;; 设置为进程调用方式
(setq cns-process-type 'shell) (setq cns-process-type 'shell)
;; 设置可执行文件路径
(setq cns-prog "~/emacs-stuff/emacs-chinese-word-segmentation/cnws") (setq cns-prog "~/emacs-stuff/emacs-chinese-word-segmentation/cnws")
;; 设置字典目录
(setq cns-dict-directory "~/emacs-stuff/emacs-chinese-word-segmentation/cppjieba/dict/"))) (setq cns-dict-directory "~/emacs-stuff/emacs-chinese-word-segmentation/cppjieba/dict/")))
;; 其他配置 ;; 其他配置
@@ -39,20 +32,12 @@
;; 自动启动 ;; 自动启动
(when (featurep 'cns) (when (featurep 'cns)
(add-hook 'find-file-hook 'global-cns-mode)) (add-hook 'after-init-hook 'global-cns-mode))
;; 取消C-<backspace>绑定 ;; 取消C-<backspace>绑定
(with-eval-after-load 'cns (with-eval-after-load 'cns
(define-key cns-mode-map (kbd "C-<backspace>") nil)) (define-key cns-mode-map (kbd "C-<backspace>") nil))
;; vterm下关闭cns-mode
(add-hook 'vterm-mode-hook
(lambda ()
(run-at-time 0 nil
(lambda ()
(when (derived-mode-p 'vterm-mode)
(cns-mode -1))))))
(provide 'init-segmentation) (provide 'init-segmentation)
;;; init-segmentation.el ends here ;;; init-segmentation.el ends here

View File

@@ -86,6 +86,9 @@
;; 移动到垃圾桶 ;; 移动到垃圾桶
(setq delete-by-moving-to-trash t) (setq delete-by-moving-to-trash t)
;; 优化换行规则
(setq word-wrap-by-category t)
(provide 'init-startup) (provide 'init-startup)
;;; init-startup.el ends here ;;; init-startup.el ends here

View File

@@ -6,11 +6,12 @@
(use-package gcmh (use-package gcmh
:delight :delight
:hook
(emacs-startup . gcmh-mode)
:init :init
(setq gcmh-idle-delay 'auto (setq gcmh-idle-delay 'auto
gcmh-auto-idle-delay-factor 10 gcmh-auto-idle-delay-factor 10
gcmh-high-cons-threshold #x4000000) gcmh-high-cons-threshold #x4000000))
(gcmh-mode))
(use-package benchmark-init (use-package benchmark-init
:init :init

View File

@@ -51,10 +51,14 @@
`(font-lock-keyword-face ((,class (:foreground ,cyan :weight bold)))) `(font-lock-keyword-face ((,class (:foreground ,cyan :weight bold))))
`(font-lock-doc-face ((,class (:foreground ,green :slant normal)))) `(font-lock-doc-face ((,class (:foreground ,green :slant normal))))
`(font-lock-string-face ((,class (:foreground ,green)))) `(font-lock-string-face ((,class (:foreground ,green))))
`(line-number ((,class (:foreground ,base01 :weight light))))
`(button ((,class (:foreground ,yellow :underline t))))
`(dashboard-footer-face ((,class (:foreground ,blue)))) `(dashboard-footer-face ((,class (:foreground ,blue))))
`(dashboard-text-banner ((,class (:foreground ,green)))) `(dashboard-text-banner ((,class (:foreground ,green))))
`(dashboard-heading ((,class (:foreground ,green :weight bold)))) `(dashboard-heading ((,class (:foreground ,green :weight bold))))
`(dirvish-file-time ((,class (:foreground ,base01)))) `(dirvish-file-time ((,class (:foreground ,base01))))
`(dirvish-free-space ((,class (:foreground ,green))))
`(dired-broken-symlink ((,class (:inherit dired-symlink :foreground ,orange))))
`(dired-header ((,class (:foreground ,green)))) `(dired-header ((,class (:foreground ,green))))
`(dired-async-mode-message ((,class (:foreground ,red)))) `(dired-async-mode-message ((,class (:foreground ,red))))
`(dired-async-message ((,class (:foreground ,yellow)))) `(dired-async-message ((,class (:foreground ,yellow))))

View File

@@ -51,10 +51,14 @@
`(font-lock-keyword-face ((,class (:foreground ,cyan :weight bold)))) `(font-lock-keyword-face ((,class (:foreground ,cyan :weight bold))))
`(font-lock-doc-face ((,class (:foreground ,green :slant normal)))) `(font-lock-doc-face ((,class (:foreground ,green :slant normal))))
`(font-lock-string-face ((,class (:foreground ,green)))) `(font-lock-string-face ((,class (:foreground ,green))))
`(line-number ((,class (:foreground ,base01 :weight light))))
`(button ((,class (:foreground ,yellow :underline t))))
`(dashboard-footer-face ((,class (:foreground ,blue)))) `(dashboard-footer-face ((,class (:foreground ,blue))))
`(dashboard-text-banner ((,class (:foreground ,green)))) `(dashboard-text-banner ((,class (:foreground ,green))))
`(dashboard-heading ((,class (:foreground ,green :weight bold)))) `(dashboard-heading ((,class (:foreground ,green :weight bold))))
`(dirvish-file-time ((,class (:foreground ,base01)))) `(dirvish-file-time ((,class (:foreground ,base01))))
`(dirvish-free-space ((,class (:foreground ,green))))
`(dired-broken-symlink ((,class (:inherit dired-symlink :foreground ,orange))))
`(dired-header ((,class (:foreground ,green)))) `(dired-header ((,class (:foreground ,green))))
`(dired-async-mode-message ((,class (:foreground ,red)))) `(dired-async-mode-message ((,class (:foreground ,red))))
`(dired-async-message ((,class (:foreground ,yellow)))) `(dired-async-message ((,class (:foreground ,yellow))))