7

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?

Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87
lawlist
  • 13,099
  • 3
  • 49
  • 158

3 Answers3

7

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

Community
  • 1
  • 1
lawlist
  • 13,099
  • 3
  • 49
  • 158
0

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
linuxhackerman
  • 300
  • 2
  • 8
-1

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.

Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87
  • 1
    This setting doesn't seem to have any affect on a fairly recent version of Emacs Trunk built `--with-ns`. The information about this particular file `.#filename` is that it is an `alias` -- information is visible in Finder.app. Is it possible that this is an OSX system specific animal? I also have the following settings: `(setq backup-inhibited t)`; `(setq auto-save-default nil)`; `(setq savehist-autosave-interval nil)`; `(savehist-mode -1)`. – lawlist Apr 26 '14 at 22:45
  • Mmm... but now I don't understand. You have backup inhibited, so you shouldn't be seeing any backup file at all. There must be some problem in either your configuration or in how Emacs reads your configure files. Having `backup-inhibited` to non nil will never create backup files. – Diego Sevilla Apr 26 '14 at 23:19
  • 1
    Ahh, sorry, my fault. I confused backup files with auto-save files. I'm changing my response. – Diego Sevilla Apr 26 '14 at 23:28
  • Thanks for looking into this issue -- I got semi-luck and at least found a description of what it is: `# Lock files used by the Emacs editor.` The auto-save files use a `~` I think. In my case, I have the `.#` going on. https://github.com/core-plot/core-plot/blob/master/.gitignore#L7 Instead of using a Git ignore, can we tell Emacs to put that lock file in the `/tmp` directory? – lawlist Apr 26 '14 at 23:51