For me there is no question the winner is the new function definitions. It allows you do a number of things that were either not possible or clumsy.
Output any filter as text, if using a function as a variable
\function display.today() [<now "DDth MMM YYYY">]
<<display.today>>
- You will no longer need to use the $text widget to stop it being treated like a link.
- eg;
<$text text={{{ [<now "DDth MMM YYYY">] }}}/>
- Note how unlike procedures and macros it is evaluated before the final render. This means it can be used as a conditional inside filters without using wikify.
- Only the first result is returned, unless you use join. This works like a cascade returning the first value that is non-blank
\function design.mode() [<design-mode>match[yes]] :else[{!!design-mode}match[yes]] :else[{$:/config/design-mode}match[yes]]
`<<design.mode>>` or `[design.mode[]]`
-
<<design.mode>>
or [design.mode[]]
will return yes if
- The variable design-mode matches yes,
- or The current tiddlers design-mode field matches yes
- or The config tiddler $:/config/design-mode contains yes
- else Otherwise nothing is returned.
You can take any filter an give it a name or include a .
in the name and use it as a custom filter operator.
- A bit like subfilter variables
- This allows you to define reusable filters or filter operators with an appropriate name and bring them together to form a larger filter, whilst keeping it easier to read.
- I would like to see this adopted as a de facto standard by us all, including debug, author and other “modes”
Such filter operators can then be used inside the new %if structure
<%if [design.mode[]] %>
Display things only when in design mode
<%endif%>
- Notice how it resembles plain language and the complexities of determining design mode is hidden away in a reusable definition.
- I think the
<%if condition %>
will be my next reply.
Finally as we can use custom filter operators we can use them to filter out candidates for a list;
\function active.todo() [tag[todo]!has[done-date]]
<$list filter="[active.todo[]] +[limit[5]]">
</$list>
- So here you can forget the details of what makes an active todo and just use
[active.todo[]]
- You may add a new feature such as an archive tag whether it is done or not.
\function active.todo() [tag[todo]!has[done-date]!tag[archive]]
- All your lists using
[active.todo[]]
will now no longer include archive items, without modification.
- We may call this a logical abstraction, in a global function.
I won’t detail it here, but given the above, and the power of filters, it is now very easy to write sophisticated reusable filters and achieve a great deal.
- At the same time reducing the brain power needed to juggle the details.