As Emacs opens a file it does all sorts of useful things including walking up the directory tree for more information (repos etc). I'm in a situation where I need to curtail that climb. Is there a mechanism for this or other work around?
Asked
Active
Viewed 147 times
1 Answers
1
There's locate-dominating-stop-dir-regexp
:
Regexp of directory names which stop the search in ‘locate-dominating-file’.
Any directory whose name matches this regexp will be treated like
a kind of root directory by ‘locate-dominating-file’ which will stop its search
when it bumps into it.
The default regexp prevents fruitless and time-consuming attempts to find
special files in directories in which filenames are interpreted as hostnames,
or mount points potentially requiring authentication as a different user.

Stefan
- 26,404
- 3
- 48
- 85
-
By no means am I a regex pro but I can't even get a near-static value to stop the directory search.(custom-set-variables '(locate-dominating-stop-dir-regexp "\`/uufs/chpc\.utah\.edu/home/camp-group1\'")) does not work (nor does adding a forward slash after "group1" – rjs May 12 '18 at 15:50
-
As emacs walks up the dir stack looking for multiple possible version control systems etc I get a three second delay (strace) for each as it crosses an automount point at /uufs/chpc.utah.edu/home. I suppose I could remove the list of things to look for (I'm only using one vcs) but that would still leave one 3 second delay at least. (Much better than the 20-30 sec. currently) – rjs May 12 '18 at 19:46
-
the path should read "...edu/common/home/" which is what I'm using in my attempts – rjs May 12 '18 at 19:57
-
I have tested my expression (using the same test seen in locate-dominating-file) and it returns true (non-nil) when the directory is ONLY my intended stopper and nil otherwise, so I'm starting to doubt that this mechanism is used under find-file. Any other suggestions? – rjs May 13 '18 at 03:13
-
Have you tried with or without a trailing slash? When
locate-dominating-stop-dir-regexp
is passed tostring-match
, the file name used is as returned byfile-name-directory
so it has a trailing slash. – Stefan May 13 '18 at 13:41 -
Yes with and without trailing forward slash (and /?) but from your input I'll add it explicitly. string-match does return nil comparing my regex to anything other than my intended "root" and zero for my intended root – rjs May 14 '18 at 15:45
-
Maybe the problem doesn't come from
locate-dominating-file
, then? I suggest you start debugging this withM-x trace-function RET locate-dominating-file RET
. You can alsoM-x elp-instrument-function RET locate-dominating-file RET
and look atM-x elp-resullts
to see how much time is spent inside it. – Stefan May 14 '18 at 16:21 -
Is it possible that the "(defvar locate-dominating-stop-dir-regexp ...)" in files.el is not really overridden by my "(custom-set-variables(locate-dominating-stop-dir-regexp (purecopy( "\`/uufs/chpc.utah.edu/common/home/camp-group1/"\'")) Ctrl-Hv certainly shows my custom value. And this test work (returns 0).(setq tfile "/uufs/chpc.utah.edu/common/home/camp-group1/") (string-match locate-dominating-stop-dir-regexp tfile) and nil with any other value for tfile – rjs May 14 '18 at 16:57
-
trace-function shows: 1 -> locate-dominating-file: file="/uufs/chpc.utah.edu/common/home/camp-group1/bin/segmentViewGT.awk" name=".dir-locals.el" 1 <- locate-dominating-file: nil repeated for .hg, .svn, git et al – rjs May 15 '18 at 23:17
-
elp-instrument-function shows: function=locate-dominating-file calls=7 total-time=20.386204558 avg-time=2.9123149368 which is what I'm seeing (time-wise) using strace. I get there by C-x C-f on a file on the camp-group1 partition. Emacs tools don't report for each dir assessed in locate-dominating-file as strace does. Only the test of home (one up from camp-group1) >95% of the delay – rjs May 15 '18 at 23:28
-
I have managed to step through the workings of locate-dominating-file. I supplied a custom stop regex and that was used but only the first time through. The second time through (testing for a subsequent dominating file) the built-in value for the stop regex was used. Is this an emacs bug in custom-set-variables. I added my stop regex to that list manually. – rjs May 16 '18 at 00:47
-
So "defvar" is largely immutable. I can only see rebuilding files.el with "defcustom locate-dominating-stop-dir-regexp" (or maybe defvar with nil default) as way to getting a site specific stop regex. – rjs May 18 '18 at 04:42
-
defvar
is definitely not immutable. Something confuses you, but this is not a good place to track it down. Better do it in a discussion forum (e.g. gnu.emacs.help). – Stefan May 18 '18 at 05:25 -
1For completeness, I submitted a bug against "vc-ignore-dir-regexp" which resets the default value of locate-dominating-file-regexp, over-writing what ever one assigns. – rjs Sep 10 '18 at 20:17
-
@rjs: just a nitpick:
vc-ignore-dir-regexp
does not reset the value, it only temporarily overrides it. – Stefan Sep 11 '18 at 00:12 -
not temporarily enough ;). IIRC It overrides any current value with the default value, then uses that default (plus what it wants to look for) and that lands me in trouble. I also feel the default is a bit outdated? – rjs Sep 12 '18 at 16:22
-
FWIW
"\\
/uufs/chpc.utah.edu/common/home/camp-group1/"\'"should be
"\`/uufs/chpc.utah.edu/common/home/camp-group1/"\'"(although I think stackexchange was responsible for the first of those differences, and I suspect that
"` near the end isn't supposed to be there at all, and may have just been a typo in the comment). – phils Oct 08 '18 at 22:48
find-file
? – Drew May 11 '18 at 17:54