Why is this macro doing recursion and crashing my wiki?

77 views
Skip to first unread message

Petri M.

unread,
Jan 8, 2021, 4:49:11 AM1/8/21
to TiddlyWiki
I have a todo list and I would like to automatically add a timestamp to each tiddler's title so that each todo-tiddler has a unique title. I have a button that uses a state tiddler's body as the title of the new todo-toddler. So I was thinking that I would just have a macro that has two variables, the state tiddler's body and my timestamp and then just put them together and replace the body of the state tiddler.

As a test I made a tiddler test1  with this macro to try:

\define addtimestamp(tiddler)
<$set name="curtext" tiddler=$tiddler$ >
<$set name="ts" value=<<now [UTC]YYYY0MM0DD0hh0mm0ssXXX>> >
<<ts>> <<curtext>>
</$set>
</$set>
\end

And using <<addtimestamp test2>> works fine, the macro seems to give me a text with the timestamp and whatever I have in tiddler test2.

And then I tried to trigger it with a button so that it would put that text back into the tiddler test2.

<$button>
<$action-setfield $tiddler="test2" text=<<addtimestamp test2>>/>
test
</$button>

And everything crashes. I can see that there's a billion timestamps in test2 but I have no idea why that is! Can someone shine some light on this?

Thanks,
Petri M.

Petri M.

unread,
Jan 8, 2021, 8:25:27 AM1/8/21
to TiddlyWiki
Oh apparently my <<addtimestamp test2>> tries to put the entire contents  of the addtimestamp macro into the test2 tiddler. I think this is why it breaks.  Can I not use <$set ...> </$set> within a macro? Or what is going on here?

This works fine if I use

\define concat(a b)
$a$ $b$
\def

<$set name="curtext" tiddler="test2" >

<$set name="ts" value=<<now [UTC]YYYY0MM0DD0hh0mm0ssXXX>> >
<$button>
<$action-setfield $tiddler="test2" text=<<concat $(curtext)$ $(ts)$>> />
test
</$button>
</$set>
</$set>

It just looks ugly.

-Petri

Mark S.

unread,
Jan 8, 2021, 8:33:08 PM1/8/21
to TiddlyWiki
If you wikify (render) the contents before stashing in the tiddler, you'll prevent the recursion. In the following I'm using "HelloThere" from TiddlyWiki.com

\define addtimestamp(tiddler)
<$set name="curtext" tiddler=$tiddler$ >
<$set name="ts" value=<<now [UTC]YYYY0MM0DD0hh0mm0ssXXX>> >
<<ts>> <<curtext>>
</$set>
</$set>
\end

<$button>test
<$wikify name=out text=<<addtimestamp HelloThere>> >
<$action-setfield $tiddler="HelloThere" text=<<out>>/>
</$wikify>
</$button>
Reply all
Reply to author
Forward
0 new messages