mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-07 15:37:14 +02:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
NSString *alternateServerName;
|
||||
ATSFontContainerRef fontContainerRef;
|
||||
NSFont *oldWideFont;
|
||||
BOOL isTerminating;
|
||||
}
|
||||
|
||||
+ (MMBackend *)sharedInstance;
|
||||
|
||||
+10
-4
@@ -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
|
||||
|
||||
@@ -156,6 +156,7 @@ enum {
|
||||
BuffersModifiedMsgID,
|
||||
AddInputMsgID,
|
||||
SetPreEditPositionMsgID,
|
||||
TerminateNowMsgID,
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ char *MessageStrings[] =
|
||||
"BuffersModifiedMsgID",
|
||||
"AddInputMsgID",
|
||||
"SetPreEditPositionMsgID",
|
||||
"TerminateNowMsgID",
|
||||
};
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user