When two users edit the same file at the same time, they are likely to interfere with each other. SXEmacs tries to prevent this situation from arising by recording a file lock when a file is being modified. SXEmacs can then detect the first attempt to modify a buffer visiting a file that is locked by another SXEmacs process, and ask the user what to do.
File locks do not work properly when multiple machines can share file systems, such as with NFS or AFS. Perhaps a better file locking system will be implemented in the future. When file locks do not work, it is possible for two users to make changes simultaneously, but SXEmacs can still warn the user who saves second. Also, the detection of modification of a buffer visiting a file changed on disk catches some cases of simultaneous editing; see Modification Time.
This function returns
nilif the file filename is not locked by this SXEmacs process. It returnstif it is locked by this SXEmacs, and it returns the name of the user who has locked it if it is locked by someone else.(file-locked-p "foo") ⇒ nil
This function locks the file filename, if the current buffer is modified. The argument filename defaults to the current buffer's visited file. Nothing is done if the current buffer is not visiting a file, or is not modified.
This function unlocks the file being visited in the current buffer, if the buffer is modified. If the buffer is not modified, then the file should not be locked, so this function does nothing. It also does nothing if the current buffer is not visiting a file.
This function is called when the user tries to modify filename, but it is locked by another user named other-user. The value it returns determines what happens next:
- A value of
tsays to grab the lock on the file. Then this user may edit the file and other-user loses the lock.- A value of
nilsays to ignore the lock and let this user edit the file anyway.- This function may instead signal a
file-lockederror, in which case the change that the user was about to make does not take place.The error message for this error looks like this:
error--> File is locked: filename other-userwhere filename is the name of the file and other-user is the name of the user who has locked the file.
The default definition of this function asks the user to choose what to do. If you wish, you can replace the
ask-user-about-lockfunction with your own version that decides in another way. The code for its usual definition is in userlock.el.