emacs - 限制 .dir-locals.el 搜索遍历子目录
问题描述
一个快速的问题,以防有人以前这样做过:
我试图阻止 Emacs.dir-locals.el
在打开文件时尝试在所有父子目录下递归打开。我已经找到了如何完全停止它(通过强制所有文件都是远程的 - 与此相反:In Emacs, how do I use directory local variables for remote projects?)但我想至少允许.dir-locals.el
访问Emacs 正在编辑的文件的当前目录,或对变量实施类似的解决方案(git在到达此变量中定义的特定目录后GIT_CEILING_DIRECTORIES
停止寻找)。.git
不幸的是,我没有使用 Emacs 的经验。
strace
编辑:我运行时emacs testfile
的示例/tmp/test/a/b/c/d
。
stat("/tmp/test/a/b/c/d/.dir-locals.el", 0x7ffe15dd1ee0) = -1 ENOENT (No such file or directory)
stat("/tmp/test/a/b/c/.dir-locals.el", 0x7ffe15dd1ee0) = -1 ENOENT (No such file or directory)
stat("/tmp/test/a/b/.dir-locals.el", 0x7ffe15dd1ee0) = -1 ENOENT (No such file or directory)
stat("/tmp/test/a/.dir-locals.el", 0x7ffe15dd1ee0) = -1 ENOENT (No such file or directory)
stat("/tmp/test/.dir-locals.el", 0x7ffe15dd1ee0) = -1 ENOENT (No such file or directory)
stat("/tmp/.dir-locals.el", 0x7ffe15dd1ee0) = -1 ENOENT (No such file or directory)
stat("/.dir-locals.el", 0x7ffe15dd1ee0) = -1 ENOENT (No such file or directory)
例如,这不会发生/home/user/a/b/c/d
,并且当它到达时它会停止查找/home/user
。
EDIT2:有关我为什么要寻找解决方案的更多信息:
该目录/mnt/groups/
是自动挂载目录,例如/mnt/groups/project1
, /mnt/groups/workA
, /mnt/groups/final_presentation
,允许用户在其中工作。当用户在 eg 中启动 Emacs 时/mnt/groups/project1/documentation
,Emacs 会在每个父子目录中搜索、、、.dir-locals.el
等,.bzr
直到找到. 我已经使用(在. 虽然我已列入黑名单.git
_MTN
/
vc-ignore-dir-regexp
site-start.d
/mnt/groups
.dir-locals.el
.dir-locals.el
在自动挂载程序中(因此我的问题部分解决了),我宁愿完全阻止 Emacs 遍历所有父子目录。我尝试了设置locate-dominating-stop-dir-regexp
,但它似乎并没有影响寻找.dir-locals.el
,除非它与vc-ignore-dir-regexp
. 不幸的是,正如我所提到的,我没有使用 Emacs 的经验(我自己没有使用它),所以我无法理解如何编写更高级的东西。
解决方案
答案确实是在locate-dominating-stop-dir-regexp
. 我没有为 Emacs 中的正则表达式提供正确的格式。
在 .el 文件中添加以下内容/usr/share/emacs/site-lisp/site-start.d/
:
(setq locate-dominating-stop-dir-regexp (concat locate-dominating-stop-dir-regexp "\\|\\`/mnt\\/groups\\/\\'" ))
成功了。
推荐阅读
- aws-lambda - AWS Lambda 写入 DynamoDB 并发送电子邮件
- c# - Azure Storage Queue via REST API c# using Shared Key Authentication
- javascript - 在简单的 CRUD 应用程序之外构建 Django/React 项目(概念)
- javascript - 关闭模态控制器外部的 ngb-modal
- node.js - IIS/ASP.Net 与 NodeJs/ExpressJS
- wordpress - 如何将“大”添加到 wordpress API 发布数据
- go - delphi/pascal <> golang(异或加密)
- kubernetes - Kubernetes:将 HPA 与来自其他 pod 的指标结合使用
- python - 将目标函数和约束转换为代码
- python - XGBoostError: 检查失败: typestr.size() == 3 (2 vs. 3) : `typestr' 应该是格式