Emacs 26

I have a file rest.api.rc. When I start editing it, the following lock file is automatically created:


After saving file rest.api.rc, the lock file .#rest.api.rc is gone.

How I can prevent generating the lock file .#rest.api.rc?


How I can prevent generating the lock file .#rest.api.rc?

Set the user option create-lockfiles to nil, but note that this can stop Emacs from being able to detect simultaneous edits to the same file.

C-hvcreate-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 (info-emacs-manual)
  • i (Info-index)
  • .#TAB (completes to .#, lock file names)
  • RET

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
unsaved changes.

   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.

Quoth also (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.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.