diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-03-03 13:56:24 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-03-03 13:56:24 +0000 |
commit | 1fc34225acbee5ddca2b9ec3f82b3014d385b7f8 (patch) | |
tree | fb70c61fa811d9acbbddfc40fed5d54d79208df7 | |
parent | 35d8c2010ea6ee5c9bcfa6a8285648172b92ed83 (diff) | |
download | vim-git-1fc34225acbee5ddca2b9ec3f82b3014d385b7f8.tar.gz |
patch 8.2.4498: using <Plug> with "noremap" does not workv8.2.4498
Problem: Using <Plug> with "noremap" does not work.
Solution: Always remap <Plug>. (closes #9879, closes #9789)
-rw-r--r-- | runtime/doc/map.txt | 2 | ||||
-rw-r--r-- | src/getchar.c | 11 | ||||
-rw-r--r-- | src/testdir/test_mapping.vim | 30 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 43 insertions, 2 deletions
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index 61e312702..877be5809 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -80,6 +80,8 @@ modes. where the map command applies. Disallow mapping of {rhs}, to avoid nested and recursive mappings. Often used to redefine a command. + Note: When <Plug> appears in the {rhs} this part is + always applied even if remapping is disallowed. :unm[ap] {lhs} |mapmode-nvo| *:unm* *:unmap* diff --git a/src/getchar.c b/src/getchar.c index fcc9b9ac4..9939bbdbc 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -2424,6 +2424,13 @@ handle_mapping( int keylen = *keylenp; int i; int local_State = get_real_state(); + int is_plug_map = FALSE; + + // If typehead starts with <Plug> then remap, even for a "noremap" mapping. + if (typebuf.tb_buf[typebuf.tb_off] == K_SPECIAL + && typebuf.tb_buf[typebuf.tb_off + 1] == KS_EXTRA + && typebuf.tb_buf[typebuf.tb_off + 2] == KE_PLUG) + is_plug_map = TRUE; /* * Check for a mappable key sequence. @@ -2441,7 +2448,7 @@ handle_mapping( tb_c1 = typebuf.tb_buf[typebuf.tb_off]; if (no_mapping == 0 && is_maphash_valid() && (no_zero_mapping == 0 || tb_c1 != '0') - && (typebuf.tb_maplen == 0 + && (typebuf.tb_maplen == 0 || is_plug_map || (p_remap && (typebuf.tb_noremap[typebuf.tb_off] & (RM_NONE|RM_ABBR)) == 0)) @@ -2562,7 +2569,7 @@ handle_mapping( for (n = mlen; --n >= 0; ) if (*s++ & (RM_NONE|RM_ABBR)) break; - if (n >= 0) + if (!is_plug_map && n >= 0) continue; if (keylen > typebuf.tb_len) diff --git a/src/testdir/test_mapping.vim b/src/testdir/test_mapping.vim index 35db43637..6421058b0 100644 --- a/src/testdir/test_mapping.vim +++ b/src/testdir/test_mapping.vim @@ -1536,4 +1536,34 @@ func Test_abbreviate_latin1_encoding() set encoding=utf-8 endfunc +" Test for <Plug> always being mapped, even when used with "noremap". +func Test_plug_remap() + let g:foo = 0 + nnoremap <Plug>(Increase_x) <Cmd>let g:foo += 1<CR> + nmap <F2> <Plug>(Increase_x) + nnoremap <F3> <Plug>(Increase_x) + call feedkeys("\<F2>", 'xt') + call assert_equal(1, g:foo) + call feedkeys("\<F3>", 'xt') + call assert_equal(2, g:foo) + nnoremap x <Nop> + nmap <F4> x<Plug>(Increase_x)x + nnoremap <F5> x<Plug>(Increase_x)x + call setline(1, 'Some text') + normal! gg$ + call feedkeys("\<F4>", 'xt') + call assert_equal(3, g:foo) + call assert_equal('Some text', getline(1)) + call feedkeys("\<F5>", 'xt') + call assert_equal(4, g:foo) + call assert_equal('Some te', getline(1)) + nunmap <Plug>(Increase_x) + nunmap <F2> + nunmap <F3> + nunmap <F4> + nunmap <F5> + unlet g:foo + %bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 73b6af745..6131427f8 100644 --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4498, +/**/ 4497, /**/ 4496, |