Why does emacs create temporary symbolic links for modified files?

Emacs

Emacs Problem Overview


When I modify a buffer, Emacs automatically creates a temporary symlink in the same directory as the file being edited (e.g. foo.c):

.#foo.c -> user@host.12345:1296583136

where '12345' is Emacs' PID (I don't know what the last number means).

Why does Emacs create these links, and how do I prevent it from doing that?

Note that I have turned off auto save mode (M-x auto-save-mode) and disabled backup files (M-x set-variable -> make-backup-files -> nil). When I save a modified buffer, or undo the changes to it, the symlink disappears.

In particular, I'm trying to prevent Emacs from creating these links because they cause the directory timestamp to be modified, which causes our build system to rebuild an entire module instead of compiling and linking for one changed file :/

Thanks for any input!


Update: In order to prevent Emacs from creating interlocking files permanently, you can change src/filelock.c and build a custom binary:

void
lock_file (fn)
     Lisp_Object fn;
{
     return;
     // Unused code below...
}

Update 2: Arne's answer is correct. It's now possible to disable lock files in the latest Emacs (24.3.1), by adding this to your .emacs file:

(setq create-lockfiles nil)

Emacs Solutions


Solution 1 - Emacs

Update: Emacs 24.3 has been released with full support for this new setting!

In the current trunk of emacs, you can simply customize the variable create-lockfiles:

C-h v create-lockfiles

Documentation: Non-nil means use lockfiles to avoid editing collisions.

In your init file, you can set

(setq create-lockfiles nil)

Get it via

bzr branch bzr://bzr.savannah.gnu.org/emacs/trunk emacs-trunk
make
src/emacs

(I found out about this, because I decided to get active and just add an option like that myself… :) )

Solution 2 - Emacs

The symbolic link is emacs' file interlocking system: the symbolic link indicates that an instance of emacs is editing this file. If another instance tries to edit the same file, emacs will issue a warning. See http://www.gnu.org/software/emacs/manual/html_node/emacs/Interlocking.html

This has nothing to do with auto-save.

I cannot find how to modify or disable file locking from within emacs.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaniel SchulerView Question on Stackoverflow
Solution 1 - EmacsArne BabenhauserheideView Answer on Stackoverflow
Solution 2 - EmacsJuanchoView Answer on Stackoverflow