Mercurial > vim
comparison src/regexp.c @ 2904:c249d9aa60f7 v7.3.225
updated for version 7.3.225
Problem: Using "\n" in a substitute inside ":s" does not result in a line
break.
Solution: Change behavior inside vim_regexec_nl(). Add tests. (Motoya
Kurotsu)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sun, 19 Jun 2011 04:32:15 +0200 |
parents | 766918de9e3a |
children | 59130cd78dfc |
comparison
equal
deleted
inserted
replaced
2903:df5d2e1bff34 | 2904:c249d9aa60f7 |
---|---|
6870 * that contains a call to substitute() and submatch(). */ | 6870 * that contains a call to substitute() and submatch(). */ |
6871 static regmatch_T *submatch_match; | 6871 static regmatch_T *submatch_match; |
6872 static regmmatch_T *submatch_mmatch; | 6872 static regmmatch_T *submatch_mmatch; |
6873 static linenr_T submatch_firstlnum; | 6873 static linenr_T submatch_firstlnum; |
6874 static linenr_T submatch_maxline; | 6874 static linenr_T submatch_maxline; |
6875 static int submatch_line_lbr; | |
6875 #endif | 6876 #endif |
6876 | 6877 |
6877 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO) | 6878 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO) |
6878 /* | 6879 /* |
6879 * vim_regsub() - perform substitutions after a vim_regexec() or | 6880 * vim_regsub() - perform substitutions after a vim_regexec() or |
6996 * vim_regexec_multi() can't be called recursively. */ | 6997 * vim_regexec_multi() can't be called recursively. */ |
6997 submatch_match = reg_match; | 6998 submatch_match = reg_match; |
6998 submatch_mmatch = reg_mmatch; | 6999 submatch_mmatch = reg_mmatch; |
6999 submatch_firstlnum = reg_firstlnum; | 7000 submatch_firstlnum = reg_firstlnum; |
7000 submatch_maxline = reg_maxline; | 7001 submatch_maxline = reg_maxline; |
7002 submatch_line_lbr = reg_line_lbr; | |
7001 save_reg_win = reg_win; | 7003 save_reg_win = reg_win; |
7002 save_ireg_ic = ireg_ic; | 7004 save_ireg_ic = ireg_ic; |
7003 can_f_submatch = TRUE; | 7005 can_f_submatch = TRUE; |
7004 | 7006 |
7005 eval_result = eval_to_string(source + 2, NULL, TRUE); | 7007 eval_result = eval_to_string(source + 2, NULL, TRUE); |
7007 { | 7009 { |
7008 int had_backslash = FALSE; | 7010 int had_backslash = FALSE; |
7009 | 7011 |
7010 for (s = eval_result; *s != NUL; mb_ptr_adv(s)) | 7012 for (s = eval_result; *s != NUL; mb_ptr_adv(s)) |
7011 { | 7013 { |
7012 /* Change NL to CR, so that it becomes a line break. | 7014 /* Change NL to CR, so that it becomes a line break, |
7015 * unless called from vim_regexec_nl(). | |
7013 * Skip over a backslashed character. */ | 7016 * Skip over a backslashed character. */ |
7014 if (*s == NL) | 7017 if (*s == NL && !submatch_line_lbr) |
7015 *s = CAR; | 7018 *s = CAR; |
7016 else if (*s == '\\' && s[1] != NUL) | 7019 else if (*s == '\\' && s[1] != NUL) |
7017 { | 7020 { |
7018 ++s; | 7021 ++s; |
7019 /* Change NL to CR here too, so that this works: | 7022 /* Change NL to CR here too, so that this works: |
7020 * :s/abc\\\ndef/\="aaa\\\nbbb"/ on text: | 7023 * :s/abc\\\ndef/\="aaa\\\nbbb"/ on text: |
7021 * abc\ | 7024 * abc\ |
7022 * def | 7025 * def |
7026 * Not when called from vim_regexec_nl(). | |
7023 */ | 7027 */ |
7024 if (*s == NL) | 7028 if (*s == NL && !submatch_line_lbr) |
7025 *s = CAR; | 7029 *s = CAR; |
7026 had_backslash = TRUE; | 7030 had_backslash = TRUE; |
7027 } | 7031 } |
7028 } | 7032 } |
7029 if (had_backslash && backslash) | 7033 if (had_backslash && backslash) |
7042 | 7046 |
7043 reg_match = submatch_match; | 7047 reg_match = submatch_match; |
7044 reg_mmatch = submatch_mmatch; | 7048 reg_mmatch = submatch_mmatch; |
7045 reg_firstlnum = submatch_firstlnum; | 7049 reg_firstlnum = submatch_firstlnum; |
7046 reg_maxline = submatch_maxline; | 7050 reg_maxline = submatch_maxline; |
7051 reg_line_lbr = submatch_line_lbr; | |
7047 reg_win = save_reg_win; | 7052 reg_win = save_reg_win; |
7048 ireg_ic = save_ireg_ic; | 7053 ireg_ic = save_ireg_ic; |
7049 can_f_submatch = FALSE; | 7054 can_f_submatch = FALSE; |
7050 } | 7055 } |
7051 #endif | 7056 #endif |