diff options
Diffstat (limited to 'src/nvim/mapping.c')
-rw-r--r-- | src/nvim/mapping.c | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 342b1b0d47..333fb847f6 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -29,6 +29,7 @@ #include "nvim/message.h" #include "nvim/option.h" #include "nvim/regexp.h" +#include "nvim/runtime.h" #include "nvim/ui.h" #include "nvim/vim.h" @@ -149,8 +150,8 @@ 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((char_u *)mp->m_desc))) { + if (message_filtered((char *)mp->m_keys) && message_filtered(mp->m_str) + && (mp->m_desc == NULL || message_filtered(mp->m_desc))) { return; } @@ -202,7 +203,7 @@ static void showmap(mapblock_T *mp, bool local) } else if (mp->m_str[0] == NUL) { msg_puts_attr("<Nop>", HL_ATTR(HLF_8)); } else { - msg_outtrans_special(mp->m_str, false, 0); + msg_outtrans_special((char_u *)mp->m_str, false, 0); } if (mp->m_desc != NULL) { @@ -292,7 +293,7 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, REPTERM_DO_LT, NULL, cpo_flags); mapargs->rhs_len = STRLEN(replaced); - // XXX: replace_termcodes may produce an empty string even if orig_rhs is non-empty + // 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) mapargs->rhs_is_noop = orig_rhs_len != 0 && mapargs->rhs_len == 0; mapargs->rhs = (char_u *)replaced; @@ -333,7 +334,7 @@ static int str_to_mapargs(const char_u *strargs, bool is_unmap, MapArguments *ma { const char_u *to_parse = strargs; to_parse = (char_u *)skipwhite((char *)to_parse); - memset(mapargs, 0, sizeof(*mapargs)); + CLEAR_POINTER(mapargs); // Accept <buffer>, <nowait>, <silent>, <expr>, <script>, and <unique> in // any order. @@ -448,8 +449,8 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, } mp->m_keys = vim_strsave(keys); - mp->m_str = args->rhs; - mp->m_orig_str = args->orig_rhs; + mp->m_str = (char *)args->rhs; + mp->m_orig_str = (char *)args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!simplified) { args->rhs = NULL; @@ -469,7 +470,7 @@ static void map_add(buf_T *buf, mapblock_T **map_table, mapblock_T **abbr_table, mp->m_script_ctx.sc_lnum = lnum; } else { mp->m_script_ctx = current_sctx; - mp->m_script_ctx.sc_lnum += sourcing_lnum; + mp->m_script_ctx.sc_lnum += SOURCING_LNUM; nlua_set_sctx(&mp->m_script_ctx); } mp->m_desc = NULL; @@ -703,7 +704,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, } else { // do we have a match? if (round) { // second round: Try unmap "rhs" string n = (int)STRLEN(mp->m_str); - p = mp->m_str; + p = (char_u *)mp->m_str; } else { n = mp->m_keylen; p = mp->m_keys; @@ -760,8 +761,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, XFREE_CLEAR(mp->m_str); XFREE_CLEAR(mp->m_orig_str); } - mp->m_str = args->rhs; - mp->m_orig_str = args->orig_rhs; + mp->m_str = (char *)args->rhs; + mp->m_orig_str = (char *)args->orig_rhs; mp->m_luaref = args->rhs_lua; if (!keyround1_simplified) { args->rhs = NULL; @@ -776,7 +777,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, mp->m_expr = args->expr; mp->m_replace_keycodes = args->replace_keycodes; mp->m_script_ctx = current_sctx; - mp->m_script_ctx.sc_lnum += sourcing_lnum; + mp->m_script_ctx.sc_lnum += SOURCING_LNUM; nlua_set_sctx(&mp->m_script_ctx); if (args->desc != NULL) { mp->m_desc = xstrdup(args->desc); @@ -964,7 +965,7 @@ static int get_map_mode(char **cmdp, bool forceit) /// Clear all mappings (":mapclear") or abbreviations (":abclear"). /// "abbr" should be false for mappings, true for abbreviations. /// This function used to be called map_clear(). -static void do_mapclear(char_u *cmdp, char_u *arg, int forceit, int abbr) +static void do_mapclear(char *cmdp, char_u *arg, int forceit, int abbr) { int mode; int local; @@ -975,7 +976,7 @@ static void do_mapclear(char_u *cmdp, char_u *arg, int forceit, int abbr) return; } - mode = get_map_mode((char **)&cmdp, forceit); + mode = get_map_mode(&cmdp, forceit); map_clear_mode(curbuf, mode, local, abbr); } @@ -1051,9 +1052,9 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo int mode = 0; int retval; - char_u *buf = NULL; + char *buf = NULL; const char_u *const rhs = (char_u *)replace_termcodes(str, strlen(str), - (char **)&buf, REPTERM_DO_LT, + &buf, REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); #define MAPMODE(mode, modechars, chr, modeflags) \ @@ -1112,7 +1113,7 @@ int map_to_exists_mode(const char *const rhs, const int mode, const bool abbr) mp = maphash[hash]; } for (; mp; mp = mp->m_next) { - if ((mp->m_mode & mode) && strstr((char *)mp->m_str, rhs) != NULL) { + if ((mp->m_mode & mode) && strstr(mp->m_str, rhs) != NULL) { return true; } } @@ -1194,14 +1195,14 @@ 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_u *cmd, char_u *arg, bool forceit, bool isabbrev, +char_u *set_context_in_map_cmd(expand_T *xp, char *cmd, char_u *arg, bool forceit, bool isabbrev, bool isunmap, cmdidx_T cmdidx) { if (forceit && cmdidx != CMD_map && cmdidx != CMD_unmap) { xp->xp_context = EXPAND_NOTHING; } else { if (isunmap) { - expand_mapmodes = get_map_mode((char **)&cmd, forceit || isabbrev); + expand_mapmodes = get_map_mode(&cmd, forceit || isabbrev); } else { expand_mapmodes = MODE_INSERT | MODE_CMDLINE; if (!isabbrev) { @@ -1505,7 +1506,7 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol) if (mp->m_expr) { s = eval_map_expr(mp, c); } else { - s = mp->m_str; + s = (char_u *)mp->m_str; } if (s != NULL) { // insert the to string @@ -1541,7 +1542,7 @@ char_u *eval_map_expr(mapblock_T *mp, int c) // Remove escaping of K_SPECIAL, because "str" is in a format to be used as // typeahead. if (mp->m_luaref == LUA_NOREF) { - expr = vim_strsave(mp->m_str); + expr = vim_strsave((char_u *)mp->m_str); vim_unescape_ks(expr); } @@ -1638,7 +1639,7 @@ int makemap(FILE *fd, buf_T *buf) if (mp->m_luaref != LUA_NOREF) { continue; } - for (p = mp->m_str; *p != NUL; p++) { + for (p = (char_u *)mp->m_str; *p != NUL; p++) { if (p[0] == K_SPECIAL && p[1] == KS_EXTRA && p[2] == KE_SNR) { break; @@ -1784,7 +1785,7 @@ int makemap(FILE *fd, buf_T *buf) if (putc(' ', fd) < 0 || put_escstr(fd, mp->m_keys, 0) == FAIL || putc(' ', fd) < 0 - || put_escstr(fd, mp->m_str, 1) == FAIL + || put_escstr(fd, (char_u *)mp->m_str, 1) == FAIL || put_eol(fd) < 0) { return FAIL; } @@ -1955,7 +1956,7 @@ char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, mapb *local_ptr = local; } *rhs_lua = mp->m_luaref; - return mp->m_luaref == LUA_NOREF ? mp->m_str : NULL; + return mp->m_luaref == LUA_NOREF ? (char_u *)mp->m_str : NULL; } } } @@ -1966,7 +1967,7 @@ char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, mapb } /// "hasmapto()" function -void f_hasmapto(typval_T *argvars, typval_T *rettv, FunPtr fptr) +void f_hasmapto(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { const char *mode; const char *const name = tv_get_string(&argvars[0]); @@ -2079,7 +2080,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) } char *keys_buf = NULL; - char_u *alt_keys_buf = NULL; + char *alt_keys_buf = NULL; bool did_simplify = false; const int flags = REPTERM_FROM_PART | REPTERM_DO_LT; const int mode = get_map_mode((char **)&which, 0); @@ -2096,9 +2097,9 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) // preferred for printing, like in do_map(). (void)replace_termcodes(keys, STRLEN(keys), - (char **)&alt_keys_buf, flags | REPTERM_NO_SIMPLIFY, NULL, + &alt_keys_buf, flags | REPTERM_NO_SIMPLIFY, NULL, CPO_TO_CPO_FLAGS); - rhs = check_map(alt_keys_buf, mode, exact, false, abbr, &mp, &buffer_local, &rhs_lua); + rhs = check_map((char_u *)alt_keys_buf, mode, exact, false, abbr, &mp, &buffer_local, &rhs_lua); } if (!get_dict) { @@ -2126,7 +2127,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) } /// "mapset()" function -void f_mapset(typval_T *argvars, typval_T *rettv, FunPtr fptr) +void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { char buf[NUMBUFLEN]; const char *which = tv_get_string_buf_chk(&argvars[0], buf); @@ -2194,13 +2195,13 @@ void f_mapset(typval_T *argvars, typval_T *rettv, FunPtr fptr) } /// "maparg()" function -void f_maparg(typval_T *argvars, typval_T *rettv, FunPtr fptr) +void f_maparg(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { get_maparg(argvars, rettv, true); } /// "mapcheck()" function -void f_mapcheck(typval_T *argvars, typval_T *rettv, FunPtr fptr) +void f_mapcheck(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { get_maparg(argvars, rettv, false); } @@ -2321,7 +2322,7 @@ void langmap_set(void) 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 (p = (char_u *)p_langmap; p[0] != NUL;) { for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';'; MB_PTR_ADV(p2)) { if (p2[0] == '\\' && p2[1] != NUL) { @@ -2439,13 +2440,13 @@ void ex_unmap(exarg_T *eap) /// ":mapclear" and friends. void ex_mapclear(exarg_T *eap) { - do_mapclear((char_u *)eap->cmd, (char_u *)eap->arg, eap->forceit, false); + do_mapclear(eap->cmd, (char_u *)eap->arg, eap->forceit, false); } /// ":abclear" and friends. void ex_abclear(exarg_T *eap) { - do_mapclear((char_u *)eap->cmd, (char_u *)eap->arg, true, true); + do_mapclear(eap->cmd, (char_u *)eap->arg, true, true); } /// Set, tweak, or remove a mapping in a mode. Acts as the implementation for |