[SPAM] need help with reinplace
Ryan Schmidt
ryandesign at macports.org
Sun Nov 4 07:49:33 UTC 2018
On Nov 3, 2018, at 16:10, Helmut K. C. Tessarek wrote:
> Hi Ryan,
>
> On 2018-11-03 01:45, Ryan Schmidt wrote:
>> That's in the Tcl documentation:
>
> I think you are missing my point. I don't really know Tcl, thus I would
> have never thought about using `set reinplace_cmd` and or any other
> workaround you Tcl experts know.
In fact, the solution Joshua suggested had not occurred to me either, and I haven't come across it being used in any portfiles. I usually just deal with the extra backslashes when needed. If your regex has gotten so complicated that this becomes a problem, it may be time to rethink whether that regex was the best way to solve the problem. If the regex is so hard to understand that you're having trouble figuring out what needs to be escaped, it will also be hard for someone else to understand later, which will make it difficult when inevitably sometime in the future the port is updated to a new version and the message appears that the reinplace didn't change anything, because someone will then have to understand and either update or remove that regex.
For instance, you said:
> I want to replace the following line in configure.ac
> AC_INIT([tmux], next-2.9)
> with
> AC_INIT([tmux], next-2.9 (${version}))
The way I would approach this is to write a patch file which inserts "@VERSION@" into the file where you want the version to appear. Then you can simply reinplace "s|@VERSION@|${version}|g" to get the real version into the file. That's very simple to understand and it's a pattern we use in many other portfiles to insert the prefix or other portfile variables.
> So why not add a paragraph like this to reinplace:
>
> Since the Tcl way of how regexes are used/interpreted (or whatnot) in
> reinplace truly sucks (and is fucked up), here's a way to use a regex as
> it used in any other language.
>
> set reinplace_cmd [subst -nobackslashes -nocommands
> {s/bad/awesome/g}]
> reinplace -E $reinplace_cmd FILE
>
> The text in () brackets is optional.
> Of course you can remove the sarcasm, but I think it has a nice touch.
> Anyway, you get the idea.
>
> Boom, all of a sudden people who read the documentation know how to use
> a regex with Portfiles. Isn't that wonderful?
Certainly, and we do accept pull requests for the documentation on GitHub. :) In my opinion the guide needs a complete rewrite from scratch, but until someone finds the time and energy to do that minor improvements are of course welcomed.
More information about the macports-dev
mailing list