diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-06-01 21:37:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-01 21:37:01 +0800 |
commit | 96c494dec345f9a3dd2676048292267552e3f5f8 (patch) | |
tree | 20be26182c603ee6126624b6d90741c16e1e6f65 /src | |
parent | f40adf770d090d12f7b14dd519fe649ada40bfe6 (diff) | |
download | rneovim-96c494dec345f9a3dd2676048292267552e3f5f8.tar.gz rneovim-96c494dec345f9a3dd2676048292267552e3f5f8.tar.bz2 rneovim-96c494dec345f9a3dd2676048292267552e3f5f8.zip |
refactor: correct comments and assertions about mapping rhs <Nop> (#18821)
Also avoid referring to mappings as "keymaps" in commands and docs.
*map_empty_rhs* *map-empty-rhs*
You can create an empty {rhs} by typing nothing after a single CTRL-V (you
have to type CTRL-V two times). Unfortunately, you cannot do this in a vimrc
file.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/private/helpers.c | 6 | ||||
-rw-r--r-- | src/nvim/getchar.c | 9 | ||||
-rw-r--r-- | src/nvim/getchar.h | 4 | ||||
-rw-r--r-- | src/nvim/normal.c | 2 |
4 files changed, 9 insertions, 12 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 6981ecc455..af4aaf01aa 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -678,11 +678,7 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod if (rhs.size == 0) { // assume that the user wants RHS to be a <Nop> parsed_args.rhs_is_noop = true; } else { - // the given RHS was nonempty and not a <Nop>, but was parsed as if it - // were empty? - assert(false && "Failed to parse nonempty RHS!"); - api_set_error(err, kErrorTypeValidation, "Parsing of nonempty RHS failed: %s", rhs.data); - goto fail_and_free; + abort(); // should never happen } } else if (is_unmap && (parsed_args.rhs_len || parsed_args.rhs_lua != LUA_NOREF)) { if (parsed_args.rhs_len) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 788e1113e2..85ac52cafd 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2839,8 +2839,8 @@ int fix_input_buffer(char_u *buf, int len) /// the final `lhs` exceeds `MAXMAPLEN`, `lhs_len` will be set equal to the /// original larger length and `lhs` will be truncated. /// -/// If RHS is equal to "<Nop>", `rhs` will be the empty string, `rhs_len` -/// will be zero, and `rhs_is_noop` will be set to true. +/// If RHS should be <Nop>, `rhs` will be an empty string, `rhs_len` will be +/// zero, and `rhs_is_noop` will be set to true. /// /// Any memory allocated by @ref replace_termcodes is freed before this function /// returns. @@ -2898,8 +2898,9 @@ void set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs_len, replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, REPTERM_DO_LT, NULL, cpo_flags); mapargs->rhs_len = STRLEN(replaced); - // XXX: even when orig_rhs is non-empty, replace_termcodes may produce an empty string. - mapargs->rhs_is_noop = orig_rhs[0] != NUL && mapargs->rhs_len == 0; + // XXX: replace_termcodes may produce an empty string even if orig_rhs is non-empty + // (e.g. a single ^V, see :h map-empty-rhs) + mapargs->rhs_is_noop = orig_rhs_len != 0 && mapargs->rhs_len == 0; mapargs->rhs = xcalloc(mapargs->rhs_len + 1, sizeof(char_u)); STRLCPY(mapargs->rhs, replaced, mapargs->rhs_len + 1); } diff --git a/src/nvim/getchar.h b/src/nvim/getchar.h index 237f0632bd..ddd6d81aef 100644 --- a/src/nvim/getchar.h +++ b/src/nvim/getchar.h @@ -54,8 +54,8 @@ struct map_arguments { char_u *rhs; /// The {rhs} of the mapping. size_t rhs_len; - LuaRef rhs_lua; /// lua function as rhs - bool rhs_is_noop; /// True when the {orig_rhs} is <nop>. + LuaRef rhs_lua; /// lua function as {rhs} + bool rhs_is_noop; /// True when the {rhs} should be <Nop>. char_u *orig_rhs; /// The original text of the {rhs}. size_t orig_rhs_len; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 3b91044f41..bf0ea2aeec 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -3917,7 +3917,7 @@ static void nv_regreplay(cmdarg_T *cap) } } -/// Handle a ":" command and <Cmd> or Lua keymaps. +/// Handle a ":" command and <Cmd> or Lua mappings. static void nv_colon(cmdarg_T *cap) { bool cmd_result; |