Skip to content

Commit c207fd2

Browse files
zeertzjqbrammool
authored andcommitted
patch 9.0.0002: map functionality outside of map.c
Problem: Map functionality outside of map.c. Solution: Move f_hasmapto() to map.c. Rename a function. (closes #10611)
1 parent 75417d9 commit c207fd2

5 files changed

Lines changed: 45 additions & 43 deletions

File tree

src/buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,8 @@ free_buffer_stuff(
10041004
#ifdef FEAT_NETBEANS_INTG
10051005
netbeans_file_killed(buf);
10061006
#endif
1007-
map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); // clear local mappings
1008-
map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); // clear local abbrevs
1007+
map_clear_mode(buf, MAP_ALL_MODES, TRUE, FALSE); // clear local mappings
1008+
map_clear_mode(buf, MAP_ALL_MODES, TRUE, TRUE); // clear local abbrevs
10091009
VIM_CLEAR(buf->b_start_fenc);
10101010
}
10111011

src/evalfunc.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ static void f_getregtype(typval_T *argvars, typval_T *rettv);
7575
static void f_gettagstack(typval_T *argvars, typval_T *rettv);
7676
static void f_gettext(typval_T *argvars, typval_T *rettv);
7777
static void f_haslocaldir(typval_T *argvars, typval_T *rettv);
78-
static void f_hasmapto(typval_T *argvars, typval_T *rettv);
7978
static void f_hlID(typval_T *argvars, typval_T *rettv);
8079
static void f_hlexists(typval_T *argvars, typval_T *rettv);
8180
static void f_hostname(typval_T *argvars, typval_T *rettv);
@@ -6653,40 +6652,6 @@ f_haslocaldir(typval_T *argvars, typval_T *rettv)
66536652
rettv->vval.v_number = 0;
66546653
}
66556654

6656-
/*
6657-
* "hasmapto()" function
6658-
*/
6659-
static void
6660-
f_hasmapto(typval_T *argvars, typval_T *rettv)
6661-
{
6662-
char_u *name;
6663-
char_u *mode;
6664-
char_u buf[NUMBUFLEN];
6665-
int abbr = FALSE;
6666-
6667-
if (in_vim9script()
6668-
&& (check_for_string_arg(argvars, 0) == FAIL
6669-
|| check_for_opt_string_arg(argvars, 1) == FAIL
6670-
|| (argvars[1].v_type != VAR_UNKNOWN
6671-
&& check_for_opt_bool_arg(argvars, 2) == FAIL)))
6672-
return;
6673-
6674-
name = tv_get_string(&argvars[0]);
6675-
if (argvars[1].v_type == VAR_UNKNOWN)
6676-
mode = (char_u *)"nvo";
6677-
else
6678-
{
6679-
mode = tv_get_string_buf(&argvars[1], buf);
6680-
if (argvars[2].v_type != VAR_UNKNOWN)
6681-
abbr = (int)tv_get_bool(&argvars[2]);
6682-
}
6683-
6684-
if (map_to_exists(name, mode, abbr))
6685-
rettv->vval.v_number = TRUE;
6686-
else
6687-
rettv->vval.v_number = FALSE;
6688-
}
6689-
66906655
/*
66916656
* "highlightID(name)" function
66926657
*/

src/map.c

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -908,13 +908,13 @@ get_map_mode(char_u **cmdp, int forceit)
908908
}
909909

910910
/*
911-
* Clear all mappings or abbreviations.
912-
* 'abbr' should be FALSE for mappings, TRUE for abbreviations.
911+
* Clear all mappings (":mapclear") or abbreviations (":abclear").
912+
* "abbr" should be FALSE for mappings, TRUE for abbreviations.
913913
*/
914914
static void
915915
map_clear(
916916
char_u *cmdp,
917-
char_u *arg UNUSED,
917+
char_u *arg,
918918
int forceit,
919919
int abbr)
920920
{
@@ -929,14 +929,14 @@ map_clear(
929929
}
930930

931931
mode = get_map_mode(&cmdp, forceit);
932-
map_clear_int(curbuf, mode, local, abbr);
932+
map_clear_mode(curbuf, mode, local, abbr);
933933
}
934934

935935
/*
936936
* Clear all mappings in "mode".
937937
*/
938938
void
939-
map_clear_int(
939+
map_clear_mode(
940940
buf_T *buf, // buffer for local mappings
941941
int mode, // mode in which to delete
942942
int local, // TRUE for buffer-local mappings
@@ -2272,6 +2272,40 @@ check_map(
22722272
return NULL;
22732273
}
22742274

2275+
/*
2276+
* "hasmapto()" function
2277+
*/
2278+
void
2279+
f_hasmapto(typval_T *argvars, typval_T *rettv)
2280+
{
2281+
char_u *name;
2282+
char_u *mode;
2283+
char_u buf[NUMBUFLEN];
2284+
int abbr = FALSE;
2285+
2286+
if (in_vim9script()
2287+
&& (check_for_string_arg(argvars, 0) == FAIL
2288+
|| check_for_opt_string_arg(argvars, 1) == FAIL
2289+
|| (argvars[1].v_type != VAR_UNKNOWN
2290+
&& check_for_opt_bool_arg(argvars, 2) == FAIL)))
2291+
return;
2292+
2293+
name = tv_get_string(&argvars[0]);
2294+
if (argvars[1].v_type == VAR_UNKNOWN)
2295+
mode = (char_u *)"nvo";
2296+
else
2297+
{
2298+
mode = tv_get_string_buf(&argvars[1], buf);
2299+
if (argvars[2].v_type != VAR_UNKNOWN)
2300+
abbr = (int)tv_get_bool(&argvars[2]);
2301+
}
2302+
2303+
if (map_to_exists(name, mode, abbr))
2304+
rettv->vval.v_number = TRUE;
2305+
else
2306+
rettv->vval.v_number = FALSE;
2307+
}
2308+
22752309
/*
22762310
* Fill in the empty dictionary with items as defined by maparg builtin.
22772311
*/

src/proto/map.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mapblock_T *get_maphash_list(int state, int c);
33
mapblock_T *get_buf_maphash_list(int state, int c);
44
int is_maphash_valid(void);
55
int do_map(int maptype, char_u *arg, int mode, int abbrev);
6-
void map_clear_int(buf_T *buf, int mode, int local, int abbr);
6+
void map_clear_mode(buf_T *buf, int mode, int local, int abbr);
77
int mode_str2flags(char_u *modechars);
88
int map_to_exists(char_u *str, char_u *modechars, int abbr);
99
int map_to_exists_mode(char_u *rhs, int mode, int abbr);
@@ -17,6 +17,7 @@ int makemap(FILE *fd, buf_T *buf);
1717
int put_escstr(FILE *fd, char_u *strstart, int what);
1818
void check_map_keycodes(void);
1919
char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, mapblock_T **mp_ptr, int *local_ptr);
20+
void f_hasmapto(typval_T *argvars, typval_T *rettv);
2021
void f_maplist(typval_T *argvars, typval_T *rettv);
2122
void f_maparg(typval_T *argvars, typval_T *rettv);
2223
void f_mapcheck(typval_T *argvars, typval_T *rettv);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static char *(features[]) =
735735

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
2,
738740
/**/
739741
1,
740742
/**/

0 commit comments

Comments
 (0)