New magic of $list widget in Tiddlywiki 5.1.24: The index attribute

634 views
Skip to first unread message

Mohammad Rahmani

unread,
Apr 24, 2021, 11:22:40 AM4/24/21
to tiddl...@googlegroups.com
You may now, the $list widget, is the most common widget you use in Tiddlywiki! It is everywhere like a nice dog!

The $list widget in 5.1.24 has got a new attribute index! in which the numeric index of each listed tiddler is stored  It can produce very nice results like below


<$list filter="[tag[About]sort[title]]" index="index">
<div>
<<index>>: ''<$text text=<<currentTiddler>>/>'' (is first: <<index-first>>, is last: <<index-last>>)
</div>
</$list>


Displays as:

0: Acknowledgements (is first: yes, is last: no)
1: Contributors (is first: no, is last: no)
2: History of TiddlyWiki (is first: no, is last: no)
3: License (is first: no, is last: no)
4: Releases (is first: no, is last: no)
5: RoadMap (is first: no, is last: yes)

Ah this is lovely!




Best wishes
Mohammad

Saq Imtiaz

unread,
Apr 24, 2021, 11:28:01 AM4/24/21
to TiddlyWiki
Important to be aware though that the refresh performance is of necessity rather slow when using this new attribute, so I would not suggest using it with larger numbers of tiddlers or complex templates where performance is a concern. 

For a small list like the one posted as an example in this thread, the performance different should be negligible.

Mohammad Rahmani

unread,
Apr 24, 2021, 11:39:00 AM4/24/21
to tiddl...@googlegroups.com
Thank you Saq!
I noted this in the TW-Scripts! That is quite correct!


Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/a9c51bca-41f0-460e-9e51-5907321362e5n%40googlegroups.com.

Charlie Veniot

unread,
Apr 24, 2021, 12:03:41 PM4/24/21
to TiddlyWiki
I'm not all that crazy about the choice of "index" as the keyword to handle that.

To me, index means index to an item in a data tiddler.

Now index means that or this.  When somebody is referring to index, in what context?  As in data tiddlers, or as in numerically identifiying <$list> items in a sequence?

Overloading the word index.  That annoys the daylights out of me.

TW Tones

unread,
Apr 24, 2021, 11:40:15 PM4/24/21
to TiddlyWiki
Mohammad,

I have long wanted this mechaisium my self. There are ways to emulate it, but a direct index variable is ideal. 

I wonder if the feature can be supported by the existing caching since this will have many possible uses and does become important when lists get longer. A zero OR one based index would also be helpful to avoid adding one every time in many cases.

There are a whole class of situations when knowing the position is useful, the set index parameter can be used to access the nth item in a list, so you could use one list to map to another eg days of the week, 1, mon, monday etc...

Also when generating a list then being able to enter a range of start and end values etc...

Regards
Tones


Mohammad Rahmani

unread,
Apr 25, 2021, 12:17:55 AM4/25/21
to tiddl...@googlegroups.com
Hi Tones,
 Good points! Like you said, I believe the base 0 or 1 should be set by the user! The PR has been recently merged and It is good 
to write your feedback there.


Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

Mat

unread,
Apr 25, 2021, 2:05:57 AM4/25/21
to TiddlyWiki
Mohammad wrote:
The $list widget in 5.1.24 has got a new attribute index!

Seems to be missing in the release notes.
 
It is everywhere like a nice dog!

LOL! If it is everywhere, isn't it more like mosquitos then? But nice ones?

<:-)

PMario

unread,
Apr 25, 2021, 4:07:09 AM4/25/21
to TiddlyWiki
On Saturday, April 24, 2021 at 6:03:41 PM UTC+2 cj.v...@gmail.com wrote:
Now index means that or this.  When somebody is referring to index, in what context?  As in data tiddlers, or as in numerically identifiying <$list> items in a sequence?

Overloading the word index.  That annoys the daylights out of me.

It's still time to add your concerns at the github PR or create a new issue at github. The version isn't released yet. So everything can be adjusted!

see: https://github.com/Jermolene/TiddlyWiki5/pull/5611  In a new issue you can relate to the PR
-mario

Saq Imtiaz

unread,
Apr 25, 2021, 4:22:32 AM4/25/21
to TiddlyWiki
To understand the difference in performance, try changing sidebar tabs in this wiki which has the index feature permanently switched on: https://tw5-with-hacked-list-widget.tiddlyhost.com/

Keeping the index updated and correct across refreshes requires re-rendering the DOM nodes for entire list widgets each time. We currently have no mechanism to avoid this and room for optimization is very limited at best.

Mohammad Rahmani

unread,
Apr 25, 2021, 4:33:57 AM4/25/21
to tiddl...@googlegroups.com



Best wishes
Mohammad


On Sun, Apr 25, 2021 at 12:52 PM Saq Imtiaz <saq.i...@gmail.com> wrote:
To understand the difference in performance, try changing sidebar tabs in this wiki which has the index feature permanently switched on: https://tw5-with-hacked-list-widget.tiddlyhost.com/

Keeping the index updated and correct across refreshes requires re-rendering the DOM nodes for entire list widgets each time. We currently have no mechanism to avoid this and room for optimization is very limited at best.

It is very slow! So one should be very careful!

On Sunday, April 25, 2021 at 10:07:09 AM UTC+2 PMario wrote:
On Saturday, April 24, 2021 at 6:03:41 PM UTC+2 cj.v...@gmail.com wrote:
Now index means that or this.  When somebody is referring to index, in what context?  As in data tiddlers, or as in numerically identifiying <$list> items in a sequence?

Overloading the word index.  That annoys the daylights out of me.

It's still time to add your concerns at the github PR or create a new issue at github. The version isn't released yet. So everything can be adjusted!

see: https://github.com/Jermolene/TiddlyWiki5/pull/5611  In a new issue you can relate to the PR
-mario

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

Mark S.

unread,
Apr 25, 2021, 9:52:21 AM4/25/21
to TiddlyWiki
If we can do an index, maybe some day we can do a "tee" .

A tee would be a filter operator that would take the results of the filter so far and put them in a variable. Then the results would continue down the filter for further processing, possibly including another tee. This would allow you to do in one list widget what currently takes multiple nested list widgets.


Jeremy Ruston

unread,
Apr 25, 2021, 10:42:00 AM4/25/21
to tiddl...@googlegroups.com
Hi Mark

> On 25 Apr 2021, at 14:52, 'Mark S.' via TiddlyWiki <tiddl...@googlegroups.com> wrote:
>
> If we can do an index, maybe some day we can do a "tee" .
>
> A tee would be a filter operator that would take the results of the filter so far and put them in a variable. Then the results would continue down the filter for further processing, possibly including another tee. This would allow you to do in one list widget what currently takes multiple nested list widgets.

That sounds interesting, can you flesh it out with some examples?

Best wishes

Jeremy.

Jeremy Ruston

unread,
Apr 25, 2021, 10:44:05 AM4/25/21
to tiddl...@googlegroups.com
 Good points! Like you said, I believe the base 0 or 1 should be set by the user! The PR has been recently merged and It is good 
to write your feedback there.


It seems to me that devising a mechanism to let the user specify 0 or 1-based indexes will result in more complexity than the user simply adding 1 when required. Did you have a mechanism in mind?

Best wishes

Jeremy

Jeremy Ruston

unread,
Apr 25, 2021, 11:03:52 AM4/25/21
to tiddl...@googlegroups.com

I'm not all that crazy about the choice of "index" as the keyword to handle that.

To me, index means index to an item in a data tiddler.

Now index means that or this.  When somebody is referring to index, in what context?  As in data tiddlers, or as in numerically identifiying <$list> items in a sequence?

Overloading the word index.  That annoys the daylights out of me.

Does anyone have any thoughts on an alternative?

Perhaps “counter”?

Perhaps it should actually be “counterVariable” for consistency with the existing “variable” attribute.

Best wishes

Jeremy

Mark S.

unread,
Apr 25, 2021, 11:12:12 AM4/25/21
to TiddlyWiki
"Index" makes sense to me. Especially since you can assign your own variable name to avoid crashes with existing code. "Index" is not overloaded in the context of the list widget. In terms of personal preferences, I would avoid long, camelcase names which just makes it easier to break code by a simple typo.

Thanks!

Charlie Veniot

unread,
Apr 25, 2021, 11:19:39 AM4/25/21
to TiddlyWiki
Sequence / Sequenced?  Numbered?  "OLIST" (for "ordered list" ... from "OL")?

Charlie Veniot

unread,
Apr 25, 2021, 11:37:31 AM4/25/21
to TiddlyWiki
BTW, I should mention that I only bring this up because I think it could potentially be a little confusing to have "index" mean different things depending on context.  Searching for help with the keyword "index" at TiddlyWiki.com, kind of a pain in the caboose sifting out what is what in the search results.  Maybe such is life ...

Also:  Since I'm no fan of automagically numbered lists, I definitely don't have a personal stake in the naming of this feature.

Mohammad Rahmani

unread,
Apr 25, 2021, 12:03:24 PM4/25/21
to tiddl...@googlegroups.com
Thanks for clarification! I think it is better to keep things simple! So I go with current design!

Best wishes

Jeremy

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

Mark S.

unread,
Apr 25, 2021, 12:52:13 PM4/25/21
to TiddlyWiki

It seems to me that devising a mechanism to let the user specify 0 or 1-based indexes will result in more complexity than the user simply adding 1 when required. Did you have a mechanism in mind?


Shouldn't it be 1-based, since that is what the nth filter requires? The main filter that uses an index?


Soren Bjornstad

unread,
Apr 25, 2021, 1:11:21 PM4/25/21
to TiddlyWiki
Yeah, I have trouble thinking of a situation in which you would want a zero-based index here. Nobody wants their displayed list to start with 0, and doesn't seem like there is any way to access the contents of the list using a 0-based index. In the rare situation that you actually did want it, seems like you could subtract one.

Soren Bjornstad

