[TW5] Can a Widget Set Variable be incremented?

765 views
Skip to first unread message

leeand00

unread,
Dec 16, 2015, 10:11:47 AM12/16/15
to TiddlyWiki
[TW5] Can a Widget Set Variable be incremented?

Is it possible to use the widget syntax to increment a variable, in a loop for instance?

Start: <$edit-text tiddler="sa" field="strt"/> <br/>
End: <$edit-text tiddler="sa" field="end"/>

<$button>
<$x-maketid  $title="Linux Documentation - variable-value"  tags="[[first tag]] [[another tag]]" $tags="[{!!title}] +[append:3{Days of the Week!!short}]" $date="0hh:0mm, DD/MM/YYYY" text="
|Field Name |Value |
|Field1 |{{!!field1}} |
|Field1 |{{!!field1}} |"
caption="one" field2="two"/>
Make New Tiddlers
</$button>

I'd like to loop through the start and end numbers specified in the $edit-text's above and create tiddlers with the same specified title with a number concatenated on the end.

I'm using Matabele's x-markedid widget to create each tiddler with the correct field values.

Tobias Beer

unread,
Dec 16, 2015, 10:44:47 AM12/16/15
to tiddl...@googlegroups.com
Hi,

Rather than (try and) have this a wiki-feature, would a little console script be fine for you to achieve what you want?
Or do you actually want / need to edit those tiddlers before actually creating them?

In that case, there once were list iterators I had proposed in a pull request to the core.
However, they were discarded since the iterators would not update should the list ever refresh.

Best wishes,

Tobias.

Jed Carty

unread,
Dec 16, 2015, 12:49:39 PM12/16/15
to TiddlyWiki

Tobias Beer

unread,
Dec 16, 2015, 1:57:24 PM12/16/15
to tiddl...@googlegroups.com
 Hi Jed,
Not sure that's the right thing, at least it wouldn't be if leeand00 wanted to do his iteration through a list widget.
I wouldn't quite see how that would work with MathyThing or, alternatively, calc and an action-setfield.

Perhaps this is doable using the filter tobibeer/eval provides.
I'm definitely going to add a "count" variable to it.

On the other hand, it almost feels like we want a title generating filter, one that does generate input titles based on a set of rules, e.g:
  • a way to initialize and increment a counter and have it run to a given max
  • allowing to construct a desired title from text-bits, e.g....
    • prefixes, suffixes and whatever else you want in the middle
    • text references
    • variables
    • the current count
    • some date?!?
    • a random number
<$list filter="[generate[
$:/foo/%count%/%date%/RANDOM(8)/{{!!bar}}/<
<baz>>/and-then-some \
min:1 \
max:10 \
inc:1 \
date-format:YYYY0MM0DD
]]">
!! do something
</$list>

As for the random bit, I recently made a pull request to have it be in the date string,
that didn't quite meet the necessary appreciation yet, despite its utter simplicity.
Perhaps it's better suited for this filter, after all.
Eventually you could just do:

<$set name="my-unique-id" filter="[generate[
%date%-RANDOM() \
date-format: YYYY0MM0DD
]]"/>
do stuff
</$set>

...so as to set my-unique-id to something like 20151216-xenk7hpn.

Whereas min max and inc would obviously default to 1.
Looks like that will be my next filter being fiddled.

Best wishes,

Tobias.

Matabele

unread,
Dec 16, 2015, 3:17:53 PM12/16/15
to TiddlyWiki
Hi

The $x-maketid widget looks to see if there is an existing tiddler with the specified title (and appended date/time if specified) and, if so, appends an integer to the title -- the integer begins at one and increments in steps of one. A facility could be added to begin the integer at some other value via an attribute, however, there are many more possibilities for generating titles and, I believe, a generic solution would be preferable.

One possible strategy is to create a list of terms (created and manipulated with the existing tools and operators), then join the list of items to create a title. 

Any other ideas?

regards

Tobias Beer

unread,
Dec 17, 2015, 9:03:17 AM12/17/15
to TiddlyWiki
Hi leeand00,

