Re: patsubst: multiline text

clemens fischer <[email protected]>
Newsgroups gmane.comp.gnu.m4.general
Message-ID <[email protected]>
Eric Blake wrote:

> Thanks for the question.

Thanks for the comprehensive answer  8-)

> Unfortunately, there is admittedly a problem with the current regex
> implementation - it is line based, rather than argument based, so you
> can't really get at newlines directly.  Ultimately, the right fix is
> to add another argument to the various regex macros that lets you set
> flags (line vs. argument, case insensitive, maybe others?) for how a
> given regex will behave.

REGEX(3):

REG_EXTENDED, but also "multiline" in the sense that "\`"  and "\'"
match at the very start or end of the buffer, respectively, and "^" and
"$" (also?) match after and before embedded line ends (newlines).  Then,
a syntax for matching UTF-8 characters would be nice.

BTW, I couldn't get non-greedy ".+?" or ".+\?" to work, this definitely
deserves fixing, because at times "[^abc]+" doesn't cut it, eg. if
a match for more than one character is needed.

And how about look-forward/look-behind, like in Perl/Python/PCRE?

> On the other hand, since it is all line based, it may be easier than
> you think.  First, note that this inserts spaces on every line:
> 
> patsubst({ml_text}, {^}, {  })

That's funny, I'm already using this for other purposes, but ...

> Then, if you concatenate text before the first line, then a second
> pass can clean up the first line:
> 
> patsubst({-}patsubst({{ml_text}}, {^}, {  }), {^-  }, {- })

... never got this far!  Thanks!


clemens
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.