1

a quick question in case someone has done this before:

I'm trying to stop Emacs from trying to recursively open .dir-locals.el under all parent subdirectories when opening a file. I have found how to stop it completely (by forcing all files to be remote - the opposite of this: In Emacs, how do I use directory local variables for remote projects?) but I would like to allow access to at least the .dir-locals.el in the current directory of the file Emacs is editing, or implement a similar solution to the GIT_CEILING_DIRECTORIES variable (where git stops looking for .git after reaching a specific directory defined in this variable).

I have no experience with Emacs unfortunately.

EDIT: A sample from strace when I run emacs testfile in /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)

This is not happening for example in /home/user/a/b/c/d, and it stops looking when it reaches /home/user.

EDIT2: Some more information regarding why I'm looking for a solution to this:
the directory /mnt/groups/ is automounting directories such as /mnt/groups/project1, /mnt/groups/workA, /mnt/groups/final_presentation, where users are allowed to work. When a user launches Emacs inside e.g. /mnt/groups/project1/documentation, Emacs searches for .dir-locals.el, .bzr, .git, _MTN etc through every parent subdirectory until it reaches /. I've used vc-ignore-dir-regexp (in a file in site-start.d, so it would apply globally) to stop it from looking for version control related directories after /mnt/groups, but I cannot stop it from doing the same for .dir-locals.el. While I've blacklisted .dir-locals.el in the automounter (so a solution is partially in place for my problem), I would prefer to stop Emacs altogether from going through all parent subdirectories. I tried setting locate-dominating-stop-dir-regexp but it didn't seem to affect looking for .dir-locals.el, unless it is somehow clashing with vc-ignore-dir-regexp. Unfortunately, as I mentioned, I have no experience with Emacs (I'm not using it myself) so I wasn't able to understand how to program anything more advanced.

athanasio
  • 21
  • 3
  • Could you describe what you're doing in more detail, e.g. step by step, explaining what you'd like to be able to do here or there along the way? – Drew Jan 22 '19 at 04:07
  • "stops looking ... after reaching a specific directory" -- just put an empty `.dir-locals.el` file in that directory? – phils Jan 22 '19 at 07:22
  • @phils I would like to avoid placing the `.dir-locals.el` as the directory in question that I don't want Emacs to look for it is where automounting occurs. – athanasio Jan 22 '19 at 09:29
  • @Drew I want to avoid this from happening: `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)` – athanasio Jan 22 '19 at 09:38
  • 1
    Put any useful info in the question, not in comments. Comments can be deleted at any time. – Drew Jan 22 '19 at 14:18
  • If you prefer to disable them entirely, you can customize `enable-dir-local-variables`; otherwise you're probably going to need to redefine or advise `dir-locals-find-file`. Advice to let-bind `locate-dominating-stop-dir-regexp` based on `default-directory` would probably do the trick (but might be awkward to implement). – phils Jan 22 '19 at 18:53
  • You could advise `dir-locals--all-files` (the `--` means "private function", so it may break on Emacs updates). You can make it return `nil` for directories you don't want to search. Read the docs for it and `locate-dominating-file`. You should put more details in your question, like what are the exact criteria to exclude searching a directory. – jpkotta Jan 22 '19 at 21:25

1 Answers1

1

The answer is indeed adding a regexp in locate-dominating-stop-dir-regexp. I wasn't providing the correct format for regexp in Emacs.

Adding the following in a .el file in /usr/share/emacs/site-lisp/site-start.d/:

(setq locate-dominating-stop-dir-regexp (concat locate-dominating-stop-dir-regexp "\\|\\`/mnt\\/groups\\/\\'" ))

does the trick.

athanasio
  • 21
  • 3