Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Emacs has elaborate protection against simultaneous editing by two different users. If there a way to have that same facility for protecting against simultaneous editing by the same user?

With lots of windows and workspaces open, it's easy to reopen a file that you already have open somewhere else. But because it does not detect a lock conflict when you open the file, you will only learn about the collision when you save.

share|improve this question
    
Are you editing the file in two different copies of emacs? –  ijw Jan 5 '11 at 12:26
    
Yes, on two different consoles. –  Peter Eisentraut Jan 5 '11 at 12:47
    
I want basically the same behavior as vi with its swap files. –  Peter Eisentraut Jan 5 '11 at 13:10
add comment

1 Answer

If you edit a file you are visiting with another editor, GNU Emacs will warn you. If a programme updates a file that you are visiting, GNU Emacs will warn you.

If you revisit a file that is already in one of your buffers, then GNU Emacs will simply go to that buffer.

Practical examples;

  • If you visit a file in GNU Emacs, and then edit and save that same file in nano, as soon as you try to edit in the Emacs buffer again (not just when you save), you will get a warning that the file has changed on disk and some options.

  • If you visit a file and then, say, open a few more buffers and do other stuff (the usual thing), and then revisit that file later (eg. with C-x C-f or by hitting "enter" in dired) then GNU Emacs will not open a new buffer but will simply go back to the previous buffer you already have with that file.

Note: I'm using GNU Emacs 22 in gNewSense GNU/Linux

share|improve this answer
    
As mentioned in the question, I want to know about the conflict when I open the file, not when I save it. –  Peter Eisentraut Jan 5 '11 at 11:35
1  
@PeterEisentraut If both Emacs are just viewing the file, there's no need. As soon as they modify the file, Emacs will warn (before saving, just modifying will trigger the warning). –  Trey Jackson Jan 5 '11 at 17:44
    
@PeterEisentraut: I've confirmed Trey Jackson's answer - as soon as you try to edit the buffer, Emacs will prompt: some_text_file.txt changed on disk; really edit the buffer? (y, n, r or C-h). –  Charles Jan 31 '11 at 16:35
    
@Charles: I know that, but that is not the question. –  Peter Eisentraut Feb 1 '11 at 6:00
    
Your question says "simultaneous editing. –  Vivi Jun 6 '11 at 21:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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