I created a new filter plugin that allows to generate new titles for use with things like the set or list widget:


Best wishes,

Tobias. 

Matabele

unread,
Dec 17, 2015, 10:04:04 AM12/17/15
to TiddlyWiki
Hi Tobias

That looks like the job :-)

As it appears that this filter could be used in other widgets to generate new titles by using the output of a filter expression (specified as an attribute):

<$x-maketid $title="[make[operand expression]]" />

I'll have a look at this option -- flexible creation of titles has been sorely missed in TW5.

regards

leeand00

unread,
Dec 17, 2015, 1:43:18 PM12/17/15
to TiddlyWiki
Thanks Tobias!  That's the ticket!  That's exactly what I needed!  This will save me tons of time and effort and scrolling!

Tobias Beer

unread,
Dec 17, 2015, 3:02:07 PM12/17/15
to TiddlyWiki
Hi leeand00,
 
Thanks Tobias!  That's the ticket!  That's exactly what I needed!  This will save me tons of time and effort and scrolling!

Cool! :-)

When you've implemented it, please post an example / demo of how you actually use it.
I'd like to put a more specific use case like that up with the documentation.

Best wishes,

Tobias. 

leeand00

unread,
Dec 18, 2015, 2:14:49 PM12/18/15
to TiddlyWiki
Yes that would be very good indeed!  The only thing that's lacking in make is the ability to preset and increment fieldnames / tags.  Tags shouldn't be a big deal, but fieldnames should be able to be incremented, since then you can select and sort them using a filter for tab creation quite easily. 

<<tabs "[tag[Making Commits]sort[caption]]">>

I actually like Tobias's way of creating the tiddlers because of the flexibility of the name creation and ease of use, and the generating of the links, but I like Matabele's way of creating the tiddlers with preset field names and tags because it can be done at all. 

If we could combine the two and include a way to create a list of strings that could optionally be added to the title we'd have a perfect solution!

leeand00

unread,
Dec 18, 2015, 2:35:17 PM12/18/15
to TiddlyWiki
Not that I know anything about this but...

It would probably be better to have a json similar syntax like this:

{{{ [make[the pattern %count% max:11, fields:{'caption','%count%'}, tags {'tag1', 'tag2'}]] }}}

{{{ [titleList: {'init', 'commit', 'diff'} ][make[the pattern %title% max:11, fields:{'caption','%title%'}, tags {'tag1', 'tag2'}]] }}}


On Thursday, 17 December 2015 10:04:04 UTC-5, Matabele wrote:

leeand00

unread,
Dec 18, 2015, 2:36:01 PM12/18/15
to TiddlyWiki
And then when you click on the link, that new tiddler gets the specified tags, titles and fields:

Matabele

unread,
Dec 18, 2015, 3:51:22 PM12/18/15
to tiddl...@googlegroups.com
Hi leeand00 

It should be possible to use the make[] filter operator to generate the title for my $x-maketid widget -- the title could then include any of the varied options available in the make[] operator.

I can not think, off hand, of a way of creating several new tiddlers with the $x-maketid widget (with one button click) based upon the output of the make[] operator. If I set about modifying the $x-maketid widget, a mechanism might become apparent.

Is this what you had in mind?

regards

On Friday, 18 December 2015 21:14:49 UTC+2, leeand00 wrote

Matabele

unread,
Dec 18, 2015, 4:14:03 PM12/18/15
to TiddlyWiki
Hi

It turns out that this can be done without modification to the $x-maketid widget -- a simple example follows:

<$button>
<$list filter="[make[<
<currentTiddler>> %count% \ max:3]]">
<$x-maketid text="My New Tiddlers" $title=<
<currentTiddler>>/>
</$list>
Make New Tiddlers
</$button>

Other fields may also be set for the newly created tiddlers, by specifying additional parameters for the $x-maketid widget.

regards

Tobias Beer

unread,
Dec 18, 2015, 4:52:05 PM12/18/15
to TiddlyWiki
Hi leeand00,
 
{{{ [make[the pattern %count% max:11, fields:{'caption','%count%'}, tags {'tag1', 'tag2'}]] }}}

