Search Macro: How Not to Use Text Substitution?

I have a macro to search, but it uses text substitution:

\define search-macro(filter, searchop, term)
<$list filter="$filter$ +[$searchop$<__term__>]">

</$list>
\end

Example i

<<search-macro "[all[tiddlers]!is[system]]" "regexp:title" "\.[a-zA-Z]{2,4}$">>

Example ii

<<search-macro "[!is[system]limit[250]]" "search:text" "operator">>

I am afraid it’s not clear to me what your point is, is it a question or observation?

This is a question: How not to use text substitution inside macro? One improvement here is:

instead of using this old wikitext

filter="$filter$ +[$searchop$<__term__>]"

Use this one

filter="[subfilter<__filter__>] +[$searchop$<__term__>]"

But still we need to see how not to use $searchop$ in the second step.

I revised the OP. The reason is the last step: limit[10].

The avoidance of substitution has being discussed a number of times and I have attempted to get this clarified a little, because as I understand it is fine for simple cases like this and a few others, and although may be eventually be deprecated, in favor of some of the features in V5.3.x it may still prove necessary until then.

  • Even then, I understand since to maintain backwards compatibility at most, it will be deprecated not removed.
  • If you look at the complexity of the code to avoid substitution altogether t is not as easy to use as simple substitution.
  • As a result we need to document when you should definitely avoid substitution and when its OK.

Unfortunately I don’t understand it enough (yet) to document this.

I think the subfilter operator and splitting the different elements is key here.

Using the different elements gives you much more flexibility.

In the code the sub variable is the substituted string, where the “text” elements are covered in single quotes … The “debug” line shows the sub-filter string.

It’s a bit trickier as it should be. … I’ll run a new test with the new \function definition from parametrized transclusions preview.

\define search-macro(f, operator, suffix, term)
<$let sub={{{ "[" [<__operator__>] ":" [<__suffix__>] "<__term__>]" +[join[]] }}}>

debug: <$text text=<<sub>>/>

<$list filter="[subfilter<__f__>] +[subfilter<sub>]"/>

</$let>
\end

<<search-macro "[all[tiddlers]!is[system]]" "regexp" "title" "\.[a-zA-Z]{2,4}$">>

----

<<search-macro "[!is[system]limit[250]]" "search" "text" "operator">>
1 Like

Thank you @pmario. It works.

Yes, it seems a string variable contains a correct filter (syntax) shall be created and then fed to the subfilter. The magic is in subfilter!

A post was split to a new topic: How Text Substitution can Look Like with v5.3.0-prerelease