1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Using "\n" in a substitute inside ":s" does not result in a line
13 Solution: Change behavior inside vim_regexec_nl(). Add tests. (Motoya
15 Files: src/regexp.c, src/testdir/test79.in, src/testdir/test79.ok,
16 src/testdir/test80.in, src/testdir/test80.ok,
17 src/testdir/Makefile, src/testdir/Make_amiga.mak,
18 src/testdir/Make_dos.mak, src/testdir/Make_ming.mak,
19 src/testdir/Make_os2.mak, src/testdir/Make_vms.mms
21 *** ../mercurial/vim73/src/regexp.c 2010-09-14 10:55:24.000000000 +0200
22 --- src/regexp.c 2011-06-19 04:03:54.000000000 +0200
26 static regmmatch_T *submatch_mmatch;
27 static linenr_T submatch_firstlnum;
28 static linenr_T submatch_maxline;
29 + static int submatch_line_lbr;
32 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO)
36 submatch_mmatch = reg_mmatch;
37 submatch_firstlnum = reg_firstlnum;
38 submatch_maxline = reg_maxline;
39 + submatch_line_lbr = reg_line_lbr;
40 save_reg_win = reg_win;
41 save_ireg_ic = ireg_ic;
42 can_f_submatch = TRUE;
46 for (s = eval_result; *s != NUL; mb_ptr_adv(s))
48 ! /* Change NL to CR, so that it becomes a line break.
49 * Skip over a backslashed character. */
52 else if (*s == '\\' && s[1] != NUL)
56 for (s = eval_result; *s != NUL; mb_ptr_adv(s))
58 ! /* Change NL to CR, so that it becomes a line break,
59 ! * unless called from vim_regexec_nl().
60 * Skip over a backslashed character. */
61 ! if (*s == NL && !submatch_line_lbr)
63 else if (*s == '\\' && s[1] != NUL)
67 * :s/abc\\\ndef/\="aaa\\\nbbb"/ on text:
76 * :s/abc\\\ndef/\="aaa\\\nbbb"/ on text:
79 + * Not when called from vim_regexec_nl().
81 ! if (*s == NL && !submatch_line_lbr)
88 reg_mmatch = submatch_mmatch;
89 reg_firstlnum = submatch_firstlnum;
90 reg_maxline = submatch_maxline;
91 + reg_line_lbr = submatch_line_lbr;
92 reg_win = save_reg_win;
93 ireg_ic = save_ireg_ic;
94 can_f_submatch = FALSE;
95 *** ../mercurial/vim73/src/testdir/test79.in 2011-06-19 04:30:54.000000000 +0200
96 --- src/testdir/test79.in 2011-06-19 03:45:26.000000000 +0200
100 + Test for *sub-replace-special* and *sub-replace-expression* on :substitute.
101 + Test for submatch() on :substitue.
102 + Test for *:s%* on :substitute.
116 + j:s/C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/
164 + j:s/\mC\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/
242 + j:s/A/\=substitute(submatch(0), '.', '\', '')/
243 + j:s/B/\=substitute(submatch(0), '.', '\\', '')/
244 + j:s/C/\=substitute(submatch(0), '.', '
\16', '')/
245 + j:s/D/\=substitute(submatch(0), '.', '\
\16', '')/
246 + j:s/E/\=substitute(submatch(0), '.', '\\
\16', '')/
247 + j:s/F/\=substitute(submatch(0), '.', '\r', '')/
248 + j:s/G/\=substitute(submatch(0), '.', '
\16\0', '')/
249 + j:s/H/\=substitute(submatch(0), '.', '\
\16\0', '')/
250 + j:s/I/\=substitute(submatch(0), '.', '\\
\16\0', '')/
251 + j:s/J/\=substitute(submatch(0), '.', '\n', '')/
252 + j:s/K/\=substitute(submatch(0), '.', "\r", '')/
253 + j:s/L/\=substitute(submatch(0), '.', "\n", '')/
274 + j:s/A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . submatch(6) . submatch(5) . submatch(4) . submatch(3) . submatch(2) . submatch(1)/
301 + j:s/A./\=submatch(0)/
302 + j:s/B./\=submatch(0)/
310 + :g/^STARTTEST/.,/^ENDTEST/d
311 + :1;/^Results/,$wq! test.out
313 *** ../mercurial/vim73/src/testdir/test79.ok 2011-06-19 04:30:54.000000000 +0200
314 --- src/testdir/test79.ok 2011-06-19 03:45:26.000000000 +0200
324 + C123456789987654321
349 + C123456789987654321
420 + A123456789987654321
436 *** ../mercurial/vim73/src/testdir/test80.in 2011-06-19 04:30:54.000000000 +0200
437 --- src/testdir/test80.in 2011-06-19 03:45:26.000000000 +0200
441 + Test for *sub-replace-special* and *sub-replace-expression* on substitue().
442 + Test for submatch() on substitue().
443 + Test for *:s%* on :substitute.
454 + :$put =\"\n\nTEST_1:\"
455 + :$put =substitute('A', 'A', '&&', '')
456 + :$put =substitute('B', 'B', '\&', '')
457 + :$put =substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', '')
458 + :$put =substitute('D', 'D', 'd', '')
459 + :$put =substitute('E', 'E', '~', '')
460 + :$put =substitute('F', 'F', '\~', '')
461 + :$put =substitute('G', 'G', '\ugg', '')
462 + :$put =substitute('H', 'H', '\Uh\Eh', '')
463 + :$put =substitute('I', 'I', '\lII', '')
464 + :$put =substitute('J', 'J', '\LJ\EJ', '')
465 + :$put =substitute('K', 'K', '\Uk\ek', '')
466 + :$put =substitute('lLl', 'L', '
\16', '')
467 + :$put =substitute('mMm', 'M', '\r', '')
468 + :$put =substitute('nNn', 'N', '\
\16', '')
469 + :$put =substitute('oOo', 'O', '\n', '')
470 + :$put =substitute('pPp', 'P', '\b', '')
471 + :$put =substitute('qQq', 'Q', '\t', '')
472 + :$put =substitute('rRr', 'R', '\\', '')
473 + :$put =substitute('sSs', 'S', '\c', '')
474 + :$put =substitute('uUu', 'U', \"\n\", '')
475 + :$put =substitute('vVv', 'V', \"\b\", '')
476 + :$put =substitute('wWw', 'W', \"\\\", '')
477 + :$put =substitute('xXx', 'X', \"\r\", '')
486 + :$put =\"\n\nTEST_2:\"
487 + :$put =substitute('A', 'A', '&&', '')
488 + :$put =substitute('B', 'B', '\&', '')
489 + :$put =substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', '')
490 + :$put =substitute('D', 'D', 'd', '')
491 + :$put =substitute('E', 'E', '~', '')
492 + :$put =substitute('F', 'F', '\~', '')
493 + :$put =substitute('G', 'G', '\ugg', '')
494 + :$put =substitute('H', 'H', '\Uh\Eh', '')
495 + :$put =substitute('I', 'I', '\lII', '')
496 + :$put =substitute('J', 'J', '\LJ\EJ', '')
497 + :$put =substitute('K', 'K', '\Uk\ek', '')
498 + :$put =substitute('lLl', 'L', '
\16', '')
499 + :$put =substitute('mMm', 'M', '\r', '')
500 + :$put =substitute('nNn', 'N', '\
\16', '')
501 + :$put =substitute('oOo', 'O', '\n', '')
502 + :$put =substitute('pPp', 'P', '\b', '')
503 + :$put =substitute('qQq', 'Q', '\t', '')
504 + :$put =substitute('rRr', 'R', '\\', '')
505 + :$put =substitute('sSs', 'S', '\c', '')
506 + :$put =substitute('tTt', 'T', \"\r\", '')
507 + :$put =substitute('uUu', 'U', \"\n\", '')
508 + :$put =substitute('vVv', 'V', \"\b\", '')
509 + :$put =substitute('wWw', 'W', \"\\\", '')
518 + :$put =\"\n\nTEST_3:\"
519 + :let y = substitute('aAa', 'A', '\="\\"', '') | $put =y
520 + :let y = substitute('bBb', 'B', '\="\\\\"', '') | $put =y
521 + :let y = substitute('cCc', 'C', '\="
\16"', '') | $put =y
522 + :let y = substitute('dDd', 'D', '\="\\
\16"', '') | $put =y
523 + :let y = substitute('eEe', 'E', '\="\\\\
\16"', '') | $put =y
524 + :let y = substitute('fFf', 'F', '\="\\r"', '') | $put =y
525 + :let y = substitute('jJj', 'J', '\="\\n"', '') | $put =y
526 + :let y = substitute('kKk', 'K', '\="\r"', '') | $put =y
527 + :let y = substitute('lLl', 'L', '\="\n"', '') | $put =y
536 + :$put =\"\n\nTEST_4:\"
537 + :let y = substitute('aAa', 'A', '\=substitute(submatch(0), ".", "\\", "")', '') | $put =y
538 + :let y = substitute('bBb', 'B', '\=substitute(submatch(0), ".", "\\\\", "")', '') | $put =y
539 + :let y = substitute('cCc', 'C', '\=substitute(submatch(0), ".", "
\16", "")', '') | $put =y
540 + :let y = substitute('dDd', 'D', '\=substitute(submatch(0), ".", "\\
\16", "")', '') | $put =y
541 + :let y = substitute('eEe', 'E', '\=substitute(submatch(0), ".", "\\\\
\16", "")', '') | $put =y
542 + :let y = substitute('fFf', 'F', '\=substitute(submatch(0), ".", "\\r", "")', '') | $put =y
543 + :let y = substitute('jJj', 'J', '\=substitute(submatch(0), ".", "\\n", "")', '') | $put =y
544 + :let y = substitute('kKk', 'K', '\=substitute(submatch(0), ".", "\r", "")', '') | $put =y
545 + :let y = substitute('lLl', 'L', '\=substitute(submatch(0), ".", "\n", "")', '') | $put =y
554 + :$put =\"\n\nTEST_5:\"
555 + :$put =substitute('A123456789', 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . submatch(6) . submatch(5) . submatch(4) . submatch(3) . submatch(2) . submatch(1)', '')
563 + :$put =\"\n\nTEST_6:\"
565 + :$put =substitute('A', 'A', 'a', '')
566 + :$put =substitute('B', 'B', '%', '')
568 + :$put =substitute('C', 'C', 'c', '')
569 + :$put =substitute('D', 'D', '%', '')
578 + :$put =\"\n\nTEST_7:\"
579 + :$put =substitute('A
\16A', 'A.', '\=submatch(0)', '')
580 + :$put =substitute(\"B\nB\", 'B.', '\=submatch(0)', '')
587 + :/^Results/,$wq! test.out
591 *** ../mercurial/vim73/src/testdir/test80.ok 2011-06-19 04:30:54.000000000 +0200
592 --- src/testdir/test80.ok 2011-06-19 03:45:26.000000000 +0200
602 + C123456789987654321
630 + C123456789987654321
683 + A123456789987654321
697 *** ../mercurial/vim73/src/testdir/Makefile 2011-06-13 01:07:22.000000000 +0200
698 --- src/testdir/Makefile 2011-06-19 03:53:36.000000000 +0200
701 test59.out test60.out test61.out test62.out test63.out \
702 test64.out test65.out test66.out test67.out test68.out \
703 test69.out test70.out test71.out test72.out test73.out \
704 ! test74.out test75.out test76.out test77.out test78.out
706 SCRIPTS_GUI = test16.out
709 test59.out test60.out test61.out test62.out test63.out \
710 test64.out test65.out test66.out test67.out test68.out \
711 test69.out test70.out test71.out test72.out test73.out \
712 ! test74.out test75.out test76.out test77.out test78.out \
713 ! test79.out test80.out
715 SCRIPTS_GUI = test16.out
717 *** ../mercurial/vim73/src/testdir/Make_amiga.mak 2011-06-13 01:07:22.000000000 +0200
718 --- src/testdir/Make_amiga.mak 2011-06-19 03:52:32.000000000 +0200
721 test61.out test62.out test63.out test64.out test65.out \
722 test66.out test67.out test68.out test69.out test70.out \
723 test71.out test72.out test73.out test74.out test75.out \
724 ! test76.out test77.out test78.out
729 test61.out test62.out test63.out test64.out test65.out \
730 test66.out test67.out test68.out test69.out test70.out \
731 test71.out test72.out test73.out test74.out test75.out \
732 ! test76.out test77.out test78.out test79.out test80.out
739 test76.out: test76.in
740 test77.out: test77.in
741 test78.out: test78.in
742 + test79.out: test79.in
743 + test80.out: test80.in
744 *** ../mercurial/vim73/src/testdir/Make_dos.mak 2011-06-13 01:07:22.000000000 +0200
745 --- src/testdir/Make_dos.mak 2011-06-19 03:52:43.000000000 +0200
748 test37.out test38.out test39.out test40.out test41.out \
749 test42.out test52.out test65.out test66.out test67.out \
750 test68.out test69.out test71.out test72.out test73.out \
751 ! test74.out test75.out test76.out test77.out test78.out
753 SCRIPTS32 = test50.out test70.out
756 test37.out test38.out test39.out test40.out test41.out \
757 test42.out test52.out test65.out test66.out test67.out \
758 test68.out test69.out test71.out test72.out test73.out \
759 ! test74.out test75.out test76.out test77.out test78.out \
760 ! test79.out test80.out
762 SCRIPTS32 = test50.out test70.out
764 *** ../mercurial/vim73/src/testdir/Make_ming.mak 2011-06-13 01:07:22.000000000 +0200
765 --- src/testdir/Make_ming.mak 2011-06-19 03:52:58.000000000 +0200
768 test37.out test38.out test39.out test40.out test41.out \
769 test42.out test52.out test65.out test66.out test67.out \
770 test68.out test69.out test71.out test72.out test73.out \
771 ! test74.out test75.out test76.out test77.out test78.out
773 SCRIPTS32 = test50.out test70.out
776 test37.out test38.out test39.out test40.out test41.out \
777 test42.out test52.out test65.out test66.out test67.out \
778 test68.out test69.out test71.out test72.out test73.out \
779 ! test74.out test75.out test76.out test77.out test78.out \
780 ! test79.out test80.out
782 SCRIPTS32 = test50.out test70.out
784 *** ../mercurial/vim73/src/testdir/Make_os2.mak 2011-06-13 01:07:22.000000000 +0200
785 --- src/testdir/Make_os2.mak 2011-06-19 03:53:09.000000000 +0200
788 test61.out test62.out test63.out test64.out test65.out \
789 test66.out test67.out test68.out test69.out test70.out \
790 test71.out test72.out test73.out test74.out test75.out \
791 ! test76.out test77.out test78.out
796 test61.out test62.out test63.out test64.out test65.out \
797 test66.out test67.out test68.out test69.out test70.out \
798 test71.out test72.out test73.out test74.out test75.out \
799 ! test76.out test77.out test78.out test79.out test80.out
803 *** ../mercurial/vim73/src/testdir/Make_vms.mms 2011-06-13 01:07:22.000000000 +0200
804 --- src/testdir/Make_vms.mms 2011-06-19 03:53:18.000000000 +0200
807 # Authors: Zoltan Arpadffy, <arpadffy@polarhome.com>
808 # Sandor Kopanyi, <sandor.kopanyi@mailbox.hu>
810 ! # Last change: 2011 Jun 13
812 # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
813 # Edit the lines in the Configuration section below to select.
815 # Authors: Zoltan Arpadffy, <arpadffy@polarhome.com>
816 # Sandor Kopanyi, <sandor.kopanyi@mailbox.hu>
818 ! # Last change: 2011 Jun 19
820 # This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
821 # Edit the lines in the Configuration section below to select.
824 test61.out test62.out test63.out test64.out test65.out \
825 test66.out test67.out test68.out test69.out \
826 test71.out test72.out test74.out test75.out test76.out \
827 ! test77.out test78.out
830 # Test 30: a problem around mac format - unknown reason
832 test61.out test62.out test63.out test64.out test65.out \
833 test66.out test67.out test68.out test69.out \
834 test71.out test72.out test74.out test75.out test76.out \
835 ! test77.out test78.out test79.out test80.out
838 # Test 30: a problem around mac format - unknown reason
839 *** ../vim-7.3.224/src/version.c 2011-06-19 02:55:32.000000000 +0200
840 --- src/version.c 2011-06-19 04:27:54.000000000 +0200
844 { /* Add new patch number below this line */
850 hundred-and-one symptoms of being an internet addict:
851 194. Your business cards contain your e-mail and home page address.
853 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
854 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
855 \\\ an exciting new programming language -- http://www.Zimbu.org ///
856 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///