Hi,

The patch is attached. Please check and correct.

I deleted the following expression in
*sub-replace-expression* because the function has been lost
since Patch 7.2.437.

 Prepend a backslash to get a real <NL> character (which will be
 a NUL in the file).

I added the description that "\=" notation is valid in not only
:substitute command but also substitute() function.

I also added the description that submatch() is valid in not only
:substitute command but also substitute() function because the
code seems to work so. I'm not sure why :help submatch() insists
on "Only for an expression in a :substitute command". Since the
introduction of submatch() in eval.c (vim-6.0d or CVS revision 1.12),
it seems to have worked with the first level substitute() such like
the following.

let y = substitute("hello", '\l', '\=toupper(submatch(0)), "g")

Regards,

Motoya Kurotsu

====================== attachment =================
diff -Nur vim73.orig/runtime/doc/change.txt vim73/runtime/doc/
change.txt
--- vim73.orig/runtime/doc/change.txt   2010-08-15 21:23:19.000000000
+0900
+++ vim73/runtime/doc/change.txt        2011-03-16 13:30:57.000000000
+0900
@@ -793,10 +793,11 @@
 not apply except for "<CR>", "\<CR>" and "\\".  Thus in the result of
the
 expression you need to use two backslashes to get one, put a
backslash before a
 <CR> you want to insert, and use a <CR> without a backslash where you
want to
-break the line.
+break the line. For convenience a <NL> character is also used as a
line break.

-For convenience a <NL> character is also used as a line break.
Prepend a
-backslash to get a real <NL> character (which will be a NUL in the
file).
+The notation "\=" is valid inside the third argument of substitute()
+function.  In this case, the special meaning for characters as
mentioned
+at |sub-replace-special| does not apply at all.

 When the result is a |List| then the items are joined with separating
line
 breaks.  Thus each item becomes a line, except that they can contain
line
diff -Nur vim73.orig/runtime/doc/eval.txt vim73/runtime/doc/eval.txt
--- vim73.orig/runtime/doc/eval.txt     2010-08-15 21:23:20.000000000
+0900
+++ vim73/runtime/doc/eval.txt  2011-03-16 14:49:22.000000000 +0900
@@ -5507,9 +5507,10 @@
                Also see |strlen()|, |strdisplaywidth()| and |
strchars()|.

 submatch({nr})                                         *submatch()*
-               Only for an expression in a |:substitute| command.
Returns
-               the {nr}'th submatch of the matched text.  When {nr}
is 0
-               the whole matched text is returned.
+               This is used in the expression for |:substitute|
command or
+                |substitute()| function. See also |sub-replace-
expression|.
+                This returns the {nr}'th submatch of the matched
text.  When
+                {nr} is 0 the whole matched text is returned.
                Example: >
                        :s/\d\+/\=submatch(0) + 1/
 <              This finds the first number in the line and adds one
to it.
@@ -5526,7 +5527,9 @@
                And a "~" in {sub} is not replaced with the previous
{sub}.
                Note that some codes in {sub} have a special meaning
                |sub-replace-special|.  For example, to replace
something with
-               "\n" (two characters), use "\\\\n" or '\\n'.
+               "\n" (two characters), use "\\\\n" or '\\n'. When
{sub} starts
+                with "\=", the remainder is interpreted as an
expression. This
+                does not work recursively. See |sub-replace-
expression|.
                When {pat} does not match in {expr}, {expr} is
returned
                unmodified.
                When {flags} is "g", all matches of {pat} in {expr}
are
diff -Nur vim73.orig/src/regexp.c vim73/src/regexp.c
--- vim73.orig/src/regexp.c     2011-03-06 16:45:15.000000000 +0900
+++ vim73/src/regexp.c  2011-03-16 13:18:11.000000000 +0900
@@ -6872,6 +6872,7 @@
 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,6 +6999,7 @@
            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;
@@ -7011,7 +7013,7 @@
                {
                    /* Change NL to CR, so that it becomes a line
break.
                     * Skip over a backslashed character. */
-                   if (*s == NL)
+                   if (*s == NL && !submatch_line_lbr)
                        *s = CAR;
                    else if (*s == '\\' && s[1] != NUL)
                    {
@@ -7021,7 +7023,7 @@
                         *   abc\
                         *   def
                         */
-                       if (*s == NL)
+                       if (*s == NL && !submatch_line_lbr)
                            *s = CAR;
                        had_backslash = TRUE;
                    }
@@ -7044,6 +7046,7 @@
            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;

On 3月14日, 午前8:42, motz <motoya.kuro...@gmail.com> wrote:
> Hi,
>
> I would. But English is not my native language. So I hope that
> someone would check and correct.
>
> In Japan or at Tokyo, the periodical blackout is planned from
> the effect of the earthquake. So it may take a while to post the
> patch. But I would do so as possible as I can.
>
> Regards,
>
> Motoya Kurotsu
>
> On 3月12日, 午前4:34, Bram Moolenaar <b...@moolenaar.net> wrote:
>
> > Ben Schmidt wrote:
> > > > I would like to propose a patch which suppresses the conversion of
> > > > <NL>  to<CR>  when evaluaation ('\=') is used inside substitute()
> > > > function.
> > > > Simply this patch is what makes x == y true in the following code.
>
> > > >   let x = substitute('a', '.', "\n", "")
> > > >   let y = substitute('a', '.', '\="\n"', "")
>
> > > Regardless of whether the functionality change of the patch is accepted,
> > > I think there should be a change to :help sub-replace-expression to
> > > explain what is done when \= is used within substitute().
>
> > Can someone propose a patch?
>
> > --
> > Why isn't there mouse-flavored cat food?
>
> >  /// Bram Moolenaar -- b...@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  ///

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui