aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mapping.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-06-29 19:25:38 +0800
committerGitHub <noreply@github.com>2022-06-29 19:25:38 +0800
commitbab32bba7adc8ba9461629e51d8c7a7d2fa5976b (patch)
treec399542044bc628b08e72b33d05cc3c340c4f393 /src/nvim/mapping.c
parent21a1f1f552c1d79165cdb51e9e1297d4a4fe9eb6 (diff)
downloadrneovim-bab32bba7adc8ba9461629e51d8c7a7d2fa5976b.tar.gz
rneovim-bab32bba7adc8ba9461629e51d8c7a7d2fa5976b.tar.bz2
rneovim-bab32bba7adc8ba9461629e51d8c7a7d2fa5976b.zip
vim-patch:9.0.0002: map functionality outside of map.c (#19150)
Problem: Map functionality outside of map.c. Solution: Move f_hasmapto() to map.c. Rename a function. (closes vim/vim#10611) https://github.com/vim/vim/commit/c207fd2535717030d78f9b92839e5f2ac004cc78
Diffstat (limited to 'src/nvim/mapping.c')
-rw-r--r--src/nvim/mapping.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c
index ce313b4f46..ff7a3da5c3 100644
--- a/src/nvim/mapping.c
+++ b/src/nvim/mapping.c
@@ -939,8 +939,8 @@ static int get_map_mode(char **cmdp, bool forceit)
return mode;
}
-/// Clear all mappings or abbreviations.
-/// 'abbr' should be false for mappings, true for abbreviations.
+/// 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)
{
@@ -954,7 +954,7 @@ static void do_mapclear(char_u *cmdp, char_u *arg, int forceit, int abbr)
}
mode = get_map_mode((char **)&cmdp, forceit);
- map_clear_int(curbuf, mode, local, abbr);
+ map_clear_mode(curbuf, mode, local, abbr);
}
/// Clear all mappings in "mode".
@@ -963,7 +963,7 @@ static void do_mapclear(char_u *cmdp, char_u *arg, int forceit, int abbr)
/// @param mode mode in which to delete
/// @param local true for buffer-local mappings
/// @param abbr true for abbreviations
-void map_clear_int(buf_T *buf, int mode, bool local, bool abbr)
+void map_clear_mode(buf_T *buf, int mode, bool local, bool abbr)
{
mapblock_T *mp, **mpp;
int hash;
@@ -1944,6 +1944,29 @@ char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, mapb
return NULL;
}
+/// "hasmapto()" function
+void f_hasmapto(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ const char *mode;
+ const char *const name = tv_get_string(&argvars[0]);
+ bool abbr = false;
+ char buf[NUMBUFLEN];
+ if (argvars[1].v_type == VAR_UNKNOWN) {
+ mode = "nvo";
+ } else {
+ mode = tv_get_string_buf(&argvars[1], buf);
+ if (argvars[2].v_type != VAR_UNKNOWN) {
+ abbr = tv_get_number(&argvars[2]);
+ }
+ }
+
+ if (map_to_exists(name, mode, abbr)) {
+ rettv->vval.v_number = true;
+ } else {
+ rettv->vval.v_number = false;
+ }
+}
+
/// Fill a dictionary with all applicable maparg() like dictionaries
///
/// @param dict The dictionary to be filled