Numeric position info in $list widget and other filters (working implementation)

428 views
Skip to first unread message

Evan Balster

unread,
May 13, 2016, 12:32:48 AM5/13/16
to TiddlyWiki
Hello!

There's a feature I've wanted to see in TiddlyWiki for a while:  The ability, when using the $list widget, to create a variable corresponding to the position of the current item in the list.  My interest in this feature is to use it for coordinates when generating SVGs.  I took the initiative of making a crude working implementation.  Modifying the list widget proved a bit intimidating, so I implemented a filter operator instead.

The new operator is attached and can be imported to a wiki.  It is called addposition, and formats each title in the input list into some combination of title, list position, list size and customizable delimiters.  The intended use is to glue positions onto each list item and un-glue them later with string operations.

The filter operand is a format string, where T is replaced by the input title, P by the position and N by the size of the list.  The default format (when calling addposition[], no operand) is "P:T".  Prefix notation makes it easy to use the splitbefore operator.

Example code:

<table>
<tr><th>index</th><th>tiddler</th></tr>
<$list variable="item" filter="[all[shadows]regexp[list]sort[title]addposition[P/N:T]]">
<$set name=pos filter="[<item>splitbefore[:]removesuffix[:]]">
<$set name=tiddler filter="[<item>removeprefix<pos>removeprefix[:]]">
<tr>
  <td>^^#^^<<pos>></td>
  <td><<tiddler>></td>
</tr>
</$set>
</$set>
</$list>
</table>

If this function proves useful to others, it might be worth investigating position and/or size variable options in the $list widget itself, which would be somewhat more convenient to use.
$__ebalster_modules_filters_addposition.json

PMario

unread,
May 13, 2016, 3:25:55 AM5/13/16
to TiddlyWiki
That's an interesting approach.
thx for sharing
-m

Jed Carty

unread,
May 13, 2016, 3:45:21 PM5/13/16
to TiddlyWiki
The list widget is very important to tiddlywiki so any modifications need to be done very carefully. In the past Tobias tried adding an index variable to the widget but it didn't play well with some other parts so it had to be removed. I think that your workaround may be a good alternative.

For many use cases you can get away with just using the before and after operators which is one reason this hasn't gotten more work.

And since you mentioned svg, I am working on making a plugin for snap.svg, my work is here http://ooktech.com/jed/ExampleWikis/SnapSVG/

Evan Balster

unread,
May 13, 2016, 8:57:10 PM5/13/16
to tiddlywiki
Yeah, after reading through the list widget's code -- particularly the refresh routine, whose performance would be negatively impacted -- I had an inkling that it might make more sense to make a new widget (EG. $numbered-list) rather than customize the existing one.  I may investigate that later.

– Evan


--
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/13_TTJqEEiw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@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/21d9ac05-34b2-4877-98d1-214396d7de4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mat

unread,
Jan 31, 2017, 5:12:38 AM1/31/17
to TiddlyWiki
@Evan - did you happen to take this further?

..or anyone else?

It is in deed a desirable feature and would make it possible to use the listwidget a bit like arrays.

<:-)

Evan Balster

unread,
Jan 31, 2017, 12:56:14 PM1/31/17
to TiddlyWiki
Hey, Mat —

Yes, I implemented it.  I believe that implementation was lost in a hard drive failure, but it wasn't difficult at all...  So perhaps I'll try implementing it again and post my solution here.

Mat

unread,
Jan 31, 2017, 3:03:51 PM1/31/17
to TiddlyWiki
@Evan - yes please! That'd be great!

<:-)

Jeremy Ruston

unread,
Jan 31, 2017, 6:47:48 PM1/31/17
to tiddl...@googlegroups.com
Hi Mat

On 31 Jan 2017, at 10:12, Mat <matia...@gmail.com> wrote:

It is in deed a desirable feature and would make it possible to use the listwidget a bit like arrays.

I think Tobias contributed a patch some years ago that added an “index” variable to the list widget. The problem is that it breaks an important optimisation for the list widget whereby existing DOM nodes are reused when entries are added or removed from a list. As I recall it, we decided finally that it would be better in a separate widget.

Best wishes

Jeremy

Tobias Beer

unread,
Feb 1, 2017, 2:48:34 AM2/1/17
to TiddlyWiki
Hi Evan,

