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,12 +4,118 @@
;;; Code:
;; verticominibuffer补全
(use-package vertico
:hook
(after-init . vertico-mode))
;; orderless模糊搜索
(use-package orderless
:custom
(completion-styles '(orderless basic)))
;; marginalia命令注释
(use-package marginalia
:hook
(after-init . marginalia-mode))
;; consult搜索与导航
(use-package consult
:config
;; set locate arguments
(cond
(*is-windows*
(setq consult-locate-args (encode-coding-string "es.exe -i -p -r" 'gbk)
consult-ripgrep-args (encode-coding-string
"rg --null --line-buffered --color=never --max-columns=1000 --path-separator / --smart-case --no-heading --line-number"
'gbk))
(add-to-list 'process-coding-system-alist '("es" gbk . gbk)))
(*is-mac*
(setq consult-locate-args "mdfind -name"))
(*is-linux*
(setq consult-locate-args "plocate --basename --ignore-case")))
;; set some buffer filter
(setq consult-buffer-filter
(cl-union consult-buffer-filter
'("^\\*dirvish"
"^PREVIEW"
"^\\*helpful"
"^\\*Help"
"Diff"
"straight"
"\\*Messages\\*")
:test 'equal)))
;; embark快捷指令
(use-package embark
:commands
embark-prefix-help-command
:init
(setq prefix-help-command 'embark-prefix-help-command)
:config
(defun my/embark-preview ()
"Previews candidate in vertico buffer, unless it's a consult command."
(interactive)
(unless (bound-and-true-p consult--preview-function)
(save-selected-window
(let ((embark-quit-after-action nil))
(embark-dwim)))))
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none))))
(with-no-warnings
(with-eval-after-load 'which-key
(defun embark-which-key-indicator ()
"An embark indicator that displays keymaps using which-key.
The which-key help message will show the type and value of the
current target followed by an ellipsis if there are further
targets."
(lambda (&optional keymap targets prefix)
(if (null keymap)
(which-key--hide-popup-ignore-command)
(which-key--show-keymap
(if (eq (plist-get (car targets) :type) 'embark-become)
"Become"
(format "Act on %s '%s'%s"
(plist-get (car targets) :type)
(embark--truncate-target (plist-get (car targets) :target))
(if (cdr targets) "" "")))
(if prefix
(pcase (lookup-key keymap prefix 'accept-default)
((and (pred keymapp) km) km)
(_ (key-binding prefix 'accept-default)))
keymap)
nil nil t (lambda (binding)
(not (string-suffix-p "-argument" (cdr binding))))))))
(setq embark-indicators
'(embark-which-key-indicator
embark-highlight-indicator
embark-isearch-highlight-indicator))
(defun embark-hide-which-key-indicator (fn &rest args)
"Hide the which-key indicator immediately when using the completing-read prompter."
(which-key--hide-popup-ignore-command)
(let ((embark-indicators
(remq #'embark-which-key-indicator embark-indicators)))
(apply fn args)))
(advice-add #'embark-completing-read-prompter
:around #'embark-hide-which-key-indicator))))
;; embark-consult
(use-package embark-consult
:config
(add-hook
'embark-collect-mode-hook
#'consult-preview-at-point-mode))
;; eglot
(use-package eglot
:hook
((python-mode . eglot-ensure)
;; (scheme-mode . eglot-ensure)
)
:config
(setq eglot-send-changes-idle-time 0.25)
(add-to-list 'eglot-server-programs
@@ -27,8 +133,6 @@
(use-package corfu
:autoload
(corfu-quit consult-completion-in-region)
:functions
(persistent-scratch-save)
:custom
(corfu-auto t)
(corfu-auto-prefix 2)
@@ -43,14 +147,13 @@
gud-mode
vterm-mode)
t))
:init
(global-corfu-mode)
(corfu-popupinfo-mode)
(corfu-history-mode)
:hook
(after-init . global-corfu-mode)
(after-init . corfu-popupinfo-mode)
(after-init . corfu-history-mode)
:config
;;Quit completion before saving
(add-hook 'before-save-hook #'corfu-quit)
(advice-add #'persistent-scratch-save :before #'corfu-quit)
:bind
(:map corfu-map
("RET" . nil)))
@@ -58,8 +161,8 @@
(use-package corfu-terminal
:if (not (and (display-graphic-p)
(>= emacs-major-version 31)))
:init
(corfu-terminal-mode))
:hook
(after-init . corfu-terminal-mode))
;; 在eshell中使用tab打开补全
(add-hook 'eshell-mode-hook