restrict .dir-locals.el searching walk through subdirectories - emacs

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.

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.

Related

Total Commander external editor emacs "permission denied" on editing files

I configured my Total Commander so I can open a file *.txt i.e. within emacs.
Therefore I setup my Editor
D:\Tools\emacs\bin\emacsclientw.exe "%1"
When I now open my file everything is ok. But when I edit it and save it emacs tells me the following:
Saving file c:/log.txt...
basic-save-buffer-2: Opening output file: permission denied, c:/log.txt
How do I make it run so it can actually edit files?
By Default you should not be saving anything to root C:\
It is just bad practice and by default a normal user does not have permission to it.
Instead, create a working DIR in your Documents folder and a log directory in that, then you will have something like:
C:\Users\Frank\Documents\Working\logs\log.txt
This should not create any permission errrors.

how to use backup files to create regular files in emacs

I am trying to create a file named caseexp.sml . Emacs created a backup file of this file when I was working on it at some earlier point, and now when I try to open it as caseexp.sml, emacs opens a #caseexp.sml# file and everytime I try to save it using C-x C-w, emacs saves it as another backup file with another tilde added to its name. Several attempts later, I have only managed to save it as #caseexp.sml"~~~.
How can I avoid creating these "tilde" backup files and save my file simply as caseexp.sml ?
There are a few unexpected behaviors here, so I can't be sure that this is what's going on, but usually what happens is that if files with hashes are left around, it's possible that Emacs crashed while you had unsaved changes. However, usually Emacs should prompt you to run "M-x recover-this-file" to restore changes from the unsaved-changes file (the filename with the hashes) to the actual file, so it's not clear what's going on there. Try fixing this from the command line.
You probably want to cp all the files to another location first, in order to have a backup (I'm assuming a Unix-like OS):
$ cp *caseexp* /tmp
Then delete the extra files while preserving the one with the most recent changes:
$ cp <most recent file with latest changes> caseexp.sml
$ rm \#caseexp*

How to create temporary files `.#filename` in `/tmp`, not working directory

When files are being modified in Emacs, a temporary file is created in the working directory that looks like this: .#filename. The file is deleted when the buffer is saved.
I found a few of these types of temporary files in my Git remote repositories, and I thought it might be better to nip the bud at the source instead of configuring Git to ignore them for every project.
How can we configure Emacs to create those files in the /tmp directory instead of the working directory?
The file at issue is called a lock file -- commencing with Emacs version 24.3, it can be controlled with the following setting:
(setq create-lockfiles nil)
https://stackoverflow.com/a/12974060/2112489
These files are auto-save files. The variable auto-save-file-name-transforms controls what modifications to make to the buffer's file name to generate the auto save file name. Usually, the default in file.el will suffice to put all the auto save files in the /tmp directory. It's default value is:
(("\\`/[^/]*:\\([^/]*/\\)*\\([^/]*\\)\\'" "/tmp/\\2" t))
That /tmp comes by reading the variable temporary-file-directory. Check that value so that it points to /tmp. Then, the value constructed for auto-save-file-name-transforms (and hence for the auto save file name) will be correct.
As a more general solution, you could also make a global exclude file, which applies to all repositories locally. By default, this will be in $XDG_CONFIG_HOME/git/ignore (usually ~/.config/git/ignore). The path can be overridden using the core.excludesFile option. See the gitignore manpage for more details.
$ mkdir -p ~/.config/git
$ echo '.#*' >> ~/.config/git/ignore

info files in subdirectory is not recognized in emacs

I installed an additional info file using
install-info /usr/share/info/asymptote/asymptote.info.gz /usr/share/info/dir
it is perfectly visible by info command from the command line, i.e. info asymptote return content of asymptote/asymptote.info.gz properly. Also it is visible by emacs in the top node when I use M-x info command, but when I try to go to asymptote node, it complains "Info-find-file: Info file asymptote does not exist". The problem looks similar to info indexing (within and without emacs) although it is not quite the same. It seems that info command in emacs does not recognize the subdirectory, while the original info command does. Is it possible to force emacs behave in the same way?
My understanding is that the main directory listing for M-x info is built from dir files found under directories in the Info-directory-list variable, and that same variable is used when searching for a named info file; so this is slightly odd.
You should verify that Info-suffix-list contains an entry for .info.gz, but that should be pretty standard, so my best guess is that the dir entry added by install-info is not quite correct (or not supported, at any rate).
Could you show us what the entry for asymptote looks like in /usr/share/info/dir?

Trying to run ftpsync.pl from post-commit hook

As the title says, I'm trying to ftpsync changed tree to our dev web server. On committing I get this error:
post-commit hook failed (exit code 13)
with output: Cannot create syncfile
for time sync option at
/data/ftpsync/ftpsync.pl line 484.
I've tried looking at line 484 but Perl looks like a foreign language to me :)
What permissions do I need to set and where so that syncfile can be created?
It creates the file in the current directory, and as far as I can tell doesn't change directories before that point. The easiest thing to do would be to change directories to /tmp before starting the script (and specify a local directory in its args instead of using the default .).