获取 Emacs Lisp 中的当前目录
我正在尝试编写 .dir-locals.el 文件。我想动态查找文件所在的目录并将其与“TAGS”连接起来。这是我的第一次尝试:
((nil . ((tags-file-name . (concat default-directory "TAGS")))))
这不起作用。我不是 Emacs Lisp 专家。这有什么问题吗?
I am trying to write a .dir-locals.el file. I want to dynamically find the directory that the file is in and concatenate it with "TAGS". This was my first try:
((nil . ((tags-file-name . (concat default-directory "TAGS")))))
This doesn't work. I am not an Emacs Lisp expert. What is wrong with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在linux下,怎么样:
In linux, how about:
结合 sanityinc 的解决方案和我在其他地方找到的其他一些片段,我得到:
我认为它可以满足您的要求(以稍微低效的方式,因为我们必须查找 .dir-locals.el 两次)。
Combining sanityinc's solution and some other snippet I found elsewhere, I get:
I think it does what you want (in a slightly inefficient manner, since we have to look for .dir-locals.el twice).
从技术上讲,您需要执行类似的操作才能获取代码表单以在
.dir-locals.el
内进行评估:但是,我尝试了此操作,并且出现了
default-directory
当执行 dir-locals 中的代码时为 nil ,因此看起来不可能执行您正在尝试的操作。也就是说,
tags-file-name
看起来并不像是需要手动设置的。相反,当您第一次访问标签文件时,它是由标签代码设置的。那么为什么不保留它并只使用标签功能呢?毕竟,
TAGS
是默认的标记文件名。编辑:您还可以考虑使用附加
project-local-variables
库,它使用类似的每个项目.el文件,但代码更灵活你可以把它放进去。这就是我个人解决您的问题的方式。Technically, you'd need to do something like this to get code forms to evaluate inside
.dir-locals.el
:However, I tried this, and
default-directory
appears to benil
at the time when the code indir-locals
is executed, so it looks impossible do what you are trying.That said,
tags-file-name
doesn't look like it's meant to be set manually. Rather, it gets set by the tags code when you first access the tags file.So why not leave it unset and just use the tag functions?
TAGS
is the default tag file name, after all.Edit: you might also consider using the add-on
project-local-variables
library, which uses a similar per-project .el file, but is more flexible about the code you can put inside it. This is how I would personally solve your issue.我不清楚你想要什么,但
(concat default-directory "TAGS")
看起来是正确的。如果你想设置
tags-file-name
变量,你可以这样做:(setq tags-file-name (concat default-directory "TAGS"))
。It's not clear to me what you want, but
(concat default-directory "TAGS")
looks correct.If you want to set the
tags-file-name
variable, you can do it like this:(setq tags-file-name (concat default-directory "TAGS"))
.