From 316034e1db4e3497e088d6ee3369fb6ee02d5af3 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Fri, 22 Aug 2008 01:53:24 +0200 Subject: [PATCH] Now works to use :maca on VimLeave auto command To fix this the output queue is flushed before exiting a Vim process. Also, the CloseWindowMsgID is added to the "unsafe" list so that other unsafe messages (such as ExecuteActionMsgID) are not delayed until after CloseWindowMsgID. --- src/MacVim/MMBackend.m | 8 ++++---- src/MacVim/MMVimController.m | 27 ++++++++++++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 02b02dcebc..7c3f90395e 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -589,10 +589,10 @@ static NSString *MMSymlinkWarningString = if ([connection isValid]) { @try { - int msgid = CloseWindowMsgID; - NSData *data = [NSData dataWithBytes:&msgid length:sizeof(int)]; - NSArray *q = [NSArray arrayWithObjects:data, [NSData data], nil]; - [frontendProxy processCommandQueue:q]; + // Flush the entire queue in case a VimLeave autocommand added + // something to the queue. + [self queueMessage:CloseWindowMsgID data:nil]; + [frontendProxy processCommandQueue:outputQueue]; } @catch (NSException *e) { NSLog(@"Exception caught when sending CloseWindowMsgID: \"%@\"", e); diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 08f69fd721..c778a517a2 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -1457,17 +1457,26 @@ isUnsafeMessage(int msgid) // example, UpdateTabBarMsgID may delete NSTabViewItem objects so it goes // on this list. static int unsafeMessages[] = { // REASON MESSAGE IS ON THIS LIST: - //OpenWindowMsgID, // Changes lots of state - UpdateTabBarMsgID, // May delete NSTabViewItem - RemoveMenuItemMsgID, // Deletes NSMenuItem - DestroyScrollbarMsgID, // Deletes NSScroller - ExecuteActionMsgID, // Impossible to predict - ShowPopupMenuMsgID, // Enters modal loop - ActivateMsgID, // ? - EnterFullscreenMsgID, // Modifies delegate of window controller - LeaveFullscreenMsgID, // Modifies delegate of window controller + //OpenWindowMsgID, // Changes lots of state + UpdateTabBarMsgID, // May delete NSTabViewItem + RemoveMenuItemMsgID, // Deletes NSMenuItem + DestroyScrollbarMsgID, // Deletes NSScroller + ExecuteActionMsgID, // Impossible to predict + ShowPopupMenuMsgID, // Enters modal loop + ActivateMsgID, // ? + EnterFullscreenMsgID, // Modifies delegate of window controller + LeaveFullscreenMsgID, // Modifies delegate of window controller + CloseWindowMsgID, // See note below }; + // NOTE about CloseWindowMsgID: If this arrives at the same time as say + // ExecuteActionMsgID, then the "execute" message will be lost due to it + // being queued and handled after the "close" message has caused the + // controller to cleanup...UNLESS we add CloseWindowMsgID to the list of + // unsafe messages. This is the _only_ reason it is on this list (since + // all that happens in response to it is that we schedule another message + // for later handling). + int i, count = sizeof(unsafeMessages)/sizeof(unsafeMessages[0]); for (i = 0; i < count; ++i) if (msgid == unsafeMessages[i])