On Wednesday, October 14, 2020 at 11:29:25 PM UTC-7, Shareda wrote:
>
>
> \define validFilter()<$macrocall $name="validateregexp"
> regexp={{!!add.filter}}/>
> and change filter
> [search:text:regexp{!!add.filter}]
> to
> [search:text:regexp<validFilter>]
> then the second filter always returns nothing even if {!!add.filter}
> and <validFilter> are equal and the first filter works correctly.
>
This is, perhaps, the most frequently misunderstood concept in TiddlyWiki:
*** Macros are NOT functions ***
They do not "evaluate their contents and return the results". Rather,
they just perform TWO actions:
1) replace occurrences of $param$ with corresponding values passed as macro
parameters
2) replace occurrences of $(variable)$ with corresponding values of
variables define outside the macro
After doing these replacements, the macro's literal contents are inserted
in place of the macro call itself.
It is then up to the calling context to do any rendering (aka,
"wikification") of the results.
Thus, your second filter becomes:
[search:text:regexp<$macrocall $name="validateregexp" regexp={{!!add.filter
}}/>]
and filter operators do NOT process widgets. Thus, the regexp filter
operator sees it's parameter
as a reference to a variable named "$macrocall". In addition, variable
references inside filters do
not allow use of arguments, so the rest of the $macrocall -- the $name...
and regexp... parts -- are ignored.
In effect, your filter is:
[search:text:regexp<$macrocall>]
and since there is no variable named "$macrocall", it is trying to match a
blank pattern which,
of course, produces no results.
To actually get the rendered results of the validateregexp $macrocall into
a variable that can then be
used in the filter, you need to use the <$wikify> widget to process and
capture the *output* of the
validFilter() macro into a variable, and then use that variable in the
filter. Something like this:
<$wikify name="thefilter" text=<<validFilter>>>
...
[search:text:regexp<theFilter>]
...
</$wikify>
I hope this explanation doesn't make your head explode. :)
https://www.youtube.com/watch?v=B_Lnz64vXB8
Let me know how it goes...
-e
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/211cb86b-3697-4279-91d2-262453022d92o%40googlegroups.com.