(TW5) Problem with operator on: subfilter:"sort[created]" ?

171 views
Skip to first unread message

Daniel Cunningham

unread,
Feb 22, 2017, 1:42:58 PM2/22/17
to TiddlyWiki
Hi All -- new TW5 user here.  Really love the product so far. 

I've run into a behavior that might be a bug, or (more likely) me just not understanding the syntax.  I'm trying to display a list of tiddlers by date created (not just modified).  And it seems to me that the negation operator in my subfilter is not acting upon my sort criteria. 

I thought the code below would produce different ordered lists, but it does not.  

!! List tiddlers by creation (not modification) date:

!!! Show oldest on top, newest on bottom?

<<timeline dateField:"created"
    subfilter:"sort[created]"
    format:"ddd 0DD MMM YYYY">>

---

!!! Show newest on top, oldest on bottom?

<<timeline dateField:"created"
    subfilter:"!sort[created]"
    format:"ddd 0DD MMM YYYY">>



This is with a freshly downloaded "empty" TW5 instance.

My preference is to do this in "vanilla" TW5, because (1) I want to make sure I actually understand the syntax, and (2) I'm not sure which plug-in "pet" I want to adopt yet (I want to take them ALL home, but I know that's not wise).

-- Daniel

Mark S.

unread,
Feb 22, 2017, 5:19:59 PM2/22/17
to TiddlyWiki
Per the documentation, timeline uses this filter:

[!is[system]$subfilter$has[modified]!sort[modified]limit[$limit$]eachday[modified]]

This means that a sort on the modified field is applied after the subfilter and will take precedence over a sort order specified in the subfilter.

I guess I would consider cloning $:/core/macros/timeline perhaps creating a macro "timeline2" and then change the sort in the filter expression to work your way. If you clone and modify, remember that you have to save and refresh before the new macro will take effect. Also be sure to have a backup of your TW file before you start.

Good luck,
Mark

Daniel Cunningham

unread,
Feb 22, 2017, 5:48:49 PM2/22/17
to TiddlyWiki
Ahhhh!  Thanks much, Mark!  I saw that documentation, but did not realize its implications.

So, just to be clear, it's saying?...
  1. look at stuff that's not a system tiddler;
  2. filter anything that's got a "modified" field;
  3. do a reverse sort on the "modified" date;
  4. and then, if the user put some limits on the listing, use those limits.
And then what you are saying is that since this is embedded in the timeline macro, any sort criteria I try to apply to "created" will be to no avail?

Unless... I clone the macro & modfify it to use the "created" field?

Thanks again!

PMario

unread,
Feb 22, 2017, 7:22:50 PM2/22/17
to TiddlyWiki
On Wednesday, February 22, 2017 at 11:48:49 PM UTC+1, Daniel Cunningham wrote:
And then what you are saying is that since this is embedded in the timeline macro, any sort criteria I try to apply to "created" will be to no avail?

Have a look at the docs: http://tiddlywiki.com/#timeline%20Macro
 

Unless... I clone the macro & modfify it to use the "created" field?

Edit: $:/core/ui/SideBar/Recent

like so: <$macrocall $name="timeline" format={{$:/language/RecentChanges/DateFormat}} dateField="created"/>

and you should be good to go.

have fun!
mario

Mark S.

unread,
Feb 22, 2017, 10:32:35 PM2/22/17
to TiddlyWiki
So this line in the documentation is incorrect:


[!is[system]$subfilter$has[modified]!sort[modified]limit[$limit$]eachday[modified]]

and should read instead

[!is[system]$subfilter$has[$dateField$]!sort[$dateField$]limit[$limit$]eachday[$dateField$]]

Mark

Mark S.

unread,
Feb 22, 2017, 10:42:03 PM2/22/17
to TiddlyWiki
I've made a PR for this fix.

Daniel Cunningham

unread,
Feb 23, 2017, 7:12:26 PM2/23/17
to TiddlyWiki
Many thanks, Mario!  I tried that, and it works. 

But rather than change a shadow tiddler, I elected to put in into a "end-user" tiddler, that I can then place in the sidebar with a "$:tags/SideBar" tag.  That gives me the functionality I was looking for.  Also, I won't shoot myself in the foot if core changes during my "learning curve".  :-)

As a follow-up, the results are still in descending order (same as the original Recent tab functionality).  So, to get ascending order, I recon I should apply a sort operator to the results of your code segment.  But the syntax of your code is very different than that shown in the docs -- can you give guidance on this?

Best,

-- Daniel



On Wednesday, February 22, 2017 at 4:22:50 PM UTC-8, PMario wrote:

