Can anyone help me with a recursive macro?

94 views
Skip to first unread message

si

unread,
Jan 13, 2021, 11:17:37 AM1/13/21
to TiddlyWiki
I'm using Streams, where tiddlers are related hierarchically, and I'm trying to create a macro that will return the ancestors of the current tiddler in a formatted bullet list.

So for example if I had a Stream like this:
  • A
    • B
      • E
    • C
    • D
      • F
Then the macro, when applied to tiddler F, would return this:
  • A
    • D
      • F
I know that I can use the following kin filter to return a list of the ancestors: [kin:stream-list:to:<currentTiddler>]. What I am struggling to figure out is how to turn it into a list that is actually formatted as per the example above.

Can anyone help me out here? Thanks in advance.
 

Saq Imtiaz

unread,
Jan 13, 2021, 2:55:34 PM1/13/21
to TiddlyWiki
@si

This is a really rough and quick attempt, there are probably simpler ways:

\define showAncestors()
<$list filter="[enlist<mylist>first[]]">
<ul><li>
<<currentTiddler>>
<$set name="mylist" filter="[enlist<mylist>rest[1]]">
<<showAncestors>>
</$set>
</li></ul>
</$list>
\end

\define getAncestors()
<$list filter="[all[current]get[parent]!is[blank]]" emptyMessage="""<$set name="mylist" filter="[enlist<mylist>reverse[]]"><<showAncestors>></$set>""">
<$log/>
    <$set name="mylist" filter="[enlist<mylist>] [<currentTiddler>]">
            <<getAncestors>>
    </$set>
</$list>
\end

<$set name="mylist" filter="[<currentTiddler>]">
<<getAncestors>>
</$set>

Apologies for the formatting, it's a bit of a struggle on a touch device.

si

unread,
Jan 14, 2021, 12:15:37 PM1/14/21
to TiddlyWiki
That's really helpful - thank you saq!
Reply all
Reply to author
Forward
0 new messages