Hi Bram!

On So, 14 Dez 2014, Bram Moolenaar wrote:

> 
> Christian Brabandt wrote:
> 
> > On Fr, 12 Dez 2014, Ingo Karkat wrote:
> > 
> > > Hello Vim developers,
> > > 
> > > patch 7.4.468 (BTW it doesn't appear in the list on
> > > ftp://ftp.vim.org/vol/2/vim/patches/7.4/README) addressed
> > > 
> > > > Issue 26: CTRL-C does not interrupt after it was mapped and then 
> > > > unmapped
> > > 
> > > However, it apparently fails to consider the mapping _modes_ of
> > > CTRL-C, so when I have such insert mode mapping, then do :cmap <C-c>
> > > ... | cunmap <C-c>, the insert mode mapping (though it still is listed
> > > by :imap) becomes ineffective! (Same for other mode combinations.) I
> > > have various mappings that include the <C-c> key (have I mentioned I'm
> > > running out of keys?), and all of these get broken because one of my
> > > plugins temporarily sets up a :cmap <C-c>.
> > > 
> > > 
> > > I've used the following scriptlet to bisect the problem:
> > > 
> > > nnoremap <C-c> :quit!<CR>
> > > nnoremap <C-x> :cquit!<CR>
> > > cnoremap <C-c> dummy
> > > cunmap <C-c>
> > > echomsg "Press <C-c><C-x> now"
> > > 
> > > Interestingly, it requires actual typed keys, even :call
> > > feedkeys("\<C-c>", 't') doesn't work.
> > > 
> > > I can reproduce this both on Windows/x64 and Linux/x64, up to the
> > > current Vim 7.4.542.
> > > 
> > > Christian (as the author of the original patch), I hope you'll be able
> > > to get a fix for that!
> > 
> > The fix is easy. Simply increment the mapped_ctrl_c flag when mapping 
> > CTRL-C and decrement it when unmapping. Then Ctrl-C will work as 
> > interrupt only, when ctrl-c is never mapped.
> 
> Looks like this patch does not handle the sequence:
> 
>       :map <C-C> a
>       :map <C-C> b
>       :unmap <C-C>
> 
> I would suggest getting the state flags for the mapping and using "OR"
> when mapping and "AND with inverted" when unmapping.  Then when the
> result is zero we know CTRL-C is not mapped.
> 
> As mentioned further on in the thread, ideally we would use the mask
> also for handling CTRL-C differently depending on the current mode.
> Not sure how easy or difficult that would be.

Okay, how about that patch?

Best,
Christian
-- 
Anmut ist ein Ausströmen der inneren Harmonie.
                -- Marie von Ebner-Eschenbach

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/getchar.c b/src/getchar.c
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -3709,7 +3709,7 @@ do_map(maptype, arg, mode, abbrev)
 	    retval = 2;			    /* no match */
 	else if (*keys == Ctrl_C)
 	    /* If CTRL-C has been unmapped, reuse it for Interrupting. */
-	    mapped_ctrl_c = FALSE;
+	    mapped_ctrl_c &= ~mode;
 	goto theend;
     }
 
@@ -3744,7 +3744,12 @@ do_map(maptype, arg, mode, abbrev)
 
     /* If CTRL-C has been mapped, don't always use it for Interrupting. */
     if (*keys == Ctrl_C)
-	mapped_ctrl_c = TRUE;
+    {
+	if (map_table == curbuf->b_maphash)
+	    curbuf->b_mapped_ctrl_c |= mode;
+	else
+	    mapped_ctrl_c |= mode;
+    }
 
     mp->m_keys = vim_strsave(keys);
     mp->m_str = vim_strsave(rhs);
diff --git a/src/structs.h b/src/structs.h
--- a/src/structs.h
+++ b/src/structs.h
@@ -1802,6 +1802,7 @@ struct file_buffer
     cryptstate_T *b_cryptstate;	/* Encryption state while reading or writing
 				 * the file. NULL when not using encryption. */
 #endif
+    int		b_mapped_ctrl_c; /* needed to check, whether ctrl_c is mapped for that buffer */
 
 }; /* file_buffer */
 
diff --git a/src/testdir/test_mapping.in b/src/testdir/test_mapping.in
--- a/src/testdir/test_mapping.in
+++ b/src/testdir/test_mapping.in
@@ -8,6 +8,15 @@ STARTTEST
 :inoreab чкпр   vim
 GAчкпр 
 
+:" mapping of ctrl-c in insert mode
+:set cpo-=< cpo-=k
+:inoremap <c-c> <ctrl-c>
+:cnoremap <c-c> dummy
+:cunmap <c-c>
+GA
+TEST2: CTRL-C |A|
+
+:nunmap <c-c>
 
 : " langmap should not get remapped in insert mode
 :inoremap { FAIL_ilangmap
diff --git a/src/testdir/test_mapping.ok b/src/testdir/test_mapping.ok
--- a/src/testdir/test_mapping.ok
+++ b/src/testdir/test_mapping.ok
@@ -1,4 +1,6 @@
 test starts here:
 vim
+TEST2: CTRL-C |<ctrl-c>A|
+
 +
 +
diff --git a/src/ui.c b/src/ui.c
--- a/src/ui.c
+++ b/src/ui.c
@@ -180,7 +180,8 @@ ui_inchar(buf, maxlen, wtime, tb_change_
 
 	/* ... there is no need for CTRL-C to interrupt something, don't let
 	 * it set got_int when it was mapped. */
-	if (mapped_ctrl_c)
+	if (mapped_ctrl_c & State ||
+		curbuf->b_mapped_ctrl_c & State)
 	    ctrl_c_interrupts = FALSE;
     }
 

Raspunde prin e-mail lui