aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/eval.c7
-rw-r--r--src/nvim/message.c21
-rw-r--r--src/nvim/option.c3
-rw-r--r--test/functional/api/keymap_spec.lua13
4 files changed, 26 insertions, 18 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 8ea0969dd5..662270e788 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -12120,7 +12120,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)
// Return a string.
if (rhs != NULL) {
rettv->vval.v_string = (char_u *)str2special_save(
- (const char *)rhs, false);
+ (const char *)rhs, false, false);
}
} else {
@@ -12157,7 +12157,7 @@ void mapblock_fill_dict(dict_T *const dict,
FUNC_ATTR_NONNULL_ALL
{
char *const lhs = str2special_save((const char *)mp->m_keys,
- compatible ? true : false);
+ compatible, !compatible);
char *const mapmode = map_mode_to_chars(mp->m_mode);
varnumber_T noremap_value;
@@ -12175,7 +12175,8 @@ void mapblock_fill_dict(dict_T *const dict,
tv_dict_add_str(dict, S_LEN("rhs"), (const char *)mp->m_orig_str);
} else {
tv_dict_add_allocated_str(dict, S_LEN("rhs"),
- str2special_save((const char *)mp->m_str, false));
+ str2special_save((const char *)mp->m_str, false,
+ true));
}
tv_dict_add_allocated_str(dict, S_LEN("lhs"), lhs);
tv_dict_add_nr(dict, S_LEN("noremap"), noremap_value);
diff --git a/src/nvim/message.c b/src/nvim/message.c
index feb2fb214e..8a9d8e1bc6 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -1269,7 +1269,7 @@ msg_outtrans_special (
string = "<Space>";
str++;
} else {
- string = str2special((const char **)&str, from);
+ string = str2special((const char **)&str, from, false);
}
const int len = vim_strsize((char_u *)string);
// Highlight special keys
@@ -1286,11 +1286,13 @@ msg_outtrans_special (
/// Used for lhs or rhs of mappings.
///
/// @param[in] str String to convert.
-/// @param[in] replace_spaces Convert spaces into <Space>, normally used for
+/// @param[in] replace_spaces Convert spaces into `<Space>`, normally used fo
/// lhs, but not rhs.
+/// @param[in] replace_lt Convert `<` into `<lt>`.
///
/// @return [allocated] Converted string.
-char *str2special_save(const char *const str, const bool replace_spaces)
+char *str2special_save(const char *const str, const bool replace_spaces,
+ const bool replace_lt)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
FUNC_ATTR_NONNULL_RET
{
@@ -1299,7 +1301,7 @@ char *str2special_save(const char *const str, const bool replace_spaces)
const char *p = str;
while (*p != NUL) {
- ga_concat(&ga, (const char_u *)str2special(&p, replace_spaces));
+ ga_concat(&ga, (const char_u *)str2special(&p, replace_spaces, replace_lt));
}
ga_append(&ga, NUL);
return (char *)ga.ga_data;
@@ -1310,11 +1312,13 @@ char *str2special_save(const char *const str, const bool replace_spaces)
/// @param[in,out] sp String to convert. Is advanced to the next key code.
/// @param[in] replace_spaces Convert spaces into <Space>, normally used for
/// lhs, but not rhs.
+/// @param[in] replace_lt Convert `<` into `<lt>`.
///
/// @return Converted key code, in a static buffer. Buffer is always one and the
/// same, so save converted string somewhere before running str2special
/// for the second time.
-const char *str2special(const char **const sp, const bool replace_spaces)
+const char *str2special(const char **const sp, const bool replace_spaces,
+ const bool replace_lt)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET
{
static char buf[7];
@@ -1366,7 +1370,10 @@ const char *str2special(const char **const sp, const bool replace_spaces)
}
// Make unprintable characters in <> form, also <M-Space> and <Tab>.
- if (special || char2cells(c) > 1 || (replace_spaces && c == ' ')) {
+ if (special
+ || char2cells(c) > 1
+ || (replace_spaces && c == ' ')
+ || (replace_lt && c == '<')) {
return (const char *)get_special_key_name(c, modifiers);
}
buf[0] = c;
@@ -1383,7 +1390,7 @@ void str2specialbuf(const char *sp, char *buf, size_t len)
FUNC_ATTR_NONNULL_ALL
{
while (*sp) {
- const char *s = str2special(&sp, false);
+ const char *s = str2special(&sp, false, false);
const size_t s_len = strlen(s);
if (s_len <= len) {
break;
diff --git a/src/nvim/option.c b/src/nvim/option.c
index bc101ba703..7287db6eb8 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -5176,7 +5176,8 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int e
if (valuep == &p_pt) {
s = *valuep;
while (*s != NUL) {
- if (put_escstr(fd, (char_u *)str2special((const char **)&s, false), 2)
+ if (put_escstr(fd, (char_u *)str2special((const char **)&s, false,
+ false), 2)
== FAIL) {
return FAIL;
}
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index b7858888c4..fc3ab2d179 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -281,13 +281,12 @@ describe('get_keymap', function()
command(cmd)
eq({cpomap('\\<C-C>', '\\<C-D>', 'n'), cpomap('\\<C-A>', '\\<C-B>', 'n')},
meths.get_keymap('n'))
- -- FIXME
- -- eq({cpomap('\\<C-C>', '\\<C-D>', 'x'), cpomap('\\<LT>C-A>', '\\<LT>C-B>', 'x')},
- -- meths.get_keymap('x'))
- -- eq({cpomap('<LT>C-C>', '<LT>C-D>', 's'), cpomap('<LT>C-A>', '<LT>C-B>', 's')},
- -- meths.get_keymap('x'))
- -- eq({cpomap('<LT>C-C>', '<LT>C-D>', 'o'), cpomap('<LT>C-A>', '<LT>C-B>', 'o')},
- -- meths.get_keymap('x'))
+ eq({cpomap('\\<C-C>', '\\<C-D>', 'x'), cpomap('\\<lt>C-a>', '\\<lt>C-b>', 'x')},
+ meths.get_keymap('x'))
+ eq({cpomap('<lt>C-c>', '<lt>C-d>', 's'), cpomap('<lt>C-a>', '<lt>C-b>', 's')},
+ meths.get_keymap('s'))
+ eq({cpomap('<lt>C-c>', '<lt>C-d>', 'o'), cpomap('<lt>C-a>', '<lt>C-b>', 'o')},
+ meths.get_keymap('o'))
end
end)
end)