From e706fca4d6e364aa520ca7bab06ca2ef0aa04447 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sat, 10 Jan 2009 17:38:11 +0100 Subject: [PATCH] Cmd-. sends SIGINT Ctrl-C does not always work to interrupt a stuck Vim process. By making Cmd-. send SIGINT it is more likely to succeed where Ctrl-C has failed. (E.g. Ctrl-C may fail if a DO message is dropped, or if the Vim process is stuck in a loop and isn't checking for new input.) --- runtime/doc/gui_mac.txt | 10 ++++++---- src/MacVim/MMBackend.m | 14 +++----------- src/MacVim/MMTextViewHelper.m | 8 ++++++-- src/MacVim/MacVim.h | 1 - src/MacVim/MacVim.m | 1 - src/MacVim/gui_macvim.m | 3 ++- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/runtime/doc/gui_mac.txt b/runtime/doc/gui_mac.txt index d7b3553598..00cf919e5d 100644 --- a/runtime/doc/gui_mac.txt +++ b/runtime/doc/gui_mac.txt @@ -1,4 +1,4 @@ -*gui_mac.txt* For Vim version 7.2. Last change: 2009 Jan 07 +*gui_mac.txt* For Vim version 7.2. Last change: 2009 Jan 08 VIM REFERENCE MANUAL by Bjorn Winckler @@ -563,9 +563,11 @@ discovered by looking through the menus (see |macvim-menus| on how to create your own menu shortcuts). The remaining shortcuts are listed here: *Cmd-.* ** -Cmd-. Interrupt Vim. This is synonymous with CTRL-C and can - hence be used instead of Esc to exit insert mode (in - case you find Esc a bit hard to reach). +Cmd-. Interrupt Vim. Unlike Ctrl-C which is sent as normal + keyboard input (and hence has to be received and then + interpreted) this sends a SIGINT signal to the Vim + process. Use this shortcut if the Vim process appears + to have locked up and is not responding to key presses. *Cmd-`* ** Cmd-` Cycle to the next window. On an American keyboard the diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 44d27ff78d..5316c9ad88 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1037,11 +1037,7 @@ extern GuiFont gui_mch_retain_font(GuiFont font); // which waits on the run loop will fail to detect this message (e.g. in // waitForConnectionAcknowledgement). - BOOL shouldClearQueue = NO; - if (InterruptMsgID == msgid) { - shouldClearQueue = YES; - got_int = TRUE; - } else if (InsertTextMsgID == msgid && data != nil) { + if (InsertTextMsgID == msgid && data != nil) { const void *bytes = [data bytes]; bytes += sizeof(int); int len = *((int*)bytes); bytes += sizeof(int); @@ -1049,8 +1045,9 @@ extern GuiFont gui_mch_retain_font(GuiFont font); char_u *str = (char_u*)bytes; if ((str[0] == Ctrl_C && ctrl_c_interrupts) || (str[0] == intr_char && intr_char != Ctrl_C)) { - shouldClearQueue = YES; got_int = TRUE; + [inputQueue removeAllObjects]; + return; } } } else if (TerminateNowMsgID == msgid) { @@ -1061,11 +1058,6 @@ extern GuiFont gui_mch_retain_font(GuiFont font); return; } - if (shouldClearQueue) { - [inputQueue removeAllObjects]; - return; - } - // Remove all previous instances of this message from the input queue, else // the input queue may fill up as a result of Vim not being able to keep up // with the speed at which new messages are received. diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index 295304665b..8494575017 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -264,10 +264,14 @@ static float MMDragAreaSize = 73.0f; if ([unmodchars isEqual:@"?"]) return NO; - // Cmd-. is hard-wired to send an interrupt (like Ctrl-C). + // Cmd-. is hard-wired to send SIGINT unlike Ctrl-C which is just another + // key press which Vim has to interpret. This means that Cmd-. always + // works to interrupt a Vim process whereas Ctrl-C can suffer from problems + // such as dropped DO messages (or if Vim is stuck in a loop without + // checking for keyboard input). if ((flags & NSDeviceIndependentModifierFlagsMask) == NSCommandKeyMask && [unmodchars isEqual:@"."]) { - [[self vimController] sendMessage:InterruptMsgID data:nil]; + kill([[self vimController] pid], SIGINT); return YES; } diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 88e5e3c0a5..2f52306061 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -174,7 +174,6 @@ enum { SetDocumentFilenameMsgID, OpenWithArgumentsMsgID, CloseWindowMsgID, - InterruptMsgID, SetFullscreenColorMsgID, ShowFindReplaceDialogMsgID, FindReplaceMsgID, diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index dd6d21ea5a..c361be302e 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -81,7 +81,6 @@ char *MessageStrings[] = "SetDocumentFilenameMsgID", "OpenWithArgumentsMsgID", "CloseWindowMsgID", - "InterruptMsgID", "SetFullscreenColorMsgID", "ShowFindReplaceDialogMsgID", "FindReplaceMsgID", diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index cea57bbdd0..25d5ade70a 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -189,7 +189,8 @@ gui_mch_update(void) // interrupt Vim by presssing Ctrl-C during lengthy operations (e.g. after // entering "10gs" it would not be possible to bring Vim out of the 10 s // sleep prematurely). As a compromise we check for Ctrl-C only once per - // second. + // second. Note that Cmd-. sends SIGINT so it has higher success rate at + // interrupting Vim. static CFAbsoluteTime lastTime = 0; CFAbsoluteTime nowTime = CFAbsoluteTimeGetCurrent();