The Power of macrocall widget: Call macro with variable

162 views
Skip to first unread message

Mohammad

unread,
Dec 13, 2018, 2:50:06 PM12/13/18
to TiddlyWiki
By accident I learned an amazing feature of macrocall widget during experimenting with Thomas Elmiger extract macro.

Thomas used variable to make aliases of macro and call them using macrocall based on different condition.

As an example see (this is only for demo purpose, so it is very simple)

\define mac(mytag, output:"simple")


<$list filter="[tag[$mytag$]]" variable=v>
<$macrocall $name=<<__output__>> p=<<v>> />
</
$list>


\end



where simple here can be for example

\define simple(p)
<span style="color:red"><$view text=<<__p__>> /></span><br>
\end


You can call mac like

<<mac "Concepts">>

Now you can have a customized output like

\define myout(p)
<li><$text text=<<__p__>>/></li>
\end

<ol>
<<mac Concepts output:"myout">>
</ol>


So, this is a great TW5 capability and you can send your customized output to a macro already developed by other.
This can also be used for core macro and lets user customize their output.

You can test this on tiddlywiki.com

--Mohammad.

Mark S.

unread,
Dec 13, 2018, 3:49:22 PM12/13/18
to TiddlyWiki
Kind of like Design Patterns for TiddlyWiki.

Possibly similar to the Factory pattern.

-- Mark

Mohammad

unread,
Dec 13, 2018, 4:06:48 PM12/13/18
to TiddlyWiki
Hi Mark,
 Yes, amazingly the customized output macro does not need to be in a tiddler tagged with $:/tags/Macro
It can be whenever you use your macrocall

-Mohammad

Mark S.

unread,
Dec 13, 2018, 4:58:41 PM12/13/18
to TiddlyWiki
Hi Mohammad,

You know about https://tiddlywiki.com/#ImportVariablesWidget right? There's a new pragma so you can import one or more macros  into your working tiddler.

Have fun
-- Mark

Mohammad

unread,
Dec 13, 2018, 5:16:42 PM12/13/18
to TiddlyWiki
Yes, I know it. I use it whenever I want to import macro from tiddler not tagged with $:/tags/Macro.
I tried to create some private macros (can be seen globally).

-Mohammad

Mark S.

unread,
Dec 13, 2018, 5:44:21 PM12/13/18
to TiddlyWiki
Similar to how some (but not all) of the TOC macros can have their output changed by using a local version of \define toc-caption() .

-- Mark


On Thursday, December 13, 2018 at 1:06:48 PM UTC-8, Mohammad wrote:

TonyM

unread,
Dec 13, 2018, 6:08:10 PM12/13/18
to TiddlyWiki
Mohammad,

Thanks for sharing. This could be quite a powerful method. I think the trick will be finding a way to use it to simplify coding perhaps by reducing the number of macros you need to remember by pushing them into parameters of a shared macro.

For example I have a desire to provide filters that generate a list of tiddlers however specify if they are displayed in an list, interactive table, print ready form or TOC structure.

Regards
Tony

Mohammad

unread,
Dec 14, 2018, 12:37:42 AM12/14/18
to tiddl...@googlegroups.com
Hello Tony!
 That's true. I think this is kind of object oriented and actually we are overwriting a method of main class. I am using it with a bibliography code for TW5.
I have written the main code to do the citation and bibliography but as you know there are too many different output styles. User can write his/her own style
no need to go into my code or even understand what it is. I think this is what Mark said in his above post: https://groups.google.com/d/msg/tiddlywiki/ELeopXtx5D8/nzGLo0APBwAJ
factory method pattern.

--Mohammad

bimlas

unread,
Dec 18, 2018, 2:12:26 PM12/18/18
to TiddlyWiki
An example of one more usage of this "pattern": you can share <$set and <$wikify variables between macros: https://bimlas.gitlab.io/demo/tw5/sharing-variables-between-macros.html

Mohammad

unread,
Dec 19, 2018, 7:59:28 AM12/19/18
to TiddlyWiki
Hello bimlas,
 Would you please add few examples to this wiki!

-- Mohammad

bimlas

unread,
Dec 20, 2018, 6:03:01 PM12/20/18
to TiddlyWiki
If you think of clearer examples, I added them, but I realized that this method of sharing variables is not so beneficial:

Originally, I thought we only had to declare the variables once and then we could use their values again without spending more (processor) time, but I was wrong: every time calling of the "container" macro declare them again.

TonyM

unread,
Dec 20, 2018, 6:41:54 PM12/20/18
to TiddlyWiki
Bimlas,

Is there a reason you are not tagging the "Definition of variables" with $:/tags/Macro and making them global? No need to import them.

If a variable is defined [first[5]] I believe it will find the first [first[5]] when used, not when defined.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages