refactor: Reorganize config with use-package and optimize startup hooks

- Split monolithic init-package.el into focused modules
- Convert eager `:init` blocks to lazy `:hook`
- Consolidate UI settings and defer theme loading.
- Remove duplicated config between GUI and terminal paths.
This commit is contained in:
2026-06-04 02:27:20 +08:00
parent 8db37d1c6d
commit b4733718d4
20 changed files with 910 additions and 849 deletions

View File

@@ -4,49 +4,6 @@
;;; Code:
;; 设置系统编码
(when (fboundp 'set-charset-priority)
(set-charset-priority 'unicode))
(if *is-windows*
(progn
(set-language-environment 'chinese-gbk)
(prefer-coding-system 'utf-8-auto))
(progn
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8)))
;; 预览所有可用emacs颜色
(defun my-color-picker ()
"Pick a color with preview."
(interactive)
(let* ((colors (defined-colors))
(choice (completing-read
"Color: "
(mapcar (lambda (c)
(propertize
(format "%-20s %s" c "████")
'face `(:foreground ,c)))
colors))))
(string-trim (car (split-string choice)))))
;; org-mode美化
(use-package olivetti
:delight
:init
(add-hook 'olivetti-mode-hook
(lambda ()
(display-line-numbers-mode -1)))
(add-hook 'org-mode-hook
(lambda ()
(olivetti-mode 1))))
;; rainbow mode
(use-package rainbow-mode)
;; rainbow-delimiters
(use-package rainbow-delimiters)
;; 自定义主题路径
(add-to-list 'custom-theme-load-path "~/.emacs.d/lisp/")
@@ -56,22 +13,45 @@
;; 安装solarized dark
(use-package solarized-theme
:straight
'(solarized-emacs :fork (:host github :repo "Andsy10/solarized-emacs")))
'(solarized-emacs :fork (:host github :repo "Andsy10/solarized-emacs"))
:init
;; 把主题加载延迟到frame创建之后防止daemon模式下宏不能正常展开
;; (if *is-android*
;; (if (daemonp)
;; (add-hook 'after-make-frame-functions
;; (lambda (frame)
;; (with-selected-frame frame
;; (load-theme 'my-base16-light t))))
;; (load-theme 'my-base16-light t))
;; (if (daemonp)
;; (add-hook 'after-make-frame-functions
;; (lambda (frame)
;; (with-selected-frame frame
;; (load-theme 'my-base16-dark t))))
;; (load-theme 'my-base16-dark t)))
(load-theme 'my-base16-dark))
;; 把主题加载延迟到frame创建之后防止daemon模式下宏不能正常展开
(if *is-android*
(if (daemonp)
(add-hook 'after-make-frame-functions
(lambda (frame)
(with-selected-frame frame
(load-theme 'my-base16-light t))))
(load-theme 'my-base16-light t))
(if (daemonp)
(add-hook 'after-make-frame-functions
(lambda (frame)
(with-selected-frame frame
(load-theme 'my-base16-dark t))))
(load-theme 'my-base16-dark t)))
;; 行号
(use-package display-line-numbers
:hook
(after-init . global-display-line-numbers-mode)
:config
(setq display-line-numbers-type '2
display-line-numbers-grow-only t
display-line-numbers-width-start 4))
;; org-mode美化
(use-package olivetti
:delight
:hook
(org-mode . olivetti-mode)
(olivetti-mode . (lambda () (display-line-numbers-mode -1))))
;; rainbow mode
(use-package rainbow-mode)
;; rainbow-delimiters
(use-package rainbow-delimiters)
;; 很多主题
;; (use-package doom-themes)
@@ -79,24 +59,25 @@
(use-package naysayer-theme)
(use-package ef-themes)
(if *is-android*
(use-package simple-modeline
:init
(simple-modeline-mode)))
(use-package simple-modeline
:if
*is-android*
:hook
(after-init . simple-modeline-mode))
;; eshell高亮
(use-package eshell-syntax-highlighting
:hook
(eshell-mode . eshell-syntax-highlighting-global-mode))
(add-hook 'eshell-mode-hook
(lambda ()
(setenv "TERM" "xterm-256color")
(setenv "COLORTERM" "truecolor")
(add-to-list 'eshell-output-filter-functions 'eshell-handle-ansi-color t)
(setq-local eshell-prefer-lisp-functions nil)
(setenv "LS_COLORS"
"di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46")))
(eshell-mode . eshell-syntax-highlighting-global-mode)
:config
(add-hook 'eshell-mode-hook
(lambda ()
(setenv "TERM" "xterm-256color")
(setenv "COLORTERM" "truecolor")
(add-to-list 'eshell-output-filter-functions 'eshell-handle-ansi-color t)
(setq-local eshell-prefer-lisp-functions nil)
(setenv "LS_COLORS"
"di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46"))))
;; 缩进线
(use-package indent-bars
@@ -111,46 +92,41 @@
(indent-bars-prefer-character t))
;; 高亮当前行
(global-hl-line-mode t)
;; 显示文件大小
(size-indication-mode t)
;; 显示行号列号
(column-number-mode t)
(use-package hl-line
:hook
(after-init . global-hl-line-mode))
;; 显示时间
(unless (or *is-linux* *is-android*)
(use-package time
:if
(not *is-android*)
:init
(if *is-linux*
(add-hook 'exwm-wm-mode-hook 'display-time-mode)
(add-hook 'after-init-hook 'display-time-mode))
:config
(setq display-time-default-load-average nil
display-time-string-forms
'((propertize
(concat
(propertize (format-time-string " %I:%M") 'face 'display-time-date-and-time)
(propertize (format-time-string "-%p") 'face 'font-lock-comment-face))
'help-echo (format-time-string "%A, %B %d, %Y"))))
(display-time-mode))
;; 添加个人字体到 cnfonts
(setq cnfonts-personal-fontnames
'(("Sarasa Fixed TC") ; 英文字体
("Sarasa Fixed TC") ; 中文字体
nil ; Ext-B 字体(可选)
nil ; Symbol 字体(可选)
nil)) ; 装饰字体(可选)
'help-echo (format-time-string "%A, %B %d, %Y")))))
;; 安装cnfonts脚本用于修复中英文对齐
(use-package cnfonts
:hook
(after-init . cnfonts-mode)
:init
(add-hook 'after-init-hook 'cnfonts-mode)
(setq cnfonts-personal-fontnames
'(("Sarasa Fixed TC") ;英文
("Sarasa Fixed TC") ;中文
nil ;ext-B
nil ;symbol
nil)) ;装饰
:config
(cnfonts--select-profile "profile1"))
;; 主题修复脚本
(defun fix-theme-colors ()
"Fix invalid color name in theme files."
(interactive)
(load-file (expand-file-name "~/.emacs.d/lisp/fix-theme-colors.el")))
(provide 'init-ui)
;;; init-ui.el ends here