Skip to content

Commit e729ce2

Browse files
committed
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.
1 parent 6db7b63 commit e729ce2

6 files changed

Lines changed: 63 additions & 5 deletions

File tree

src/ex_cmds.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5277,6 +5277,16 @@ ex_drop(exarg_T *eap)
52775277
*/
52785278
char_u *
52795279
skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
5280+
{
5281+
return skip_vimgrep_pat_ext(p, s, flags, NULL, NULL);
5282+
}
5283+
5284+
/*
5285+
* As skip_vimgrep_pat() and store the character overwritten by NUL in "cp"
5286+
* and the pointer to it in "nulp".
5287+
*/
5288+
char_u *
5289+
skip_vimgrep_pat_ext(char_u *p, char_u **s, int *flags, char_u **nulp, int *cp)
52805290
{
52815291
int c;
52825292

@@ -5287,7 +5297,14 @@ skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
52875297
*s = p;
52885298
p = skiptowhite(p);
52895299
if (s != NULL && *p != NUL)
5300+
{
5301+
if (nulp != NULL)
5302+
{
5303+
*nulp = p;
5304+
*cp = *p;
5305+
}
52905306
*p++ = NUL;
5307+
}
52915308
}
52925309
else
52935310
{
@@ -5301,7 +5318,14 @@ skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
53015318

53025319
// Truncate the pattern.
53035320
if (s != NULL)
5321+
{
5322+
if (nulp != NULL)
5323+
{
5324+
*nulp = p;
5325+
*cp = *p;
5326+
}
53045327
*p = NUL;
5328+
}
53055329
++p;
53065330

53075331
// Find the flags

src/ex_docmd.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,9 @@ parse_command_modifiers(
28812881

28822882
case 'f': // only accept ":filter {pat} cmd"
28832883
{
2884-
char_u *reg_pat;
2884+
char_u *reg_pat;
2885+
char_u *nulp = NULL;
2886+
int c = 0;
28852887

28862888
if (!checkforcmd_noparen(&p, "filter", 4)
28872889
|| *p == NUL || ends_excmd(*p))
@@ -2902,7 +2904,8 @@ parse_command_modifiers(
29022904
p = skip_vimgrep_pat(p, NULL, NULL);
29032905
else
29042906
// NOTE: This puts a NUL after the pattern.
2905-
p = skip_vimgrep_pat(p, &reg_pat, NULL);
2907+
p = skip_vimgrep_pat_ext(p, &reg_pat, NULL,
2908+
&nulp, &c);
29062909
if (p == NULL || *p == NUL)
29072910
break;
29082911
if (!skip_only)
@@ -2911,6 +2914,9 @@ parse_command_modifiers(
29112914
vim_regcomp(reg_pat, RE_MAGIC);
29122915
if (cmod->cmod_filter_regmatch.regprog == NULL)
29132916
break;
2917+
// restore the character overwritten by NUL
2918+
if (nulp != NULL)
2919+
*nulp = c;
29142920
}
29152921
eap->cmd = p;
29162922
continue;

src/proto/ex_cmds.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ int prepare_tagpreview(int undo_sync, int use_previewpopup, use_popup_T use_popu
3939
void ex_smile(exarg_T *eap);
4040
void ex_drop(exarg_T *eap);
4141
char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags);
42+
char_u *skip_vimgrep_pat_ext(char_u *p, char_u **s, int *flags, char_u **nulp, int *cp);
4243
void ex_oldfiles(exarg_T *eap);
4344
/* vim: set ft=c : */

src/testdir/test_vim9_cmd.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,14 @@ def Test_command_modifier_filter()
534534
assert_equal(execute('filter /piyo/ registers abc'), expected)
535535
END
536536
CheckDefAndScriptSuccess(lines)
537+
538+
# also do this compiled
539+
lines =<< trim END
540+
@a = 'very specific z3d37dh234 string'
541+
filter z3d37dh234 registers
542+
assert_match('very specific z3d37dh234 string', Screenline(&lines))
543+
END
544+
CheckDefAndScriptSuccess(lines)
537545
enddef
538546

539547
def Test_win_command_modifiers()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2955,
753755
/**/
754756
2954,
755757
/**/

src/vim9compile.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8536,13 +8536,30 @@ compile_put(char_u *arg, exarg_T *eap, cctx_T *cctx)
85368536
static char_u *
85378537
compile_exec(char_u *line, exarg_T *eap, cctx_T *cctx)
85388538
{
8539-
char_u *p;
8540-
int has_expr = FALSE;
8541-
char_u *nextcmd = (char_u *)"";
8539+
char_u *p;
8540+
int has_expr = FALSE;
8541+
char_u *nextcmd = (char_u *)"";
85428542

85438543
if (cctx->ctx_skip == SKIP_YES)
85448544
goto theend;
85458545

8546+
// If there was a prececing command modifier, drop it and include it in the
8547+
// EXEC command.
8548+
if (cctx->ctx_has_cmdmod)
8549+
{
8550+
garray_T *instr = &cctx->ctx_instr;
8551+
isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
8552+
8553+
if (isn->isn_type == ISN_CMDMOD)
8554+
{
8555+
vim_regfree(isn->isn_arg.cmdmod.cf_cmdmod
8556+
->cmod_filter_regmatch.regprog);
8557+
vim_free(isn->isn_arg.cmdmod.cf_cmdmod);
8558+
--instr->ga_len;
8559+
cctx->ctx_has_cmdmod = FALSE;
8560+
}
8561+
}
8562+
85468563
if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
85478564
{
85488565
long argt = eap->argt;

0 commit comments

Comments
 (0)