forked from aniani/vim
patch 8.2.2955: Vim9: using filter in compiled command does not work
Problem: Vim9: using filter in compiled command does not work. Solution: Generate EXEC including the command modifier.
This commit is contained in:
@@ -5277,6 +5277,16 @@ ex_drop(exarg_T *eap)
|
|||||||
*/
|
*/
|
||||||
char_u *
|
char_u *
|
||||||
skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
|
skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
|
||||||
|
{
|
||||||
|
return skip_vimgrep_pat_ext(p, s, flags, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* As skip_vimgrep_pat() and store the character overwritten by NUL in "cp"
|
||||||
|
* and the pointer to it in "nulp".
|
||||||
|
*/
|
||||||
|
char_u *
|
||||||
|
skip_vimgrep_pat_ext(char_u *p, char_u **s, int *flags, char_u **nulp, int *cp)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@@ -5287,8 +5297,15 @@ skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
|
|||||||
*s = p;
|
*s = p;
|
||||||
p = skiptowhite(p);
|
p = skiptowhite(p);
|
||||||
if (s != NULL && *p != NUL)
|
if (s != NULL && *p != NUL)
|
||||||
|
{
|
||||||
|
if (nulp != NULL)
|
||||||
|
{
|
||||||
|
*nulp = p;
|
||||||
|
*cp = *p;
|
||||||
|
}
|
||||||
*p++ = NUL;
|
*p++ = NUL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// ":vimgrep /pattern/[g][j] fname"
|
// ":vimgrep /pattern/[g][j] fname"
|
||||||
@@ -5301,7 +5318,14 @@ skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
|
|||||||
|
|
||||||
// Truncate the pattern.
|
// Truncate the pattern.
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
|
{
|
||||||
|
if (nulp != NULL)
|
||||||
|
{
|
||||||
|
*nulp = p;
|
||||||
|
*cp = *p;
|
||||||
|
}
|
||||||
*p = NUL;
|
*p = NUL;
|
||||||
|
}
|
||||||
++p;
|
++p;
|
||||||
|
|
||||||
// Find the flags
|
// Find the flags
|
||||||
|
|||||||
@@ -2882,6 +2882,8 @@ parse_command_modifiers(
|
|||||||
case 'f': // only accept ":filter {pat} cmd"
|
case 'f': // only accept ":filter {pat} cmd"
|
||||||
{
|
{
|
||||||
char_u *reg_pat;
|
char_u *reg_pat;
|
||||||
|
char_u *nulp = NULL;
|
||||||
|
int c = 0;
|
||||||
|
|
||||||
if (!checkforcmd_noparen(&p, "filter", 4)
|
if (!checkforcmd_noparen(&p, "filter", 4)
|
||||||
|| *p == NUL || ends_excmd(*p))
|
|| *p == NUL || ends_excmd(*p))
|
||||||
@@ -2902,7 +2904,8 @@ parse_command_modifiers(
|
|||||||
p = skip_vimgrep_pat(p, NULL, NULL);
|
p = skip_vimgrep_pat(p, NULL, NULL);
|
||||||
else
|
else
|
||||||
// NOTE: This puts a NUL after the pattern.
|
// NOTE: This puts a NUL after the pattern.
|
||||||
p = skip_vimgrep_pat(p, ®_pat, NULL);
|
p = skip_vimgrep_pat_ext(p, ®_pat, NULL,
|
||||||
|
&nulp, &c);
|
||||||
if (p == NULL || *p == NUL)
|
if (p == NULL || *p == NUL)
|
||||||
break;
|
break;
|
||||||
if (!skip_only)
|
if (!skip_only)
|
||||||
@@ -2911,6 +2914,9 @@ parse_command_modifiers(
|
|||||||
vim_regcomp(reg_pat, RE_MAGIC);
|
vim_regcomp(reg_pat, RE_MAGIC);
|
||||||
if (cmod->cmod_filter_regmatch.regprog == NULL)
|
if (cmod->cmod_filter_regmatch.regprog == NULL)
|
||||||
break;
|
break;
|
||||||
|
// restore the character overwritten by NUL
|
||||||
|
if (nulp != NULL)
|
||||||
|
*nulp = c;
|
||||||
}
|
}
|
||||||
eap->cmd = p;
|
eap->cmd = p;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -39,5 +39,6 @@ int prepare_tagpreview(int undo_sync, int use_previewpopup, use_popup_T use_popu
|
|||||||
void ex_smile(exarg_T *eap);
|
void ex_smile(exarg_T *eap);
|
||||||
void ex_drop(exarg_T *eap);
|
void ex_drop(exarg_T *eap);
|
||||||
char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags);
|
char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags);
|
||||||
|
char_u *skip_vimgrep_pat_ext(char_u *p, char_u **s, int *flags, char_u **nulp, int *cp);
|
||||||
void ex_oldfiles(exarg_T *eap);
|
void ex_oldfiles(exarg_T *eap);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
|||||||
@@ -534,6 +534,14 @@ def Test_command_modifier_filter()
|
|||||||
assert_equal(execute('filter /piyo/ registers abc'), expected)
|
assert_equal(execute('filter /piyo/ registers abc'), expected)
|
||||||
END
|
END
|
||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
|
||||||
|
# also do this compiled
|
||||||
|
lines =<< trim END
|
||||||
|
@a = 'very specific z3d37dh234 string'
|
||||||
|
filter z3d37dh234 registers
|
||||||
|
assert_match('very specific z3d37dh234 string', Screenline(&lines))
|
||||||
|
END
|
||||||
|
CheckDefAndScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_win_command_modifiers()
|
def Test_win_command_modifiers()
|
||||||
|
|||||||
@@ -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 */
|
||||||
|
/**/
|
||||||
|
2955,
|
||||||
/**/
|
/**/
|
||||||
2954,
|
2954,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
@@ -8543,6 +8543,23 @@ compile_exec(char_u *line, exarg_T *eap, cctx_T *cctx)
|
|||||||
if (cctx->ctx_skip == SKIP_YES)
|
if (cctx->ctx_skip == SKIP_YES)
|
||||||
goto theend;
|
goto theend;
|
||||||
|
|
||||||
|
// If there was a prececing command modifier, drop it and include it in the
|
||||||
|
// EXEC command.
|
||||||
|
if (cctx->ctx_has_cmdmod)
|
||||||
|
{
|
||||||
|
garray_T *instr = &cctx->ctx_instr;
|
||||||
|
isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
|
||||||
|
|
||||||
|
if (isn->isn_type == ISN_CMDMOD)
|
||||||
|
{
|
||||||
|
vim_regfree(isn->isn_arg.cmdmod.cf_cmdmod
|
||||||
|
->cmod_filter_regmatch.regprog);
|
||||||
|
vim_free(isn->isn_arg.cmdmod.cf_cmdmod);
|
||||||
|
--instr->ga_len;
|
||||||
|
cctx->ctx_has_cmdmod = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
|
if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
|
||||||
{
|
{
|
||||||
long argt = eap->argt;
|
long argt = eap->argt;
|
||||||
|
|||||||
Reference in New Issue
Block a user