Haha, I think you are mildly mistaken about what filters do. :D

Yes, this filter is called make.
No, it does — in itself — not (allow to) create tiddlers!

What it does is generate a number of unique titles or actually, simple strings ...since you are not required to actually use the output of the make filter as titles for new tiddlers to be created, but perhaps for field-names or anything, really ...data tiddler indexes, who knows.

Does that make sense?


And then when you click on the link, that new tiddler gets the specified tags, titles and fields:

There could be a make widget that operates in your proposed mode, e.g.:

<$make
$min="5"
$
max="10"
title="the pattern %count%"
caption="%count%"
tags="foo [[bar baz]]"
tag1="mumble"
tag2="frotz gronk">
Click to create 5 tiddlers
</$make>

Whereas it would check for any tag attributes so long as they exist, starting from tag1, incrementing. So, in the above, the eventual tags field would contain "foo [[bar baz]] mumble [[frotz gronk]]". However, what would be the use-case to create tiddlers with otherwise similar / identical properties? When do I need a button to create 10 tiddlers?

The one appeal this has is that it doesn't sound as complicated as action-x-maketid. With a simple button it really only needs to trigger a simple message that contains a reference to a state tiddler to which we push the json string for all the stuff we want created ...to be picked up by the message handler.

Best wishes,

Tobias.

Matabele

unread,
Dec 18, 2015, 11:35:30 PM12/18/15
to tiddl...@googlegroups.com
Hi

I like the use of a make[] operator to generate new titles in advance of the creation of new tiddlers -- as action-widgets can then be used to modify the new tiddler. The operator may be used with the $action-listops widget to create a list of new titles, or directly with a $list widget.

For example -- new tiddlers can be created in the background with the use of the $action-setfield widget (without the need for the $x-maketid widget) and navigated to with the use of the $action-navigate widget. Any other action-widgets can also be optionally added to the stack to modify the new tiddler.

<$button>
<$list filter="[make[<
<currentTiddler>
> %count% \ max:3]]">
<$action-setfield text="My New Tiddlers" title=<
<currentTiddler>>/>
<$action-setfield tags="one [[and two]] three"/>
<$action-navigate/>

</$list>
Make New Tiddlers
</$button>

A unique caption (or any other field) may also be set with the use of $action-listops widgets -- like so:

<$button>
<$list filter="[make[<
<currentTiddler>> %count% \ max:2]]">
<$action-setfield text="My New Tiddlers" title=<
<currentTiddler>> tags="one [[and two]] three"/>
<$action-listops $list="caption" $filter="[make[MyTab%count%]] [[Description]]"/>
<$action-navigate/>

</$list>
Make New Tiddlers
</$button>

regards

On Friday, 18 December 2015 23:52:05 UTC+2, Tobias Beer wrote

Tobias Beer

unread,
Dec 19, 2015, 3:09:13 AM12/19/15
to TiddlyWiki
Hi Matabele,

Just know that you  possibly don't even need to use any %count% for the new titles.

So, instead of...

<$list filter="[make[<<currentTiddler>> %count% \ max:3]]">

This will equally work...

<$list filter="[make[max:3]]">

Best wishes,

Tobias.

Matabele

unread,
Dec 19, 2015, 4:18:43 AM12/19/15
to TiddlyWiki
Hi Tobias

Neat -- to replace most of the functionality of the $x-maketid widget, use:

<$button>
<$list filter="[make[MyNewTitle  \max:3]]">
<$action-setfield text="My New Tiddlers"  tags="one [[and two]] three" field-one="myvalue"/>
<$action-navigate/>
</$list>
Make New Tiddlers
</$button>

-- can create one or more new tiddlers with unique names
-- can set the tags for the new tiddlers (all the same)
-- can set any number of fields (all the same)
-- can create new tiddlers in the background, or navigate to without opening
-- but can't use a template

Can't work out how to set different values for a field in each new tiddler -- any ideas?

regards

Tobias Beer