A very neat trick indeed and something I've been wanting for a while now.

Just realized my plugins tobibeer/make and tobibeer/split
also allow you to achieve the effect, see:
Best wishes,

Tobias.

Evan Balster

unread,
Feb 1, 2017, 1:10:54 PM2/1/17
to tiddlywiki
Oh hey --- there's my own numbered list implementation, which was apparently implemented with a filter trick.  Didn't realize that was its own thread.


– Evan

On Wed, Feb 1, 2017 at 12:08 PM, Evan Balster <ev...@imitone.com> wrote:
Oh hey --- there's my own numbered list implementation, which was apparently implemented with a filter trick.  Didn't realize that was its own thread.


– Evan Balster
creator of imitone

--
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/13_TTJqEEiw/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.

Evan Balster

unread,
Feb 1, 2017, 1:27:53 PM2/1/17
to TiddlyWiki
Ah wait, no, that's this thread.  Not my brightest moment.

Jeremy, would it be possible to get an unoptimized version of the list widget as a basis for customization?  As it is, it looks like the optimization adds a lot of code complexity and it's a little hard to know what to strip out without a strong understanding of TW's codebase.

Jeremy Ruston

unread,
Feb 1, 2017, 2:01:38 PM2/1/17
to tiddl...@googlegroups.com
Hi Evan

Jeremy, would it be possible to get an unoptimized version of the list widget as a basis for customization?  As it is, it looks like the optimization adds a lot of code complexity and it's a little hard to know what to strip out without a strong understanding of TW's codebase.

I'll try to do it if I have a chance. To be honest, it may be easier to go the other way: to take a generic widget and gradually add the list functionality in bits and pieces.

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.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.

Mat

unread,
Feb 15, 2017, 4:58:20 PM2/15/17
to TiddlyWiki
Jeremy or Evan - any follow up on this?  I keep hitting cases where it would be useful. I believe a solution would also function as a kind of array, which should appeal to coders coming here.

Tobias' workaround IS an optoin but it's a bit contrived to explicitly add and deduct stuff for each item. Just generally, I reason that the items have a natural position in the provided filter output that one probably could take advantage of - alternatively; I assume the list widget runs through that number of iterations so some kind of counter could maybe follow along for each iteration...

<:-)

Steven Schneider

unread,
Apr 17, 2017, 7:15:14 PM4/17/17
to TiddlyWiki
I'm interested in this also, just ran into a use case and found this thread. Importing large # of pix from flickr and providing a first-previous-next-last nav bar based on shared tag. $count tells me how many, but there isn't a $which, so we could generate "Tiddler X of Y" (Tiddler $which of $count).

//steve.

Jed Carty

unread,
Apr 18, 2017, 1:23:10 AM4/18/17
to TiddlyWiki
You can list 'Tiddler m of n' without anything new, the wizard wizard plugin does it. I just used count widgets. https://ooktech.com/TiddlyWiki/WizardWizard/

Steven Schneider

unread,
Apr 19, 2017, 1:17:40 PM4/19/17
to TiddlyWiki
Jed, I had a look at WizardWizard, which is pretty cool, I must say. Thanks for doing that.

And thanks especially for pointing me towards your macro. You inspired me to explore the "allbefore" operator, which allows me to generate a Tiddler X of Y, where Y is the number of tiddlers counted by a filter and X is the nth tiddler in the list.

Here is code, which if placed in tiddlers tagged "HelloThere" in tiddlywiki.com will create the desired output:

Tiddler <$count filter="[tag[HelloThere]allbefore:include<currentTiddler>]"/> of <$count filter="[tag[HelloThere]]"/> tagged with <<tag HelloThere>><br>


Thanks,

//steve.

Evan Balster

unread,
Apr 19, 2017, 1:36:55 PM4/19/17
to tiddlywiki
Quick reminder because I managed to forget about this myself at one point:  I did provide a working (if hacky) solution in the OP.  The addposition operator is a fairly low-impact way to achieve this effect, and it doesn't take O(N^2) time to execute.

To review, a filter step addposition[P/N:T] will turn "MyItem" into "13/26:MyItem" if it is the thirteenth of twenty-six items.

– Evan

--
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/13_TTJqEEiw/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.
Reply all
Reply to author
Forward
0 new messages