building a tag for filtering

129 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Oct 6, 2020, 11:28:05 AM10/6/20
to TiddlyWiki
I have to filter tiddler with tags names of the form "criterion 2.4", "criterion 10.1", etc...

I have devised a simple macro:

\define countCrit(crit) <$count filter="[tag[$crit$]]"/>

which is call like <<countCrit "criterion 4.2">>

But repeating "criterion" is tedious and could make error. what I'd like is to have

<<counting 4.2>>

which would itself call <<countCrit "criterion 4.2">> for me. Or make the computation by itself (I tried both ways).

But I cannot be successfull on transforming 4.2 into "criterion 4.2" for this purpose.

Getting the string seems easy, for instance using the addprefix operator. But the whole filter has a syntax error.

My code:

\define counting(ref) <$count filter="[tag[ [$ref$] +[addprefix[critère ]] ]]"/>

used as <<counting "1.3">>.

Is there a tool for checking filter syntax and help getting it right? The .operator-example macro of the doc is of limited use for that. It just help making tries but when all your tries are wrong without your knowing why...


Atronoush Parsi

unread,
Oct 6, 2020, 11:53:24 AM10/6/20
to tiddl...@googlegroups.com
Try this

\define  countCrit (rTag)
<$vars cTag={{{ [<__rTag__>addprefix[
criterion   ]] }}}>
<$count filter="[tag<cTag>]"/>
</$vars>
\end



Or more simpler

\define countCrit(crit) <$count filter="[<__crit__>addprefix[ab ]tagging[]]"/>

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/0c9b34a1-3e08-44ab-a53f-6f6fbe7b5a65n%40googlegroups.com.

Atronoush Parsi

unread,
Oct 6, 2020, 11:55:08 AM10/6/20
to tiddl...@googlegroups.com
Ah, in the previous post I used ab as the prefix, use below which is what you want criterion as prefix.
Or more simpler

\define countCrit(crit) <$count filter="[<__crit__>addprefix[criterion ]tagging[]]"/>


Eric Shulman

unread,
Oct 6, 2020, 1:18:31 PM10/6/20
to TiddlyWiki
On Tuesday, October 6, 2020 at 8:28:05 AM UTC-7, Jean-Pierre Rivière wrote:
I have to filter tiddler with tags names of the form "criterion 2.4", "criterion 10.1", etc...
I have devised a simple macro:
\define countCrit(crit) <$count filter="[tag[$crit$]]"/>
which is call like <<countCrit "criterion 4.2">>
But repeating "criterion" is tedious and could make error...

Macros do ONLY two things:
1) replace $param$ with values passed in as parameters
2) replace $(variable)$ with values defined outside the macro as variables

They do *NOT* actually parse or interpret the syntax inside the macro.  They simply treat the entire macro content as a text string, and then use a "string replace" action to insert the values where they belong.

Thus, if you have a macro like this:
\define countCrit(crit) <$count filter="[tag[critère $crit$]]" />

and you invoke it using
<<countCrit 4.2>>
the resulting syntax that is produced by the macro,*before any parsing occurs*, will be:
<$count filter="[tag[critère 4.2]]" />
which is just what you want.

No fancy use of inline filters or other methods needed to assemble the desired value.

enjoy,
-e

Jean-Pierre Rivière

unread,
Oct 9, 2020, 5:55:10 AM10/9/20
to TiddlyWiki
Yes, both of you helped me, in different ways. The use of __ was not very well explained. Here, I have a working example in full, coupled within a filter, and that's a real gem for me.

And yes, the macro is not mean for black magic! Ony pouring text. That's simple but so easy to forget!!! Repeating again and again until it's an habit :-)

But I have a problem with the macro text substitution and the wiki parsing. But this I will tell in an other subject, because this one has been fully answered!

Mega thanks to our experts!

Jean-Pierre Rivière

unread,
Oct 9, 2020, 7:38:21 AM10/9/20
to TiddlyWiki
As a final word, here are united 4 macros doing exactly the same thing. The interesting spot is the little differences in the way to use the syntax of accessing a variable or a parameter. Notably, see the use of <__myVar__> when the official doc just speaks of <<__myVar__>> (which is not helping). Most of these macros were given by Atronoush and Eric. I thought it would be nice to have them united for reference.

\define compter(tagg) <$count filter="[tag[critère $tagg$]]"/> tagged

\define compteux(rTag)
<$vars cTag={{{ [<__rTag__>addprefix[critère ]] }}}>
pour <<cTag>>, <$count filter="[tag<cTag>]"/> tagged
</$vars>
\end

\define comptard(rTag) <$count filter="[<__rTag__>addprefix[critère ]tagging[]]"/> tagged

\define comptine(rTag) <$count filter="[[critère $rTag$]tagging[]]"/> tagged

<<compteux 1.2>> :: <<compter 1.2>> %% <<comptard 1.2>> ~/~ <<comptine 1.2>>


Atronoush Parsi

unread,
Oct 9, 2020, 11:39:26 AM10/9/20
to tiddl...@googlegroups.com
Have you looked at TW-Scripts? https://kookma.github.io/TW-Scripts/
Have you searched for syntax?

It is a great resource for the TW community made by the TW community!

--Atro

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

TW Tones

unread,
Oct 9, 2020, 5:54:16 PM10/9/20
to tiddl...@googlegroups.com
Folks,

I am currently working on a comprehensive cheat sheet here based on various contributors work, Mohammad's useful reference was in part based on an earlier version by Tobias.

I would appreciate feedback and I will update this resource.

I just added the use of 
<__parmname__>

 in filters but need to test it further.

Regards
Tony


On Saturday, 10 October 2020 02:39:26 UTC+11, Atronoush wrote:
Have you looked at TW-Scripts? https://kookma.github.io/TW-Scripts/
Have you searched for syntax?

It is a great resource for the TW community made by the TW community!

--Atro

To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.

TW Tones

unread,
Oct 9, 2020, 5:55:17 PM10/9/20
to TiddlyWiki
Reply all
Reply to author
Forward
0 new messages