To: vim_dev@googlegroups.com Subject: Patch 7.3.225 Fcc: outbox From: Bram Moolenaar <Bram@moolenaar.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 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) Files: src/regexp.c, src/testdir/test79.in, src/testdir/test79.ok, src/testdir/test80.in, src/testdir/test80.ok, src/testdir/Makefile, src/testdir/Make_amiga.mak, src/testdir/Make_dos.mak, src/testdir/Make_ming.mak, src/testdir/Make_os2.mak, src/testdir/Make_vms.mms *** ../mercurial/vim73/src/regexp.c 2010-09-14 10:55:24.000000000 +0200 --- src/regexp.c 2011-06-19 04:03:54.000000000 +0200 *************** *** 6872,6877 **** --- 6872,6878 ---- static regmmatch_T *submatch_mmatch; static linenr_T submatch_firstlnum; static linenr_T submatch_maxline; + static int submatch_line_lbr; #endif #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO) *************** *** 6998,7003 **** --- 6999,7005 ---- submatch_mmatch = reg_mmatch; submatch_firstlnum = reg_firstlnum; submatch_maxline = reg_maxline; + submatch_line_lbr = reg_line_lbr; save_reg_win = reg_win; save_ireg_ic = ireg_ic; can_f_submatch = TRUE; *************** *** 7009,7017 **** for (s = eval_result; *s != NUL; mb_ptr_adv(s)) { ! /* Change NL to CR, so that it becomes a line break. * Skip over a backslashed character. */ ! if (*s == NL) *s = CAR; else if (*s == '\\' && s[1] != NUL) { --- 7011,7020 ---- for (s = eval_result; *s != NUL; mb_ptr_adv(s)) { ! /* Change NL to CR, so that it becomes a line break, ! * unless called from vim_regexec_nl(). * Skip over a backslashed character. */ ! if (*s == NL && !submatch_line_lbr) *s = CAR; else if (*s == '\\' && s[1] != NUL) { *************** *** 7020,7027 **** * :s/abc\\\ndef/\="aaa\\\nbbb"/ on text: * abc\ * def */ ! if (*s == NL) *s = CAR; had_backslash = TRUE; } --- 7023,7031 ---- * :s/abc\\\ndef/\="aaa\\\nbbb"/ on text: * abc\ * def + * Not when called from vim_regexec_nl(). */ ! if (*s == NL && !submatch_line_lbr) *s = CAR; had_backslash = TRUE; } *************** *** 7044,7049 **** --- 7048,7054 ---- reg_mmatch = submatch_mmatch; reg_firstlnum = submatch_firstlnum; reg_maxline = submatch_maxline; + reg_line_lbr = submatch_line_lbr; reg_win = save_reg_win; ireg_ic = save_ireg_ic; can_f_submatch = FALSE; *** ../mercurial/vim73/src/testdir/test79.in 2011-06-19 04:30:54.000000000 +0200 --- src/testdir/test79.in 2011-06-19 03:45:26.000000000 +0200 *************** *** 0 **** --- 1,213 ---- + Test for *sub-replace-special* and *sub-replace-expression* on :substitute. + Test for submatch() on :substitue. + Test for *:s%* on :substitute. + + STARTTEST + :so small.vim + ENDTEST + + Results of test71: + + STARTTEST + :set magic + :set cpo& + /^TEST/ + j:s/A/&&/ + j:s/B/\&/ + j:s/C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/ + j:s/D/d/ + j:s/E/~/ + j:s/F/\~/ + j:s/G/\ugg/ + j:s/H/\Uh\Eh/ + j:s/I/\lII/ + j:s/J/\LJ\EJ/ + j:s/K/\Uk\ek/ + j:s/L/ / + j:s/M/\r/ + j:s/N/\ / + j:s/O/\n/ + j:s/P/\b/ + j:s/Q/\t/ + j:s/R/\\/ + j:s/S/\c/ + j:s/T/