mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 07:18:17 +00:00
vim-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 vim/vim#10580) Use
symbols for the first do_map() argument.
44068e97db
This commit is contained in:
@@ -2121,7 +2121,7 @@ void 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(0, buf, MODE_LANGMAP, false);
|
(void)do_map(MAPTYPE_MAP, buf, MODE_LANGMAP, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
p_cpo = save_cpo;
|
p_cpo = save_cpo;
|
||||||
@@ -2158,7 +2158,7 @@ static void keymap_unload(void)
|
|||||||
|
|
||||||
for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) {
|
for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) {
|
||||||
vim_snprintf(buf, sizeof(buf), "<buffer> %s", kp[i].from);
|
vim_snprintf(buf, sizeof(buf), "<buffer> %s", kp[i].from);
|
||||||
(void)do_map(1, (char_u *)buf, MODE_LANGMAP, false);
|
(void)do_map(MAPTYPE_UNMAP, (char_u *)buf, MODE_LANGMAP, false);
|
||||||
}
|
}
|
||||||
keymap_ga_clear(&curbuf->b_kmap_ga);
|
keymap_ga_clear(&curbuf->b_kmap_ga);
|
||||||
|
|
||||||
|
@@ -509,7 +509,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
|
|||||||
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;
|
||||||
@@ -527,10 +527,10 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
|
|||||||
|
|
||||||
const bool has_lhs = (args->lhs[0] != NUL);
|
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;
|
const bool has_rhs = args->rhs_lua != LUA_NOREF || (args->rhs[0] != NUL) || args->rhs_is_noop;
|
||||||
const bool do_print = !has_lhs || (maptype != 1 && !has_rhs);
|
const bool do_print = !has_lhs || (maptype != MAPTYPE_UNMAP && !has_rhs);
|
||||||
|
|
||||||
// check for :unmap without argument
|
// check for :unmap without argument
|
||||||
if (maptype == 1 && !has_lhs) {
|
if (maptype == MAPTYPE_UNMAP && !has_lhs) {
|
||||||
retval = 1;
|
retval = 1;
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
@@ -564,13 +564,11 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_abbrev && maptype != 1) {
|
if (is_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.
|
||||||
// Otherwise we won't be able to find the start of it in a
|
// Otherwise we won't be able to find the start of it in a
|
||||||
// vi-compatible way.
|
// vi-compatible way.
|
||||||
//
|
|
||||||
int same = -1;
|
int same = -1;
|
||||||
|
|
||||||
const int first = vim_iswordp(lhs);
|
const int first = vim_iswordp(lhs);
|
||||||
@@ -608,7 +606,8 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if a new local mapping wasn't already defined globally.
|
// Check if a new local mapping wasn't already defined globally.
|
||||||
if (args->unique && map_table == buf->b_maphash && has_lhs && has_rhs && maptype != 1) {
|
if (args->unique && map_table == buf->b_maphash && has_lhs && has_rhs
|
||||||
|
&& maptype != MAPTYPE_UNMAP) {
|
||||||
// need to loop over all global hash lists
|
// need to loop over all global hash lists
|
||||||
for (int hash = 0; hash < 256 && !got_int; hash++) {
|
for (int hash = 0; hash < 256 && !got_int; hash++) {
|
||||||
if (is_abbrev) {
|
if (is_abbrev) {
|
||||||
@@ -638,7 +637,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When listing global mappings, also list buffer-local ones here.
|
// When listing global mappings, also list buffer-local ones here.
|
||||||
if (map_table != buf->b_maphash && !has_rhs && maptype != 1) {
|
if (map_table != buf->b_maphash && !has_rhs && maptype != MAPTYPE_UNMAP) {
|
||||||
// need to loop over all global hash lists
|
// need to loop over all global hash lists
|
||||||
for (int hash = 0; hash < 256 && !got_int; hash++) {
|
for (int hash = 0; hash < 256 && !got_int; hash++) {
|
||||||
if (is_abbrev) {
|
if (is_abbrev) {
|
||||||
@@ -673,7 +672,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
|
|||||||
// entry with a matching 'to' part. This was done to allow ":ab foo bar"
|
// entry with a matching 'to' part. This was done to allow ":ab foo bar"
|
||||||
// to be unmapped by typing ":unab foo", where "foo" will be replaced by
|
// to be unmapped by typing ":unab foo", where "foo" will be replaced by
|
||||||
// "bar" because of the abbreviation.
|
// "bar" because of the abbreviation.
|
||||||
for (int round = 0; (round == 0 || maptype == 1) && round <= 1
|
for (int round = 0; (round == 0 || maptype == MAPTYPE_UNMAP) && round <= 1
|
||||||
&& !did_it && !got_int; round++) {
|
&& !did_it && !got_int; round++) {
|
||||||
int hash_start, hash_end;
|
int hash_start, hash_end;
|
||||||
if (has_lhs || is_abbrev) {
|
if (has_lhs || is_abbrev) {
|
||||||
@@ -707,7 +706,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
|
|||||||
p = mp->m_keys;
|
p = mp->m_keys;
|
||||||
}
|
}
|
||||||
if (STRNCMP(p, lhs, (size_t)(n < len ? n : len)) == 0) {
|
if (STRNCMP(p, lhs, (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
|
||||||
// we ignore trailing space when matching with
|
// we ignore trailing space when matching with
|
||||||
@@ -803,7 +802,7 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maptype == 1) {
|
if (maptype == MAPTYPE_UNMAP) {
|
||||||
// delete entry
|
// delete entry
|
||||||
if (!did_it) {
|
if (!did_it) {
|
||||||
if (!keyround1_simplified) {
|
if (!keyround1_simplified) {
|
||||||
@@ -879,7 +878,9 @@ theend:
|
|||||||
/// for :cabbr mode is MODE_CMDLINE
|
/// for :cabbr mode is MODE_CMDLINE
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// @param maptype 0 for |:map|, 1 for |:unmap|, 2 for |noremap|.
|
/// @param maptype MAPTYPE_MAP for |:map|
|
||||||
|
/// MAPTYPE_UNMAP for |:unmap|
|
||||||
|
/// MAPTYPE_NOREMAP for |noremap|.
|
||||||
/// @param arg C-string containing the arguments of the map/abbrev
|
/// @param arg C-string containing the arguments of the map/abbrev
|
||||||
/// command, i.e. everything except the initial `:[X][nore]map`.
|
/// command, i.e. everything except the initial `:[X][nore]map`.
|
||||||
/// - Cannot be a read-only string; it will be modified.
|
/// - Cannot be a read-only string; it will be modified.
|
||||||
@@ -896,7 +897,7 @@ theend:
|
|||||||
int do_map(int maptype, char_u *arg, int mode, bool is_abbrev)
|
int do_map(int maptype, char_u *arg, int mode, bool is_abbrev)
|
||||||
{
|
{
|
||||||
MapArguments parsed_args;
|
MapArguments parsed_args;
|
||||||
int result = str_to_mapargs(arg, maptype == 1, &parsed_args);
|
int result = str_to_mapargs(arg, maptype == MAPTYPE_UNMAP, &parsed_args);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
@@ -2183,7 +2184,7 @@ void f_mapset(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
MapArguments unmap_args = MAP_ARGUMENTS_INIT;
|
MapArguments unmap_args = MAP_ARGUMENTS_INIT;
|
||||||
set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &unmap_args);
|
set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &unmap_args);
|
||||||
unmap_args.buffer = buffer;
|
unmap_args.buffer = buffer;
|
||||||
buf_do_map(1, &unmap_args, mode, false, curbuf);
|
buf_do_map(MAPTYPE_UNMAP, &unmap_args, mode, false, curbuf);
|
||||||
xfree(unmap_args.rhs);
|
xfree(unmap_args.rhs);
|
||||||
xfree(unmap_args.orig_rhs);
|
xfree(unmap_args.orig_rhs);
|
||||||
|
|
||||||
@@ -2221,7 +2222,7 @@ void add_map(char *lhs, char *rhs, int mode, bool buffer)
|
|||||||
set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &args);
|
set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &args);
|
||||||
args.buffer = buffer;
|
args.buffer = buffer;
|
||||||
|
|
||||||
buf_do_map(2, &args, mode, false, curbuf);
|
buf_do_map(MAPTYPE_NOREMAP, &args, mode, false, curbuf);
|
||||||
xfree(args.rhs);
|
xfree(args.rhs);
|
||||||
xfree(args.orig_rhs);
|
xfree(args.orig_rhs);
|
||||||
}
|
}
|
||||||
@@ -2401,7 +2402,8 @@ static void do_exmap(exarg_T *eap, int isabbrev)
|
|||||||
char *cmdp = eap->cmd;
|
char *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,
|
||||||
(char_u *)eap->arg, mode, isabbrev)) {
|
(char_u *)eap->arg, mode, isabbrev)) {
|
||||||
case 1:
|
case 1:
|
||||||
emsg(_(e_invarg));
|
emsg(_(e_invarg));
|
||||||
@@ -2561,11 +2563,11 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// buf_do_map() reads noremap/unmap as its own argument.
|
// buf_do_map() reads noremap/unmap as its own argument.
|
||||||
int maptype_val = 0;
|
int maptype_val = MAPTYPE_MAP;
|
||||||
if (is_unmap) {
|
if (is_unmap) {
|
||||||
maptype_val = 1;
|
maptype_val = MAPTYPE_UNMAP;
|
||||||
} else if (is_noremap) {
|
} else if (is_noremap) {
|
||||||
maptype_val = 2;
|
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, 0, target_buf)) {
|
||||||
|
@@ -48,6 +48,11 @@ typedef struct map_arguments MapArguments;
|
|||||||
#define MAP_ARGUMENTS_INIT { false, false, false, false, false, false, false, false, \
|
#define MAP_ARGUMENTS_INIT { false, false, false, false, false, false, false, false, \
|
||||||
{ 0 }, 0, { 0 }, 0, NULL, 0, LUA_NOREF, false, NULL, 0, NULL }
|
{ 0 }, 0, { 0 }, 0, NULL, 0, LUA_NOREF, false, NULL, 0, NULL }
|
||||||
|
|
||||||
|
// Used for the first argument of do_map()
|
||||||
|
#define MAPTYPE_MAP 0
|
||||||
|
#define MAPTYPE_UNMAP 1
|
||||||
|
#define MAPTYPE_NOREMAP 2
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "mapping.h.generated.h"
|
# include "mapping.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user