From c8c930ea785aa393ebc819139913a9e05f0ccd45 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:24:46 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22206) --- src/nvim/mapping.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 831d1299a8..5547b6c367 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1434,15 +1434,11 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat // Return true if there is an abbreviation, false if not. bool check_abbr(int c, char *ptr, int col, int mincol) { - int len; int scol; // starting column of the abbr. - int j; - char *s; char_u tb[MB_MAXBYTES + 4]; mapblock_T *mp; mapblock_T *mp2; int clen = 0; // length in characters - bool is_id = true; if (typebuf.tb_no_abbr_cnt) { // abbrev. are not recursive return false; @@ -1462,6 +1458,7 @@ bool check_abbr(int c, char *ptr, int col, int mincol) } { + bool is_id = true; bool vim_abbr; char *p = mb_prevptr(ptr, ptr + col); if (!vim_iswordp(p)) { @@ -1489,7 +1486,7 @@ bool check_abbr(int c, char *ptr, int col, int mincol) } if (scol < col) { // there is a word in front of the cursor ptr += scol; - len = col - scol; + int len = col - scol; mp = curbuf->b_first_abbr; mp2 = first_abbr; if (mp == NULL) { @@ -1532,7 +1529,7 @@ bool check_abbr(int c, char *ptr, int col, int mincol) // // Character CTRL-] is treated specially - it completes the // abbreviation, but is not inserted into the input stream. - j = 0; + int j = 0; if (c != Ctrl_RSB) { // special key code, split up if (IS_SPECIAL(c) || c == K_SPECIAL) { @@ -1568,6 +1565,7 @@ bool check_abbr(int c, char *ptr, int col, int mincol) const bool silent = mp->m_silent; const bool expr = mp->m_expr; + char *s; if (expr) { s = eval_map_expr(mp, c); } else { -- cgit From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/mapping.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 5547b6c367..c740fb41bc 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1162,7 +1162,7 @@ static bool expand_buffer = false; /// @param cpo_flags Value of various flags present in &cpo /// /// @return NULL when there is a problem. -static char_u *translate_mapping(char_u *str, int cpo_flags) +static char *translate_mapping(char_u *str, int cpo_flags) { garray_T ga; ga_init(&ga, 1, 40); @@ -1203,7 +1203,7 @@ static char_u *translate_mapping(char_u *str, int cpo_flags) } } ga_append(&ga, NUL); - return (char_u *)(ga.ga_data); + return (char *)ga.ga_data; } /// Work out what to complete when doing command line completion of mapping @@ -1212,8 +1212,8 @@ static char_u *translate_mapping(char_u *str, int cpo_flags) /// @param forceit true if '!' given /// @param isabbrev true if abbreviation /// @param isunmap true if unmap/unabbrev command -char_u *set_context_in_map_cmd(expand_T *xp, char *cmd, char *arg, bool forceit, bool isabbrev, - bool isunmap, cmdidx_T cmdidx) +char *set_context_in_map_cmd(expand_T *xp, char *cmd, char *arg, bool forceit, bool isabbrev, + bool isunmap, cmdidx_T cmdidx) { if (forceit && cmdidx != CMD_map && cmdidx != CMD_unmap) { xp->xp_context = EXPAND_NOTHING; @@ -1346,7 +1346,7 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat continue; } - char *p = (char *)translate_mapping((char_u *)mp->m_keys, CPO_TO_CPO_FLAGS); + char *p = translate_mapping((char_u *)mp->m_keys, CPO_TO_CPO_FLAGS); if (p == NULL) { continue; } @@ -1503,7 +1503,7 @@ bool check_abbr(int c, char *ptr, int col, int mincol) if (strchr((const char *)mp->m_keys, K_SPECIAL) != NULL) { // Might have K_SPECIAL escaped mp->m_keys. q = xstrdup(mp->m_keys); - vim_unescape_ks((char_u *)q); + vim_unescape_ks(q); qlen = (int)strlen(q); } // find entries with right mode and keys @@ -1607,7 +1607,7 @@ char *eval_map_expr(mapblock_T *mp, int c) // typeahead. if (mp->m_luaref == LUA_NOREF) { expr = xstrdup(mp->m_str); - vim_unescape_ks((char_u *)expr); + vim_unescape_ks(expr); } const bool replace_keycodes = mp->m_replace_keycodes; -- cgit From df666521ac4dd338b59082b1100a4673acde9e64 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Feb 2023 08:41:04 +0800 Subject: fix(mappings): fix check for cpo-B inverted in completion --- src/nvim/mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index c740fb41bc..0b2cf6ea47 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1167,7 +1167,7 @@ static char *translate_mapping(char_u *str, int cpo_flags) garray_T ga; ga_init(&ga, 1, 40); - bool cpo_bslash = !(cpo_flags&FLAG_CPO_BSLASH); + bool cpo_bslash = cpo_flags & FLAG_CPO_BSLASH; for (; *str; str++) { int c = *str; -- cgit From 75dab3cf0781f664ac866f511df2fb2c06aa7d17 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 18 Feb 2023 06:52:56 +0800 Subject: fix(mappings): make "<" escaping in completion match Vim --- src/nvim/mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 0b2cf6ea47..ce4c0586e3 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1194,7 +1194,7 @@ static char *translate_mapping(char_u *str, int cpo_flags) } if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V - || (c == '\\' && !cpo_bslash)) { + || c == '<' || (c == '\\' && !cpo_bslash)) { ga_append(&ga, cpo_bslash ? Ctrl_V : '\\'); } -- cgit From 8784f064f15e5ae0b6bc85c2972ec16c64656e2b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 20 Feb 2023 08:24:49 +0800 Subject: vim-patch:9.0.1329: completion of map includes simplified ones (#22335) Problem: Completion of map includes simplified ones. Solution: Do not complete simplified mappings. (closes vim/vim#12013) https://github.com/vim/vim/commit/997b8a015cd39141866e953651d55c705275cbd6 --- src/nvim/mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index ce4c0586e3..3840a00981 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1342,7 +1342,7 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat mp = maphash[hash]; } for (; mp; mp = mp->m_next) { - if (!(mp->m_mode & expand_mapmodes)) { + if (mp->m_simplified || !(mp->m_mode & expand_mapmodes)) { continue; } -- cgit From f113cba3ec127201f54094f9174b50ee3001fbee Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 28 Feb 2023 08:49:02 +0800 Subject: refactor(getchar.c): change most char_u to uint8_t (#22444) --- src/nvim/mapping.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 3840a00981..60524b9fb7 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -323,7 +323,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len mapargs->orig_rhs_len = 0; // stores ref_no in map_str mapargs->rhs_len = (size_t)vim_snprintf(S_LEN(tmp_buf), "%c%c%c%d\r", K_SPECIAL, - (char_u)KS_EXTRA, KE_LUA, rhs_lua); + KS_EXTRA, KE_LUA, rhs_lua); mapargs->rhs = xstrdup(tmp_buf); } } @@ -1879,7 +1879,7 @@ int makemap(FILE *fd, buf_T *buf) // return FAIL for failure, OK otherwise int put_escstr(FILE *fd, char *strstart, int what) { - char_u *str = (char_u *)strstart; + uint8_t *str = (uint8_t *)strstart; int c; // :map xx @@ -1956,7 +1956,7 @@ int put_escstr(FILE *fd, char *strstart, int what) } } else if (c < ' ' || c > '~' || c == '|' || (what == 0 && c == ' ') - || (what == 1 && str == (char_u *)strstart && c == ' ') + || (what == 1 && str == (uint8_t *)strstart && c == ' ') || (what != 2 && c == '<')) { if (putc(Ctrl_V, fd) < 0) { return FAIL; @@ -2383,7 +2383,7 @@ int langmap_adjust_mb(int c) void langmap_init(void) { for (int i = 0; i < 256; i++) { - langmap_mapchar[i] = (char_u)i; // we init with a one-to-one map + langmap_mapchar[i] = (uint8_t)i; // we init with a one-to-one map } ga_init(&langmap_mapga, sizeof(langmap_entry_T), 8); } @@ -2447,7 +2447,7 @@ void langmap_set(void) langmap_set_entry(from, to); } else { assert(to <= UCHAR_MAX); - langmap_mapchar[from & 255] = (char_u)to; + langmap_mapchar[from & 255] = (uint8_t)to; } // Advance to next pair -- cgit From 6cab36e5b7b0d741abe6c5a7c0e20bad30361034 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 4 Mar 2023 13:10:00 +0100 Subject: refactor: replace char_u with char or uint8_t (#22400) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/mapping.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 60524b9fb7..3c4ce0ee2b 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1162,8 +1162,9 @@ static bool expand_buffer = false; /// @param cpo_flags Value of various flags present in &cpo /// /// @return NULL when there is a problem. -static char *translate_mapping(char_u *str, int cpo_flags) +static char *translate_mapping(char *str_in, int cpo_flags) { + uint8_t *str = (uint8_t *)str_in; garray_T ga; ga_init(&ga, 1, 40); @@ -1346,7 +1347,7 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat continue; } - char *p = translate_mapping((char_u *)mp->m_keys, CPO_TO_CPO_FLAGS); + char *p = translate_mapping(mp->m_keys, CPO_TO_CPO_FLAGS); if (p == NULL) { continue; } -- cgit From e1db0e35e4d5859b96e6aff882df62d6c714b569 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 15 Mar 2023 23:30:14 +0000 Subject: feat(api): add filetype option nvim_get_option_value - Also adjust the expr-mapping behaviour so normal commands and text changes are allowed in internal dummy buffers. --- src/nvim/mapping.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 3c4ce0ee2b..5cedc5e97d 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1615,8 +1615,7 @@ char *eval_map_expr(mapblock_T *mp, int c) // Forbid changing text or using ":normal" to avoid most of the bad side // effects. Also restore the cursor position. - textlock++; - ex_normal_lock++; + expr_map_lock++; set_vim_var_char(c); // set v:char to the typed character const pos_T save_cursor = curwin->w_cursor; const int save_msg_col = msg_col; @@ -1637,8 +1636,7 @@ char *eval_map_expr(mapblock_T *mp, int c) p = eval_to_string(expr, NULL, false); xfree(expr); } - textlock--; - ex_normal_lock--; + expr_map_lock--; curwin->w_cursor = save_cursor; msg_col = save_msg_col; msg_row = save_msg_row; -- cgit From d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 2 Apr 2023 10:11:42 +0200 Subject: refactor: remove char_u (#22829) Closes https://github.com/neovim/neovim/issues/459 --- src/nvim/mapping.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 5cedc5e97d..2941d5965b 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1189,7 +1189,7 @@ static char *translate_mapping(char *str_in, int cpo_flags) str += 2; } if (IS_SPECIAL(c) || modifiers) { // special key - ga_concat(&ga, (char *)get_special_key_name(c, modifiers)); + ga_concat(&ga, get_special_key_name(c, modifiers)); continue; // for (str) } } @@ -1436,7 +1436,7 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat bool check_abbr(int c, char *ptr, int col, int mincol) { int scol; // starting column of the abbr. - char_u tb[MB_MAXBYTES + 4]; + uint8_t tb[MB_MAXBYTES + 4]; mapblock_T *mp; mapblock_T *mp2; int clen = 0; // length in characters @@ -1535,8 +1535,8 @@ bool check_abbr(int c, char *ptr, int col, int mincol) // special key code, split up if (IS_SPECIAL(c) || c == K_SPECIAL) { tb[j++] = K_SPECIAL; - tb[j++] = (char_u)K_SECOND(c); - tb[j++] = (char_u)K_THIRD(c); + tb[j++] = (uint8_t)K_SECOND(c); + tb[j++] = (uint8_t)K_THIRD(c); } else { if (c < ABBR_OFF && (c < ' ' || c > '~')) { tb[j++] = Ctrl_V; // special char needs CTRL-V @@ -1918,7 +1918,7 @@ int put_escstr(FILE *fd, char *strstart, int what) str += 2; } if (IS_SPECIAL(c) || modifiers) { // special key - if (fputs((char *)get_special_key_name(c, modifiers), fd) < 0) { + if (fputs(get_special_key_name(c, modifiers), fd) < 0) { return FAIL; } continue; -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/mapping.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 2941d5965b..1887afef1c 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1501,7 +1501,7 @@ bool check_abbr(int c, char *ptr, int col, int mincol) char *q = mp->m_keys; int match; - if (strchr((const char *)mp->m_keys, K_SPECIAL) != NULL) { + if (strchr(mp->m_keys, K_SPECIAL) != NULL) { // Might have K_SPECIAL escaped mp->m_keys. q = xstrdup(mp->m_keys); vim_unescape_ks(q); @@ -1811,8 +1811,7 @@ int makemap(FILE *fd, buf_T *buf) did_cpo = true; } else { const char specials[] = { (char)(uint8_t)K_SPECIAL, NL, NUL }; - if (strpbrk((const char *)mp->m_str, specials) != NULL - || strpbrk((const char *)mp->m_keys, specials) != NULL) { + if (strpbrk(mp->m_str, specials) != NULL || strpbrk(mp->m_keys, specials) != NULL) { did_cpo = true; } } @@ -2091,7 +2090,7 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs PUT(dict, "desc", STRING_OBJ(cstr_to_string(mp->m_desc))); } PUT(dict, "lhs", STRING_OBJ(cstr_as_string(lhs))); - PUT(dict, "lhsraw", STRING_OBJ(cstr_to_string((const char *)mp->m_keys))); + PUT(dict, "lhsraw", STRING_OBJ(cstr_to_string(mp->m_keys))); if (lhsrawalt != NULL) { // Also add the value for the simplified entry. PUT(dict, "lhsrawalt", STRING_OBJ(cstr_to_string(lhsrawalt))); -- cgit From 04933b1ea968f958d2541dd65fd33ebb503caac3 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:08:16 +0200 Subject: refactor: remove redundant casts --- src/nvim/mapping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 1887afef1c..68a3778a47 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -596,13 +596,13 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, int last = first; p = (char *)lhs + utfc_ptr2len((char *)lhs); n = 1; - while (p < (char *)lhs + len) { + while (p < lhs + len) { n++; // nr of (multi-byte) chars last = vim_iswordp(p); // type of last char if (same == -1 && last != first) { same = n - 1; // count of same char type } - p += utfc_ptr2len((char *)p); + p += utfc_ptr2len(p); } if (last && n > 2 && same >= 0 && same < n - 1) { retval = 1; -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/mapping.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 68a3778a47..8176fe9ce0 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -422,7 +422,7 @@ static int str_to_mapargs(const char *strargs, bool is_unmap, MapArguments *mapa // {lhs_end} is a pointer to the "terminating whitespace" after {lhs}. // Use that to initialize {rhs_start}. - const char *rhs_start = skipwhite((char *)lhs_end); + const char *rhs_start = skipwhite(lhs_end); // Given {lhs} might be larger than MAXMAPLEN before replace_termcodes // (e.g. "" is longer than ' '), so first copy into a buffer. @@ -594,7 +594,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, const int first = vim_iswordp(lhs); int last = first; - p = (char *)lhs + utfc_ptr2len((char *)lhs); + p = lhs + utfc_ptr2len(lhs); n = 1; while (p < lhs + len) { n++; // nr of (multi-byte) chars @@ -733,8 +733,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, // we ignore trailing space when matching with // the "lhs", since an abbreviation can't have // trailing space. - if (n != len && (!is_abbrev || round || n > len - || *skipwhite((char *)lhs + n) != NUL)) { + if (n != len && (!is_abbrev || round || n > len || *skipwhite(lhs + n) != NUL)) { mpp = &(mp->m_next); continue; } @@ -857,7 +856,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, } // Get here when adding a new entry to the maphash[] list or abbrlist. - map_add(buf, map_table, abbr_table, (char *)lhs, args, noremap, mode, is_abbrev, + map_add(buf, map_table, abbr_table, lhs, args, noremap, mode, is_abbrev, -1, // sid 0, // lnum keyround1_simplified); @@ -2645,10 +2644,10 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod case 0: break; case 1: - api_set_error(err, kErrorTypeException, (char *)e_invarg, 0); + api_set_error(err, kErrorTypeException, e_invarg, 0); goto fail_and_free; case 2: - api_set_error(err, kErrorTypeException, (char *)e_nomap, 0); + api_set_error(err, kErrorTypeException, e_nomap, 0); goto fail_and_free; case 5: api_set_error(err, kErrorTypeException, -- cgit From bc66b755f61ba0e3383177b2866e05557ffa3966 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 8 Apr 2023 08:21:09 +0800 Subject: vim-patch:9.0.1442: mapset() does not restore non-script context (#22942) Problem: mapset() does not restore non-script context. Solution: Also accept negative sid. (closes vim/vim#12132) https://github.com/vim/vim/commit/bfc7cbd1d44e53e844a079d8ad16ae990dad664d --- src/nvim/mapping.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 8176fe9ce0..19a2aca75e 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -449,7 +449,7 @@ static int str_to_mapargs(const char *strargs, bool is_unmap, MapArguments *mapa /// @param args "rhs", "rhs_lua", "orig_rhs", "expr", "silent", "nowait", "replace_keycodes" and /// and "desc" fields are used. /// "rhs", "rhs_lua", "orig_rhs" fields are cleared if "simplified" is false. -/// @param sid -1 to use current_sctx +/// @param sid 0 to use current_sctx static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, const char *keys, MapArguments *args, int noremap, int mode, bool is_abbr, scid_T sid, linenr_T lnum, bool simplified) @@ -482,7 +482,7 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, mp->m_simplified = simplified; mp->m_expr = args->expr; mp->m_replace_keycodes = args->replace_keycodes; - if (sid >= 0) { + if (sid != 0) { mp->m_script_ctx.sc_sid = sid; mp->m_script_ctx.sc_lnum = lnum; } else { @@ -857,8 +857,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, // Get here when adding a new entry to the maphash[] list or abbrlist. map_add(buf, map_table, abbr_table, lhs, args, noremap, mode, is_abbrev, - -1, // sid - 0, // lnum + 0, // sid + 0, // lnum keyround1_simplified); } -- cgit From 8e2903d2fe810cfa3be41fc1e7a4d8394c84cf11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 09:11:37 +0800 Subject: vim-patch:8.2.1049: Vim9: leaking memory when using continuation line Problem: Vim9: leaking memory when using continuation line. Solution: Keep a pointer to the continuation line in evalarg_T. Centralize checking for a next command. https://github.com/vim/vim/commit/b171fb179053fa631fec74911b5fb9374cb6a8a1 Omit eval_next_line(): Vim9 script only. vim-patch:8.2.1050: missing change in struct Problem: Missing change in struct. Solution: Add missing change. https://github.com/vim/vim/commit/65a8ed37f7bc61fbe5c612a7b0eb0dfc16ad3e11 Co-authored-by: Bram Moolenaar --- src/nvim/mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 19a2aca75e..c1565a84f5 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1632,7 +1632,7 @@ char *eval_map_expr(mapblock_T *mp, int c) api_clear_error(&err); } } else { - p = eval_to_string(expr, NULL, false); + p = eval_to_string(expr, false); xfree(expr); } expr_map_lock--; -- cgit From 43c49746d9cf82dba0d56b07d39722f9ebeecf90 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 25 Apr 2023 21:32:12 +0800 Subject: vim-patch:9.0.0335: checks for Dictionary argument often give a vague error (#23309) Problem: Checks for Dictionary argument often give a vague error message. Solution: Give a useful error message. (Yegappan Lakshmanan, closes vim/vim#11009) https://github.com/vim/vim/commit/04c4c5746e15884768d2cb41370c3276a196cd4c Cherry-pick removal of E922 from docs from patch 9.0.1403. Co-authored-by: Yegappan Lakshmanan --- src/nvim/mapping.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index c1565a84f5..f88c0deb87 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2204,8 +2204,7 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const int mode = get_map_mode((char **)&which, 0); const bool is_abbr = tv_get_number(&argvars[1]) != 0; - if (argvars[2].v_type != VAR_DICT) { - emsg(_(e_dictreq)); + if (tv_check_for_dict_arg(argvars, 2) == FAIL) { return; } dict_T *d = argvars[2].vval.v_dict; -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/mapping.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index f88c0deb87..9a835e0eb8 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -706,7 +706,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, hash_end = 256; } for (int hash = hash_start; hash < hash_end && !got_int; hash++) { - mpp = is_abbrev ? abbr_table : &(map_table[hash]); + mpp = is_abbrev ? abbr_table : &(map_table[hash]); for (mp = *mpp; mp != NULL && !got_int; mp = *mpp) { if ((mp->m_mode & mode) == 0) { // skip entries with wrong mode @@ -1112,7 +1112,7 @@ int map_to_exists_mode(const char *const rhs, const int mode, const bool abbr) bool exp_buffer = false; // Do it twice: once for global maps and once for local maps. - for (;;) { + while (true) { for (hash = 0; hash < 256; hash++) { if (abbr) { if (hash > 0) { // There is only one abbr list. @@ -1229,7 +1229,7 @@ char *set_context_in_map_cmd(expand_T *xp, char *cmd, char *arg, bool forceit, b expand_isabbrev = isabbrev; xp->xp_context = EXPAND_MAPPINGS; expand_buffer = false; - for (;;) { + while (true) { if (strncmp(arg, "", 8) == 0) { expand_buffer = true; arg = skipwhite(arg + 8); @@ -2322,13 +2322,13 @@ static garray_T langmap_mapga = GA_EMPTY_INIT_VALUE; static void langmap_set_entry(int from, int to) { langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data); - unsigned int a = 0; + unsigned a = 0; assert(langmap_mapga.ga_len >= 0); - unsigned int b = (unsigned int)langmap_mapga.ga_len; + unsigned b = (unsigned)langmap_mapga.ga_len; // Do a binary search for an existing entry. while (a != b) { - unsigned int i = (a + b) / 2; + unsigned i = (a + b) / 2; int d = entries[i].from - from; if (d == 0) { @@ -2347,7 +2347,7 @@ static void langmap_set_entry(int from, int to) // insert new entry at position "a" entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a; memmove(entries + 1, entries, - ((unsigned int)langmap_mapga.ga_len - a) * sizeof(langmap_entry_T)); + ((unsigned)langmap_mapga.ga_len - a) * sizeof(langmap_entry_T)); langmap_mapga.ga_len++; entries[0].from = from; entries[0].to = to; -- cgit From ff34c91194f9ab9d02808f2880029c38a4655eb5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Apr 2023 17:23:47 +0100 Subject: vim-patch:9.0.1330: handling new value of an option has a long "else if" chain Problem: Handling new value of an option has a long "else if" chain. Solution: Use a function pointer. (Yegappan Lakshmanan, closes vim/vim#12015) https://github.com/vim/vim/commit/af93691b53f38784efce0b93fe7644c44a7e382e --- src/nvim/mapping.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 9a835e0eb8..a2f2ed4d86 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2386,7 +2386,7 @@ void langmap_init(void) /// Called when langmap option is set; the language map can be /// changed at any time! -void langmap_set(void) +const char *did_set_langmap(optset_T *args FUNC_ATTR_UNUSED) { char *p; char *p2; @@ -2434,9 +2434,11 @@ void langmap_set(void) } } if (to == NUL) { + // TODO(vim): Need to use errbuf argument for this error message + // and return it. semsg(_("E357: 'langmap': Matching character missing for %s"), transchar(from)); - return; + return NULL; } if (from >= 256) { @@ -2454,8 +2456,10 @@ void langmap_set(void) p = p2; if (p[0] != NUL) { if (p[0] != ',') { + // TODO(vim): Need to use errbuf argument for this error + // message and return it. semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p); - return; + return NULL; } p++; } @@ -2464,6 +2468,8 @@ void langmap_set(void) } } } + + return NULL; } static void do_exmap(exarg_T *eap, int isabbrev) -- cgit From 5cda9c267ab951c9d3ba05cddd0e8f63b3a7680a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 26 Apr 2023 15:32:48 +0100 Subject: vim-patch:9.0.1359: too many "else if" statements in handling options Problem: Too many "else if" statements in handling options. Solution: Add more functions for handling option changes. (Yegappan Lakshmanan, closes vim/vim#12060) https://github.com/vim/vim/commit/5da901bb68717b2baff6e971c1517219b6ee3a67 --- src/nvim/mapping.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index a2f2ed4d86..c1d02e89b8 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2386,7 +2386,7 @@ void langmap_init(void) /// Called when langmap option is set; the language map can be /// changed at any time! -const char *did_set_langmap(optset_T *args FUNC_ATTR_UNUSED) +const char *did_set_langmap(optset_T *args) { char *p; char *p2; @@ -2434,11 +2434,10 @@ const char *did_set_langmap(optset_T *args FUNC_ATTR_UNUSED) } } if (to == NUL) { - // TODO(vim): Need to use errbuf argument for this error message - // and return it. - semsg(_("E357: 'langmap': Matching character missing for %s"), - transchar(from)); - return NULL; + snprintf(args->os_errbuf, args->os_errbuflen, + _("E357: 'langmap': Matching character missing for %s"), + transchar(from)); + return args->os_errbuf; } if (from >= 256) { @@ -2456,10 +2455,10 @@ const char *did_set_langmap(optset_T *args FUNC_ATTR_UNUSED) p = p2; if (p[0] != NUL) { if (p[0] != ',') { - // TODO(vim): Need to use errbuf argument for this error - // message and return it. - semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p); - return NULL; + snprintf(args->os_errbuf, args->os_errbuflen, + _("E358: 'langmap': Extra characters after semicolon: %s"), + p); + return args->os_errbuf; } p++; } -- cgit From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- src/nvim/mapping.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index c1d02e89b8..c5449bd66e 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -65,6 +65,17 @@ static mapblock_T *(maphash[MAX_MAPHASH]) = { 0 }; # include "mapping.c.generated.h" #endif +static const char e_global_abbreviation_already_exists_for_str[] + = N_("E224: Global abbreviation already exists for %s"); +static const char e_global_mapping_already_exists_for_str[] + = N_("E225: Global mapping already exists for %s"); +static const char e_abbreviation_already_exists_for_str[] + = N_("E226: Abbreviation already exists for %s"); +static const char e_mapping_already_exists_for_str[] + = N_("E227: Mapping already exists for %s"); +static const char e_entries_missing_in_mapset_dict_argument[] + = N_("E460: Entries missing in mapset() dict argument"); + /// Get the start of the hashed map list for "state" and first character "c". mapblock_T *get_maphash_list(int state, int c) { @@ -645,10 +656,9 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, && mp->m_keylen == len && strncmp(mp->m_keys, lhs, (size_t)len) == 0) { if (is_abbrev) { - semsg(_("E224: global abbreviation already exists for %s"), - mp->m_keys); + semsg(_(e_global_abbreviation_already_exists_for_str), mp->m_keys); } else { - semsg(_("E225: global mapping already exists for %s"), mp->m_keys); + semsg(_(e_global_mapping_already_exists_for_str), mp->m_keys); } retval = 5; goto theend; @@ -761,9 +771,9 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, break; } else if (args->unique) { if (is_abbrev) { - semsg(_("E226: abbreviation already exists for %s"), p); + semsg(_(e_abbreviation_already_exists_for_str), p); } else { - semsg(_("E227: mapping already exists for %s"), p); + semsg(_(e_mapping_already_exists_for_str), p); } retval = 5; goto theend; @@ -2226,7 +2236,7 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) api_free_object(callback_obj); } if (lhs == NULL || lhsraw == NULL || orig_rhs == NULL) { - emsg(_("E460: entries missing in mapset() dict argument")); + emsg(_(e_entries_missing_in_mapset_dict_argument)); api_free_luaref(rhs_lua); return; } -- cgit From cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 23 May 2023 14:25:10 +0600 Subject: refactor(api): new helper macros Adds new API helper macros `CSTR_AS_OBJ()`, `STATIC_CSTR_AS_OBJ()`, and `STATIC_CSTR_TO_OBJ()`, which cleans up a lot of the current code. These macros will also be used extensively in the upcoming option refactor PRs because then API Objects will be used to get/set options. This PR also modifies pre-existing code to use old API helper macros like `CSTR_TO_OBJ()` to make them cleaner. --- src/nvim/mapping.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index c5449bd66e..e40e67cead 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2096,13 +2096,13 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs : cstr_as_string(str2special_save(mp->m_str, false, true)))); } if (mp->m_desc != NULL) { - PUT(dict, "desc", STRING_OBJ(cstr_to_string(mp->m_desc))); + PUT(dict, "desc", CSTR_TO_OBJ(mp->m_desc)); } - PUT(dict, "lhs", STRING_OBJ(cstr_as_string(lhs))); - PUT(dict, "lhsraw", STRING_OBJ(cstr_to_string(mp->m_keys))); + PUT(dict, "lhs", CSTR_AS_OBJ(lhs)); + PUT(dict, "lhsraw", CSTR_TO_OBJ(mp->m_keys)); if (lhsrawalt != NULL) { // Also add the value for the simplified entry. - PUT(dict, "lhsrawalt", STRING_OBJ(cstr_to_string(lhsrawalt))); + PUT(dict, "lhsrawalt", CSTR_TO_OBJ(lhsrawalt)); } PUT(dict, "noremap", INTEGER_OBJ(noremap_value)); PUT(dict, "script", INTEGER_OBJ(mp->m_noremap == REMAP_SCRIPT ? 1 : 0)); @@ -2115,7 +2115,7 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs if (mp->m_replace_keycodes) { PUT(dict, "replace_keycodes", INTEGER_OBJ(1)); } - PUT(dict, "mode", STRING_OBJ(cstr_as_string(mapmode))); + PUT(dict, "mode", CSTR_AS_OBJ(mapmode)); return dict; } -- cgit From 42bbc4fabcf948ac6b8798b8992bcba1fc1d3e59 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 28 May 2023 12:09:52 +0200 Subject: feat(api): support abbreviations in nvim_set_keymap closes #19198 --- src/nvim/mapping.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index e40e67cead..d7747ee291 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2603,13 +2603,21 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod goto fail_and_free; } - if (mode.size > 1) { + bool is_abbrev = false; + if (mode.size > 2) { api_set_error(err, kErrorTypeValidation, "Shortname is too long: %s", mode.data); goto fail_and_free; + } else if (mode.size == 2) { + if ((mode.data[0] != '!' && mode.data[0] != 'i' && mode.data[0] != 'c') + || mode.data[1] != 'a') { + api_set_error(err, kErrorTypeValidation, "Shortname is too long: %s", mode.data); + goto fail_and_free; + } + is_abbrev = true; } int mode_val; // integer value of the mapping mode, to be passed to do_map() char *p = (mode.size) ? mode.data : "m"; - if (strncmp(p, "!", 2) == 0) { + if (*p == '!') { mode_val = get_map_mode(&p, true); // mapmode-ic } else { mode_val = get_map_mode(&p, false); @@ -2654,7 +2662,7 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod maptype_val = MAPTYPE_NOREMAP; } - switch (buf_do_map(maptype_val, &parsed_args, mode_val, 0, target_buf)) { + switch (buf_do_map(maptype_val, &parsed_args, mode_val, is_abbrev, target_buf)) { case 0: break; case 1: -- cgit From 7bc93e0e2f246dd78026a3472d929a0fe450f70d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 1 Aug 2023 14:01:19 +0200 Subject: refactor(api): use typed keysets Initially this is just for geting rid of boilerplate, but eventually the types could get exposed as metadata --- src/nvim/mapping.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index d7747ee291..0cb94e6f5b 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2558,26 +2558,22 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod const sctx_T save_current_sctx = api_set_sctx(channel_id); - if (opts != NULL && opts->callback.type == kObjectTypeLuaRef) { - lua_funcref = opts->callback.data.luaref; - opts->callback.data.luaref = LUA_NOREF; - } MapArguments parsed_args = MAP_ARGUMENTS_INIT; if (opts) { -#define KEY_TO_BOOL(name) \ - parsed_args.name = api_object_to_bool(opts->name, #name, false, err); \ - if (ERROR_SET(err)) { \ - goto fail_and_free; \ - } - - KEY_TO_BOOL(nowait); - KEY_TO_BOOL(noremap); - KEY_TO_BOOL(silent); - KEY_TO_BOOL(script); - KEY_TO_BOOL(expr); - KEY_TO_BOOL(unique); - KEY_TO_BOOL(replace_keycodes); -#undef KEY_TO_BOOL + parsed_args.nowait = opts->nowait; + parsed_args.noremap = opts->noremap; + parsed_args.silent = opts->silent; + parsed_args.script = opts->script; + parsed_args.expr = opts->expr; + parsed_args.unique = opts->unique; + parsed_args.replace_keycodes = opts->replace_keycodes; + if (HAS_KEY(opts, keymap, callback)) { + lua_funcref = opts->callback; + opts->callback = LUA_NOREF; + } + if (HAS_KEY(opts, keymap, desc)) { + parsed_args.desc = string_to_cstr(opts->desc); + } } parsed_args.buffer = !global; @@ -2593,11 +2589,6 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod goto fail_and_free; } - if (opts != NULL && opts->desc.type == kObjectTypeString) { - parsed_args.desc = string_to_cstr(opts->desc.data.string); - } else { - parsed_args.desc = NULL; - } if (parsed_args.lhs_len > MAXMAPLEN || parsed_args.alt_lhs_len > MAXMAPLEN) { api_set_error(err, kErrorTypeValidation, "LHS exceeds maximum map length: %s", lhs.data); goto fail_and_free; -- cgit From 713311be62db5c5453bcd0a7f1dbed8d1d1add15 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Aug 2023 06:08:07 +0800 Subject: vim-patch:9.0.1687: mapset() not properly handling script ID (#24666) Problem: mapset() not properly handling script ID Solution: replace_termcodes() may accept a script ID closes: vim/vim#12699 closes: vim/vim#12697 https://github.com/vim/vim/commit/7e0bae024d4c1673cff31763227ad52b936fa56f --- src/nvim/mapping.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 0cb94e6f5b..f2732184db 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -279,16 +279,16 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs bool did_simplify = false; const int flags = REPTERM_FROM_PART | REPTERM_DO_LT; char *bufarg = lhs_buf; - char *replaced = replace_termcodes(orig_lhs, orig_lhs_len, &bufarg, flags, &did_simplify, - cpo_flags); + char *replaced = replace_termcodes(orig_lhs, orig_lhs_len, &bufarg, 0, + flags, &did_simplify, cpo_flags); if (replaced == NULL) { return false; } mapargs->lhs_len = strlen(replaced); xstrlcpy(mapargs->lhs, replaced, sizeof(mapargs->lhs)); if (did_simplify) { - replaced = replace_termcodes(orig_lhs, orig_lhs_len, &bufarg, flags | REPTERM_NO_SIMPLIFY, - NULL, cpo_flags); + replaced = replace_termcodes(orig_lhs, orig_lhs_len, &bufarg, 0, + flags | REPTERM_NO_SIMPLIFY, NULL, cpo_flags); if (replaced == NULL) { return false; } @@ -298,14 +298,15 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs mapargs->alt_lhs_len = 0; } - set_maparg_rhs(orig_rhs, orig_rhs_len, rhs_lua, cpo_flags, mapargs); + set_maparg_rhs(orig_rhs, orig_rhs_len, rhs_lua, 0, cpo_flags, mapargs); return true; } /// @see set_maparg_lhs_rhs static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len, - const LuaRef rhs_lua, const int cpo_flags, MapArguments *const mapargs) + const LuaRef rhs_lua, const scid_T sid, const int cpo_flags, + MapArguments *const mapargs) { mapargs->rhs_lua = rhs_lua; @@ -319,8 +320,8 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len mapargs->rhs_is_noop = true; } else { char *rhs_buf = NULL; - char *replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, REPTERM_DO_LT, NULL, - cpo_flags); + char *replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, sid, + REPTERM_DO_LT, NULL, cpo_flags); mapargs->rhs_len = strlen(replaced); // NB: replace_termcodes may produce an empty string even if orig_rhs is non-empty // (e.g. a single ^V, see :h map-empty-rhs) @@ -1079,9 +1080,8 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo int retval; char *buf = NULL; - const char *const rhs = replace_termcodes(str, strlen(str), - &buf, REPTERM_DO_LT, - NULL, CPO_TO_CPO_FLAGS); + const char *const rhs = replace_termcodes(str, strlen(str), &buf, 0, + REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); #define MAPMODE(mode, modechars, chr, modeflags) \ do { \ @@ -1657,7 +1657,7 @@ char *eval_map_expr(mapblock_T *mp, int c) char *res = NULL; if (replace_keycodes) { - replace_termcodes(p, strlen(p), &res, REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); + replace_termcodes(p, strlen(p), &res, 0, REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); } else { // Escape K_SPECIAL in the result to be able to use the string as typeahead. res = vim_strsave_escape_ks(p); @@ -2157,8 +2157,8 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) const int flags = REPTERM_FROM_PART | REPTERM_DO_LT; const int mode = get_map_mode((char **)&which, 0); - char *keys_simplified = replace_termcodes(keys, strlen(keys), &keys_buf, flags, &did_simplify, - CPO_TO_CPO_FLAGS); + char *keys_simplified = replace_termcodes(keys, strlen(keys), &keys_buf, 0, + flags, &did_simplify, CPO_TO_CPO_FLAGS); mapblock_T *mp = NULL; int buffer_local; LuaRef rhs_lua; @@ -2167,10 +2167,8 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) if (did_simplify) { // When the lhs is being simplified the not-simplified keys are // preferred for printing, like in do_map(). - (void)replace_termcodes(keys, - strlen(keys), - &alt_keys_buf, flags | REPTERM_NO_SIMPLIFY, NULL, - CPO_TO_CPO_FLAGS); + (void)replace_termcodes(keys, strlen(keys), &alt_keys_buf, 0, + flags | REPTERM_NO_SIMPLIFY, NULL, CPO_TO_CPO_FLAGS); rhs = check_map(alt_keys_buf, mode, exact, false, abbr, &mp, &buffer_local, &rhs_lua); } @@ -2252,12 +2250,13 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) .replace_keycodes = tv_dict_get_number(d, "replace_keycodes") != 0, .desc = tv_dict_get_string(d, "desc", false), }; - set_maparg_rhs(orig_rhs, strlen(orig_rhs), rhs_lua, CPO_TO_CPO_FLAGS, &args); scid_T sid = (scid_T)tv_dict_get_number(d, "sid"); linenr_T lnum = (linenr_T)tv_dict_get_number(d, "lnum"); bool buffer = tv_dict_get_number(d, "buffer") != 0; // mode from the dict is not used + set_maparg_rhs(orig_rhs, strlen(orig_rhs), rhs_lua, sid, CPO_TO_CPO_FLAGS, &args); + mapblock_T **map_table = buffer ? curbuf->b_maphash : maphash; mapblock_T **abbr_table = buffer ? &curbuf->b_first_abbr : &first_abbr; -- cgit From 1635c9e75e21e07c4331cf983e14a11c7e09b119 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 26 Aug 2023 11:13:20 +0800 Subject: refactor: move some structs out of buffer_defs.h (#24878) --- src/nvim/mapping.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index f2732184db..ab528f8865 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -61,6 +61,48 @@ static mapblock_T *(maphash[MAX_MAPHASH]) = { 0 }; (MODE_NORMAL | MODE_VISUAL | MODE_SELECT | \ MODE_OP_PENDING | MODE_TERMINAL)) ? (c1) : ((c1) ^ 0x80)) +/// All possible |:map-arguments| usable in a |:map| command. +/// +/// The argument has no effect on mappings and is excluded from this +/// struct declaration. |:noremap| is included, since it behaves like a map +/// argument when used in a mapping. +/// +/// @see mapblock_T +struct map_arguments { + bool buffer; + bool expr; + bool noremap; + bool nowait; + bool script; + bool silent; + bool unique; + bool replace_keycodes; + + /// The {lhs} of the mapping. + /// + /// vim limits this to MAXMAPLEN characters, allowing us to use a static + /// buffer. Setting lhs_len to a value larger than MAXMAPLEN can signal + /// that {lhs} was too long and truncated. + char lhs[MAXMAPLEN + 1]; + size_t lhs_len; + + /// Unsimplifed {lhs} of the mapping. If no simplification has been done then alt_lhs_len is 0. + char alt_lhs[MAXMAPLEN + 1]; + size_t alt_lhs_len; + + char *rhs; /// The {rhs} of the mapping. + size_t rhs_len; + LuaRef rhs_lua; /// lua function as {rhs} + bool rhs_is_noop; /// True when the {rhs} should be . + + char *orig_rhs; /// The original text of the {rhs}. + size_t orig_rhs_len; + char *desc; /// map description +}; +typedef struct map_arguments MapArguments; +#define MAP_ARGUMENTS_INIT { false, false, false, false, false, false, false, false, \ + { 0 }, 0, { 0 }, 0, NULL, 0, LUA_NOREF, false, NULL, 0, NULL } + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "mapping.c.generated.h" #endif -- cgit From 091b57d766a48768ca97240a0ec8f63d2c1aaac0 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 16 Sep 2023 10:52:42 +0100 Subject: refactor(mapping.c): reduce scope of locals --- src/nvim/mapping.c | 158 +++++++++++++++++++---------------------------------- 1 file changed, 55 insertions(+), 103 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index ab528f8865..35a728314c 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -148,9 +148,7 @@ mapblock_T *get_maphash(int index, buf_T *buf) /// "mpp" is a pointer to the m_next field of the PREVIOUS entry! static void mapblock_free(mapblock_T **mpp) { - mapblock_T *mp; - - mp = *mpp; + mapblock_T *mp = *mpp; xfree(mp->m_keys); if (!mp->m_simplified) { NLUA_CLEAR_REF(mp->m_luaref); @@ -212,8 +210,6 @@ static char *map_mode_to_chars(int mode) /// @param local true for buffer-local map static void showmap(mapblock_T *mp, bool local) { - size_t len = 1; - if (message_filtered(mp->m_keys) && message_filtered(mp->m_str) && (mp->m_desc == NULL || message_filtered(mp->m_desc))) { return; @@ -226,12 +222,10 @@ static void showmap(mapblock_T *mp, bool local) } } - { - char *const mapchars = map_mode_to_chars(mp->m_mode); - msg_puts(mapchars); - len = strlen(mapchars); - xfree(mapchars); - } + char *const mapchars = map_mode_to_chars(mp->m_mode); + msg_puts(mapchars); + size_t len = strlen(mapchars); + xfree(mapchars); while (++len <= 3) { msg_putchar(' '); @@ -572,33 +566,16 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, /// @param buf Target Buffer static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T *buf) { - mapblock_T *mp, **mpp; - const char *p; - int n; int retval = 0; - mapblock_T **abbr_table; - mapblock_T **map_table; - int noremap; - map_table = maphash; - abbr_table = &first_abbr; + // If was given, we'll be searching through the buffer's + // mappings/abbreviations, not the globals. + mapblock_T **map_table = args->buffer ? buf->b_maphash : maphash; + mapblock_T **abbr_table = args->buffer ? &buf->b_first_abbr : &first_abbr; // For ":noremap" don't remap, otherwise do remap. - if (maptype == MAPTYPE_NOREMAP) { - noremap = REMAP_NONE; - } else { - noremap = REMAP_YES; - } - - if (args->buffer) { - // If was given, we'll be searching through the buffer's - // mappings/abbreviations, not the globals. - map_table = buf->b_maphash; - abbr_table = &buf->b_first_abbr; - } - if (args->script) { - noremap = REMAP_SCRIPT; - } + int noremap = args->script ? REMAP_SCRIPT : + maptype == MAPTYPE_NOREMAP ? REMAP_NONE : REMAP_YES; const bool has_lhs = (args->lhs[0] != NUL); const bool has_rhs = args->rhs_lua != LUA_NOREF || (args->rhs[0] != NUL) || args->rhs_is_noop; @@ -648,8 +625,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, const int first = vim_iswordp(lhs); int last = first; - p = lhs + utfc_ptr2len(lhs); - n = 1; + const char *p = lhs + utfc_ptr2len(lhs); + int n = 1; while (p < lhs + len) { n++; // nr of (multi-byte) chars last = vim_iswordp(p); // type of last char @@ -685,6 +662,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, && maptype != MAPTYPE_UNMAP) { // need to loop over all global hash lists for (int hash = 0; hash < 256 && !got_int; hash++) { + mapblock_T *mp; if (is_abbrev) { if (hash != 0) { // there is only one abbreviation list break; @@ -714,6 +692,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, if (map_table != buf->b_maphash && !has_rhs && maptype != MAPTYPE_UNMAP) { // need to loop over all global hash lists for (int hash = 0; hash < 256 && !got_int; hash++) { + mapblock_T *mp; if (is_abbrev) { if (hash != 0) { // there is only one abbreviation list break; @@ -729,7 +708,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, showmap(mp, true); did_local = true; } else { - n = mp->m_keylen; + int n = mp->m_keylen; if (strncmp(mp->m_keys, lhs, (size_t)(n < len ? n : len)) == 0) { showmap(mp, true); did_local = true; @@ -759,8 +738,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, hash_end = 256; } for (int hash = hash_start; hash < hash_end && !got_int; hash++) { - mpp = is_abbrev ? abbr_table : &(map_table[hash]); - for (mp = *mpp; mp != NULL && !got_int; mp = *mpp) { + mapblock_T **mpp = is_abbrev ? abbr_table : &(map_table[hash]); + for (mapblock_T *mp = *mpp; mp != NULL && !got_int; mp = *mpp) { if ((mp->m_mode & mode) == 0) { // skip entries with wrong mode mpp = &(mp->m_next); @@ -772,6 +751,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, did_it = true; } } else { // do we have a match? + int n; + const char *p; if (round) { // second round: Try unmap "rhs" string n = (int)strlen(mp->m_str); p = mp->m_str; @@ -994,12 +975,10 @@ free_and_return: /// Get the mapping mode from the command name. static int get_map_mode(char **cmdp, bool forceit) { - char *p; - int modec; int mode; - p = *cmdp; - modec = (uint8_t)(*p++); + char *p = *cmdp; + int modec = (uint8_t)(*p++); if (modec == 'i') { mode = MODE_INSERT; // :imap } else if (modec == 'l') { @@ -1036,16 +1015,13 @@ static int get_map_mode(char **cmdp, bool forceit) /// This function used to be called map_clear(). static void do_mapclear(char *cmdp, char *arg, int forceit, int abbr) { - int mode; - int local; - - local = (strcmp(arg, "") == 0); + bool local = strcmp(arg, "") == 0; if (!local && *arg != NUL) { emsg(_(e_invarg)); return; } - mode = get_map_mode(&cmdp, forceit); + int mode = get_map_mode(&cmdp, forceit); map_clear_mode(curbuf, mode, local, abbr); } @@ -1057,11 +1033,8 @@ static void do_mapclear(char *cmdp, char *arg, int forceit, int abbr) /// @param abbr true for abbreviations void map_clear_mode(buf_T *buf, int mode, bool local, bool abbr) { - mapblock_T *mp, **mpp; - int hash; - int new_hash; - - for (hash = 0; hash < 256; hash++) { + for (int hash = 0; hash < 256; hash++) { + mapblock_T **mpp; if (abbr) { if (hash > 0) { // there is only one abbrlist break; @@ -1079,7 +1052,7 @@ void map_clear_mode(buf_T *buf, int mode, bool local, bool abbr) } } while (*mpp != NULL) { - mp = *mpp; + mapblock_T *mp = *mpp; if (mp->m_mode & mode) { mp->m_mode &= ~mode; if (mp->m_mode == 0) { // entry can be deleted @@ -1087,7 +1060,7 @@ void map_clear_mode(buf_T *buf, int mode, bool local, bool abbr) continue; } // May need to put this entry into another hash list. - new_hash = MAP_HASH(mp->m_mode, (uint8_t)mp->m_keys[0]); + int new_hash = MAP_HASH(mp->m_mode, (uint8_t)mp->m_keys[0]); if (!abbr && new_hash != hash) { *mpp = mp->m_next; if (local) { @@ -1119,7 +1092,6 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { int mode = 0; - int retval; char *buf = NULL; const char *const rhs = replace_termcodes(str, strlen(str), &buf, 0, @@ -1141,7 +1113,7 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo MAPMODE(mode, modechars, 'c', MODE_CMDLINE); #undef MAPMODE - retval = map_to_exists_mode(rhs, mode, abbr); + int retval = map_to_exists_mode(rhs, mode, abbr); xfree(buf); return retval; @@ -1159,13 +1131,12 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo /// @return true if there is at least one mapping with given parameters. int map_to_exists_mode(const char *const rhs, const int mode, const bool abbr) { - mapblock_T *mp; - int hash; bool exp_buffer = false; // Do it twice: once for global maps and once for local maps. while (true) { - for (hash = 0; hash < 256; hash++) { + for (int hash = 0; hash < 256; hash++) { + mapblock_T *mp; if (abbr) { if (hash > 0) { // There is only one abbr list. break; @@ -1486,10 +1457,7 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat // Return true if there is an abbreviation, false if not. bool check_abbr(int c, char *ptr, int col, int mincol) { - int scol; // starting column of the abbr. uint8_t tb[MB_MAXBYTES + 4]; - mapblock_T *mp; - mapblock_T *mp2; int clen = 0; // length in characters if (typebuf.tb_no_abbr_cnt) { // abbrev. are not recursive @@ -1509,6 +1477,8 @@ bool check_abbr(int c, char *ptr, int col, int mincol) return false; } + int scol; // starting column of the abbr. + { bool is_id = true; bool vim_abbr; @@ -1539,8 +1509,8 @@ bool check_abbr(int c, char *ptr, int col, int mincol) if (scol < col) { // there is a word in front of the cursor ptr += scol; int len = col - scol; - mp = curbuf->b_first_abbr; - mp2 = first_abbr; + mapblock_T *mp = curbuf->b_first_abbr; + mapblock_T *mp2 = first_abbr; if (mp == NULL) { mp = mp2; mp2 = NULL; @@ -1715,18 +1685,13 @@ char *eval_map_expr(mapblock_T *mp, int c) /// @param buf buffer for local mappings or NULL int makemap(FILE *fd, buf_T *buf) { - mapblock_T *mp; - char c1, c2, c3; - char *p; - char *cmd; - int abbr; - int hash; bool did_cpo = false; // Do the loop twice: Once for mappings, once for abbreviations. // Then loop over all map hash lists. - for (abbr = 0; abbr < 2; abbr++) { - for (hash = 0; hash < 256; hash++) { + for (int abbr = 0; abbr < 2; abbr++) { + for (int hash = 0; hash < 256; hash++) { + mapblock_T *mp; if (abbr) { if (hash > 0) { // there is only one abbr list break; @@ -1755,6 +1720,7 @@ int makemap(FILE *fd, buf_T *buf) if (mp->m_luaref != LUA_NOREF) { continue; } + char *p; for (p = mp->m_str; *p != NUL; p++) { if ((uint8_t)p[0] == K_SPECIAL && (uint8_t)p[1] == KS_EXTRA && p[2] == KE_SNR) { @@ -1768,14 +1734,10 @@ int makemap(FILE *fd, buf_T *buf) // It's possible to create a mapping and then ":unmap" certain // modes. We recreate this here by mapping the individual // modes, which requires up to three of them. - c1 = NUL; - c2 = NUL; - c3 = NUL; - if (abbr) { - cmd = "abbr"; - } else { - cmd = "map"; - } + char c1 = NUL; + char c2 = NUL; + char c3 = NUL; + char *cmd = abbr ? "abbr" : "map"; switch (mp->m_mode) { case MODE_NORMAL | MODE_VISUAL | MODE_SELECT | MODE_OP_PENDING: break; @@ -1929,7 +1891,6 @@ int makemap(FILE *fd, buf_T *buf) int put_escstr(FILE *fd, char *strstart, int what) { uint8_t *str = (uint8_t *)strstart; - int c; // :map xx if (*str == NUL && what == 1) { @@ -1953,7 +1914,7 @@ int put_escstr(FILE *fd, char *strstart, int what) continue; } - c = *str; + int c = *str; // Special key codes have to be translated to be able to make sense // when they are read back. if (c == K_SPECIAL && what != 2) { @@ -2030,14 +1991,13 @@ int put_escstr(FILE *fd, char *strstart, int what) char *check_map(char *keys, int mode, int exact, int ign_mod, int abbr, mapblock_T **mp_ptr, int *local_ptr, int *rhs_lua) { - int len, minlen; - mapblock_T *mp; *rhs_lua = LUA_NOREF; - len = (int)strlen(keys); + int len = (int)strlen(keys); for (int local = 1; local >= 0; local--) { // loop over all hash lists for (int hash = 0; hash < 256; hash++) { + mapblock_T *mp; if (abbr) { if (hash > 0) { // there is only one list. break; @@ -2062,7 +2022,7 @@ char *check_map(char *keys, int mode, int exact, int ign_mod, int abbr, mapblock s += 3; keylen -= 3; } - minlen = keylen < len ? keylen : len; + int minlen = keylen < len ? keylen : len; if (strncmp(s, keys, (size_t)minlen) == 0) { if (mp_ptr != NULL) { *mp_ptr = mp; @@ -2097,11 +2057,7 @@ void f_hasmapto(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } - if (map_to_exists(name, mode, abbr)) { - rettv->vval.v_number = true; - } else { - rettv->vval.v_number = false; - } + rettv->vval.v_number = map_to_exists(name, mode, abbr); } /// Fill a Dictionary with all applicable maparg() like dictionaries @@ -2439,14 +2395,11 @@ void langmap_init(void) /// changed at any time! const char *did_set_langmap(optset_T *args) { - char *p; - char *p2; - int from, to; - - ga_clear(&langmap_mapga); // clear the previous map first - langmap_init(); // back to one-to-one map + ga_clear(&langmap_mapga); // clear the previous map first + langmap_init(); // back to one-to-one map - for (p = p_langmap; p[0] != NUL;) { + for (char *p = p_langmap; p[0] != NUL;) { + char *p2; for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';'; MB_PTR_ADV(p2)) { if (p2[0] == '\\' && p2[1] != NUL) { @@ -2466,8 +2419,8 @@ const char *did_set_langmap(optset_T *args) if (p[0] == '\\' && p[1] != NUL) { p++; } - from = utf_ptr2char(p); - to = NUL; + int from = utf_ptr2char(p); + int to = NUL; if (p2 == NULL) { MB_PTR_ADV(p); if (p[0] != ',') { @@ -2524,9 +2477,8 @@ const char *did_set_langmap(optset_T *args) static void do_exmap(exarg_T *eap, int isabbrev) { - int mode; char *cmdp = eap->cmd; - mode = get_map_mode(&cmdp, eap->forceit || isabbrev); + int mode = get_map_mode(&cmdp, eap->forceit || isabbrev); switch (do_map((*cmdp == 'n') ? MAPTYPE_NOREMAP : (*cmdp == 'u') ? MAPTYPE_UNMAP : MAPTYPE_MAP, -- cgit From f91cd31d7d9d70006e0000592637d5d997eab52c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 21:46:39 +0200 Subject: refactor(messages): fold msg_outtrans_attr into msg_outtrans problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 35a728314c..f2aeedd430 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2504,7 +2504,7 @@ void ex_map(exarg_T *eap) // If we are in a secure mode we print the mappings for security reasons. if (secure) { secure = 2; - msg_outtrans(eap->cmd); + msg_outtrans(eap->cmd, 0); msg_putchar('\n'); } do_exmap(eap, false); -- cgit From b85f1dafc7c0a19704135617454f1c66f41202c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: refactor(messages): fold msg_attr into msg problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/mapping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index f2aeedd430..a19dbe78c5 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -877,9 +877,9 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, // print entries if (!did_it && !did_local) { if (is_abbrev) { - msg(_("No abbreviation found")); + msg(_("No abbreviation found"), 0); } else { - msg(_("No mapping found")); + msg(_("No mapping found"), 0); } } goto theend; // listing finished -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/mapping.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index a19dbe78c5..cbb51961d4 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -4,14 +4,16 @@ // mapping.c: Code for mappings and abbreviations. #include -#include #include #include #include +#include +#include #include #include #include +#include "nvim/api/keysets.h" #include "nvim/api/private/converter.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" @@ -39,9 +41,11 @@ #include "nvim/option_defs.h" #include "nvim/pos.h" #include "nvim/regexp.h" +#include "nvim/regexp_defs.h" #include "nvim/runtime.h" #include "nvim/search.h" #include "nvim/strings.h" +#include "nvim/types.h" #include "nvim/vim.h" /// List used for abbreviations. -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/mapping.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index cbb51961d4..1fb91d85b4 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -39,6 +39,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/pos.h" #include "nvim/regexp.h" #include "nvim/regexp_defs.h" -- cgit From 09a17f91d0d362c6e58bfdbe3ccdeacffb0b44b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 2 Oct 2023 10:45:33 +0800 Subject: refactor: move cmdline completion types to cmdexpand_defs.h (#25465) --- src/nvim/mapping.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 1fb91d85b4..2cfa264754 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -21,6 +21,7 @@ #include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cmdexpand.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" -- cgit From 8e932480f61d6101bf8bea1abc07ed93826221fd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/mapping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 2cfa264754..da98f5e6c0 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2074,7 +2074,7 @@ void f_hasmapto(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// /// @return A Dictionary. static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhsrawalt, - const long buffer_value, const bool compatible) + const int buffer_value, const bool compatible) FUNC_ATTR_NONNULL_ARG(1) { Dictionary dict = ARRAY_DICT_INIT; @@ -2694,7 +2694,7 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) int int_mode = get_map_mode(&p, 0); // Determine the desired buffer value - long buffer_value = (buf == NULL) ? 0 : buf->handle; + int buffer_value = (buf == NULL) ? 0 : buf->handle; for (int i = 0; i < MAX_MAPHASH; i++) { for (const mapblock_T *current_maphash = get_maphash(i, buf); -- cgit From 43b0e2752c06ec5460a417fb9a8c60856011f563 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 12:28:43 +0800 Subject: refactor(api): simplify nvim_set_keymap shortname check (#25945) --- src/nvim/mapping.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index da98f5e6c0..4435e91993 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2080,7 +2080,7 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs Dictionary dict = ARRAY_DICT_INIT; char *const lhs = str2special_save(mp->m_keys, compatible, !compatible); char *const mapmode = map_mode_to_chars(mp->m_mode); - varnumber_T noremap_value; + int noremap_value; if (compatible) { // Keep old compatible behavior @@ -2112,9 +2112,9 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs PUT(dict, "script", INTEGER_OBJ(mp->m_noremap == REMAP_SCRIPT ? 1 : 0)); PUT(dict, "expr", INTEGER_OBJ(mp->m_expr ? 1 : 0)); PUT(dict, "silent", INTEGER_OBJ(mp->m_silent ? 1 : 0)); - PUT(dict, "sid", INTEGER_OBJ((varnumber_T)mp->m_script_ctx.sc_sid)); - PUT(dict, "lnum", INTEGER_OBJ((varnumber_T)mp->m_script_ctx.sc_lnum)); - PUT(dict, "buffer", INTEGER_OBJ((varnumber_T)buffer_value)); + PUT(dict, "sid", INTEGER_OBJ(mp->m_script_ctx.sc_sid)); + PUT(dict, "lnum", INTEGER_OBJ(mp->m_script_ctx.sc_lnum)); + PUT(dict, "buffer", INTEGER_OBJ(buffer_value)); PUT(dict, "nowait", INTEGER_OBJ(mp->m_nowait ? 1 : 0)); if (mp->m_replace_keycodes) { PUT(dict, "replace_keycodes", INTEGER_OBJ(1)); @@ -2593,30 +2593,21 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod goto fail_and_free; } - bool is_abbrev = false; - if (mode.size > 2) { - api_set_error(err, kErrorTypeValidation, "Shortname is too long: %s", mode.data); + char *p = mode.size > 0 ? mode.data : "m"; + bool forceit = *p == '!'; + // integer value of the mapping mode, to be passed to do_map() + int mode_val = get_map_mode(&p, forceit); + if (forceit) { + assert(p == mode.data); + p++; + } + bool is_abbrev = (mode_val & (MODE_INSERT | MODE_CMDLINE)) != 0 && *p == 'a'; + if (is_abbrev) { + p++; + } + if (mode.size > 0 && (size_t)(p - mode.data) != mode.size) { + api_set_error(err, kErrorTypeValidation, "Invalid mode shortname: \"%s\"", mode.data); goto fail_and_free; - } else if (mode.size == 2) { - if ((mode.data[0] != '!' && mode.data[0] != 'i' && mode.data[0] != 'c') - || mode.data[1] != 'a') { - api_set_error(err, kErrorTypeValidation, "Shortname is too long: %s", mode.data); - goto fail_and_free; - } - is_abbrev = true; - } - int mode_val; // integer value of the mapping mode, to be passed to do_map() - char *p = (mode.size) ? mode.data : "m"; - if (*p == '!') { - mode_val = get_map_mode(&p, true); // mapmode-ic - } else { - mode_val = get_map_mode(&p, false); - if (mode_val == (MODE_VISUAL | MODE_SELECT | MODE_NORMAL | MODE_OP_PENDING) && mode.size > 0) { - // get_map_mode() treats unrecognized mode shortnames as ":map". - // This is an error unless the given shortname was empty string "". - api_set_error(err, kErrorTypeValidation, "Invalid mode shortname: \"%s\"", p); - goto fail_and_free; - } } if (parsed_args.lhs_len == 0) { -- cgit From a4b80c71eae09a5f6f76bce46be46efd247c7223 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 15:17:53 +0800 Subject: vim-patch:8.2.4140: maparg() does not indicate the type of script Problem: maparg() does not indicate the type of script where it was defined. Solution: Add "scriptversion". https://github.com/vim/vim/commit/a9528b39a666dbaa026320f73bae4b1628a7fe51 Co-authored-by: Bram Moolenaar --- src/nvim/mapping.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 4435e91993..6786b5efe9 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2113,6 +2113,7 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs PUT(dict, "expr", INTEGER_OBJ(mp->m_expr ? 1 : 0)); PUT(dict, "silent", INTEGER_OBJ(mp->m_silent ? 1 : 0)); PUT(dict, "sid", INTEGER_OBJ(mp->m_script_ctx.sc_sid)); + PUT(dict, "scriptversion", INTEGER_OBJ(1)); PUT(dict, "lnum", INTEGER_OBJ(mp->m_script_ctx.sc_lnum)); PUT(dict, "buffer", INTEGER_OBJ(buffer_value)); PUT(dict, "nowait", INTEGER_OBJ(mp->m_nowait ? 1 : 0)); -- cgit From 2dfcd5a22b8f26091aa7398fdb8b0ea70ed7b28d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 18:16:49 +0800 Subject: vim-patch:8.2.4820: not simple programmatic way to find a specific mapping Problem: Not simple programmatic way to find a specific mapping. Solution: Add getmappings(). (Ernie Rael, closes vim/vim#10273) https://github.com/vim/vim/commit/659c240cf769925ff432b88df8719e7ace4629b0 Co-authored-by: Ernie Rael --- src/nvim/mapping.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 6786b5efe9..2cc469feec 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2281,6 +2281,49 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) sid, lnum, false); } +/// "maplist()" function +void f_getmappings(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + const int flags = REPTERM_FROM_PART | REPTERM_DO_LT; + + tv_list_alloc_ret(rettv, kListLenUnknown); + + // Do it twice: once for global maps and once for local maps. + for (int buffer_local = 0; buffer_local <= 1; buffer_local++) { + for (int hash = 0; hash < 256; hash++) { + mapblock_T *mp; + if (buffer_local) { + mp = curbuf->b_maphash[hash]; + } else { + mp = maphash[hash]; + } + for (; mp; mp = mp->m_next) { + if (mp->m_simplified) { + continue; + } + + char *keys_buf = NULL; + bool did_simplify = false; + + char *lhs = str2special_save(mp->m_keys, true, false); + (void)replace_termcodes(lhs, strlen(lhs), &keys_buf, 0, flags, &did_simplify, + CPO_TO_CPO_FLAGS); + xfree(lhs); + + Dictionary dict = mapblock_fill_dict(mp, + did_simplify ? keys_buf : NULL, + buffer_local, true); + typval_T d = TV_INITIAL_VALUE; + (void)object_to_vim(DICTIONARY_OBJ(dict), &d, NULL); + assert(d.v_type == VAR_DICT); + tv_list_append_dict(rettv->vval.v_list, d.vval.v_dict); + api_free_dictionary(dict); + xfree(keys_buf); + } + } + } +} + /// "maparg()" function void f_maparg(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { -- cgit From d4dbfb092b370bced6728e07a38661a579ff5e4b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 19:36:58 +0800 Subject: vim-patch:8.2.4825: can only get a list of mappings Problem: Can only get a list of mappings. Solution: Add the optional {abbr} argument. (Ernie Rael, closes vim/vim#10277) Rename to maplist(). Rename test file. https://github.com/vim/vim/commit/09661203ecefbee6a6f09438afcff1843e9dbfb4 Co-authored-by: Ernie Rael --- src/nvim/mapping.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 2cc469feec..905e742f51 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2282,9 +2282,10 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } /// "maplist()" function -void f_getmappings(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +void f_maplist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { const int flags = REPTERM_FROM_PART | REPTERM_DO_LT; + const bool abbr = argvars[0].v_type != VAR_UNKNOWN && tv_get_bool(&argvars[0]); tv_list_alloc_ret(rettv, kListLenUnknown); @@ -2292,7 +2293,16 @@ void f_getmappings(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) for (int buffer_local = 0; buffer_local <= 1; buffer_local++) { for (int hash = 0; hash < 256; hash++) { mapblock_T *mp; - if (buffer_local) { + if (abbr) { + if (hash > 0) { // there is only one abbr list + break; + } + if (buffer_local) { + mp = curbuf->b_first_abbr; + } else { + mp = first_abbr; + } + } else if (buffer_local) { mp = curbuf->b_maphash[hash]; } else { mp = maphash[hash]; -- cgit From f748a73a357710db6094d4a428cd056f5df226a9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 19:48:50 +0800 Subject: vim-patch:8.2.4861: it is not easy to restore saved mappings Problem: It is not easy to restore saved mappings. Solution: Make mapset() accept a dict argument. (Ernie Rael, closes vim/vim#10295) https://github.com/vim/vim/commit/51d04d16f21e19d6eded98f9530d84089102f925 Co-authored-by: Ernie Rael --- src/nvim/mapping.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 12 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 905e742f51..c90c0c5529 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -123,6 +123,8 @@ static const char e_mapping_already_exists_for_str[] = N_("E227: Mapping already exists for %s"); static const char e_entries_missing_in_mapset_dict_argument[] = N_("E460: Entries missing in mapset() dict argument"); +static const char e_illegal_map_mode_string_str[] + = N_("E1276: Illegal map mode string: '%s'"); /// Get the start of the hashed map list for "state" and first character "c". mapblock_T *get_maphash_list(int state, int c) @@ -2070,11 +2072,12 @@ void f_hasmapto(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// /// @param mp The maphash that contains the mapping information /// @param buffer_value The "buffer" value +/// @param abbr True if abbreviation /// @param compatible True for compatible with old maparg() dict /// /// @return A Dictionary. static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhsrawalt, - const int buffer_value, const bool compatible) + const int buffer_value, const bool abbr, const bool compatible) FUNC_ATTR_NONNULL_ARG(1) { Dictionary dict = ARRAY_DICT_INIT; @@ -2121,6 +2124,7 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs PUT(dict, "replace_keycodes", INTEGER_OBJ(1)); } PUT(dict, "mode", CSTR_AS_OBJ(mapmode)); + PUT(dict, "abbr", INTEGER_OBJ(abbr ? 1 : 0)); return dict; } @@ -2193,7 +2197,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) if (mp != NULL && (rhs != NULL || rhs_lua != LUA_NOREF)) { Dictionary dict = mapblock_fill_dict(mp, did_simplify ? keys_simplified : NULL, - buffer_local, true); + buffer_local, abbr, true); (void)object_to_vim(DICTIONARY_OBJ(dict), rettv, NULL); api_free_dictionary(dict); } else { @@ -2206,21 +2210,99 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) xfree(alt_keys_buf); } +/// Get the mapping mode from the mode string. +/// It may contain multiple characters, eg "nox", or "!", or ' ' +/// Return 0 if there is an error. +static int get_map_mode_string(const char *const mode_string, const bool abbr) +{ + const char *p = mode_string; + const int MASK_V = MODE_VISUAL | MODE_SELECT; + const int MASK_MAP = MODE_VISUAL | MODE_SELECT | MODE_NORMAL | MODE_OP_PENDING; + const int MASK_BANG = MODE_INSERT | MODE_CMDLINE; + + if (*p == NUL) { + p = " "; // compatibility + } + int mode = 0; + int modec; + while ((modec = (uint8_t)(*p++))) { + int tmode; + switch (modec) { + case 'i': + tmode = MODE_INSERT; break; + case 'l': + tmode = MODE_LANGMAP; break; + case 'c': + tmode = MODE_CMDLINE; break; + case 'n': + tmode = MODE_NORMAL; break; + case 'x': + tmode = MODE_VISUAL; break; + case 's': + tmode = MODE_SELECT; break; + case 'o': + tmode = MODE_OP_PENDING; break; + case 't': + tmode = MODE_TERMINAL; break; + case 'v': + tmode = MASK_V; break; + case '!': + tmode = MASK_BANG; break; + case ' ': + tmode = MASK_MAP; break; + default: + return 0; // error, unknown mode character + } + mode |= tmode; + } + if ((abbr && (mode & ~MASK_BANG) != 0) + || (!abbr && (mode & (mode - 1)) != 0 // more than one bit set + && ( + // false if multiple bits set in mode and mode is fully + // contained in one mask + !(((mode & MASK_BANG) != 0 && (mode & ~MASK_BANG) == 0) + || ((mode & MASK_MAP) != 0 && (mode & ~MASK_MAP) == 0))))) { + return 0; + } + + return mode; +} + /// "mapset()" function void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { + const char *which; char buf[NUMBUFLEN]; - const char *which = tv_get_string_buf_chk(&argvars[0], buf); - if (which == NULL) { - return; + int is_abbr; + dict_T *d; + + // If first arg is a dict, then that's the only arg permitted. + const bool dict_only = argvars[0].v_type == VAR_DICT; + + if (dict_only) { + d = argvars[0].vval.v_dict; + which = tv_dict_get_string(d, "mode", false); + is_abbr = (int)tv_dict_get_bool(d, "abbr", -1); + if (which == NULL || is_abbr < 0) { + emsg(_(e_entries_missing_in_mapset_dict_argument)); + return; + } + } else { + which = tv_get_string_buf_chk(&argvars[0], buf); + if (which == NULL) { + return; + } + is_abbr = (int)tv_get_bool(&argvars[1]); + if (tv_check_for_dict_arg(argvars, 2) == FAIL) { + return; + } + d = argvars[2].vval.v_dict; } - const int mode = get_map_mode((char **)&which, 0); - const bool is_abbr = tv_get_number(&argvars[1]) != 0; - - if (tv_check_for_dict_arg(argvars, 2) == FAIL) { + const int mode = get_map_mode_string(which, is_abbr); + if (mode == 0) { + semsg(_(e_illegal_map_mode_string_str), which); return; } - dict_T *d = argvars[2].vval.v_dict; // Get the values in the same order as above in get_maparg(). char *lhs = tv_dict_get_string(d, "lhs", false); @@ -2322,7 +2404,7 @@ void f_maplist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) Dictionary dict = mapblock_fill_dict(mp, did_simplify ? keys_buf : NULL, - buffer_local, true); + buffer_local, abbr, true); typval_T d = TV_INITIAL_VALUE; (void)object_to_vim(DICTIONARY_OBJ(dict), &d, NULL); assert(d.v_type == VAR_DICT); @@ -2751,7 +2833,8 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) // Check for correct mode if (int_mode & current_maphash->m_mode) { ADD(mappings, - DICTIONARY_OBJ(mapblock_fill_dict(current_maphash, NULL, buffer_value, false))); + DICTIONARY_OBJ(mapblock_fill_dict(current_maphash, NULL, + buffer_value, false, false))); } } } -- cgit From 04d299c17014b0802c79613252e4de26da84a7c9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 9 Nov 2023 20:42:55 +0800 Subject: vim-patch:8.2.4932: not easy to filter the output of maplist() Problem: Not easy to filter the output of maplist(). Solution: Add mode_bits to the dictionary. (Ernie Rael, closes vim/vim#10356) https://github.com/vim/vim/commit/d8f5f766219273a8579947cc80b92580b6988a4b Co-authored-by: Ernie Rael --- src/nvim/mapping.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index c90c0c5529..2ee1e2e02d 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2125,6 +2125,7 @@ static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhs } PUT(dict, "mode", CSTR_AS_OBJ(mapmode)); PUT(dict, "abbr", INTEGER_OBJ(abbr ? 1 : 0)); + PUT(dict, "mode_bits", INTEGER_OBJ(mp->m_mode)); return dict; } -- cgit From cd63a9addd6e1114c3524fa041ece560550cfe7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 08:39:21 +0800 Subject: refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959) When the given length is exactly the number of bytes to copy, xmemdupz() makes the intention clearer. --- src/nvim/mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 2ee1e2e02d..b54b07fc20 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1654,7 +1654,7 @@ char *eval_map_expr(mapblock_T *mp, int c) Array args = ARRAY_DICT_INIT; Object ret = nlua_call_ref(mp->m_luaref, NULL, args, true, &err); if (ret.type == kObjectTypeString) { - p = xstrndup(ret.data.string.data, ret.data.string.size); + p = string_to_cstr(ret.data.string); } api_free_object(ret); if (err.type != kErrorTypeNone) { -- cgit From 8e58d37f2e15ac8540377148e55ed08a039aadb6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 11 Nov 2023 11:20:08 +0100 Subject: refactor: remove redundant casts --- src/nvim/mapping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index b54b07fc20..467041e310 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1339,7 +1339,7 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat bool match; int score = 0; if (!fuzzy) { - match = vim_regexec(regmatch, p, (colnr_T)0); + match = vim_regexec(regmatch, p, 0); } else { score = fuzzy_match_str(p, pat); match = (score != 0); @@ -1385,7 +1385,7 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat bool match; int score = 0; if (!fuzzy) { - match = vim_regexec(regmatch, p, (colnr_T)0); + match = vim_regexec(regmatch, p, 0); } else { score = fuzzy_match_str(p, pat); match = (score != 0); -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/mapping.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 467041e310..77fdd02a14 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // mapping.c: Code for mappings and abbreviations. #include -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/mapping.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 77fdd02a14..a758bd16bd 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -579,8 +579,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, mapblock_T **abbr_table = args->buffer ? &buf->b_first_abbr : &first_abbr; // For ":noremap" don't remap, otherwise do remap. - int noremap = args->script ? REMAP_SCRIPT : - maptype == MAPTYPE_NOREMAP ? REMAP_NONE : REMAP_YES; + int noremap = args->script ? REMAP_SCRIPT + : maptype == MAPTYPE_NOREMAP ? REMAP_NONE : REMAP_YES; const bool has_lhs = (args->lhs[0] != NUL); const bool has_rhs = args->rhs_lua != LUA_NOREF || (args->rhs[0] != NUL) || args->rhs_is_noop; @@ -1521,8 +1521,8 @@ bool check_abbr(int c, char *ptr, int col, int mincol) mp2 = NULL; } for (; mp; - mp->m_next == NULL ? (mp = mp2, mp2 = NULL) : - (mp = mp->m_next)) { + mp->m_next == NULL ? (mp = mp2, mp2 = NULL) + : (mp = mp->m_next)) { int qlen = mp->m_keylen; char *q = mp->m_keys; int match; @@ -2621,7 +2621,7 @@ static void do_exmap(exarg_T *eap, int isabbrev) int mode = get_map_mode(&cmdp, eap->forceit || isabbrev); switch (do_map((*cmdp == 'n') ? MAPTYPE_NOREMAP - : (*cmdp == 'u') ? MAPTYPE_UNMAP : MAPTYPE_MAP, + : (*cmdp == 'u') ? MAPTYPE_UNMAP : MAPTYPE_MAP, eap->arg, mode, isabbrev)) { case 1: emsg(_(e_invarg)); -- cgit From 91ef26dece6d34dbb6e1b5722ce2d3f6f7e3a6de Mon Sep 17 00:00:00 2001 From: "Bara C. Tudor" Date: Wed, 22 Nov 2023 03:50:28 +0200 Subject: fix(messages): :map output with ext_messages (#26126) --- src/nvim/mapping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index a758bd16bd..6fcade82e0 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -45,6 +45,7 @@ #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/types.h" +#include "nvim/ui.h" #include "nvim/vim.h" /// List used for abbreviations. @@ -220,7 +221,8 @@ static void showmap(mapblock_T *mp, bool local) return; } - if (msg_didout || msg_silent != 0) { + // When ext_messages is active, msg_didout is never set. + if (msg_didout || msg_silent != 0 || ui_has(kUIMessages)) { msg_putchar('\n'); if (got_int) { // 'q' typed at MORE prompt return; -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/mapping.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 6fcade82e0..0b71569c89 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -24,6 +24,7 @@ #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" #include "nvim/ex_session.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/getchar.h" #include "nvim/gettext.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 0b71569c89..94c93b436d 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -39,7 +39,7 @@ #include "nvim/message.h" #include "nvim/option_defs.h" #include "nvim/option_vars.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/regexp.h" #include "nvim/regexp_defs.h" #include "nvim/runtime.h" -- cgit From e38a05369293293b5b510b1b0014fcc2e7cb87f4 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:46:03 +0100 Subject: build(IWYU): export generated headers --- src/nvim/mapping.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 94c93b436d..0b88ebf965 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -13,6 +13,7 @@ #include "nvim/api/keysets.h" #include "nvim/api/private/converter.h" #include "nvim/api/private/defs.h" +#include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/buffer_defs.h" -- cgit From e3f735ef101d670555f44226614a5c3557053b1f Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:13:32 +0100 Subject: refactor: fix includes for api/autocmd.h --- src/nvim/mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 0b88ebf965..5d96e678a1 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -10,7 +10,7 @@ #include #include -#include "nvim/api/keysets.h" +#include "nvim/api/keysets_defs.h" #include "nvim/api/private/converter.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/dispatch.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 5d96e678a1..cac0031ff4 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -46,7 +46,7 @@ #include "nvim/runtime.h" #include "nvim/search.h" #include "nvim/strings.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/vim.h" -- cgit From 718053b7a97c4e2fbaa6077d3c9f4dc7012c8aad Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 28 Nov 2023 07:47:36 +0800 Subject: refactor: fix runtime_defs.h (#26259) --- src/nvim/mapping.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index cac0031ff4..7a39838c7e 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/mapping.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 7a39838c7e..6fc9c04194 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -14,7 +14,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/dispatch.h" #include "nvim/api/private/helpers.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cmdexpand.h" @@ -32,7 +32,7 @@ #include "nvim/highlight_defs.h" #include "nvim/keycodes.h" #include "nvim/lua/executor.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mapping.h" #include "nvim/mbyte.h" #include "nvim/memory.h" @@ -47,7 +47,7 @@ #include "nvim/strings.h" #include "nvim/types_defs.h" #include "nvim/ui.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" /// List used for abbreviations. static mapblock_T *first_abbr = NULL; // first entry in abbrlist -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/mapping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/mapping.c') diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 6fc9c04194..17593a9121 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -29,7 +29,7 @@ #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/highlight_defs.h" +#include "nvim/highlight.h" #include "nvim/keycodes.h" #include "nvim/lua/executor.h" #include "nvim/macros_defs.h" @@ -44,6 +44,7 @@ #include "nvim/regexp_defs.h" #include "nvim/runtime.h" #include "nvim/search.h" +#include "nvim/state_defs.h" #include "nvim/strings.h" #include "nvim/types_defs.h" #include "nvim/ui.h" -- cgit