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

旧城冷巷雨未停 提交于 2019-12-06 04:01:11

问题


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?


回答1:


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




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/23317002/how-to-create-temporary-files-filename-in-tmp-not-working-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!