Mark S.

unread,
Feb 23, 2017, 8:42:43 PM2/23/17
to TiddlyWiki
Hi Daniel,

Mario's syntax uses the macrocall widget, which is a somewhat more formal way of calling a macro that works better in some situations.

The problem with the timeline macro is that it doesn't give you access to the sorting order (A/D), as you can see in this filter:


[!is[system]$subfilter$has[$dateField$]!sort[$dateField$]limit[$limit$]eachday[$dateField$]]

You can't reach the !sort in the macro invocation. You can try putting the following into a tiddler, which is modified from the original timeline code:

\define timeline2(limit:"100",format:"DDth MMM YYYY",subfilter:"",dateField:"modified")
<div class="tc-timeline">
<$list filter="[!is[system]$subfilter$has[$dateField$]sort[$dateField$]limit[$limit$]eachday[$dateField$]]">
<div class="tc-menu-list-item">
<$view field="$dateField$" format="date" template="$format$"/>
<$list filter="[sameday:$dateField${!!$dateField$}!is[system]$subfilter$sort[$dateField$]]">
<div class="tc-menu-list-subitem">
<$link to={{!!title}}>
<<timeline-title>>
</$link>
</
div>
</$list>
</
div>
</$list>
</
div>
\end
<$macrocall $name="timeline2" subfilter="" format={{$:/language/RecentChanges/DateFormat}} dateField="created"/>

It seemed to work in my quick test, though I didn't look at dates too closely.

Good luck!
Mark

Daniel Cunningham

unread,
Feb 24, 2017, 1:34:03 AM2/24/17
to TiddlyWiki
Hi Mark,

Thanks for that follow-up!  I'm beginning to see (thanks to you and Mario) how this works.

OK, so I now get how you can negate the sort order inside the macro (with a bang).  And then I see from the docs that the way that expression evaluates is L-to-R via that "railroad" style filter syntax.

And now I see how you can't get to the juicy inner goodness unless you explicitly flip that bang in the middle...

...which bothered me.  So I extended your initial idea to allow an additional parameterization from outside:

\define timeline2(limit:"100",format:"DDth  MMM YYYY",subfilter:"",sortaction"sort",dateField:"modified")
<div class="tc-timeline">
<$list filter="[!is[system]$subfilter$has[$dateField$]$sortaction$[$dateField$]limit[$limit$]eachday[$dateField$]]">

[...]

<$macrocall $name="timeline2" subfilter="" format={{$:/language/RecentChanges/DateFormat}} sortaction="sort" dateField="created"/>

And so, I can make a call using a sortaction of "sort" or "!sort", and control it from outside.  Which works.  And taught me a lot, so thanks to you & Mario for investing your time explaining that to me.

Finally. some observations and questions for you veterans (keeping in mind that I'm not at all familiar with the code base yet):
  • Keep in mind I'm not a "macro-ey" kinda guy.  I'm more of "function-ey" or "object/method-ey" dude, so I'm sure you should take this with a bowling ball sized grain of salf...
  • It kind of "bothered" me that the declaration "looks" like it has a "default parameterization", but does not really.  In other words, when you call the macro, if you don't explicitly supply all parameters, it will fail.  That seems a bit fragile, right?
  • Death by whitespace:  I found out if there's any leading whitespace (before the macro definition) the tiddler fails.  Also, if there's any whitespace in the filter list, it will fail.  Again, trying not to seem harsh, but it feels rather fragile.  Am I being unfair?
  • Is this "macro-ey" stuff kind of like the STL in C++?
  • Is this "fragility" due to the macro mechanism itself?  Or is it a characteristic of JavaScript?  Or CSS?  Or HTML?  Or some intersection of those elements?

And, again, most of all... THANKS for your explanations, which have been very useful in helping me to spin up on the awesomeness that is TiddlyWiki!

Daniel Cunningham

unread,
Feb 24, 2017, 2:15:35 AM2/24/17
to TiddlyWiki
Uhhh, scratch the "leading whitespace fragility" question.  I need to chase my own sloppiness down...  :-)

Daniel Cunningham

unread,
Feb 24, 2017, 2:23:17 AM2/24/17
to TiddlyWiki
Sorry It was when I tried to add a comment above the macro that I threw the error.  I need to study up on TW5 comment syntax.

PMario

unread,
Feb 24, 2017, 3:00:19 AM2/24/17
to TiddlyWiki
Hi,

I think there is a typo. IMO it should be:

\define timeline2(limit:"100",format:"DDth  MMM YYYY",subfilter:"",sortaction:"sort",dateField:"modified")

