Skip to content

Commit 920694c

Browse files
committed
patch 7.4.2236
Problem: The 'langnoremap' option leads to double negatives. And it does not work for the last character of a mapping. Solution: Add 'langremap' with the opposite value. Keep 'langnoremap' for backwards compatibility. Make it work for the last character of a mapping. Make the test work.
1 parent 989f592 commit 920694c

6 files changed

Lines changed: 84 additions & 21 deletions

File tree

runtime/defaults.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" The default vimrc file.
22
"
33
" Maintainer: Bram Moolenaar <[email protected]>
4-
" Last change: 2016 Aug 20
4+
" Last change: 2016 Aug 21
55
"
66
" This is loaded if no vimrc file was found.
77
" Except when Vim is run with "-u NONE" or "-C".
@@ -107,9 +107,9 @@ if !exists(":DiffOrig")
107107
\ | wincmd p | diffthis
108108
endif
109109

110-
if has('langmap') && exists('+langnoremap')
110+
if has('langmap') && exists('+langremap')
111111
" Prevent that the langmap option applies to characters that result from a
112-
" mapping. If unset (default), this may break plugins (but it's backward
112+
" mapping. If set (default), this may break plugins (but it's backward
113113
" compatible).
114-
set langnoremap
114+
set nolangremap
115115
endif

src/macros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
do { \
136136
if (*p_langmap \
137137
&& (condition) \
138-
&& (!p_lnr || (p_lnr && typebuf_maplen() == 0)) \
138+
&& (p_lrm || (!p_lrm && KeyTyped)) \
139139
&& !KeyStuffed \
140140
&& (c) >= 0) \
141141
{ \
@@ -150,7 +150,7 @@
150150
do { \
151151
if (*p_langmap \
152152
&& (condition) \
153-
&& (!p_lnr || (p_lnr && typebuf_maplen() == 0)) \
153+
&& (p_lrm || (!p_lrm && KeyTyped)) \
154154
&& !KeyStuffed \
155155
&& (c) >= 0 && (c) < 256) \
156156
c = langmap_mapchar[c]; \

src/option.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,13 @@ static struct vimoption options[] =
17031703
(char_u *)&p_lnr, PV_NONE,
17041704
#else
17051705
(char_u *)NULL, PV_NONE,
1706+
#endif
1707+
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
1708+
{"langremap", "lrm", P_BOOL|P_VI_DEF,
1709+
#ifdef FEAT_LANGMAP
1710+
(char_u *)&p_lrm, PV_NONE,
1711+
#else
1712+
(char_u *)NULL, PV_NONE,
17061713
#endif
17071714
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
17081715
{"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
@@ -7894,6 +7901,15 @@ set_bool_option(
78947901
compatible_set();
78957902
}
78967903

7904+
#ifdef FEAT_LANGMAP
7905+
if ((int *)varp == &p_lrm)
7906+
/* 'langremap' -> !'langnoremap' */
7907+
p_lnr = !p_lrm;
7908+
else if ((int *)varp == &p_lnr)
7909+
/* 'langnoremap' -> !'langremap' */
7910+
p_lrm = !p_lnr;
7911+
#endif
7912+
78977913
#ifdef FEAT_PERSISTENT_UNDO
78987914
/* 'undofile' */
78997915
else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)

src/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ EXTERN char_u *p_km; /* 'keymodel' */
604604
#ifdef FEAT_LANGMAP
605605
EXTERN char_u *p_langmap; /* 'langmap'*/
606606
EXTERN int p_lnr; /* 'langnoremap' */
607+
EXTERN int p_lrm; /* 'langremap' */
607608
#endif
608609
#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
609610
EXTERN char_u *p_lm; /* 'langmenu' */

src/testdir/test_mapping.vim

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,73 @@ func Test_map_ctrl_c_visual()
3535
endfunc
3636

3737
func Test_map_langmap()
38-
" langmap should not get remapped in insert mode
39-
inoremap { FAIL_ilangmap
40-
set langmap=+{ langnoremap
38+
if !has('langmap')
39+
return
40+
endif
41+
42+
" check langmap applies in normal mode
43+
set langmap=+- nolangremap
44+
new
45+
call setline(1, ['a', 'b', 'c'])
46+
2
47+
call assert_equal('b', getline('.'))
48+
call feedkeys("+", "xt")
49+
call assert_equal('a', getline('.'))
50+
51+
" check no remapping
52+
map x +
53+
2
54+
call feedkeys("x", "xt")
55+
call assert_equal('c', getline('.'))
56+
57+
" check with remapping
58+
set langremap
59+
2
60+
call feedkeys("x", "xt")
61+
call assert_equal('a', getline('.'))
62+
63+
unmap x
64+
bwipe!
65+
66+
" 'langnoremap' follows 'langremap' and vise versa
67+
set langremap
68+
set langnoremap
69+
call assert_equal(0, &langremap)
70+
set langremap
71+
call assert_equal(0, &langnoremap)
72+
set nolangremap
73+
call assert_equal(1, &langnoremap)
74+
75+
" langmap should not apply in insert mode, 'langremap' doesn't matter
76+
set langmap=+{ nolangremap
4177
call feedkeys("Go+\<Esc>", "xt")
4278
call assert_equal('+', getline('$'))
43-
44-
" Insert-mode expr mapping with langmap
45-
inoremap <expr> { "FAIL_iexplangmap"
79+
set langmap=+{ langremap
4680
call feedkeys("Go+\<Esc>", "xt")
4781
call assert_equal('+', getline('$'))
48-
iunmap <expr> {
4982

50-
" langmap should not get remapped in Command-line mode
51-
cnoremap { FAIL_clangmap
83+
" langmap used for register name in insert mode.
84+
call setreg('a', 'aaaa')
85+
call setreg('b', 'bbbb')
86+
call setreg('c', 'cccc')
87+
set langmap=ab langremap
88+
call feedkeys("Go\<C-R>a\<Esc>", "xt")
89+
call assert_equal('bbbb', getline('$'))
90+
call feedkeys("Go\<C-R>\<C-R>a\<Esc>", "xt")
91+
call assert_equal('bbbb', getline('$'))
92+
" mapping does not apply
93+
imap c a
94+
call feedkeys("Go\<C-R>c\<Esc>", "xt")
95+
call assert_equal('cccc', getline('$'))
96+
imap a c
97+
call feedkeys("Go\<C-R>a\<Esc>", "xt")
98+
call assert_equal('bbbb', getline('$'))
99+
100+
" langmap should not apply in Command-line mode
101+
set langmap=+{ nolangremap
52102
call feedkeys(":call append(line('$'), '+')\<CR>", "xt")
53103
call assert_equal('+', getline('$'))
54-
cunmap {
55104

56-
" Command-line mode expr mapping with langmap
57-
cnoremap <expr> { "FAIL_cexplangmap"
58-
call feedkeys(":call append(line('$'), '+')\<CR>", "xt")
59-
call assert_equal('+', getline('$'))
60-
cunmap {
61105
set nomodified
62106
endfunc
63107

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ static char *(features[]) =
763763

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2236,
766768
/**/
767769
2235,
768770
/**/

0 commit comments

Comments
 (0)