0
0
mirror of https://github.com/vim/vim.git synced 2025-09-05 21:43:39 -04:00

patch 8.2.4615: mapping with escaped bar does not work in :def function

Problem:    Mapping with escaped bar does not work in :def function. (Sergey
            Vlasov)
Solution:   Do not remove the backslash. (closes #10002)
This commit is contained in:
Bram Moolenaar 2022-03-23 19:45:01 +00:00
parent c20e46a4e3
commit ac48506ac6
6 changed files with 27 additions and 10 deletions

View File

@ -2275,7 +2275,7 @@ do_one_cmd(
*/ */
if ((ea.argt & EX_TRLBAR) && !ea.usefilter) if ((ea.argt & EX_TRLBAR) && !ea.usefilter)
{ {
separate_nextcmd(&ea); separate_nextcmd(&ea, FALSE);
} }
else if (ea.cmdidx == CMD_bang else if (ea.cmdidx == CMD_bang
|| ea.cmdidx == CMD_terminal || ea.cmdidx == CMD_terminal
@ -5081,9 +5081,10 @@ repl_cmdline(
/* /*
* Check for '|' to separate commands and '"' to start comments. * Check for '|' to separate commands and '"' to start comments.
* If "keep_backslash" is TRUE do not remove any backslash.
*/ */
void void
separate_nextcmd(exarg_T *eap) separate_nextcmd(exarg_T *eap, int keep_backslash)
{ {
char_u *p; char_u *p;
@ -5097,7 +5098,7 @@ separate_nextcmd(exarg_T *eap)
{ {
if (*p == Ctrl_V) if (*p == Ctrl_V)
{ {
if (eap->argt & (EX_CTRLV | EX_XFILE)) if ((eap->argt & (EX_CTRLV | EX_XFILE)) || keep_backslash)
++p; // skip CTRL-V and next char ++p; // skip CTRL-V and next char
else else
// remove CTRL-V and skip next char // remove CTRL-V and skip next char
@ -5144,8 +5145,11 @@ separate_nextcmd(exarg_T *eap)
if ((vim_strchr(p_cpo, CPO_BAR) == NULL if ((vim_strchr(p_cpo, CPO_BAR) == NULL
|| !(eap->argt & EX_CTRLV)) && *(p - 1) == '\\') || !(eap->argt & EX_CTRLV)) && *(p - 1) == '\\')
{ {
STRMOVE(p - 1, p); // remove the '\' if (!keep_backslash)
--p; {
STRMOVE(p - 1, p); // remove the '\'
--p;
}
} }
else else
{ {

View File

@ -26,7 +26,7 @@ long excmd_get_argt(cmdidx_T idx);
char_u *skip_range(char_u *cmd_start, int skip_star, int *ctx); char_u *skip_range(char_u *cmd_start, int skip_star, int *ctx);
void ex_ni(exarg_T *eap); void ex_ni(exarg_T *eap);
int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp); int expand_filename(exarg_T *eap, char_u **cmdlinep, char **errormsgp);
void separate_nextcmd(exarg_T *eap); void separate_nextcmd(exarg_T *eap, int keep_backslash);
char_u *skip_cmd_arg(char_u *p, int rembs); char_u *skip_cmd_arg(char_u *p, int rembs);
int get_bad_opt(char_u *p, exarg_T *eap); int get_bad_opt(char_u *p, exarg_T *eap);
int ends_excmd(int c); int ends_excmd(int c);

View File

@ -4764,7 +4764,7 @@ syn_cmd_include(exarg_T *eap, int syncing UNUSED)
* filename to include. * filename to include.
*/ */
eap->argt |= (EX_XFILE | EX_NOSPC); eap->argt |= (EX_XFILE | EX_NOSPC);
separate_nextcmd(eap); separate_nextcmd(eap, FALSE);
if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg)) if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg))
{ {
// For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the // For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the

View File

@ -1178,8 +1178,19 @@ def Test_map_command()
nnoremap <F3> :echo 'hit F3 #'<CR> nnoremap <F3> :echo 'hit F3 #'<CR>
assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n")) assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n"))
END END
v9.CheckDefSuccess(lines) v9.CheckDefAndScriptSuccess(lines)
v9.CheckScriptSuccess(['vim9script'] + lines)
# backslash before bar is not removed
lines =<< trim END
vim9script
def Init()
noremap <buffer> <F5> <ScriptCmd>MyFunc('a') \| MyFunc('b')<CR>
enddef
Init()
unmap <buffer> <F5>
END
v9.CheckScriptSuccess(lines)
enddef enddef
def Test_normal_command() def Test_normal_command()

View File

@ -750,6 +750,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 */
/**/
4615,
/**/ /**/
4614, 4614,
/**/ /**/

View File

@ -1848,7 +1848,7 @@ compile_exec(char_u *line_arg, exarg_T *eap, cctx_T *cctx)
if ((argt & EX_TRLBAR) && !usefilter) if ((argt & EX_TRLBAR) && !usefilter)
{ {
eap->argt = argt; eap->argt = argt;
separate_nextcmd(eap); separate_nextcmd(eap, TRUE);
if (eap->nextcmd != NULL) if (eap->nextcmd != NULL)
nextcmd = eap->nextcmd; nextcmd = eap->nextcmd;
} }