Technically, you'd need to do something like this to get code forms to evaluate inside .dir-locals.el
:
((nil . ((eval . (setq tags-file-name (concat default-directory "TAGS"))))))
However, I tried this, and default-directory
appears to be nil
at the time when the code in dir-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.
.dir-locals.el
, the buffer-local variabledefault-directory
is set to the location of the buffer you are visiting, not the directory of the.dir-locals.el
file. The call that tolocate-dominating-file
that @Winer gives fixes thedefault-directory
problem. – Edytheee