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
;;; core-settings.el --- Core Emacs settings and package management -*- lexical-binding: t -*-
;; Copyright (C) 2026 Cytrogen
;; Many package selections and configurations adapted from
;; Steve Purcell's emacs.d: https://github.com/purcell/emacs.d
;; This file contains fundamental Emacs configuration:
;; - Character encoding settings
;; - Package repository configuration
;; - Basic system behavior
;;; Commentary:
;; This module sets up the foundation for the entire Emacs configuration.
;; It should be loaded first among all configuration modules.
;;; Code:
;; Character Encoding Configuration
;; UTF-8 is the standard encoding for modern text processing
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8-unix)
(set-default-coding-systems 'utf-8-unix)
(set-terminal-coding-system 'utf-8-unix)
(set-keyboard-coding-system 'utf-8-unix)
(set-selection-coding-system 'utf-8-unix)
(set-file-name-coding-system 'utf-8-unix)
(set-clipboard-coding-system 'utf-8-unix)
(set-buffer-file-coding-system 'utf-8-unix)
;; Windows-specific encoding adjustment
(when (eq system-type 'windows-nt)
(setq file-name-coding-system 'gbk))
;; Package Management Configuration
;; MELPA repository for modern packages
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
;; GC Magic Hack — 自适应垃圾回收,减少卡顿
(unless (package-installed-p 'gcmh)
(package-refresh-contents)
(package-install 'gcmh))
(require 'gcmh)
(setq gcmh-idle-delay 'auto
gcmh-auto-idle-delay-factor 10
gcmh-high-cons-threshold (* 16 1024 1024))
(gcmh-mode 1)
;; Native Compilation — 警告仅记录到 *native-comp-log*,不弹窗
(setq native-comp-async-report-warnings-errors 'silent)
;; File Backup and Auto-save Configuration
;; Syncthing-compatible settings to avoid conflicts
(setq backup-directory-alist `(("." . ,(concat user-emacs-directory "saves/"))))
(setq auto-save-file-name-transforms `((".*" ,(concat user-emacs-directory "saves/") t)))
(setq create-lockfiles nil)
(unless (file-exists-p (concat user-emacs-directory "saves/"))
(make-directory (concat user-emacs-directory "saves/")))
;; 内置功能启用
(savehist-mode 1)
(recentf-mode 1)
(setq recentf-max-saved-items 200)
;; Desktop — 重启 Emacs 恢复上次打开的文件
(setq desktop-path (list user-emacs-directory)
desktop-auto-save-timeout 600)
(desktop-save-mode 1)
(winner-mode 1)
;; Switch-window — 多窗口时可视化选择目标窗口
(unless (package-installed-p 'switch-window)
(package-install 'switch-window))
(require 'switch-window)
(setq switch-window-shortcut-style 'alphabet)
(global-set-key (kbd "C-x o") 'switch-window)
;; Uniquify — 同名 buffer 显示路径区分(如 init.el • project-a)
(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse
uniquify-separator " • "
uniquify-after-kill-buffer-p t
uniquify-ignore-buffers-re "^\\*")
;; ~/.local/bin 加入 exec-path(uv tool 安装的 LSP 服务器等)
(let ((local-bin (expand-file-name "~/.local/bin")))
(unless (member local-bin exec-path)
(add-to-list 'exec-path local-bin)
(setenv "PATH" (concat local-bin ":" (getenv "PATH")))))
;; 内置行为增强
(global-auto-revert-mode 1) ; 外部修改自动刷新 buffer
(delete-selection-mode 1) ; 选中文字后打字直接覆盖
(setq use-short-answers t) ; y/n 替代 yes/no
(repeat-mode 1) ; 重复命令只需按最后一键
(pixel-scroll-precision-mode 1) ; 像素级平滑滚动
;; 保存带 shebang 的脚本自动 chmod +x
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
;; 滚动与光标行为
;; 滚动行为
(setq scroll-preserve-screen-position t)
;; 鼠标滚轮每次滚动 3 行
(setq mouse-wheel-scroll-amount '(3 ((shift) . 1)))
;; 不加速滚动
(setq mouse-wheel-progressive-speed nil)
;; 高亮当前行
(global-hl-line-mode 1)
;; 光标始终居中 (centered-cursor-mode)
(unless (package-installed-p 'centered-cursor-mode)
(package-refresh-contents)
(package-install 'centered-cursor-mode))
(require 'centered-cursor-mode)
(global-centered-cursor-mode 1)
;; Default Browser Configuration
;; 使用 Floorp 特定 profile 打开链接
(setq browse-url-browser-function 'browse-url-generic)
(setq browse-url-generic-program "floorp")
(setq browse-url-generic-args '("-P" "Personal"))
;; Completion Framework (Vertico + Orderless)
;; 提供模糊搜索和垂直补全界面
(unless (package-installed-p 'vertico)
(package-refresh-contents)
(package-install 'vertico))
(unless (package-installed-p 'orderless)
(package-install 'orderless))
;; 启用 vertico 垂直补全
(require 'vertico)
(vertico-mode 1)
;; 启用 orderless 模糊匹配
(require 'orderless)
(setq completion-styles '(orderless basic)
completion-category-overrides '((file (styles basic partial-completion))))
;; Which-key — 按前缀键后显示可用键位
(unless (package-installed-p 'which-key)
(package-install 'which-key))
(require 'which-key)
(setq which-key-idle-delay 0.8)
(which-key-mode 1)
;; Embark — 对补全候选执行操作(需在 consult 之前加载)
(unless (package-installed-p 'embark)
(package-install 'embark))
(unless (package-installed-p 'embark-consult)
(package-install 'embark-consult))
(require 'embark)
;; Consult — 增强搜索/切换命令
(unless (package-installed-p 'consult)
(package-install 'consult))
(require 'consult)
(global-set-key (kbd "C-x b") 'consult-buffer)
(global-set-key (kbd "M-y") 'consult-yank-pop)
(global-set-key (kbd "M-g g") 'consult-goto-line)
(global-set-key (kbd "M-g M-g") 'consult-goto-line)
;; Marginalia — 补全候选旁显示元信息
(unless (package-installed-p 'marginalia)
(package-install 'marginalia))
(require 'marginalia)
(marginalia-mode 1)
;; embark-consult 已由 embark 的 with-eval-after-load 自动加载,显式 require 确保可用
(require 'embark-consult)
;; Project.el(内置)— 项目级导航,与 consult 自动集成
;; C-x p f 查找文件 / C-x p g grep / C-x p b 切换 buffer
(setq project-switch-commands
'((consult-find "Find file" ?f)
(consult-ripgrep "Ripgrep" ?g)
(consult-buffer "Buffer" ?b)
(project-dired "Dired" ?d)
(magit-project-status "Magit" ?m)))
;; Wgrep — 编辑 grep/ripgrep 结果并批量写回文件
(unless (package-installed-p 'wgrep)
(package-install 'wgrep))
;; Corfu — 行内补全弹窗
(unless (package-installed-p 'corfu)
(package-install 'corfu))
(require 'corfu)
(setq corfu-auto t)
(global-corfu-mode 1)
(corfu-popupinfo-mode 1)
;; Hippie-expand — M-/ 智能补全(文件名 + dabbrev)
(global-set-key (kbd "M-/") 'hippie-expand)
(setq hippie-expand-try-functions-list
'(try-complete-file-name-partially
try-complete-file-name
try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill))
;; Diredfl — Dired 目录列表彩色高亮
(unless (package-installed-p 'diredfl)
(package-install 'diredfl))
(require 'diredfl)
(diredfl-global-mode 1)
;; Unfill — M-Q 反填充段落
(unless (package-installed-p 'unfill)
(package-install 'unfill))
(require 'unfill)
(global-set-key (kbd "M-Q") 'unfill-paragraph)
;; Mode-line-bell — 可视 bell,mode-line 闪烁替代蜂鸣
(unless (package-installed-p 'mode-line-bell)
(package-install 'mode-line-bell))
(require 'mode-line-bell)
(mode-line-bell-mode 1)
;; VLF — 打开超大文件(GB 级日志)不卡死
(unless (package-installed-p 'vlf)
(package-install 'vlf))
(require 'vlf-setup)
;; Anzu — isearch 时实时显示匹配计数(第 3/17 个)
(unless (package-installed-p 'anzu)
(package-install 'anzu))
(require 'anzu)
(global-anzu-mode 1)
(global-set-key [remap query-replace] 'anzu-query-replace)
(global-set-key [remap query-replace-regexp] 'anzu-query-replace-regexp)
;; Browse-kill-ring — 可视化浏览 kill ring
(unless (package-installed-p 'browse-kill-ring)
(package-install 'browse-kill-ring))
(require 'browse-kill-ring)
(global-set-key (kbd "M-Y") 'browse-kill-ring)
(provide 'core-settings)
;;; core-settings.el ends here