unread,
Apr 25, 2021, 1:12:59 PM4/25/21
to TiddlyWiki
Or perhaps we should make it 0.5-based.

Mat

unread,
Apr 25, 2021, 1:32:50 PM4/25/21
to TiddlyWiki
Mark S. wrote:
A tee would be a filter operator that would take the results of the filter so far and put them in a variable.

YES! That would be wonderful. A particular use case is when you, in the middler of a filter expression, lose the title of the tiddler because you did e.g "get[foo]" but then again need the title.

<:-) 

Mat

unread,
Apr 25, 2021, 1:40:03 PM4/25/21
to TiddlyWiki
"index" - I think the term is fine but if we need an alternative, also "position" would do. "Each item has a position in the list."

If this new feature enables using lists as arrays then index probably makes more sense.

By the way, I cannot find this feature mentioned in the release notes. Is it even to early for that?

<:-)


Saq Imtiaz

unread,
Apr 25, 2021, 2:52:28 PM4/25/21
to TiddlyWiki
Updating release notes is a LOT of work and as such isn't always done for each change, but sometimes in spurts as we get closer to a release or as changes start to collect.

Also, volunteers to help update the release notes are always welcome.

TW Tones

unread,
Apr 25, 2021, 7:08:34 PM4/25/21
to TiddlyWiki
Jeremy,

Just some possibilities;

Alternatives that come to mind are "item", or "instance", "list item", or we could expand to "list-index" or "item-index", but depending on where used "position".

Also the work "ordinal" comes to mind as a little more specific. 

CSS can be used to generate numbers for lists so displayed, but we need this number available for logic. Knowing the first number and total number using count the "ordinal" allows us to detect the first and last instance. This allows one list to contain logic for start/initial and Last/final.

Tones

PMario

unread,
Apr 25, 2021, 7:12:15 PM4/25/21
to TiddlyWiki
On Sunday, April 25, 2021 at 5:03:52 PM UTC+2 Jeremy Ruston wrote:
Does anyone have any thoughts on an alternative?

Perhaps “counter”?

I would prefer "number" instead of counter.

-m

Brian Radspinner

unread,
Apr 25, 2021, 8:08:09 PM4/25/21
to TiddlyWiki
I like either "ordinal" or "number" rather than index

TW Tones

unread,
Apr 25, 2021, 8:39:43 PM4/25/21
to TiddlyWiki
Folks,

I penciled this working example (tiddlywiki.com) to test some of the statements, and basically found much can be satisfied with a maro.

Personally I am keen to see much of this incorporated in the list widget, but a new widget "lister" or "report" would be fine.
  • stores the original filter for reuse
  • saves the list generated by the filter for reuse
  • provides before after and during (text of first and last)
    • Perhaps later to transclude or exec macro
  • the macros before/after and each-item are to allow reformatting the output.

\define before() 
;before
:Input filter <$text text=<<filter>>/>
:Members: <<last-item>>
:Whole list in variable ''item-list''
;list with ordinal available with ''position'' variable
\end
\define after()
;after

\end
\define each-item() <<position>> <$link/> __<<first>> <<last>>__ <br>

\define position() {{{ [enlist<item-list>allbefore:include<currentTiddler>count[]] }}}
\define first()  {{{ [<position>match[1]then[first]] }}}
\define last()  {{{ [<position>match<last-item>then[last]] }}}
\define list-ordinal(filter)
<$set name=item-list filter="$filter$">
<$set name=last-item filter="$filter$ +[count[]]">
<$set name=filter value="$filter$">

<$wikify name=result text="<<before>>" output=html><<result>></$wikify>

<$list filter=<<item-list>> >
     <$wikify name=position text="<<position>>">
          <<each-item>>
     </$wikify>
</$list>

<$wikify name=result text="<<after>>" output=html><<result>></$wikify>

</$set></$set></$set>
\end

<<list-ordinal "[tag[Widgets]]">>


Tones

Álvaro

unread,
Apr 26, 2021, 6:03:43 AM4/26/21
to TiddlyWiki
It looks great feature.

I don't have any problem with the keyword "index", the keyword connect perfectly with its function, IMHO. I think that the Tones's proposal "list-index" is great alternative.

Jeremy Ruston

unread,
Apr 26, 2021, 9:59:24 AM4/26/21
to tiddl...@googlegroups.com
I’ve committed two changes:

* The “index” attribute is now called “counter”
* The counter value is now 1-based, instead of 0-based

The commit is here:


You can see the results here:


Best wishes

Jeremy.


-- 
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

Mohammad Rahmani

unread,
Apr 26, 2021, 11:14:08 AM4/26/21
to tiddl...@googlegroups.com



Best wishes
Mohammad


On Mon, Apr 26, 2021 at 6:29 PM Jeremy Ruston <jeremy...@gmail.com> wrote:
I’ve committed two changes:

* The “index” attribute is now called “counter”
* The counter value is now 1-based, instead of 0-based

Much appreciated! the base 1 makes sense and it is meaningful for most use cases in TW.
Reply all
Reply to author
Forward
0 new messages