From 8e71a26e1931e8e87e6db6e13b77dadd488790de Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Mon, 3 Apr 2017 15:59:41 +0100 Subject: Record :lmap transformed keys in gotchars() The mental model of :lmap and 'keymap' is of a transformation done before anything else. Hence when recording a macro, or writing to a scriptfile, the transformed keys should be recorded instead of the keys before the transformation. --- src/nvim/getchar.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 7df1bf8429..458c79ad4e 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1939,8 +1939,9 @@ static int vgetorpeek(int advance) char_u *save_m_keys; char_u *save_m_str; - // write chars to script file(s) - if (keylen > typebuf.tb_maplen) { + // Write chars to script file(s) + // Note: :lmap mappings are written *after* being applied. #5658 + if (keylen > typebuf.tb_maplen && (mp->m_mode & LANGMAP) == 0) { gotchars(typebuf.tb_buf + typebuf.tb_off + typebuf.tb_maplen, (size_t)(keylen - typebuf.tb_maplen)); } @@ -2015,6 +2016,12 @@ static int vgetorpeek(int advance) else { int noremap; + // If this is a LANGMAP mapping, then we didn't record the keys + // at the start of the function and have to record them now. + if (keylen > typebuf.tb_maplen && (mp->m_mode & LANGMAP) != 0) { + gotchars(s, STRLEN(s)); + } + if (save_m_noremap != REMAP_YES) noremap = save_m_noremap; else if ( -- cgit From 9beaf84d2f2bdef8e0400db78c364806008226f2 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Tue, 4 Apr 2017 14:28:20 +0100 Subject: Ensure :lmap mappings take preference If the mental model of :lmap mappings is a translation between your keyboard and vim proper, then they should take preference over :imap (and other) mappings. This patch makes that happen. --- src/nvim/getchar.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 458c79ad4e..d1a28ae3b0 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1844,8 +1844,11 @@ static int vgetorpeek(int advance) keylen = KEYLEN_PART_MAP; break; } - } else if (keylen > mp_match_len) { - /* found a longer match */ + } else if (keylen > mp_match_len + || (keylen == mp_match_len + && (mp_match->m_mode & LANGMAP) == 0 + && (mp->m_mode & LANGMAP) != 0)) { + // found a longer match mp_match = mp; mp_match_len = keylen; } -- cgit From 3b304fc04ac0ac7ffe24ba4b83fc0d0ba4b80cfd Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Wed, 24 Jan 2018 13:16:27 +0000 Subject: 'keymap' now uses :lmap instead of :lnoremap This means that the major way that :lmap mappings are applied works as one would expect with macros. This also means that having a translation with 'keymap' does not preclude using mappings in insert mode with :imap. --- src/nvim/digraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index bc4c12e0b7..ffd13da48b 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1827,12 +1827,12 @@ void ex_loadkeymap(exarg_T *eap) xfree(line); } - // setup ":lnoremap" to map the keys + // setup ":lmap" to map the keys for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)buf, sizeof(buf), " %s %s", ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); - (void)do_map(2, buf, LANGMAP, FALSE); + (void)do_map(0, buf, LANGMAP, FALSE); } p_cpo = save_cpo; -- cgit From 9058a5a19a3f62fb156203e0226eaaabb8b8da56 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Wed, 24 Jan 2018 20:30:47 +0000 Subject: clint --- src/nvim/digraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index ffd13da48b..e3d5ca07d1 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1828,11 +1828,11 @@ void ex_loadkeymap(exarg_T *eap) } // setup ":lmap" to map the keys - for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { + for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) { vim_snprintf((char *)buf, sizeof(buf), " %s %s", ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); - (void)do_map(0, buf, LANGMAP, FALSE); + (void)do_map(0, buf, LANGMAP, false); } p_cpo = save_cpo; -- cgit