compile 时只保存项目内的文件
2023-02-18 16:29:03 时间
Emacs 中有一个非常好用的 compile 模块,可以非常方便的编译代码、运行测试等。不熟悉的读者可以参考: Compiling and running scripts in Emacs - Mastering Emacs[1] 。
有一点比较烦人的是,
每次执行 compile 时,如果有已经修改,但是还未保存的文件,它都会在 minibuffer 中提示。
这样做的初衷是可以理解的,如果修改的文件没有保存,编译会用老的文件。问题是,所有未保存的文件都会提示,这就有些过分了,最好是能控制在项目内,之外的文件就不要再提示了。
幸好,compile 模块提供了一个选项用来控制提示那些文件: compilation-save-buffers-predicate
。
我定义了如下函数实现上述目的:
(defun my/file-in-project? ()
"检查当前 buffer 是否属于当前项目,如果当前目录不属于任何项目,直接返回 `nil'"
(when-let* ((pr (project-current))
(root (project-root pr)))
(string-prefix-p root (file-truename (buffer-file-name)))))
(setq compilation-save-buffers-predicate 'my/file-in-project?)
参考
- • Suppress prompt for save file in emacs with recompile - Super User[2]
引用链接
[1]
Compiling and running scripts in Emacs - Mastering Emacs: https://www.masteringemacs.org/article/compiling-running-scripts-emacs
[2]
Suppress prompt for save file in emacs with recompile - Super User: https://superuser.com/questions/799859/suppress-prompt-for-save-file-in-emacs-with-recompile
相关文章
- 力扣刷题篇——哈希表
- 动态规划模型:0-1背包问题
- java高级编程——网络编程(解析网页中的内容)
- 动态规划模型:背包二维费用问题
- TypeScript 类型体操:提取对象指定 key 并设置为必填
- 项目中使用 husky 格式化代码和校验 commit 信息
- 使用 Prettier 美化你的代码
- 牛客刷题——剑指offer
- 牛客刷题篇——剑指offer (第二期)
- React Fiber 是什么?
- 创建第一个Springboot 项目
- React 的 setState 同步还是异步
- 这次带大家彻底搞懂 flex 布局
- 牛客刷题——剑指offer(第三期)
- 牛客刷题——剑指offer(第四期)
- 探究Springboot自动装配原理
- JAVA IO流——创建文件
- Vue 组件间通信的几种方式
- JAVA IO——获取文件信息
- konva系列教程5:事件