Storing the result of a macro in raw form and pass it to a tiddler text field

109 views
Skip to first unread message

Mohammad

unread,
Feb 21, 2019, 9:06:13 AM2/21/19
to TiddlyWiki

One way to store the result of a macro has some parameters is to store it in wikified variable as below


Example
See the below code extracted from a longer code. This works correctly. It calls utility, and save the results in newText and then the action-setfield passes it to a tiddler as its text field.


<$wikify name="newText"  text="""<$macrocall $name="utility" par1=<<val1>> par2=<<val2>> />""" >
<$action-setfield $tiddler="""$tidName$""" $field="text" $value=<
<newText>> />

</$wikify>



Now, assume the result of utility macro is something like below

This is //italic// and this is {{!!caption}}


What happens? $Wikify save the wikified result as expected, but I wish to store in tidName text filed the raw non-wikified result, I mean what exactly utility  macro returns.

So, the question is how can I store the result of utility macro in non-wikified (raw form) and pass it to the text filed of some tiddler?


--Mohammad

Jeremy Ruston

unread,
Feb 21, 2019, 9:13:34 AM2/21/19
to tiddl...@googlegroups.com
Hi Mohammad

Please could you post a complete example?

Many thanks,

Jeremy

--
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 post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/099d67c2-8bb2-41c9-a372-f0948167bf41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mohammad

unread,
Feb 21, 2019, 9:37:59 AM2/21/19
to TiddlyWiki
Hi Jeremy,

I tried to reproduce a simple example though may seem meaningless.


\define utility(a, b) This is //$a$//  and ''$b$''.

\define test(tidName, v1, v2)
<$wikify name="newText" 
text="""<$macrocall $name="utility"
a=<<__v1__>> b=<<__v2__>>
/>""">
<$action-setfield $tiddler="""$tidName$""" $field="text" $value=<<newText>> />
</$wikify>
\end

<$button>Do it
<<test "myTiddler" italic bold>>
</$button>


What I expect is to see the myTiddley text field as

This is //italic//  and ''bold''.



But I see this

This is italic and bold.


--Mohammad

PS: The real story is I am developing a code to search and replace a string in a tiddler text field.

Jeremy Ruston

unread,
Feb 22, 2019, 4:58:58 AM2/22/19
to tiddl...@googlegroups.com
Hi Mohammad

Thanks that’s great.

I think the button is actually a red herring, and you can see the same behaviour with this simplified version:

\define utility(a, b) This is //$a$//  and ''$b$''.

\define test(tidName, v1, v2)
<$wikify name="newText" 
text="""<$macrocall $name="utility"
a=<<__v1__>> b=<<__v2__>>
/>""">
<$text text=<<newText>> />
</$wikify>
\end

<<test "myTiddler" italic bold>>

You don’t actually need the wikify widget here; the trick is to use macro parameter textual substitution:

\define utility(a, b) This is //$a$//  and ''$b$''.

\define test(a,b)
<$set name="newText" value=<<utility a:"""$a$""" b:"""$b$""">>>
<$text text=<<newText>> />
</$set>
\end

<<test "myTiddler" italic bold>>

Using textual substitution isn’t ideal because of the issues with quoting (e.g. the example above will fail if the parameter values started with three double quotes).

An alternate solution that might be useful would be an alternate mode to the <$macrocall> widget whereby it makes the result of calling the macro available as a variable, instead of directly rendering it.

Best wishes

Jeremy


Mohammad

unread,
Feb 22, 2019, 10:02:41 AM2/22/19
to TiddlyWiki
Thank you Jeremy!
Lets see how can I use your solution in my case and I return to you by me results.

By the way I am curious about the last paragraph of your reply:

An alternate solution that might be useful would be an alternate mode to the <$macrocall> widget whereby it makes the result of calling the macro available as a variable, instead of directly rendering it.

How this is possible? There is nothing in documentation: https://tiddlywiki.com/prerelease/#MacroCallWidget
Is it like below

<$macrocall   store=?>
scope of that var
</$macrocall>


Best regards
Mohammad

TonyM

unread,
Feb 22, 2019, 4:53:42 PM2/22/19
to TiddlyWiki
Mohammad,

I think Jeremy is suggesting storing the macro output in a variable as a future feature. This is a bit like allowing us to pipe the output of one macro into another.

I think this would be helpful, and would make some solutions much easier to code.

I would love to find a way to store a variable in a more permanent form without a button. Or store it in a field or text reference. Even if the value must be reevaluated on render.

Regards
Tony

Mohammad

unread,
Feb 23, 2019, 2:35:31 AM2/23/19
to TiddlyWiki
Hi Tony!
 Thank you! Yes, it would make life much easier!

--Mohammad

Mohammad

unread,
Feb 23, 2019, 2:50:07 AM2/23/19
to TiddlyWiki
Jeremy,
 I tested your solution and it works, BUT, this is true if utility macro itself contains wikitext like example above.
If utility itself call other macro or have some scripts, then it will fail, look at the below case


\define mac2(p) {{{ [<__p__>split[]addprefix[c]] }}}

\define utility(a, b)
This is //$a$//  and ''$b$''.
<$macrocall $name="mac2" p=<<__a__>> />
\end



\define test(a,b)
<$set name="newText" value=<<utility a:"""$a$""" b:"""$b$""">>>
<$text text=<<newText>> /
>
</$set>
\end


<<test italic bold>>


The output is:

This is //italic// and ''bold''. <$macrocall $name="mac2" p=<<__a__>> />


While I expect;

This is //italic// and ''bold''. cictcaclcicc


--Mohammad

Reply all
Reply to author
Forward
0 new messages