CDSoft / pp

PP - Generic preprocessor (with pandoc in mind) - macros, literate programming, diagrams, scripts...

Home Page:http://cdelord.fr/pp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Macro to write text to file etc.

bpj opened this issue · comments

I'm not sure whether I have mentioned this before but a !write(FILENAME)(TEXT) macro which writes (the expansion of) TEXT to file FILENAME, presumably so that you can then pass the filename as argument to a shell command would be very useful at least to me. I have tried to somehow implement this myself using shell here docs, but it is very hard to get that robust and reliable, not to mention portable!

Naturally a !tempname macro to go with that which portabily retrieves a temporary file name guaranteeing that the file not yet exists would be very good. I'm thinking that the !write macro might expand to the filename so that you just can do this in the common case:

!sh(COMMAND [ARGUMENTS] <!write(!tempname)(TEXT))

but perhaps it is more generally useful if it expands to nothing. You can always save the filename to a symbol first.

TBH I would (at least ATM) mainly use this to implement a !filter(COMMAND)(TEXT) macro to filter TEXT through COMMAND but I think that the !write and !tempname macros as described above may be more generally useful.

Have you tried literate programming macros ? (!lit)
I'm not sure tempname and filter are part of the job of a markdown preprocessor. Shells (I mean, real shells ;-) can do this better and have lots of features. I don't want to reimplement bash as pp macros.
I you want something portable, you can use bash script (they run pretty well on Windows with cygwin or mingw) or python scripts.

I finally figured out that

!quiet(!lit...) does the trick so I'm closing this.