unread,
Dec 19, 2015, 6:59:47 AM12/19/15
to tiddl...@googlegroups.com
Hi leeand00 & matabele,
 
I created a new filter plugin that allows to generate new titles for use with things like the set or list widget:


FYI, I have decided to change some fundamentals of tobibeer/make again.

For the time being, to generate new titles, please use make with an empty input set like so:

[[]make[foo]]

...instead of just...

[make[foo]]

I figured, it would be a total waste of a perfect opportunity if make could not operate on given input titles.

Also, I will add or extend a few more options:
  • sep:<string>\
    • will allow to specify the separator between the base and the unique increment
      • for already existing tiddlers / titles in the output
    • currently that separator is a blank " ", e.g. "New Tiddler 1" (notice the blank before the 1)
    • there are moments when you don't want any separator at all
      • so you can then do sep:\
  • unique:field/index\
    • allows to specify if we want to make either unique fields or indexes
      • with respect to a given (optional) tiddler (below) (defaults to currentTiddler)
    • for unique:field\, the separator will be set to sep:\ by default
      • since field-names cannot contain any blanks
    • with unique being set, make will not test against existing tiddler titles anymore
      • but, of course, keep on checking if a given title is already in the output set
  • tiddler:<title>\
    • specifies the currentTiddler, for use with...
      • unique:field / unique:index 
      • text-references w/o a specified title
  • %tiddler%
    • outputs the tiddler as specified above
  • %title%
    • if operating on input titles — which make will automatically do in the future, should there be any —
      this will be replaced with the title in the input set at the position that corresponds to the current %count%
  • max:<num>
    • when make operates on input titles, it will truncate the iteration at this maximum number
    • should the input set contain less titles, max will be set to the length of it
      • in other words, make will not iterate above a given number of input titles
        • except for when that number is 0, then max will be whatever you define, otherwise default to 1
Best wishes,

Tobias.

Matabele

unread,
Dec 19, 2015, 7:14:23 AM12/19/15
to TiddlyWiki
Hi Tobias

Good idea -- a number of tiddlers can be created from a list like so:

<$button>
<$list filter="[[]append:3{Days of the Week!!short}]">
<$action-setfield text="My New Tiddlers"  tags="one [[and two]]" field-one="myvalue"/>

<$action-navigate/>
</$list>
Make New Tiddlers
</$button>

It would be great if the make[] operator could prepend/append terms to the listed titles.

Would also be of use if the make[] operator could create unique values for fields -- currently, an operation generates the same values upon successive calls (unless the values are used to create new tiddlers.) What I have in mind is to create several new tiddlers, with differing values in the same field.

regards

Tobias Beer

unread,
Dec 19, 2015, 7:41:35 AM12/19/15
to TiddlyWiki
Hi matabele,
 
It would be great if the make[] operator could prepend/append terms to the listed titles.

Exactly what I'm saying.
I simply need to use the input titles, if any are given, and then simply do:

{{{ a b c +[make[before %title% after]] }}}
  • before a after
  • before b after
  • before c after
Easy as pie. :D

Would also be of use if the make[] operator could create unique values for fields -- currently, an operation generates the same values upon successive calls (unless the values are used to create new tiddlers.) What I have in mind is to create several new tiddlers, with differing values in the same field.

Will need experimenting. Perhaps you will have to nest those,
e.g. use setvars with make and wrap your action widget(s) with that.

Best wishes,

Tobias. 

Tobias Beer

unread,
Dec 19, 2015, 1:57:29 PM12/19/15
to TiddlyWiki
Hi guys,

I implemented all of the suggested improvements as announced here:

Best wishes,

Tobias.

leeand00

unread,
Dec 21, 2015, 8:33:08 AM12/21/15
to TiddlyWiki
Tobias!  That's great!  Good work and thank you!   The use case for making several similar tiddlers is for creating tab sets to make a quick an easy reference of steps or just tabs in general.  When the filter is run to collect the tabs and sort them in the tabs macro, it's faster to create them that way than wasting your time adding the same tag or tags to every single tiddler that's meant to be in the tab group.
Reply all
Reply to author
Forward
0 new messages