[Comment] Being NAUGHTY With Macros ...

127 views
Skip to first unread message

TiddlyTweeter

unread,
Jun 1, 2021, 3:18:18 AM6/1/21
to TiddlyWiki
I think both Macros and Macro Parsing are AMAZING in TiddlyWiki ...

Through trial and error I discovered you can comment inside \define. This works ...

\define styleSVG(
 ALL -----------
class-suf:'default'
 
ONE ----------- 
svg:'$:/core/images/print-button'
size:'250px'
fill:'black'
fill-hover:'orange'
background:''
stroke-width:'3'
stroke:'orange'
stroke-hover:'black' 
grid-class:"tt-grid-box"
grid-color:'blue'
 
MANY ----------
 m-svg: '[all[tiddlers+shadows]prefix[$:/core/images]sort[title]]'
 m-size:'40px'
 m-fill:'black'
 m-fill-hover:'brown'
 m-background:''
 m-stroke:'brown'
 m-stroke-hover:'black' 
 m-stroke-width:'3' 
 m-grid-class:''
 m-grid-color:'' 
)

I am NOT recommending using sectioning like "ALL ---------" in  production wiki. Merely commenting that the TW Macro parser is VERY forgiving.

For development wiki I think the behavior can be very helpful, especially when evolving complex macros.

Just a comment
TT 

PMario

unread,
Jun 1, 2021, 9:47:10 AM6/1/21
to TiddlyWiki
Hmmmm,
Depending on how you use it! .... I wouldn't rely on it.

TW wikitext may be forgiving. The browsers CSS parser will probably silently fail. Which will cause some headache.

just my thought.
-mario

TW Tones

unread,
Jun 1, 2021, 7:44:17 PM6/1/21
to TiddlyWiki
TT,

You are being naughty. 

There seems to be a lot of ways to "overload" aspects of tiddlywiki. This adds a lot of functionality but with power comes responsibility. 

Your example however would be more useful if inside the macro you call, we could reference all the parameters defined or passed as a single string. 

\define mymacro(anything and everything)
$params$ would contain anything and everything
\end

Or 

\define myothermacro()
$params$ would contain "anything and everything"
\end

<<mmyothermacro anything and everything>>

However there may also be a place for generating keyword value pairs

\define macroone(filter:"[all[]]" p1:"default" p2)
$values$ may contain filter="altfilter" p1="default" p2="Other".
this could then be added in another macro like create tiddler button with $values$ providing the parameter values.
\end

<<macroone "altfilter" p2:"other">>

Regards
Tones

TiddlyTweeter

unread,
Jun 2, 2021, 1:03:51 AM6/2/21
to TiddlyWiki
Ciao PMario

PMario wrote:
...The browsers CSS parser will probably silently fail. Which will cause some headache.

Thanks for the heads-up. Actually the macro where I stumbled on the behaviour simply dynamically creates a CSS stylesheet to investigate SVG styling.
So far it has worked well. Until Your mods are accepted :-)

I'm looking forward to YOUR PR on commenting in macros and elsewhere getting accepted and included as part of the core :-)

Best wishes
TT

TiddlyTweeter

unread,
Jun 2, 2021, 1:09:43 AM6/2/21
to TiddlyWiki
Ciao Tones

 TW Tones wrote:
... There seems to be a lot of ways to "overload" aspects of tiddlywiki. This adds a lot of functionality but with power comes responsibility. 

Right! I am NOT recommending it as a general method for commenting macros!
Merely noting in exceptional test cases it is v. handy. 
The specific case is dynamic sytling of SVG icons where you can better see what does what in the CSS. Here is a screen of how I actually use it ...

 Screenshot 2021-06-02 065721.jpg
Reply all
Reply to author
Forward
0 new messages