mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
message: Add support for replacing <
to str2special
This commit is contained in:
@@ -12120,7 +12120,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)
|
|||||||
// Return a string.
|
// Return a string.
|
||||||
if (rhs != NULL) {
|
if (rhs != NULL) {
|
||||||
rettv->vval.v_string = (char_u *)str2special_save(
|
rettv->vval.v_string = (char_u *)str2special_save(
|
||||||
(const char *)rhs, false);
|
(const char *)rhs, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -12157,7 +12157,7 @@ void mapblock_fill_dict(dict_T *const dict,
|
|||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
char *const lhs = str2special_save((const char *)mp->m_keys,
|
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);
|
char *const mapmode = map_mode_to_chars(mp->m_mode);
|
||||||
varnumber_T noremap_value;
|
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);
|
tv_dict_add_str(dict, S_LEN("rhs"), (const char *)mp->m_orig_str);
|
||||||
} else {
|
} else {
|
||||||
tv_dict_add_allocated_str(dict, S_LEN("rhs"),
|
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_allocated_str(dict, S_LEN("lhs"), lhs);
|
||||||
tv_dict_add_nr(dict, S_LEN("noremap"), noremap_value);
|
tv_dict_add_nr(dict, S_LEN("noremap"), noremap_value);
|
||||||
|
@@ -1269,7 +1269,7 @@ msg_outtrans_special (
|
|||||||
string = "<Space>";
|
string = "<Space>";
|
||||||
str++;
|
str++;
|
||||||
} else {
|
} else {
|
||||||
string = str2special((const char **)&str, from);
|
string = str2special((const char **)&str, from, false);
|
||||||
}
|
}
|
||||||
const int len = vim_strsize((char_u *)string);
|
const int len = vim_strsize((char_u *)string);
|
||||||
// Highlight special keys
|
// Highlight special keys
|
||||||
@@ -1286,11 +1286,13 @@ msg_outtrans_special (
|
|||||||
/// Used for lhs or rhs of mappings.
|
/// Used for lhs or rhs of mappings.
|
||||||
///
|
///
|
||||||
/// @param[in] str String to convert.
|
/// @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.
|
/// lhs, but not rhs.
|
||||||
|
/// @param[in] replace_lt Convert `<` into `<lt>`.
|
||||||
///
|
///
|
||||||
/// @return [allocated] Converted string.
|
/// @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_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
|
||||||
FUNC_ATTR_NONNULL_RET
|
FUNC_ATTR_NONNULL_RET
|
||||||
{
|
{
|
||||||
@@ -1299,7 +1301,7 @@ char *str2special_save(const char *const str, const bool replace_spaces)
|
|||||||
|
|
||||||
const char *p = str;
|
const char *p = str;
|
||||||
while (*p != NUL) {
|
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);
|
ga_append(&ga, NUL);
|
||||||
return (char *)ga.ga_data;
|
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,out] sp String to convert. Is advanced to the next key code.
|
||||||
/// @param[in] replace_spaces Convert spaces into <Space>, normally used for
|
/// @param[in] replace_spaces Convert spaces into <Space>, normally used for
|
||||||
/// lhs, but not rhs.
|
/// 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
|
/// @return Converted key code, in a static buffer. Buffer is always one and the
|
||||||
/// same, so save converted string somewhere before running str2special
|
/// same, so save converted string somewhere before running str2special
|
||||||
/// for the second time.
|
/// 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
|
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET
|
||||||
{
|
{
|
||||||
static char buf[7];
|
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>.
|
// 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);
|
return (const char *)get_special_key_name(c, modifiers);
|
||||||
}
|
}
|
||||||
buf[0] = c;
|
buf[0] = c;
|
||||||
@@ -1383,7 +1390,7 @@ void str2specialbuf(const char *sp, char *buf, size_t len)
|
|||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
while (*sp) {
|
while (*sp) {
|
||||||
const char *s = str2special(&sp, false);
|
const char *s = str2special(&sp, false, false);
|
||||||
const size_t s_len = strlen(s);
|
const size_t s_len = strlen(s);
|
||||||
if (s_len <= len) {
|
if (s_len <= len) {
|
||||||
break;
|
break;
|
||||||
|
@@ -5176,7 +5176,8 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int e
|
|||||||
if (valuep == &p_pt) {
|
if (valuep == &p_pt) {
|
||||||
s = *valuep;
|
s = *valuep;
|
||||||
while (*s != NUL) {
|
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) {
|
== FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
@@ -281,13 +281,12 @@ describe('get_keymap', function()
|
|||||||
command(cmd)
|
command(cmd)
|
||||||
eq({cpomap('\\<C-C>', '\\<C-D>', 'n'), cpomap('\\<C-A>', '\\<C-B>', 'n')},
|
eq({cpomap('\\<C-C>', '\\<C-D>', 'n'), cpomap('\\<C-A>', '\\<C-B>', 'n')},
|
||||||
meths.get_keymap('n'))
|
meths.get_keymap('n'))
|
||||||
-- FIXME
|
eq({cpomap('\\<C-C>', '\\<C-D>', 'x'), cpomap('\\<lt>C-a>', '\\<lt>C-b>', 'x')},
|
||||||
-- eq({cpomap('\\<C-C>', '\\<C-D>', 'x'), cpomap('\\<LT>C-A>', '\\<LT>C-B>', 'x')},
|
meths.get_keymap('x'))
|
||||||
-- meths.get_keymap('x'))
|
eq({cpomap('<lt>C-c>', '<lt>C-d>', 's'), cpomap('<lt>C-a>', '<lt>C-b>', 's')},
|
||||||
-- eq({cpomap('<LT>C-C>', '<LT>C-D>', 's'), cpomap('<LT>C-A>', '<LT>C-B>', 's')},
|
meths.get_keymap('s'))
|
||||||
-- meths.get_keymap('x'))
|
eq({cpomap('<lt>C-c>', '<lt>C-d>', 'o'), cpomap('<lt>C-a>', '<lt>C-b>', 'o')},
|
||||||
-- eq({cpomap('<LT>C-C>', '<LT>C-D>', 'o'), cpomap('<LT>C-A>', '<LT>C-B>', 'o')},
|
meths.get_keymap('o'))
|
||||||
-- meths.get_keymap('x'))
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user