views:

128

answers:

6

Many editors will notice when a file changes out from under them. Are there any editor that will offer to let you do a three-way merge if you have unsaved edits on the file?

The common scenario for this is I forget to save a file before I so an SVN update and when I switch back to my editor realize that I now have the choice of stomping on the update I just did, discarding my changes, or doing the copy/paste/external-diff-tool song and dance.

Yes I know the correct solution is ctrl+s before I update but I'm human and want a really easy solution to fix the problem after I muck it up.

A: 

This seems like a problem for source-control, not an editor.

Certainly Emacs could be programmed to do that, but by default it seems to merely ask if you want to save over the changed file or not. Attempting to edit a file that has been changes will give you the option to revert the buffer to the content of the file.

Vi (at least the version I'm using) does not even check to see if the file has changed. (Nor does it check if the file is read-only before I edit it, which drives me nuts. Maybe I need to find a better vi.)

Jon Ericson
+1  A: 

With vim you can enter the diff mode using :DiffOrig.
The check for a modification can be forced with :checkt

To automate it, you could put the following to your .vimrc:

au FileChangedShell * DiffOrig

Vim will then go into the diff split as soon as it realizes that the file (mtime) changed.

bene
+1  A: 

Sounds like a bad way to solve the problem of files being modified under your feet. As I usually respond: what problem are you really trying to solve?

JesperE
Good (follow-up) question. I wonder if the real answer is to use some sort of source control?
Jon Ericson
The problem is exactly as I asked to start with, OTOH it only comes up between "Oops" and "what now?"
BCS
The question was edited after my answer...
JesperE
Oddly the problem most often is a result of forgetting a step or two while using source control. (See edit)
BCS
@JesperE: Sorry, I forgot to leave that bit in my comment
BCS
+1  A: 

I very seldom encounter this, probably because I save as soon as my fingers aren't doing anything, without really having to think about it.

Otherwise, I'd suggest that you find a SVN-client integrated into your editor. Most such clients will automatically (or ask) save before doing a commit or update.

JesperE
+2  A: 

EditPad Pro, when it detects a file that you have open with unsaved changes has changed on disk, will ask you if you want to reload the file from disk, ignore the change on disk, or see the difference between the file on disk and the version with unsaved changes that you have open.

That is a two-way diff rather than the three-way diff you asked. I don't know any text editor that will offer to do a three-way diff. If the file on disk has been clobbered, a text editor no longer has a copy of the original. That would be something for version control to solve.

A preventive measure could be to have your editor keep a lock on files that you have open. Then the SVN update will fail on any files you have open in your editor. In EditPad Pro, there's an option for that in Options, Preferences, Files.

Jan Goyvaerts
The editor could keep a copy of the last loaded file (as part of the undo buffer?). Re: locking, I have never liked locking solutions :(
BCS
Keeping a copy of the original file would instantly double the memory used by the file when you make the first change. EditPad Pro doesn't have an option for that.
Jan Goyvaerts
+1  A: 

So you have unsaved changes on a file and then you do an SVN update of that file, right?

In that case you should just save the changes after the update and run SVN update again. The second run of SVN update will try to merge the changes from the repository and tell you if there are conflicts.

The more/most important changes are the unsaved changes in your editor, the changes from the SVN update can always be pulled again from the repository.

Otherside
To make that work the file would have to be reverted first or an SVN merge would have to be applied. Aside from that... +1
BCS
You are probably right that the file would need to be reverted, or otherwise the update will probably not pull in the changes again. But if you just save and then compare against the repo version, you can manually merge in the necessary changes.
Otherside