Position in list code pattern? Challenge

90 views
Skip to first unread message

TonyM

unread,
Jan 13, 2020, 6:30:36 PM1/13/20
to TiddlyWiki
Folks,
I have an interesting idea, that requires the ability to get the position of a tiddlers title in a list field and return it as a number.

So if we consider the tag $:/tags/ViewTemplate then on tiddlywiki.com the Tiddler $:/core/ui/ViewTemplate/subtitle would return three (3)

I have a code pattern to achieve this using count, setWidget with its index parameter, and a range operator however it is quite long winded and possibly inefficient.

Is anyone aware of an efficient way to determine the position of a given tiddler name in a list ?

I will share the idea once get past this, in a separate thread. However I need to determine the position in a list many times over so an efficient method is critical.

Thanks in Advance
Tony 




Eric Shulman

unread,
Jan 13, 2020, 7:53:54 PM1/13/20
to TiddlyWiki
On Monday, January 13, 2020 at 3:30:36 PM UTC-8, TonyM wrote:
Is anyone aware of an efficient way to determine the position of a given tiddler name in a list ?

How about something like this:
<$list filter="NOMATCH A B C D E +[allbefore<target>count[]] " />


Notes:
* <target> is the title you are looking for
* if target doesn't exist in the list, the result is "0"
* NOMATCH is used as a "sentinel" value so that valid matches start with "1"

Thus, if in the above example
   target="FOO" returns 0
and
   target="A" returns 1
   target="B" returns 2
   etc.

let me know how it goes...

enjoy,
-e

TonyM

unread,
Jan 13, 2020, 9:54:12 PM1/13/20
to TiddlyWiki
Eric,

beautiful work. Love it. Nice and minimal. Thanks.

I will now look to using this to get a compound number 1.2.4 from a toc structure.

My design idea was to autogenerate a position in list or toc number and display it before or after the tiddler title
eg; "chapter title" n
or 1.2.3.4 tiddler title in toc

This is for tiddlers not toc lists but the numbers should match those in a numbered toc.

Thanks again
Tony

TonyM

unread,
Jan 13, 2020, 11:36:03 PM1/13/20
to TiddlyWiki
Folks,

I notice here, the list field only comes into existence if one drags and drops a tiddler in the tag pill popup.

Is any one aware of a programmatic way to cause this to happen?

Regards
Tony

TonyM

unread,
Jan 13, 2020, 11:45:21 PM1/13/20
to TiddlyWiki
Folks,

Using Erics Tips;

here is an example of finding the current tiddlers position in a list of the give tag "Code Patterns"
<$list filter="[[NOMATCH]] [enlist{Code Patterns!!list}] +[allbefore<currentTiddler>count[]]" />

Regards
Tony

On Tuesday, January 14, 2020 at 10:30:36 AM UTC+11, TonyM wrote:

Mohammad

unread,
Jan 14, 2020, 3:30:37 AM1/14/20
to tiddl...@googlegroups.com
I think if it uses allbefore:include then there is no need for NOMATCH!
like below

<$list filter="A B C D E +[allbefore:include<target>count[]] " />

--Mohammad

Mohammad

unread,
Jan 14, 2020, 3:31:31 AM1/14/20
to TiddlyWiki
For email reader: The post edited.

TonyM

unread,
Jan 14, 2020, 4:38:45 AM1/14/20
to TiddlyWiki
Mohammad,

Thanks, I note you example has a trailing space inside the filter.

All,
I have submitted a variation as an example to the documentation on tiddlywiki.com

A B C D E +[allbefore:include[C]count[]]



Regards
Tony

TonyM

unread,
Jan 17, 2020, 9:14:35 PM1/17/20
to TiddlyWiki
Bump 

Any idea on this one?

Folks,

I notice here, the list field only comes into existence if one drags and drops a tiddler in the tag pill popup.

Is any one aware of a programmatic way to cause this to happen, the creation of the list field?


Regards
Tony 
Reply all
Reply to author
Forward
0 new messages