[TW5 Bug?] Macros with filter parameter can't handle all filter expressions.

252 views
Skip to first unread message

Michael Z.

unread,
Jul 13, 2018, 9:08:56 PM7/13/18
to TiddlyWiki
To reproduce, just create a tiddler at tiddlywiki.com with the following text:

<$macrocall $name="csvtiddlers" filter="[tag<currentTiddler>]" />

The following macro filter parameter provides always an empty list. (To see this you should probably create some tiddlers tagged with the name of the current tiddler)


<$macrocall $name="csvtiddlers" filter="[tag{!!title}]" />

These errors happen whenever a macro expects a filter expression as parameter.

Is this a misunderstanding on my side? All I want is filter the tiddlers tagged with the name of the current tiddler and use them in the macro.

TonyM

unread,
Jul 13, 2018, 9:51:10 PM7/13/18
to TiddlyWiki
Michael Z.,

A Quick answer is we can easily pass filters as parameters (not demonstrated here) however life has been much easier for me since I started applying the method below to my own macros

However your issue is with a macro to which you pass a filter. Did you follow the notes in https://tiddlywiki.com/#csvtiddlers%20Macro to see the use?
<<csvtiddlers filter:"""$(exportFilter)$""" format:"quoted-comma-sep">>
in this case the export macro builds the filter into a variable 
exportFilter before calling the macro.


In my own macros the filter to select is usually outside the macro, and the macro operates only on currenttiddler

<$list filter="filterhere">
Call or do anything with the current tiddler including my macros
</$list>
filterhere would generate a list of tiddlers

You can also use the $tiddler widget for a single tiddler
<$tiddler tiddler="named tiddler">
Call or do anything with the current tiddler including my macros
</$tiddler>

So now almost all macros I write to use are written to handle the "implicit" current tiddler. Thus in my macros the filters nearly always start "[is[current]... to operate on the current tiddler

Then there are cases when the list is generating tag, string or field-names to operate on so I use a variable in the list command to stop currenttiddler changing

<$list filter="eg tags or fields[]" variable="helpfulname">
In here current tiddler remains that of the tiddler that is current, and you can use <
<helpfulname>>, including my macros
</$list>


<$list filter="a test filter" variable="null">
a bit like using reveal
In here current tiddler remains that of the tiddler that is current, including my macros, and you never use the variable, so I call it null.
</$list>


I hope the above is meaningfull to you.

Tony

Michael Z.

unread,
Jul 14, 2018, 9:07:28 AM7/14/18
to TiddlyWiki
Tony, thanks for your extensive answer and advice. I appreciate that but perhaps I expressed my problems not clearly. I don't want to use the macro inside a widget. I just want the macro to process all tiddlers tagged with the name of the current (viewed) tiddler.

So please let me rephrase my key questions:

<<csvtiddlers "[tag<currentTiddler>]">>
or
<<csvtiddlers "[tag{!!title}]">>

Is this valid macro and filter syntax? If yes, why doesn't it work?
What is the functional equivalent code that does work?

Btw, I also tried
<$tiddler tiddler={{!!title}}">
<<csvtiddlers "[tag
<currentTiddler>]">>
</$tiddler>
without success.

/Michael

Jed Carty

unread,
Jul 14, 2018, 9:27:01 AM7/14/18
to TiddlyWiki
I haven't dug into it too much but that looks like a bug in the csv tiddlers macro. I think that it isn't properly importing variables so the currentTiddler variable isn't available which prevents either of the filters you are trying from working.

This works but it is a bit awkward:
\define workAround() <$macrocall $name="csvtiddlers" filter="[tag[$(current)$]]" />

<$set name='current' value=<<currentTiddler>>>
<<workAround>>
</$set>

It looks like the problem doesn't come from filters as parameters, it comes from not importing variables so you would have to have something like the code above to use any variable in the csvtiddlers macro.

I am not sure if this bug is specific to the csvtiddlers macro or to how macros are evaluated.

Mark S.

unread,
Jul 14, 2018, 9:32:11 AM7/14/18
to TiddlyWiki
The csvtiddlers macro must change it's own current tiddler value, so your filters won't work, but might have with a different macro that made other assumptions. The "filter" string only gets immediately interpreted in the <$list> widget AFAIK

Try

\define filtbycur(title)
<<csvtiddlers "[tag[$title$]]">>
\end
<$macrocall $name=filtbycur title={{!!title}}/>

-- Mark

zemoxian

unread,
Jul 14, 2018, 9:56:19 AM7/14/18
to TiddlyWiki
Have you tried “[all[current]tagging[]]”? That’s the way I usually do it. I’ve rarely had an issue with it.

Michael Z.

unread,
Jul 14, 2018, 11:32:22 AM7/14/18
to TiddlyWiki
Thank you all for your help. I ended up using

\define csv(title) <<csvtiddlers "[tag[$title$]]>>
<$macrocall $name="
csv" title={{!!title}} />

Works great, thanks again.

/Michael

Reply all
Reply to author
Forward
0 new messages