~cytrogen/.emacs.d

8c864d76e33eaf0414695f33fd3ec4a5d3fec1c4 — Cytrogen a month ago f1ccd8c
feat(core): 添加补全框架、会话管理和编辑增强

补全栈: Vertico 垂直补全 + Orderless 模糊匹配 + Consult 增强搜索
(buffer/ripgrep/大纲/goto-line) + Embark 上下文操作 + Marginalia
元信息 + Corfu 行内补全弹窗 + Wgrep 批量编辑 grep 结果

会话管理: Desktop 重启恢复 + Savehist 命令历史 + Recentf 最近文件
+ Winner-mode 窗口布局撤销

编辑工具: Hippie-expand 智能补全(M-/)+ Browse-kill-ring(M-Y)
+ Unfill 反填充(M-Q)+ Anzu 搜索计数 + Mode-line-bell 可视响铃
+ VLF 大文件支持 + Diredfl 彩色目录

系统行为: gcmh 自适应 GC + native-comp 静默警告 + 像素滚动
+ centered-cursor-mode + Switch-window 窗口切换 + Uniquify buffer
命名 + Which-key 按键提示 + Project.el 集成 Consult/Magit
+ ~/.local/bin 加入 exec-path + 浏览器改为 Floorp
1 files changed, 197 insertions(+), 3 deletions(-)

M config/core-settings.el
M config/core-settings.el => config/core-settings.el +197 -3
@@ 1,6 1,9 @@
;;; core-settings.el --- Core Emacs settings and package management -*- lexical-binding: t -*-

;; Copyright (C) 2024 Cytrogen
;; 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


@@ 36,6 39,19 @@
(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/"))))


@@ 44,9 60,187 @@
(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
(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "librewolf")
;; 使用 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
\ No newline at end of file