see the : after sortaction!

-m

PMario

unread,
Feb 24, 2017, 3:25:18 AM2/24/17
to TiddlyWiki
On Friday, February 24, 2017 at 7:34:03 AM UTC+1, Daniel Cunningham wrote:
Finally. some observations and questions for you veterans (keeping in mind that I'm not at all familiar with the code base yet):
  • It kind of "bothered" me that the declaration "looks" like it has a "default parameterization", but does not really.  In other words, when you call the macro, if you don't explicitly supply all parameters, it will fail.  That seems a bit fragile, right?
Parameters do have default values, if you define them in the macro \define section.  IMO you just forgot the : ... see my other post..
 
  • Death by whitespace:  I found out if there's any leading whitespace (before the macro definition) the tiddler fails.  Also, if there's any whitespace in the filter list, it will fail.  Again, trying not to seem harsh, but it feels rather fragile.  Am I being unfair?
macros are TW syntax. So whitespace matters, most of the time. ... macro definitions have to start at the beginning of the line. Similar to headings and list syntax. ... It's wikitext  ...  powerful wikitext ;)

 
  • Is this "macro-ey" stuff kind of like the STL in C++?
In the sense, that macros should abstract away complexity from enduses. .. yes.

BUT TW macros are basically "text substitutions"  see: http://tiddlywiki.com/#Macros%20in%20WikiText:%5B%5BMacros%20in%20WikiText%5D%5D%20Macros%20Pragma
 
  • Is this "fragility" due to the macro mechanism itself?
I'm not exactly sure what you mean here? An example would be nice. ... Most of the time whitespace matters.

TW syntax is used to produce formatted text. .. It's no general purpose programming language.
 
have fun!
mario

PMario

unread,
Feb 24, 2017, 3:38:23 AM2/24/17
to TiddlyWiki


On Friday, February 24, 2017 at 7:34:03 AM UTC+1, Daniel Cunningham wrote:
  • Death by whitespace:  I found out if there's any leading whitespace (before the macro definition) the tiddler fails.  Also, if there's any whitespace in the filter list, it will fail.  Again, trying not to seem harsh, but it feels rather fragile.  Am I being unfair?
whitespace in filters indicates a "filter run" see: http://tiddlywiki.com/#Filter%20Run:%5B%5BFilter%20Run%5D%5D%20%5B%5BFilter%20Step%5D%5D%20%5B%5BTitle%20Selection%5D%5D%20%5B%5BTitle%20List%5D%5D%20ListField

... Filters in combination with the list-widget are the most powerful mechanic in TW. It could fill a book ;) ... but it also has a steep learning curve :)

Keep in mind: The whole TW UI we use, is built with wikitext. There is no other wiki system I know, that gives end-users that degree of freedom.  In the sense of tweakability. __and__ If you mess it up. Just delete your stuff and the core "shadow tiddlers" take over again.

-mario

Daniel Cunningham

unread,
Feb 24, 2017, 1:14:00 PM2/24/17
to tiddl...@googlegroups.com
Hi Mario,

You are quite the gentleman!  Rookie mistake on my part.  Many thanks for spotting the error!

Best regards,
-- Daniel

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/0f_9pW6XKb4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/408bddbe-4010-4e91-8139-5feddbd00b45%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Daniel Cunningham

unread,
Feb 24, 2017, 1:23:16 PM2/24/17
to tiddl...@googlegroups.com
Hi Mario,

Thanks for your efforts at explaining.  Yes, I'm coming to a new appreciation.   With TW, you can't treat declarations and invocations as a matter of personal style.  You need to understand exactly how the substitutions will take place.

So instead of: "death by whitespace?" it's simply: "Dude.  Whitespace matters."  :-)

And it's very much worth learning, because of the results (and power) it can give you.

Thanks, Mario.

-- Best regards,
   Daniel


--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/0f_9pW6XKb4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

PMario

unread,
Feb 24, 2017, 3:15:38 PM2/24/17
to tiddl...@googlegroups.com
On Friday, February 24, 2017 at 7:23:16 PM UTC+1, Daniel Cunningham wrote:
So instead of: "death by whitespace?" it's simply: "Dude.  Whitespace matters."  :-)

:) ... but you are right. It sometimes hurts quite a bit. ...

But we also have to deal with backwards compatibility. .. There are some things, that Jeremy mentioned, that he would do in a different way today. ... But that's life.

I think we have a  great product. A hell lot of flexibility.

... and some fun!
-mario
Reply all
Reply to author
Forward
0 new messages