CDSoft / pp

PP - Generic preprocessor (with pandoc in mind) - macros, literate programming, diagrams, scripts...
http://cdelord.fr/pp
GNU General Public License v3.0
252 stars 21 forks source link

Temporarily suspend printing text via storage/recall macros? #87

Closed rhagenson closed 4 years ago

rhagenson commented 4 years ago

Is there a way to temporarily store the processed text of a macro rather than print it immediately then later recall all the stored text?

Contrived (but simplified example):

!define(firstname)(!store(stored-firstname)(_!1_))
!define(middlename)(!store(stored-middlename)(~!1~))
!define(lastname)(!store(stored-lastname)(**!1**))
!define(printname)(!recall(stored-firstname) !recall(stored-middlename) !recall(stored-lastname))

The !printname would appear as: First ~Middle~ Last

One increment better would be a way to define the new storage macros based on the name of the macros used to store them then recall based on pattern match. E.g. !define(firstname)(!store(names-)(!1)) (creates a macros called names-firstname) then later !recall(names-)(firstname) to recall a single entry under "names "or !recall(names-) to recall all entries (in order they were entered).

bpj commented 4 years ago

I believe you are looking for !append.

Use it like so:

!undef(_temp) !append(_temp)(!capture_my_output)

and then later just use !_temp (which of course can be called anything!) to insert the stored value.

Den tors 3 okt. 2019 22:46Ryan A. Hagenson notifications@github.com skrev:

Is there a way to temporarily store the processed text of a macro rather than print it immediately then later recall all the stored text?

Contrived (but simplified example):

!define(firstname)(!store(stored-firstname)(!1)) !define(middlename)(!store(stored-middlename)(~!1~)) !define(lastname)(!store(stored-lastname)(!1)) !define(printname)(!recall(stored-firstname) !recall(stored-middlename) !recall(stored-lastname))

The !printname would appear as: First Middle Last

One increment better would be a way to define the new storage macros based on the name of the macros used to store them then recall based on pattern match. E.g. !define(firstname)(!store(names-)(!1)) (creates a macros called names-firstname) then later !recall(names-)(firstname) to recall a single entry under "names "or !recall(names-) to recall all entries (in order they were entered).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CDSoft/pp/issues/87?email_source=notifications&email_token=AAI3OU374V6ZDCSPGAWE2JLQMZKXHA5CNFSM4I5IA472YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HPQKGSQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AAI3OU5GOWIMEXZXEPE3RC3QMZKXHANCNFSM4I5IA47Q .

rhagenson commented 4 years ago

I kind of figured there was a way to do this already, just not the worded the same way I had in my head. I will look into the !append macro. Thank you.