How I can prevent generating the lock file
Set the user option
nil, but note that this can stop Emacs from being able to detect simultaneous edits to the same file.
create-lockfilesRET says the following:
create-lockfiles is a variable defined in `src/filelock.c'.
Its value is t
This variable is safe as a file local variable if its value
satisfies the predicate `booleanp'.
You can customize this variable.
This variable was introduced, or its default value was changed, in
version 24.3 of Emacs.
Probably introduced at or before Emacs version 24.3.
Non-nil means use lockfiles to avoid editing collisions.
The name of the (per-buffer) lockfile is constructed by prepending a
'.#' to the name of the file being locked. See also `lock-buffer' and
Info node `(emacs)Interlocking'.
Here's how I found out:
- C-hr (
- i (
.#TAB (completes to
.#, lock file names)
This takes you to
(emacs) Interlocking, which has the following to say:
Simultaneous editing occurs when two users visit the same file, both
make changes, and then both save them. If nobody is informed that this
is happening, whichever user saves first would later find that their
changes were lost.
On some systems, Emacs notices immediately when the second user
starts to change the file, and issues an immediate warning. On all
systems, Emacs checks when you save the file, and warns if you are about
to overwrite another user’s changes. You can prevent loss of the other
user’s work by taking the proper corrective action instead of saving the
When you make the first modification in an Emacs buffer that is
visiting a file, Emacs records that the file is “locked” by you. (It
does this by creating a specially-named symbolic link(1) with special
contents in the same directory. See '(elisp)File Locks', for more
details.) Emacs removes the lock when you save the changes. The idea
is that the file is locked whenever an Emacs buffer visiting it has
You can prevent the creation of lock files by setting the variable
‘create-lockfiles’ to ‘nil’. *Caution:* by doing so you will lose the
benefits that this feature provides.
(elisp) File Locks:
When two users edit the same file at the same time, they are likely to
interfere with each other. Emacs tries to prevent this situation from
arising by recording a “file lock” when a file is being modified. Emacs
can then detect the first attempt to modify a buffer visiting a file
that is locked by another Emacs job, and ask the user what to do. The
file lock is really a file, a symbolic link with a special name, stored
in the same directory as the file you are editing. The name is
constructed by prepending ‘.#’ to the filename of the buffer.