mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 07:48:18 +00:00
refactor(map): simplify add_map params
This commit is contained in:
@@ -6645,8 +6645,8 @@ static int open_cmdwin(void)
|
|||||||
const int histtype = hist_char2type(cmdwin_type);
|
const int histtype = hist_char2type(cmdwin_type);
|
||||||
if (histtype == HIST_CMD || histtype == HIST_DEBUG) {
|
if (histtype == HIST_CMD || histtype == HIST_DEBUG) {
|
||||||
if (p_wc == TAB) {
|
if (p_wc == TAB) {
|
||||||
add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", MODE_INSERT, false);
|
add_map("<Tab>", "<C-X><C-V>", MODE_INSERT, true);
|
||||||
add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", MODE_NORMAL, false);
|
add_map("<Tab>", "a<C-X><C-V>", MODE_NORMAL, true);
|
||||||
}
|
}
|
||||||
set_option_value("ft", 0L, "vim", OPT_LOCAL);
|
set_option_value("ft", 0L, "vim", OPT_LOCAL);
|
||||||
}
|
}
|
||||||
|
@@ -2092,37 +2092,35 @@ void f_mapcheck(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
|
|
||||||
void init_default_mappings(void)
|
void init_default_mappings(void)
|
||||||
{
|
{
|
||||||
add_map((char_u *)"Y y$", MODE_NORMAL, true);
|
add_map("Y", "y$", MODE_NORMAL, false);
|
||||||
|
|
||||||
// Use normal! <C-L> to prevent inserting raw <C-L> when using i_<C-O>
|
// Use normal! <C-L> to prevent inserting raw <C-L> when using i_<C-O>
|
||||||
// See https://github.com/neovim/neovim/issues/17473
|
// See https://github.com/neovim/neovim/issues/17473
|
||||||
add_map((char_u *)"<C-L> <Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>",
|
add_map("<C-L>", "<Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>",
|
||||||
MODE_NORMAL, true);
|
MODE_NORMAL, false);
|
||||||
add_map((char_u *)"<C-U> <C-G>u<C-U>", MODE_INSERT, true);
|
add_map("<C-U>", "<C-G>u<C-U>", MODE_INSERT, false);
|
||||||
add_map((char_u *)"<C-W> <C-G>u<C-W>", MODE_INSERT, true);
|
add_map("<C-W>", "<C-G>u<C-W>", MODE_INSERT, false);
|
||||||
add_map((char_u *)"* y/\\\\V<C-R>\"<CR>", MODE_VISUAL, true);
|
add_map("*", "y/\\\\V<C-R>\"<CR>", MODE_VISUAL, false);
|
||||||
add_map((char_u *)"# y?\\\\V<C-R>\"<CR>", MODE_VISUAL, true);
|
add_map("#", "y?\\\\V<C-R>\"<CR>", MODE_VISUAL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a mapping. Unlike @ref do_map this copies the {map} argument, so
|
/// Add a mapping. Unlike @ref do_map this copies the string arguments, so
|
||||||
/// static or read-only strings can be used.
|
/// static or read-only strings can be used.
|
||||||
///
|
///
|
||||||
/// @param map C-string containing the arguments of the map/abbrev command,
|
/// @param lhs C-string containing the lhs of the mapping
|
||||||
/// i.e. everything except the initial `:[X][nore]map`.
|
/// @param rhs C-string containing the rhs of the mapping
|
||||||
/// @param mode Bitflags representing the mode in which to set the mapping.
|
/// @param mode Bitflags representing the mode in which to set the mapping.
|
||||||
/// See @ref get_map_mode.
|
/// See @ref get_map_mode.
|
||||||
/// @param nore If true, make a non-recursive mapping.
|
/// @param buffer If true, make a buffer-local mapping for curbuf
|
||||||
void add_map(char_u *map, int mode, bool nore)
|
void add_map(char *lhs, char *rhs, int mode, bool buffer)
|
||||||
{
|
{
|
||||||
char_u *s;
|
MapArguments args = { 0 };
|
||||||
char *cpo_save = p_cpo;
|
set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &args);
|
||||||
|
args.buffer = buffer;
|
||||||
|
|
||||||
p_cpo = ""; // Allow <> notation
|
buf_do_map(2, &args, mode, false, curbuf);
|
||||||
// Need to put string in allocated memory, because do_map() will modify it.
|
xfree(args.rhs);
|
||||||
s = vim_strsave(map);
|
xfree(args.orig_rhs);
|
||||||
(void)do_map(nore ? 2 : 0, s, mode, false);
|
|
||||||
xfree(s);
|
|
||||||
p_cpo = cpo_save;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Any character has an equivalent 'langmap' character. This is used for
|
/// Any character has an equivalent 'langmap' character. This is used for
|
||||||
|
@@ -4282,7 +4282,7 @@ static void nv_ident(cmdarg_T *cap)
|
|||||||
// Start insert mode in terminal buffer
|
// Start insert mode in terminal buffer
|
||||||
restart_edit = 'i';
|
restart_edit = 'i';
|
||||||
|
|
||||||
add_map((char_u *)"<buffer> <esc> <Cmd>bdelete!<CR>", MODE_TERMINAL, true);
|
add_map("<esc>", "<Cmd>bdelete!<CR>", MODE_TERMINAL, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user