patch 9.1.0642: Check that mapping rhs starts with lhs fails if not simplified
Problem: Check that mapping rhs starts with lhs doesn't work if lhs is
not simplified.
Solution: Keep track of the mapblock containing the alternative lhs and
also compare with it (zeertzjq).
fixes: #15376
closes: #15384
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/getchar.c b/src/getchar.c
index 4af1769..54222ec 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -3156,6 +3156,7 @@
int save_m_noremap;
int save_m_silent;
char_u *save_m_keys;
+ char_u *save_alt_m_keys;
#else
# define save_m_noremap mp->m_noremap
# define save_m_silent mp->m_silent
@@ -3204,6 +3205,7 @@
save_m_noremap = mp->m_noremap;
save_m_silent = mp->m_silent;
save_m_keys = NULL; // only saved when needed
+ save_alt_m_keys = NULL; // only saved when needed
/*
* Handle ":map <expr>": evaluate the {rhs} as an expression. Also
@@ -3221,6 +3223,8 @@
may_garbage_collect = FALSE;
save_m_keys = vim_strsave(mp->m_keys);
+ save_alt_m_keys = mp->m_alt != NULL
+ ? vim_strsave(mp->m_alt->m_keys) : NULL;
map_str = eval_map_expr(mp, NUL);
// The mapping may do anything, but we expect it to take care of
@@ -3278,15 +3282,20 @@
noremap = save_m_noremap;
else if (
#ifdef FEAT_EVAL
- STRNCMP(map_str, save_m_keys != NULL ? save_m_keys : mp->m_keys,
- (size_t)keylen)
-#else
- STRNCMP(map_str, mp->m_keys, (size_t)keylen)
+ save_m_expr ?
+ (save_m_keys != NULL
+ && STRNCMP(map_str, save_m_keys, (size_t)keylen) == 0)
+ || (save_alt_m_keys != NULL
+ && STRNCMP(map_str, save_alt_m_keys,
+ STRLEN(save_alt_m_keys)) == 0) :
#endif
- != 0)
- noremap = REMAP_YES;
- else
+ STRNCMP(map_str, mp->m_keys, (size_t)keylen) == 0
+ || (mp->m_alt != NULL
+ && STRNCMP(map_str, mp->m_alt->m_keys,
+ STRLEN(mp->m_alt->m_keys)) == 0))
noremap = REMAP_SKIP;
+ else
+ noremap = REMAP_YES;
i = ins_typebuf(map_str, noremap,
0, TRUE, cmd_silent || save_m_silent);
#ifdef FEAT_EVAL
@@ -3296,6 +3305,7 @@
}
#ifdef FEAT_EVAL
vim_free(save_m_keys);
+ vim_free(save_alt_m_keys);
#endif
*keylenp = keylen;
if (i == FAIL)