Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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
@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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .