To: vim_dev@googlegroups.com Subject: Patch 7.3.225 Fcc: outbox From: Bram Moolenaar 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// + ENDTEST + + TEST_1: + A + B + C123456789 + D + E + F + G + H + I + J + K + lLl + mMm + nNn + oOo + pPp + qQq + rRr + sSs + tTt + + STARTTEST + :set nomagic + :set cpo& + /^TEST/ + j:s/A/&&/ + j:s/B/\&/ + j:s/\mC\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\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// + ENDTEST + + TEST_2: + A + B + C123456789 + D + E + F + G + H + I + J + K + lLl + mMm + nNn + oOo + pPp + qQq + rRr + sSs + tTt + + STARTTEST + :set magic& + :set cpo& + /^TEST/ + j:s/A/\='\'/ + j:s/B/\='\\'/ + j:s/C/\=' '/ + j:s/D/\='\ '/ + j:s/E/\='\\ '/ + j:s/F/\='\r'/ + j:s/G/\=''/ + j:s/H/\='\'/ + j:s/I/\='\\'/ + j:s/J/\='\n'/ + j:s/K/\="\r"/ + j:s/L/\="\n"/ + ENDTEST + + TEST_3: + aAa + bBb + cCc + dDd + eEe + fFf + gGg + hHh + iIi + jJj + kKk + lLl + + STARTTEST + :set magic& + :set cpo& + /^TEST/ + j:s/A/\=substitute(submatch(0), '.', '\', '')/ + j:s/B/\=substitute(submatch(0), '.', '\\', '')/ + j:s/C/\=substitute(submatch(0), '.', ' ', '')/ + j:s/D/\=substitute(submatch(0), '.', '\ ', '')/ + j:s/E/\=substitute(submatch(0), '.', '\\ ', '')/ + j:s/F/\=substitute(submatch(0), '.', '\r', '')/ + j:s/G/\=substitute(submatch(0), '.', '', '')/ + j:s/H/\=substitute(submatch(0), '.', '\', '')/ + j:s/I/\=substitute(submatch(0), '.', '\\', '')/ + j:s/J/\=substitute(submatch(0), '.', '\n', '')/ + j:s/K/\=substitute(submatch(0), '.', "\r", '')/ + j:s/L/\=substitute(submatch(0), '.', "\n", '')/ + ENDTEST + + TEST_4: + aAa + bBb + cCc + dDd + eEe + fFf + gGg + hHh + iIi + jJj + kKk + lLl + + STARTTEST + :set magic& + :set cpo& + /^TEST/ + j:s/A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . submatch(6) . submatch(5) . submatch(4) . submatch(3) . submatch(2) . submatch(1)/ + ENDTEST + + TEST_5: + A123456789 + + STARTTEST + :set magic& + /^TEST/ + :set cpo+=/ + j:s/A/a/ + j:s/B/%/ + :set cpo-=/ + j:s/C/c/ + j:s/D/%/ + ENDTEST + + TEST_6: + A + B + C + D + + STARTTEST + :set magic& + :set cpo& + /^TEST/ + j:s/A./\=submatch(0)/ + j:s/B./\=submatch(0)/ + ENDTEST + + TEST_7: + A A + BB + + STARTTEST + :g/^STARTTEST/.,/^ENDTEST/d + :1;/^Results/,$wq! test.out + ENDTEST *** ../mercurial/vim73/src/testdir/test79.ok 2011-06-19 04:30:54.000000000 +0200 --- src/testdir/test79.ok 2011-06-19 03:45:26.000000000 +0200 *************** *** 0 **** --- 1,118 ---- + Results of test71: + + + TEST_1: + AA + & + C123456789987654321 + d + d + ~ + Gg + Hh + iI + jJ + Kk + l + l + m + m + n n + oo + pp + q q + r\r + scs + tt + + + TEST_2: + && + B + C123456789987654321 + d + ~ + ~ + Gg + Hh + iI + jJ + Kk + l + l + m + m + n n + oo + pp + q q + r\r + scs + tt + + + TEST_3: + a\a + b\\b + c + c + d\ + d + e\\ + e + f\rf + g + g + h\ + h + i\\ + i + j\nj + k + k + l + l + + + TEST_4: + a\a + b\b + c + c + d + d + e\ + e + f + f + g + g + h + h + i\ + i + j + j + k + k + l + l + + + TEST_5: + A123456789987654321 + + + TEST_6: + a + a + c + % + + + TEST_7: + A + A + B + B + *** ../mercurial/vim73/src/testdir/test80.in 2011-06-19 04:30:54.000000000 +0200 --- src/testdir/test80.in 2011-06-19 03:45:26.000000000 +0200 *************** *** 0 **** --- 1,150 ---- + Test for *sub-replace-special* and *sub-replace-expression* on substitue(). + Test for submatch() on substitue(). + Test for *:s%* on :substitute. + + STARTTEST + :so small.vim + ENDTEST + + TEST_1: + + STARTTEST + :set magic + :set cpo& + :$put =\"\n\nTEST_1:\" + :$put =substitute('A', 'A', '&&', '') + :$put =substitute('B', 'B', '\&', '') + :$put =substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', '') + :$put =substitute('D', 'D', 'd', '') + :$put =substitute('E', 'E', '~', '') + :$put =substitute('F', 'F', '\~', '') + :$put =substitute('G', 'G', '\ugg', '') + :$put =substitute('H', 'H', '\Uh\Eh', '') + :$put =substitute('I', 'I', '\lII', '') + :$put =substitute('J', 'J', '\LJ\EJ', '') + :$put =substitute('K', 'K', '\Uk\ek', '') + :$put =substitute('lLl', 'L', ' ', '') + :$put =substitute('mMm', 'M', '\r', '') + :$put =substitute('nNn', 'N', '\ ', '') + :$put =substitute('oOo', 'O', '\n', '') + :$put =substitute('pPp', 'P', '\b', '') + :$put =substitute('qQq', 'Q', '\t', '') + :$put =substitute('rRr', 'R', '\\', '') + :$put =substitute('sSs', 'S', '\c', '') + :$put =substitute('uUu', 'U', \"\n\", '') + :$put =substitute('vVv', 'V', \"\b\", '') + :$put =substitute('wWw', 'W', \"\\\", '') + :$put =substitute('xXx', 'X', \"\r\", '') + /^TEST_2 + ENDTEST + + TEST_2: + + STARTTEST + :set nomagic + :set cpo& + :$put =\"\n\nTEST_2:\" + :$put =substitute('A', 'A', '&&', '') + :$put =substitute('B', 'B', '\&', '') + :$put =substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', '') + :$put =substitute('D', 'D', 'd', '') + :$put =substitute('E', 'E', '~', '') + :$put =substitute('F', 'F', '\~', '') + :$put =substitute('G', 'G', '\ugg', '') + :$put =substitute('H', 'H', '\Uh\Eh', '') + :$put =substitute('I', 'I', '\lII', '') + :$put =substitute('J', 'J', '\LJ\EJ', '') + :$put =substitute('K', 'K', '\Uk\ek', '') + :$put =substitute('lLl', 'L', ' ', '') + :$put =substitute('mMm', 'M', '\r', '') + :$put =substitute('nNn', 'N', '\ ', '') + :$put =substitute('oOo', 'O', '\n', '') + :$put =substitute('pPp', 'P', '\b', '') + :$put =substitute('qQq', 'Q', '\t', '') + :$put =substitute('rRr', 'R', '\\', '') + :$put =substitute('sSs', 'S', '\c', '') + :$put =substitute('tTt', 'T', \"\r\", '') + :$put =substitute('uUu', 'U', \"\n\", '') + :$put =substitute('vVv', 'V', \"\b\", '') + :$put =substitute('wWw', 'W', \"\\\", '') + /^TEST_3 + ENDTEST + + TEST_3: + + STARTTEST + :set magic& + :set cpo& + :$put =\"\n\nTEST_3:\" + :let y = substitute('aAa', 'A', '\="\\"', '') | $put =y + :let y = substitute('bBb', 'B', '\="\\\\"', '') | $put =y + :let y = substitute('cCc', 'C', '\=" "', '') | $put =y + :let y = substitute('dDd', 'D', '\="\\ "', '') | $put =y + :let y = substitute('eEe', 'E', '\="\\\\ "', '') | $put =y + :let y = substitute('fFf', 'F', '\="\\r"', '') | $put =y + :let y = substitute('jJj', 'J', '\="\\n"', '') | $put =y + :let y = substitute('kKk', 'K', '\="\r"', '') | $put =y + :let y = substitute('lLl', 'L', '\="\n"', '') | $put =y + /^TEST_4 + ENDTEST + + TEST_4: + + STARTTEST + :set magic& + :set cpo& + :$put =\"\n\nTEST_4:\" + :let y = substitute('aAa', 'A', '\=substitute(submatch(0), ".", "\\", "")', '') | $put =y + :let y = substitute('bBb', 'B', '\=substitute(submatch(0), ".", "\\\\", "")', '') | $put =y + :let y = substitute('cCc', 'C', '\=substitute(submatch(0), ".", " ", "")', '') | $put =y + :let y = substitute('dDd', 'D', '\=substitute(submatch(0), ".", "\\ ", "")', '') | $put =y + :let y = substitute('eEe', 'E', '\=substitute(submatch(0), ".", "\\\\ ", "")', '') | $put =y + :let y = substitute('fFf', 'F', '\=substitute(submatch(0), ".", "\\r", "")', '') | $put =y + :let y = substitute('jJj', 'J', '\=substitute(submatch(0), ".", "\\n", "")', '') | $put =y + :let y = substitute('kKk', 'K', '\=substitute(submatch(0), ".", "\r", "")', '') | $put =y + :let y = substitute('lLl', 'L', '\=substitute(submatch(0), ".", "\n", "")', '') | $put =y + /^TEST_5 + ENDTEST + + TEST_5: + + STARTTEST + :set magic& + :set cpo& + :$put =\"\n\nTEST_5:\" + :$put =substitute('A123456789', 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . submatch(6) . submatch(5) . submatch(4) . submatch(3) . submatch(2) . submatch(1)', '') + /^TEST_6 + ENDTEST + + TEST_6: + + STARTTEST + :set magic& + :$put =\"\n\nTEST_6:\" + :set cpo+=/ + :$put =substitute('A', 'A', 'a', '') + :$put =substitute('B', 'B', '%', '') + :set cpo-=/ + :$put =substitute('C', 'C', 'c', '') + :$put =substitute('D', 'D', '%', '') + /^TEST_7 + ENDTEST + + TEST_7: + + STARTTEST + :set magic& + :set cpo& + :$put =\"\n\nTEST_7:\" + :$put =substitute('A A', 'A.', '\=submatch(0)', '') + :$put =substitute(\"B\nB\", 'B.', '\=submatch(0)', '') + /^TEST_8 + ENDTEST + + TEST_8: + + STARTTEST + :/^Results/,$wq! test.out + ENDTEST + + Results of test72: *** ../mercurial/vim73/src/testdir/test80.ok 2011-06-19 04:30:54.000000000 +0200 --- src/testdir/test80.ok 2011-06-19 03:45:26.000000000 +0200 *************** *** 0 **** --- 1,101 ---- + Results of test72: + + + TEST_1: + AA + & + C123456789987654321 + d + ~ + ~ + Gg + Hh + iI + jJ + Kk + l l + m m + n n + o + o + pp + q q + r\r + scs + u + u + vv + w\w + x x + + + TEST_2: + AA + & + C123456789987654321 + d + ~ + ~ + Gg + Hh + iI + jJ + Kk + l l + m m + n n + o + o + pp + q q + r\r + scs + t t + u + u + vv + w\w + + + TEST_3: + a\a + b\\b + c c + d\ d + e\\ e + f\rf + j\nj + k k + l + l + + + TEST_4: + a\a + b\b + c c + d d + e\ e + f f + j + j + k k + l + l + + + TEST_5: + A123456789987654321 + + + TEST_6: + a + % + c + % + + + TEST_7: + A A + B + B *** ../mercurial/vim73/src/testdir/Makefile 2011-06-13 01:07:22.000000000 +0200 --- src/testdir/Makefile 2011-06-19 03:53:36.000000000 +0200 *************** *** 25,31 **** test59.out test60.out test61.out test62.out test63.out \ test64.out test65.out test66.out test67.out test68.out \ test69.out test70.out test71.out test72.out test73.out \ ! test74.out test75.out test76.out test77.out test78.out SCRIPTS_GUI = test16.out --- 25,32 ---- test59.out test60.out test61.out test62.out test63.out \ test64.out test65.out test66.out test67.out test68.out \ test69.out test70.out test71.out test72.out test73.out \ ! test74.out test75.out test76.out test77.out test78.out \ ! test79.out test80.out SCRIPTS_GUI = test16.out *** ../mercurial/vim73/src/testdir/Make_amiga.mak 2011-06-13 01:07:22.000000000 +0200 --- src/testdir/Make_amiga.mak 2011-06-19 03:52:32.000000000 +0200 *************** *** 28,34 **** test61.out test62.out test63.out test64.out test65.out \ test66.out test67.out test68.out test69.out test70.out \ test71.out test72.out test73.out test74.out test75.out \ ! test76.out test77.out test78.out .SUFFIXES: .in .out --- 28,34 ---- test61.out test62.out test63.out test64.out test65.out \ test66.out test67.out test68.out test69.out test70.out \ test71.out test72.out test73.out test74.out test75.out \ ! test76.out test77.out test78.out test79.out test80.out .SUFFIXES: .in .out *************** *** 126,128 **** --- 126,130 ---- test76.out: test76.in test77.out: test77.in test78.out: test78.in + test79.out: test79.in + test80.out: test80.in *** ../mercurial/vim73/src/testdir/Make_dos.mak 2011-06-13 01:07:22.000000000 +0200 --- src/testdir/Make_dos.mak 2011-06-19 03:52:43.000000000 +0200 *************** *** 28,34 **** test37.out test38.out test39.out test40.out test41.out \ test42.out test52.out test65.out test66.out test67.out \ test68.out test69.out test71.out test72.out test73.out \ ! test74.out test75.out test76.out test77.out test78.out SCRIPTS32 = test50.out test70.out --- 28,35 ---- test37.out test38.out test39.out test40.out test41.out \ test42.out test52.out test65.out test66.out test67.out \ test68.out test69.out test71.out test72.out test73.out \ ! test74.out test75.out test76.out test77.out test78.out \ ! test79.out test80.out SCRIPTS32 = test50.out test70.out *** ../mercurial/vim73/src/testdir/Make_ming.mak 2011-06-13 01:07:22.000000000 +0200 --- src/testdir/Make_ming.mak 2011-06-19 03:52:58.000000000 +0200 *************** *** 48,54 **** test37.out test38.out test39.out test40.out test41.out \ test42.out test52.out test65.out test66.out test67.out \ test68.out test69.out test71.out test72.out test73.out \ ! test74.out test75.out test76.out test77.out test78.out SCRIPTS32 = test50.out test70.out --- 48,55 ---- test37.out test38.out test39.out test40.out test41.out \ test42.out test52.out test65.out test66.out test67.out \ test68.out test69.out test71.out test72.out test73.out \ ! test74.out test75.out test76.out test77.out test78.out \ ! test79.out test80.out SCRIPTS32 = test50.out test70.out *** ../mercurial/vim73/src/testdir/Make_os2.mak 2011-06-13 01:07:22.000000000 +0200 --- src/testdir/Make_os2.mak 2011-06-19 03:53:09.000000000 +0200 *************** *** 28,34 **** test61.out test62.out test63.out test64.out test65.out \ test66.out test67.out test68.out test69.out test70.out \ test71.out test72.out test73.out test74.out test75.out \ ! test76.out test77.out test78.out .SUFFIXES: .in .out --- 28,34 ---- test61.out test62.out test63.out test64.out test65.out \ test66.out test67.out test68.out test69.out test70.out \ test71.out test72.out test73.out test74.out test75.out \ ! test76.out test77.out test78.out test79.out test80.out .SUFFIXES: .in .out *** ../mercurial/vim73/src/testdir/Make_vms.mms 2011-06-13 01:07:22.000000000 +0200 --- src/testdir/Make_vms.mms 2011-06-19 03:53:18.000000000 +0200 *************** *** 4,10 **** # Authors: Zoltan Arpadffy, # Sandor Kopanyi, # ! # Last change: 2011 Jun 13 # # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64. # Edit the lines in the Configuration section below to select. --- 4,10 ---- # Authors: Zoltan Arpadffy, # Sandor Kopanyi, # ! # Last change: 2011 Jun 19 # # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64. # Edit the lines in the Configuration section below to select. *************** *** 75,81 **** test61.out test62.out test63.out test64.out test65.out \ test66.out test67.out test68.out test69.out \ test71.out test72.out test74.out test75.out test76.out \ ! test77.out test78.out # Known problems: # Test 30: a problem around mac format - unknown reason --- 75,81 ---- test61.out test62.out test63.out test64.out test65.out \ test66.out test67.out test68.out test69.out \ test71.out test72.out test74.out test75.out test76.out \ ! test77.out test78.out test79.out test80.out # Known problems: # Test 30: a problem around mac format - unknown reason *** ../vim-7.3.224/src/version.c 2011-06-19 02:55:32.000000000 +0200 --- src/version.c 2011-06-19 04:27:54.000000000 +0200 *************** *** 711,712 **** --- 711,714 ---- { /* Add new patch number below this line */ + /**/ + 225, /**/ -- hundred-and-one symptoms of being an internet addict: 194. Your business cards contain your e-mail and home page address. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///