移除projectile插件,使用project插件

This commit is contained in:
Shawn Jones 2024-08-27 20:51:55 +08:00
parent f1e30c7648
commit 38e6b2b137
6 changed files with 97 additions and 38 deletions

View File

@ -9,10 +9,11 @@
(require 'init-theme) ; 主题配置
(require 'init-autocomplete) ; 自动补伤全配置
(require 'init-errors) ; 错误/警告提示引擎配置
(require 'init-projectile) ; 项目管理配置
(require 'init-project) ; 项目管理配置
(require 'init-magit) ; git客户端
(require 'init-dashboard) ; 首页配置
(require 'init-ide) ; ide配置 lsp
(require 'init-org) ; org的相关配置
(require 'init-hydra) ; hydra配置自定的快捷键
(require 'init-hooks) ; 钩子和扩展功能配置文件
;;; init.el ends here

View File

@ -7,11 +7,11 @@
:ensure t
:config
(setq dashboard-banner-logo-title "欢迎您!邵静!") ;; 个性签名,随读者喜好设置
(setq dashboard-projects-backend 'projectile) ;; 读者可以暂时注释掉这一行,等安装了 projectile 后再使用
(setq dashboard-projects-backend 'project-el) ;; 使用 project.el 作为项目管理工具
(setq dashboard-startup-banner 'official) ;; 也可以自定义图片
(setq dashboard-items '((recents . 5) ;; 显示多少个最近文件
(bookmarks . 5) ;; 显示多少个最近书签
(projects . 10))) ;; 显示多少个最近项目
(bookmarks . 5) ;; 显示多少个最近书签
(projects . 10))) ;; 显示多少个最近项目
(setq dashboard-set-file-icons t)
(dashboard-setup-startup-hook))
(provide 'init-dashboard)

17
lisp/init-hooks.el Normal file
View File

@ -0,0 +1,17 @@
;;; init-hooks.el --- -*- lexical-binding: t; -*-
;; 定义一个函数,用于在 mode-line模式行中显示当前缓冲区的字符数
(defun my-char-count-mode-line ()
"在 mode-line 中显示当前缓冲区的字符数。"
;; 设置 mode-line 的格式,将字符数统计信息追加到 mode-line 中
(setq mode-line-format
(append mode-line-format
'((:eval (format " [%d chars]" ; 格式化输出字符数
(- (point-max) (point-min)))))))) ; 计算字符数
;; 将 my-char-count-mode-line 函数添加到 text-mode 和 prog-mode 的钩子中
;; 这样在进入文本模式或编程模式时mode-line 就会显示字符数
(add-hook 'text-mode-hook 'my-char-count-mode-line)
(add-hook 'prog-mode-hook 'my-char-count-mode-line)
(provide 'init-hooks)

View File

@ -13,7 +13,7 @@ _f_: file operations _p_: Projectile
_g_: git client _o_: org
"
("f" hydra-file-dir-operations/body "文件目录操作")
("p" hydra-projectile-operations/body "Projectile项目管理")
("p" hydra-project-operations/body "Projectile项目管理")
("g" magit-status "git客户端")
("o" hydra-org-operations/body "org"))

74
lisp/init-project.el Normal file
View File

@ -0,0 +1,74 @@
;;; init-projectile -- 项目管理的配置
;;; Commentary:
;;; Code:
;; 这个是基础配置部分
(require 'project)
;; 配置项目根目录识别
(setq project-vc-extra-root-markers '(".project" ".git" ".hg" ".svn" "Makefile"))
;; 设置项目列表文件
(setq project-list-file "~/.emacs.d/projects")
;; 设置项目切换时的默认命令列表
(setq project-switch-commands
'((project-find-file "Find file")
(project-dired "Dired")
(project-vc-dir "VC-Dir")
(project-shell "Shell")))
;; 自定义项目根目录识别函数
(defun my/project-try-custom-root (dir)
"Define custom project roots."
(let ((root (locate-dominating-file dir ".project")))
(and root (cons 'vc root))))
(add-hook 'project-find-functions #'my/project-try-custom-root)
;; 手动添加项目到 project.el 的项目列表
(defun my/add-project (dir)
"手动将 DIR 添加到 project.el 的项目列表中。"
(interactive "D添加项目目录: ")
(let ((projects (project-known-project-roots)))
(unless (member dir projects)
(setq projects (append projects (list dir)))
(setq project--list projects)
;; 保存到 projects 文件,而不是 custom.el
(with-temp-file project-list-file
(insert (prin1-to-string projects)))
(message "项目 %s 已添加到 project.el 列表中" dir))))
;; 清除不存在的项目缓存
(defun project-forget-zombie-projects ()
"Remove non-existing projects from the known projects list."
(interactive)
(setq project--list
(cl-remove-if-not #'file-directory-p project--list))
(with-temp-file project-list-file
(insert (prin1-to-string project--list)))
(message "已移除不存在的项目"))
;; hydra配置
;; 定义一个用于Project项目管理的 hydra
(defhydra hydra-project-operations (:color blue :hint nil)
"
^Project项目管理^
^^^^^^^^^^^^^^^^^^^--------------------
_p_: 切换项目 _f_: 查找文件
_d_: 查找目录 _s_: 正则查找
_g_: 全局搜索 _b_: 切换缓冲区
_r_: 忽略项目 _a_: 添加项目
_c_: 清除缓存
"
("p" project-switch-project "切换项目")
("f" project-find-file "查找文件")
("d" project-find-dir "查找目录")
("s" project-find-regexp "正则查找")
("g" project-find-regexp "全局搜索")
("b" project-switch-to-buffer "切换缓冲区")
("r" project-forget-project "忽略项目")
("a" my/add-project "添加项目")
("c" project-forget-zombie-projects "清除缓存"))
(provide 'init-project)
;;; init-project.el ends here

View File

@ -1,33 +0,0 @@
;;; init-projectile -- 项目管理的配置
;;; Commentary:
;;; Code:
;; 安装(如未安装)
(use-package projectile
:ensure t
:config
(setq projectile-cache-file (expand-file-name ".cache/projectile.cache" user-emacs-directory))
(projectile-mode 1))
;; 定义一个用于Projectile项目管理的 hydra
(defhydra hydra-projectile-operations (:color blue :hint nil)
"
^Projectile项目管理^
^^^^^^^^^^^^^^^^^^^--------------------
_p_: 切换项目 _f_: 查找文件
_d_: 查找目录 _s_: 正则查找
_g_: 全局搜索 _b_: 切换缓冲区
_r_: 重命名项目 _a_: 添加项目
"
("p" projectile-switch-project "切换项目")
("f" projectile-find-file "查找文件")
("d" projectile-find-dir "查找目录")
("s" projectile-grep "正则查找")
("g" projectile-grep "全局搜索")
("b" projectile-switch-to-buffer "切换缓冲区")
("r" projectile-replace "重命名项目")
("a" projectile-add-known-project "添加项目")
)
(provide 'init-projectile)
;;; init-projectile.el ends here