Preserve swap files after crash

Before terminating gracefully, send a TerminateNowMsgID to every Vim process so
that they can determine whether MacVim quit or crashed.  If MacVim quits, call
getout() to exit Vim (this removes swap files), otherwise call
getout_preserve_modified() (this preserves swap files).
This commit is contained in:
Bjorn Winckler
2007-11-15 22:04:06 +01:00
parent 5ba1fac486
commit 8df6521434
6 changed files with 25 additions and 6 deletions
+10 -1
View File
@@ -198,7 +198,7 @@ static NSTimeInterval MMReplyTimeout = 5;
// 'documentEdited' flag of the window correspondingly.)
NSEnumerator *e = [[NSApp windows] objectEnumerator];
id window;
while (window = [e nextObject]) {
while ((window = [e nextObject])) {
if ([window isDocumentEdited]) {
modifiedBuffers = YES;
break;
@@ -220,6 +220,15 @@ static NSTimeInterval MMReplyTimeout = 5;
[alert release];
}
// Tell all Vim processes to terminate now (otherwise they'll leave swap
// files behind).
if (NSTerminateNow == reply) {
e = [vimControllers objectEnumerator];
id vc;
while ((vc = [e nextObject]))
[vc sendMessage:TerminateNowMsgID data:nil];
}
return reply;
}
+1
View File
@@ -44,6 +44,7 @@
NSString *alternateServerName;
ATSFontContainerRef fontContainerRef;
NSFont *oldWideFont;
BOOL isTerminating;
}
+ (MMBackend *)sharedInstance;
+10 -4
View File
@@ -1133,6 +1133,8 @@ enum {
[self addInput:string];
[string release];
}
} else if (TerminateNowMsgID == msgid) {
isTerminating = YES;
} else {
// Not keyboard or mouse event, queue it and handle later.
//NSLog(@"Add event %s to input event queue", MessageStrings[msgid]);
@@ -1776,11 +1778,15 @@ enum {
{
// If the main connection to MacVim is lost this means that MacVim was
// either quit (by the user chosing Quit on the MacVim menu), or it has
// crashed. In either case our only option is to quit now.
// TODO: Write backup file?
// crashed. In the former case the flag 'isTerminating' is set and we then
// quit cleanly; in the latter case we make sure the swap files are left
// for recovery.
//NSLog(@"A Vim process lost its connection to MacVim; quitting.");
getout(0);
NSLog(@"%s isTerminating=%d", _cmd, isTerminating);
if (isTerminating)
getout(0);
else
getout_preserve_modified(1);
}
- (void)blinkTimerFired:(NSTimer *)timer
+1
View File
@@ -156,6 +156,7 @@ enum {
BuffersModifiedMsgID,
AddInputMsgID,
SetPreEditPositionMsgID,
TerminateNowMsgID,
};
+1
View File
@@ -69,6 +69,7 @@ char *MessageStrings[] =
"BuffersModifiedMsgID",
"AddInputMsgID",
"SetPreEditPositionMsgID",
"TerminateNowMsgID",
};
+2 -1
View File
@@ -1226,7 +1226,8 @@ main_loop(cmdwin, noexmode)
}
#if defined(USE_XSMP) || defined(FEAT_GUI_MSWIN) || defined(PROTO)
#if defined(USE_XSMP) || defined(FEAT_GUI_MSWIN) || defined(PROTO) \
|| defined(FEAT_GUI_MACVIM)
/*
* Exit, but leave behind swap files for modified buffers.
*/