diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-04-19 16:48:48 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-04-19 16:48:48 +0200 |
commit | 4c13721482d7786f92f5a56e43b0f5c499264b7e (patch) | |
tree | 2aae28c81b61721cb9ecc5d9aee66bb51d67e371 /src/ex_cmds.c | |
parent | e8209b91b9974da95899b51dba4058b411d04d5b (diff) |
patch 8.2.2784: Vim9: cannot use \=expr in :substitutev8.2.2784
Problem: Vim9: cannot use \=expr in :substitute.
Solution: Compile the expression into instructions and execute them when
invoked.
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r-- | src/ex_cmds.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 6cd54d20ce..96ff6ecba6 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -3604,6 +3604,29 @@ typedef struct { } subflags_T; /* + * Skip over the "sub" part in :s/pat/sub/ where "delimiter" is the separating + * character. + */ + char_u * +skip_substitute(char_u *start, int delimiter) +{ + char_u *p = start; + + while (p[0]) + { + if (p[0] == delimiter) // end delimiter found + { + *p++ = NUL; // replace it with a NUL + break; + } + if (p[0] == '\\' && p[1] != 0) // skip escaped characters + ++p; + MB_PTR_ADV(p); + } + return p; +} + +/* * Perform a substitution from line eap->line1 to line eap->line2 using the * command pointed to by eap->arg which should be of the form: * @@ -3704,18 +3727,7 @@ ex_substitute(exarg_T *eap) * Vim we want to use '\n' to find/substitute a NUL. */ sub = cmd; // remember the start of the substitution - - while (cmd[0]) - { - if (cmd[0] == delimiter) // end delimiter found - { - *cmd++ = NUL; // replace it with a NUL - break; - } - if (cmd[0] == '\\' && cmd[1] != 0) // skip escaped characters - ++cmd; - MB_PTR_ADV(cmd); - } + cmd = skip_substitute(cmd, delimiter); if (!eap->skip) { |