jed-users mailing list

[2009 Date Index] [2009 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: replace_match()


Dear Marko,

On 26.01.09, Marko Mahnic wrote:
> from: http://www.geocities.com/mmarko.geo/jedmacros/mmutil.sl.txt

> % \usage{Int re_replace (String RegExpFind, String Replacement)}

thanks for the hint. Actually, there is a similar (and equally named)
function in http://jedmodes.sf.net/mode/txtutils.sl

The main difference is, that the jedmodes version [similar to the
standard replace()] does not return a value.

I added your usage example (with some modifications):

%!%+
%\function{re_replace}
%\synopsis{Replace all occurences of regexp \var{pattern} with \var{rep}}
%\usage{re_replace(pattern, rep)}
%\description
%  Regexp equivalent to \sfun{replace}.
%  Replaces all occurences of of regexp \var{pattern} with \var{rep}
%  from current editing point to the end of the buffer. 
%  The editing point is returned to the initial location.
%  The regexp syntax is the same as in \sfun{re_fsearch}
%  (currently S-Lang regular expressions).
%\example
%  before: ad e cf
%#v+
%     re_replace ("\([abc]\)\([def]\)"R, "\0:\2\1"R)
%#v-
%  after: ad:da e cf:fc
%\seealso{replace, re_search_forward, str_re_replace, query_replace_match}
%!%-
define re_replace(pattern, rep)
{
   push_spot();
   EXIT_BLOCK {pop_spot();}
   while (re_fsearch(pattern)) {
      !if (replace_match(rep, 0))
	 error ("replace_match failed.");
   }
}

Günter

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2009 date index] [2009 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]