Sort Text List without Writing It into a Field?

58 views
Skip to first unread message

Scott Simmons (Secret-HQ)

unread,
Oct 24, 2018, 3:10:15 PM10/24/18
to TiddlyWiki
Is there a good TiddlyWay to sort a text string without having to write it to a field?

I'm imagining a macro that could take an input of numbers and render a list.  E.g.,,

The account numbers are <ol><<sortEm "149 54 9 21">></ol>

... renders as:

The account numbers are 
1. 9
2. 21
3. 54
4. 149

Matthew Lauber

unread,
Oct 24, 2018, 3:22:39 PM10/24/18
to tiddl...@googlegroups.com
<$list filter="149 54 9 21 +[nsort[]]">

</$list>

This works because the default handling of a filter is to treat it as a tiddler title.  tiddler titles in filters don't have to correspond to existing tiddlers.  So the list filter is being passed a list of tiddlers.  Then the "+[" sytax means, run the following filter run using the previous tiddlers as input.  So now we run nsort against them, getting back a list of tiddlers in numeric sorted order.  From there, you can format them however you like.  

~Matt

c pa

unread,
Oct 24, 2018, 6:01:11 PM10/24/18
to TiddlyWiki
\define sortEm(string)
<$list filter="$string$ +[nsort[]]">

</$list>
\end

Scott Simmons (Secret-HQ)

unread,
Oct 24, 2018, 6:01:47 PM10/24/18
to tiddl...@googlegroups.com
:D  AMAZING!

Thanks, Matt!  It would have been deep into the 2020s before that ever occurred to me, and it's just the quick and dirty solution I needed
Reply all
Reply to author
Forward
0 new messages