mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.5106: default cmdwin mappings are re-mappable
Problem: Default cmdwin mappings are re-mappable. Solution: Make the default mappings not re-mappable. (closes #10580) Use symbols for the first do_map() argument.
This commit is contained in:
parent
83497f8758
commit
44068e97db
@ -2567,7 +2567,7 @@ ex_loadkeymap(exarg_T *eap)
|
|||||||
vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s %s",
|
vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s %s",
|
||||||
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from,
|
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from,
|
||||||
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to);
|
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to);
|
||||||
(void)do_map(2, buf, MODE_LANGMAP, FALSE);
|
(void)do_map(MAPTYPE_NOREMAP, buf, MODE_LANGMAP, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
p_cpo = save_cpo;
|
p_cpo = save_cpo;
|
||||||
@ -2598,7 +2598,7 @@ keymap_unload(void)
|
|||||||
for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i)
|
for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i)
|
||||||
{
|
{
|
||||||
vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from);
|
vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from);
|
||||||
(void)do_map(1, buf, MODE_LANGMAP, FALSE);
|
(void)do_map(MAPTYPE_UNMAP, buf, MODE_LANGMAP, FALSE);
|
||||||
}
|
}
|
||||||
keymap_clear(&curbuf->b_kmap_ga);
|
keymap_clear(&curbuf->b_kmap_ga);
|
||||||
|
|
||||||
|
@ -4463,8 +4463,8 @@ open_cmdwin(void)
|
|||||||
{
|
{
|
||||||
if (p_wc == TAB)
|
if (p_wc == TAB)
|
||||||
{
|
{
|
||||||
add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", MODE_INSERT);
|
add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", MODE_INSERT, TRUE);
|
||||||
add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", MODE_NORMAL);
|
add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", MODE_NORMAL, TRUE);
|
||||||
}
|
}
|
||||||
set_option_value_give_err((char_u *)"ft",
|
set_option_value_give_err((char_u *)"ft",
|
||||||
0L, (char_u *)"vim", OPT_LOCAL);
|
0L, (char_u *)"vim", OPT_LOCAL);
|
||||||
|
39
src/map.c
39
src/map.c
@ -293,7 +293,9 @@ map_add(
|
|||||||
* noreabbr {lhs} {rhs} : same, but no remapping for {rhs}
|
* noreabbr {lhs} {rhs} : same, but no remapping for {rhs}
|
||||||
* unabbr {lhs} : remove abbreviation for {lhs}
|
* unabbr {lhs} : remove abbreviation for {lhs}
|
||||||
*
|
*
|
||||||
* maptype: 0 for :map, 1 for :unmap, 2 for noremap.
|
* maptype: MAPTYPE_MAP for :map
|
||||||
|
* MAPTYPE_UNMAP for :unmap
|
||||||
|
* MAPTYPE_NOREMAP for noremap
|
||||||
*
|
*
|
||||||
* arg is pointer to any arguments. Note: arg cannot be a read-only string,
|
* arg is pointer to any arguments. Note: arg cannot be a read-only string,
|
||||||
* it will be modified.
|
* it will be modified.
|
||||||
@ -360,7 +362,7 @@ do_map(
|
|||||||
abbr_table = &first_abbr;
|
abbr_table = &first_abbr;
|
||||||
|
|
||||||
// For ":noremap" don't remap, otherwise do remap.
|
// For ":noremap" don't remap, otherwise do remap.
|
||||||
if (maptype == 2)
|
if (maptype == MAPTYPE_NOREMAP)
|
||||||
noremap = REMAP_NONE;
|
noremap = REMAP_NONE;
|
||||||
else
|
else
|
||||||
noremap = REMAP_YES;
|
noremap = REMAP_YES;
|
||||||
@ -436,7 +438,7 @@ do_map(
|
|||||||
// with :unmap white space is included in the keys, no argument possible.
|
// with :unmap white space is included in the keys, no argument possible.
|
||||||
p = keys;
|
p = keys;
|
||||||
do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL);
|
do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL);
|
||||||
while (*p && (maptype == 1 || !VIM_ISWHITE(*p)))
|
while (*p && (maptype == MAPTYPE_UNMAP || !VIM_ISWHITE(*p)))
|
||||||
{
|
{
|
||||||
if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) &&
|
if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) &&
|
||||||
p[1] != NUL)
|
p[1] != NUL)
|
||||||
@ -450,10 +452,10 @@ do_map(
|
|||||||
rhs = p;
|
rhs = p;
|
||||||
hasarg = (*rhs != NUL);
|
hasarg = (*rhs != NUL);
|
||||||
haskey = (*keys != NUL);
|
haskey = (*keys != NUL);
|
||||||
do_print = !haskey || (maptype != 1 && !hasarg);
|
do_print = !haskey || (maptype != MAPTYPE_UNMAP && !hasarg);
|
||||||
|
|
||||||
// check for :unmap without argument
|
// check for :unmap without argument
|
||||||
if (maptype == 1 && !haskey)
|
if (maptype == MAPTYPE_UNMAP && !haskey)
|
||||||
{
|
{
|
||||||
retval = 1;
|
retval = 1;
|
||||||
goto theend;
|
goto theend;
|
||||||
@ -524,7 +526,7 @@ do_map(
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abbrev && maptype != 1)
|
if (abbrev && maptype != MAPTYPE_UNMAP)
|
||||||
{
|
{
|
||||||
// If an abbreviation ends in a keyword character, the
|
// If an abbreviation ends in a keyword character, the
|
||||||
// rest must be all keyword-char or all non-keyword-char.
|
// rest must be all keyword-char or all non-keyword-char.
|
||||||
@ -580,7 +582,7 @@ do_map(
|
|||||||
|
|
||||||
// Check if a new local mapping wasn't already defined globally.
|
// Check if a new local mapping wasn't already defined globally.
|
||||||
if (unique && map_table == curbuf->b_maphash
|
if (unique && map_table == curbuf->b_maphash
|
||||||
&& haskey && hasarg && maptype != 1)
|
&& haskey && hasarg && maptype != MAPTYPE_UNMAP)
|
||||||
{
|
{
|
||||||
// need to loop over all global hash lists
|
// need to loop over all global hash lists
|
||||||
for (hash = 0; hash < 256 && !got_int; ++hash)
|
for (hash = 0; hash < 256 && !got_int; ++hash)
|
||||||
@ -615,7 +617,8 @@ do_map(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When listing global mappings, also list buffer-local ones here.
|
// When listing global mappings, also list buffer-local ones here.
|
||||||
if (map_table != curbuf->b_maphash && !hasarg && maptype != 1)
|
if (map_table != curbuf->b_maphash && !hasarg
|
||||||
|
&& maptype != MAPTYPE_UNMAP)
|
||||||
{
|
{
|
||||||
// need to loop over all global hash lists
|
// need to loop over all global hash lists
|
||||||
for (hash = 0; hash < 256 && !got_int; ++hash)
|
for (hash = 0; hash < 256 && !got_int; ++hash)
|
||||||
@ -659,7 +662,7 @@ do_map(
|
|||||||
// an entry with a matching 'to' part. This was done to allow
|
// an entry with a matching 'to' part. This was done to allow
|
||||||
// ":ab foo bar" to be unmapped by typing ":unab foo", where "foo" will
|
// ":ab foo bar" to be unmapped by typing ":unab foo", where "foo" will
|
||||||
// be replaced by "bar" because of the abbreviation.
|
// be replaced by "bar" because of the abbreviation.
|
||||||
for (round = 0; (round == 0 || maptype == 1) && round <= 1
|
for (round = 0; (round == 0 || maptype == MAPTYPE_UNMAP) && round <= 1
|
||||||
&& !did_it && !got_int; ++round)
|
&& !did_it && !got_int; ++round)
|
||||||
{
|
{
|
||||||
// need to loop over all hash lists
|
// need to loop over all hash lists
|
||||||
@ -704,7 +707,7 @@ do_map(
|
|||||||
}
|
}
|
||||||
if (STRNCMP(p, keys, (size_t)(n < len ? n : len)) == 0)
|
if (STRNCMP(p, keys, (size_t)(n < len ? n : len)) == 0)
|
||||||
{
|
{
|
||||||
if (maptype == 1)
|
if (maptype == MAPTYPE_UNMAP)
|
||||||
{
|
{
|
||||||
// Delete entry.
|
// Delete entry.
|
||||||
// Only accept a full match. For abbreviations
|
// Only accept a full match. For abbreviations
|
||||||
@ -805,7 +808,7 @@ do_map(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maptype == 1)
|
if (maptype == MAPTYPE_UNMAP)
|
||||||
{
|
{
|
||||||
// delete entry
|
// delete entry
|
||||||
if (!did_it)
|
if (!did_it)
|
||||||
@ -2661,7 +2664,7 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
if (arg == NULL)
|
if (arg == NULL)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
do_map(1, arg, mode, is_abbr);
|
do_map(MAPTYPE_UNMAP, arg, mode, is_abbr);
|
||||||
vim_free(arg);
|
vim_free(arg);
|
||||||
|
|
||||||
(void)map_add(map_table, abbr_table, lhsraw, rhs, orig_rhs, noremap,
|
(void)map_add(map_table, abbr_table, lhsraw, rhs, orig_rhs, noremap,
|
||||||
@ -2766,12 +2769,12 @@ init_mappings(void)
|
|||||||
# endif
|
# endif
|
||||||
{
|
{
|
||||||
for (i = 0; i < (int)ARRAY_LENGTH(cinitmappings); ++i)
|
for (i = 0; i < (int)ARRAY_LENGTH(cinitmappings); ++i)
|
||||||
add_map(cinitmappings[i].arg, cinitmappings[i].mode);
|
add_map(cinitmappings[i].arg, cinitmappings[i].mode, FALSE);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
# if defined(FEAT_GUI_MSWIN) || defined(MACOS_X)
|
# if defined(FEAT_GUI_MSWIN) || defined(MACOS_X)
|
||||||
for (i = 0; i < (int)ARRAY_LENGTH(initmappings); ++i)
|
for (i = 0; i < (int)ARRAY_LENGTH(initmappings); ++i)
|
||||||
add_map(initmappings[i].arg, initmappings[i].mode);
|
add_map(initmappings[i].arg, initmappings[i].mode, FALSE);
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2780,10 +2783,11 @@ init_mappings(void)
|
|||||||
|| defined(PROTO)
|
|| defined(PROTO)
|
||||||
/*
|
/*
|
||||||
* Add a mapping "map" for mode "mode".
|
* Add a mapping "map" for mode "mode".
|
||||||
|
* When "nore" is TRUE use MAPTYPE_NOREMAP.
|
||||||
* Need to put string in allocated memory, because do_map() will modify it.
|
* Need to put string in allocated memory, because do_map() will modify it.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
add_map(char_u *map, int mode)
|
add_map(char_u *map, int mode, int nore)
|
||||||
{
|
{
|
||||||
char_u *s;
|
char_u *s;
|
||||||
char_u *cpo_save = p_cpo;
|
char_u *cpo_save = p_cpo;
|
||||||
@ -2792,7 +2796,7 @@ add_map(char_u *map, int mode)
|
|||||||
s = vim_strsave(map);
|
s = vim_strsave(map);
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
{
|
{
|
||||||
(void)do_map(0, s, mode, FALSE);
|
(void)do_map(nore ? MAPTYPE_NOREMAP : MAPTYPE_MAP, s, mode, FALSE);
|
||||||
vim_free(s);
|
vim_free(s);
|
||||||
}
|
}
|
||||||
p_cpo = cpo_save;
|
p_cpo = cpo_save;
|
||||||
@ -2999,7 +3003,8 @@ do_exmap(exarg_T *eap, int isabbrev)
|
|||||||
cmdp = eap->cmd;
|
cmdp = eap->cmd;
|
||||||
mode = get_map_mode(&cmdp, eap->forceit || isabbrev);
|
mode = get_map_mode(&cmdp, eap->forceit || isabbrev);
|
||||||
|
|
||||||
switch (do_map((*cmdp == 'n') ? 2 : (*cmdp == 'u'),
|
switch (do_map(*cmdp == 'n' ? MAPTYPE_NOREMAP
|
||||||
|
: *cmdp == 'u' ? MAPTYPE_UNMAP : MAPTYPE_MAP,
|
||||||
eap->arg, mode, isabbrev))
|
eap->arg, mode, isabbrev))
|
||||||
{
|
{
|
||||||
case 1: emsg(_(e_invalid_argument));
|
case 1: emsg(_(e_invalid_argument));
|
||||||
|
@ -2323,7 +2323,7 @@ special_keys(char_u *args)
|
|||||||
strcpy(&keybuf[i], tok);
|
strcpy(&keybuf[i], tok);
|
||||||
vim_snprintf(cmdbuf, sizeof(cmdbuf),
|
vim_snprintf(cmdbuf, sizeof(cmdbuf),
|
||||||
"<silent><%s> :nbkey %s<CR>", keybuf, keybuf);
|
"<silent><%s> :nbkey %s<CR>", keybuf, keybuf);
|
||||||
do_map(0, (char_u *)cmdbuf, MODE_NORMAL, FALSE);
|
do_map(MAPTYPE_MAP, (char_u *)cmdbuf, MODE_NORMAL, FALSE);
|
||||||
}
|
}
|
||||||
tok = strtok(NULL, " ");
|
tok = strtok(NULL, " ");
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ void f_maparg(typval_T *argvars, typval_T *rettv);
|
|||||||
void f_mapcheck(typval_T *argvars, typval_T *rettv);
|
void f_mapcheck(typval_T *argvars, typval_T *rettv);
|
||||||
void f_mapset(typval_T *argvars, typval_T *rettv);
|
void f_mapset(typval_T *argvars, typval_T *rettv);
|
||||||
void init_mappings(void);
|
void init_mappings(void);
|
||||||
void add_map(char_u *map, int mode);
|
void add_map(char_u *map, int mode, int nore);
|
||||||
int langmap_adjust_mb(int c);
|
int langmap_adjust_mb(int c);
|
||||||
void langmap_init(void);
|
void langmap_init(void);
|
||||||
void langmap_set(void);
|
void langmap_set(void);
|
||||||
|
@ -734,6 +734,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
5106,
|
||||||
/**/
|
/**/
|
||||||
5105,
|
5105,
|
||||||
/**/
|
/**/
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# define MSWIN
|
# define MSWIN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MSWIN
|
#if defined(MSWIN) && !defined(PROTO)
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -378,7 +378,7 @@ typedef long long_i;
|
|||||||
* We assume that when fseeko() is available then ftello() is too.
|
* We assume that when fseeko() is available then ftello() is too.
|
||||||
* Note that Windows has different function names.
|
* Note that Windows has different function names.
|
||||||
*/
|
*/
|
||||||
#ifdef MSWIN
|
#if defined(MSWIN) && !defined(PROTO)
|
||||||
typedef __int64 off_T;
|
typedef __int64 off_T;
|
||||||
# ifdef __MINGW32__
|
# ifdef __MINGW32__
|
||||||
# define vim_lseek lseek64
|
# define vim_lseek lseek64
|
||||||
@ -967,6 +967,11 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
|
|||||||
#define KEY_OPEN_BACK 0x102
|
#define KEY_OPEN_BACK 0x102
|
||||||
#define KEY_COMPLETE 0x103 // end of completion
|
#define KEY_COMPLETE 0x103 // end of completion
|
||||||
|
|
||||||
|
// Used for the first argument of do_map()
|
||||||
|
#define MAPTYPE_MAP 0
|
||||||
|
#define MAPTYPE_UNMAP 1
|
||||||
|
#define MAPTYPE_NOREMAP 2
|
||||||
|
|
||||||
// Values for "noremap" argument of ins_typebuf(). Also used for
|
// Values for "noremap" argument of ins_typebuf(). Also used for
|
||||||
// map->m_noremap and menu->noremap[].
|
// map->m_noremap and menu->noremap[].
|
||||||
#define REMAP_YES 0 // allow remapping
|
#define REMAP_YES 0 // allow remapping
|
||||||
|
Loading…
x
Reference in New Issue
Block a user