Introduction
I am both pleased and embarrassed to announce a new PR that is planned for v5.4.0. It makes an important change to the handling of macro calls by finally allowing parameters to be specified as dynamic transclusions instead of just constant strings.
Preview build: https://deploy-preview-9055–tiddlywiki-previews.netlify.app
By changing the usual colon into an equals sign it is now possible to do things like this:
<<mymacro param={{Something}}>>
Or even this:
<div class=<<mymacro param={{Something}}>>>
Not to mention this:
<div class=<<mymacro param={{{ [<myvar>addprefix[https:] }}}>>>
We can even specify parameters for the inner call:
<div class=<<mymacro param={{{ [<innermacro p={{Something}}>addprefix[https:] }}}>>>
I am pleased about this change for obvious reasons: it removes a long-standing irregularity from TiddlyWiki’s syntax, and it adds flexibility and expressiveness that will be appreciated by all wikitext authors.
The reason I am embarrassed is that it has taken so long to address this issue, particularly as it has turned out that the implementation is not enormously complex. In mitigation the changes in v5.3.0 laid a lot of the groundwork for this change.
Background
In fact, “macro calls” has become an increasingly ill-fitting term since v5.3.0 when the same syntax was extended to allow it to be used to invoke functions and procedures. I propose we use the term “call” to refer generally to all three formulations, and “macro call”, “procedure call” and “function call” for the specific variants.
The call syntax can be used in three different settings:
- As a standalone construction
- As a widget attribute value
- As a filter operand value
In all cases, it is now possible to use an equals sign instead of a colon to allow parameter values to be passed as a transclusion, filter expression or nested call.
Backwards Compatibility
The backwards compatibility issues with this change are fairly extreme edge cases. In particular, previously a construction like this would have been interpreted as an unquoted parameter with the value “name=background”:
<<mymacro name=background>>
So, this change will break code that invokes a macro with an unquoted parameter that contains an equals sign. There is no restriction on parameters with double or single quotes.
Progress
This PR is not yet complete:
- [ ] Enforcing new syntax to only work with equals signs (currently equals and colon are considered equivalent)
- [ ] Calls within filters
- [ ] Documentation
- [x] Calls as attribute values
- [x] Standalone calls
Idea: Block Parameters
I have been toying with the idea of further extending the call syntax to allow blocks to be passed (which would be $fill widgets under the covers). This would allow for things like an inline version of the tabs macro:
<<inline-tabs mode="vertical"
:> Help
Some useful and interesting content, including wikitext like <<now>>
:> About
More useful and interesting information.
>>