ChatGPT解决这个技术问题 Extra ChatGPT

Why does emacs create temporary symbolic links for modified files?

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)
thank you lots and lots for your update! I’ll see if I can change that, because it interferes badly with the buildsystem of a project I’m working on.
The reason I had to disable lockfiles (now cleanly, with the create-lockfiles variable - thanks Emacs devs!) is that in the case of files on a Samba/CIFS share, they stick around :-( After a few editing sessions, the directories are completely cluttered with them, and because they are implemented as intentionally dangling symlinks, my filesystem lint tool reports them. Why? Mount options: rw,relatime,vers=1.0,cache=strict,domain=,uid=0,noforceuid,gid=0,noforcegid,addr=10.8.78.1,soft,unix,posixpaths,serverino,mapposix,acl,rsize=1048576,wsize=65536,echo_interval=60,actimeo=1
The second (last) number is apparently a timestamp.

B
Brandon Rhodes

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… :) )


Is there a way to retain this functionality by creating the symlink elsewhere?
J
Juancho

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.


Can you comment on whether this feature is at all useful on single-user systems? (I don't mean DOS and pre-WinNT; I mean systems with de facto single user)
@ErikAllik: Most files can only be edited by the file's owner, so single-user system or not makes very little difference. This locking system is to help you avoid shooting your own foot, e.g. when you have two Emacs instances that want to modify this file at the same time.
I wonder why it uses a symbolic link, and not just a regular lock file? Is it just to have extra information in the target?

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now