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

StackOverflow https://stackoverflow.com/questions/23317002

  •  10-07-2023
  •  | 
  •  

문제

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

다른 팁

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

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top