macro and submacro (private macro not available globally)

87 views
Skip to first unread message

Mohammad

unread,
Jul 1, 2018, 8:56:07 AM7/1/18
to TiddlyWiki
Hi
 I have a tiddler tagged with $:/tags/Macro in that I have three macros, tow of them work as sub-macro (like sub-function or private methods in other programming language) for the main macro.

  • Example
\define smac1(a)  This is $a$
\define smac2(b)  and I it is really $b$.

\define myMac(x,y)
<<smac1 $x$>> <<smac2 $y$>>
\end



I use it like 

<<myMac "TW" "lovely">>



The question is I want to have only myMac available globally and not smac1, and smac2. Is it possible with TW?

/Mohammad

Mark S.

unread,
Jul 1, 2018, 9:44:20 AM7/1/18
to TiddlyWiki
Sure. Just put the first two macros in a tiddler labeled with $:/tags/Macro. Then don't put a macro in your 2nd tiddler that has the 3rd macro. e.g:


title
: My Invocation tiddler
tags
: RandomTag


\define myMac(x,y)
<<smac1 $x$>> <<smac2 $y$>>
\end

<<myMac "TW" "lovely">>



-- Mark

Mohammad

unread,
Jul 1, 2018, 10:22:20 AM7/1/18
to TiddlyWiki
Mark!
Thank you for your quick reply!
The case is how can I have myMac available globally (can be invoked from any tiddlers) but smac1 and smac2 remain private!

/Mohammad

Eric Shulman

unread,
Jul 1, 2018, 11:46:07 AM7/1/18
to tiddl...@googlegroups.com
On Sunday, July 1, 2018 at 7:22:20 AM UTC-7, Mohammad wrote:
The case is how can I have myMac available globally (can be invoked from any tiddlers) but smac1 and smac2 remain private!

1) put myMac() in a tiddler tagged with $:/tags/Macro
2) put smac1() and smac2() in another tiddler (e.g., "smacFunctions") tagged with "MyMacroFunctions"

in the definition of myMac(), write:

\define myMac(x,y)
<$importvariables filter="[tag[MyMacroFunctions]]">
<<smac1 $x$>> <<smac2 $y$>>
</$importvariables>
\end

The <$importvariables> widget pulls in all the variables (i.e., macro definitions) contained in the tiddlers matching the specified filter.

Note that, if you only want to include variables from one specific tiddler, then you don't need to use a tag... you can just specify the name of the tiddler as the filter:
<$importvariables filter="smacFunctions">

enjoy,
-e

Mohammad

unread,
Jul 1, 2018, 12:07:45 PM7/1/18
to TiddlyWiki
Hi Eric,
 Yes, that works wonderful! In this way I can hide the macros I don't want to be accessible by other tiddlers or globally.
Some times we create a code contains several parts, but only one macro should be available.

Note:
I use the  TW 5.1.18-prerelease, it seems instead of $includevariables I have to use $importvariables



Thank again Eric.

Cheers
Mohammad


On Sunday, July 1, 2018 at 8:16:07 PM UTC+4:30, Eric Shulman wrote:
On Sunday, July 1, 2018 at 7:22:20 AM UTC-7, Mohammad wrote:
The case is how can I have myMac available globally (can be invoked from any tiddlers) but smac1 and smac2 remain private!

1) put myMac() in a tiddler tagged with $:/tags/Macro
2) put smac1() and smac2() in another tiddler (e.g., "smacFunctions") tagged with "MyMacroFunctions"

in the definition of myMac(), write:

\define myMac(x,y)
<$includevariables filter="[tag[MyMacroFunctions]]">
<<smac1 $x$>> <<smac2 $y$>>
</$includevariables>
\end

The <$includevariables> widget pulls in all the variables (i.e., macro definitions) contained in the tiddlers matching the specified filter.

Note that, if you only want to include variables from one specific tiddler, then you don't need to use a tag... you can just specify the name of the tiddler as the filter:
<$includevariables filter="smacFunctions">

enjoy,
-e

Eric Shulman

unread,
Jul 1, 2018, 5:33:15 PM7/1/18
to TiddlyWiki
On Sunday, July 1, 2018 at 9:07:45 AM UTC-7, Mohammad wrote:
I use the  TW 5.1.18-prerelease, it seems instead of $includevariables I have to use $importvariables

oops!  I meant to write "$importvariables".... my bad.

-e

Mohammad

unread,
Jul 1, 2018, 10:15:35 PM7/1/18
to TiddlyWiki
You are great Eric!
Thank you!

PMario

unread,
Jul 2, 2018, 2:45:27 AM7/2/18
to TiddlyWiki
Hi Mohammad,

If I test your example at tiddlywiki.com  I have global access to all 3 macros. ...

For me it seems you messed something up with your theme, or plugins.

-m

PMario

unread,
Jul 2, 2018, 2:47:17 AM7/2/18
to TiddlyWiki
uups, I didn't see the "not" in the request. ... So just ignore my post :)

-m
Reply all
Reply to author
Forward
0 new messages