I coded the following function. The idea is to changed the text if the tiddler is of tw2.5 type.
\define _adapt()
\define _transform() <$action-setfield changed=<<transform>> text={{{ [{!!text}search-replace:g<sourceRoot>,<destRoot>]" }}}/><$action-log $$message=_transform $$filter="currentTiddler source dest original target" newText={{!!text}}/>
<$let transform = {{{ [{!!type}match[text/vnd.tiddlywiki]then[_transform]] }}}>
<$macrocall $name=<<transform>>/>
<$action-log $$message=_adapt $$filter="transform source dest" text={{!!text}} type={{!!type}}/>
</$let>
\end
It turns out that whatever the text type, the changed it made. The changed was made by the _transform
macro, which was only called if of the proper type.
First, a code that do what I want to do:
\define _adapt()
<$let transform = {{{ [{!!type}match[text/vnd.tiddlywiki]then[_transform]] }}}
text = {{{ [{!!text}search-replace:g<sourceRoot>,<destRoot>] }}}
newText = {{{ [<transform>!is[blank]then<text>else{!!text} }}}
>
<$action-setfield text=<<newText>>/>
<$action-log $$message=_adapt $$filter="transform source dest" text={{!!text}} type={{!!type}}/>
</$let>
\end
Now, a question. I have concluded that the macro is always invoked when first encountered. Since mine had a side effect, it did its job even when not called. Am I right?
If I’m right, would it not be better to alert people on this? Could this behavior be corrected?