首页 > 解决方案 > 限制 .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-regexpsite-start.d/mnt/groups.dir-locals.el.dir-locals.el在自动挂载程序中(因此我的问题部分解决了),我宁愿完全阻止 Emacs 遍历所有父子目录。我尝试了设置locate-dominating-stop-dir-regexp,但它似乎并没有影响寻找.dir-locals.el,除非它与vc-ignore-dir-regexp. 不幸的是,正如我所提到的,我没有使用 Emacs 的经验(我自己没有使用它),所以我无法理解如何编写更高级的东西。

标签: 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\\/\\'" ))

成功了。


推荐阅读