A Code Pattern: Batch update of tags on tiddlers

121 views
Skip to first unread message

Charlie Veniot

unread,
Jun 5, 2021, 1:31:39 AM6/5/21
to TiddlyWiki
G'day,

I'm refactoring the design on a TiddlyWiki project, and wanted to apply tag changes to batches of tiddlers.

In case of any interest, here's the related code pattern:

\define doIt()
<$list variable="thisTiddler" filter="[tag[A]]">
<$action-setfield $tiddler=<<thisTiddler>> $field="tags" $value={{{ [<thisTiddler>tags[]] [[mot]] +[join[ ]] }}}/>
</$list>
\end

<$button actions=<<doIt>>>
Tag Em
</$button>

Cheers !

Mohammad Rahmani

unread,
Jun 5, 2021, 5:33:51 AM6/5/21
to tiddl...@googlegroups.com
Does this work if you want to add [[newTag from code]]?
Or if the tiddlers already have a tag with space in the title?


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/9b84cbd5-ce87-4611-a180-4dccaf611061n%40googlegroups.com.

Charlie Veniot

unread,
Jun 5, 2021, 11:25:57 AM6/5/21
to TiddlyWiki
Nah, I didn't consider that because the particular TiddlyWiki instance I'm working with I've setup with only single-word tags.

So no, that particular code sample was not designed for a tag with words separated by spaces.

To handle any multi-word tag with spaces between the words:

\define doIt()
<$vars ldb="[["
              rdb="]]">
<$list variable="thisTiddler" filter="[tag[A]]">
<$action-setfield $tiddler=<<thisTiddler>> $field="tags" $value={{{ [<thisTiddler>tags[]addprefix<ldb>addsuffix<rdb>join[ ]] [[mot]addprefix<ldb>addsuffix<rdb>] +[join[ ]] }}}/>
</$list>
</$vars>
\end

<$button actions=<<doIt>>>
Tag Em
</$button>

I've also wrapped the new tag (hard-coded in my code sample as "mot") with double-brackets, so that if you replace "mot" with a multi-word-separated by spaces tag, the code still works otherwise as-is.  (in the case of a single-word, or CamelCase word, TiddlyWiki will ignore the double-brackets.)

If you want to make the actions macro more generalized, then you'll want to add a parameter (newTag?), and then replace "mot" with "$newTag$", I think without trying it.

Mohammad Rahmani

unread,
Jun 5, 2021, 12:23:08 PM6/5/21
to tiddl...@googlegroups.com
It's a bit complicated! but it works!

have a look at TW-Scripts for example




Best wishes
Mohammad


Charlie Veniot

unread,
Jun 5, 2021, 1:06:05 PM6/5/21
to TiddlyWiki
That is definitely short and sweet (elegant !).  Thanks for posting!  Great to have in one's toolkit (i.e. knowledge of listops, or simply availability of excellent pre-canned solutions to focus on bigger problems), so into my back-pocket for delving into someday it all goes.

I'm on a hyper-focused quest to fully explore TiddlyWiki filtering, so although on my radar, I've buried listops far under the pile until I've pretty well tapped-out the possibilities with filters.  It is very easy to get overwhelmed trying to learn/remember/practice the whole buffet of options re TiddlyWiki options/features/etc.

I also tend to avoid plugins, however fantastic, unless they solve a problem I'm really not interested in solving.  For most things, trying to solve them with transclusions and filtering are just too strong and exciting/attractive exercises for this kid to pass up.

For anybody with the time and desire to dabble in "the weeds of TiddlyWiki empowerment", filtering is, to me, the greatest place to focus on.  "How would I do this/that with filters", they are such great exercises.  Well, this old fella sees those as great brain-age exercises of the puzzle-solving kind.  Every new thing learned re filtering feels like an opening up of exponential possibilities.  (I have way too much fun with this stuff...)

Mohammad Rahmani

unread,
Jun 5, 2021, 3:36:27 PM6/5/21
to tiddl...@googlegroups.com
On Sat, Jun 5, 2021 at 9:36 PM Charlie Veniot <cj.v...@gmail.com> wrote:
That is definitely short and sweet (elegant !).  Thanks for posting!  Great to have in one's toolkit (i.e. knowledge of listops, or simply availability of excellent pre-canned solutions to focus on bigger problems), so into my back-pocket for delving into someday it all goes.

I'm on a hyper-focused quest to fully explore TiddlyWiki filtering, so although on my radar, I've buried listops far under the pile until I've pretty well tapped-out the possibilities with filters.  It is very easy to get overwhelmed trying to learn/remember/practice the whole buffet of options re TiddlyWiki options/features/etc.

I also tend to avoid plugins, however fantastic, unless they solve a problem I'm really not interested in solving.  For most things, trying to solve them with transclusions and filtering are just too strong and exciting/attractive exercises for this kid to pass up.

For anybody with the time and desire to dabble in "the weeds of TiddlyWiki empowerment", filtering is, to me, the greatest place to focus on.  "How would I do this/that with filters", they are such great exercises.  Well, this old fella sees those as great brain-age exercises of the puzzle-solving kind.  Every new thing learned re filtering feels like an opening up of exponential possibilities.  (I have way too much fun with this stuff...)

Yes, I see your nice solution using filtering and transclusion! So, let's ask a question, I need it to use it in some real cases!
I have a lengthy solution! and I am looking for a simpler one!

A. 
1. Assume I have several tiddlers tagged with data and have three fields: st.name, st.number, st.average
2. I want to make a table out of these as below
2.1 each row is a tiddler
2.2 each column is a field like this: Title, Name, Number, Average
3. Sort table
3.1. I have three buttons, clicking on each button sort table by one of title, number or average
3. Now I want to sort the table by first column: Name or Number
4. Then I want to sort again (doubly sort) table based on average

B.
The general solution should be like this
 - user can click on a button and get the table sorted
- user then click on the second button and get the double sorted
- user then click on the third button and gettriply sorted table

What is the simplest filter/transclusion for this?


 

Charlie Veniot

unread,
Jun 5, 2021, 4:04:24 PM6/5/21
to TiddlyWiki
The simplest combo of filters and transclusions?  That could be wildly different for each person.

For each person, It would be what is easiest to understand and maintain for that person, based on each person's intertwingled way of seeing things, based on each person's experiences (how he/she has done things before, with the features/tool he/she is familiar with, etc. etc. etc.).  So done in a way that is likely easily recognisable long after initially written.

Likely done à-la "git 'er done" with what one knows right away, maybe with what one knows to look for without ever having worked with, maybe refactored later with newly learned things (say listops, for example), or things with which one now feels comfortable using.

There is no one simplest solution for all.  There are a plethora of solutions, one being the "simplest" for one group of people, another solution being the best for another group of people, and another for another group, ad infinitum/nauseum..  What you may consider the simplest, I consider too complex.  What I consider the simplest, you might consider too complex.

Yeah, I just went philosophical.  Too hungry for supper at the moment to get cracking on some code.  But I am mentally chewing on it, while also thinking about chowing down on some literal food...

TW Tones

unread,
Jun 5, 2021, 7:32:28 PM6/5/21
to TiddlyWiki
Mohammad,

As a community we are so grateful for your publishing and documentation. Shiraz as an example is a substantial resource.

I would like to help, extend your great content a little further and make it even more useful If I can so humbly suggest a few things


Some issues
  • To set the tiddler programaticaly including the currentTiddler the $macrocall form may be necessary
  • The current tiddler is not the default
  • Since you have to provide the tags but you could default to the current tiddler put the tags as parameter 1 and 2
  • You always have to provide the tiddlername
This is my refactored code
\define add-remove-tags(oldTag, newTag, tiddler)
<$set name=tiddler value="$tiddler$" emptyValue=<<currentTiddler>> >
<$button tooltip="Add '$newTag$' tag and Remove '$oldTag$' tag."> 
  Change ''$newTag$'' to ''$oldTag$''
  <$action-listops $tiddler=<<tiddler>> $field="tags" $subfilter="[[$newTag$]]" />
  <$action-listops $tiddler=<<tiddler>> $field="tags" $subfilter="-[[$oldTag$]]" />
</$button>
</$set>
\end
<<add-remove-tags a b>>
<<add-remove-tags b a>>

SO this is the difference
  • << add-remove-tags a b>> will operate on the current tiddler
  • the tiddler can be provided optionally.
It is my approach to always write macros for the current tiddler by default, this means they remain valid inside lists and edit/view templates
  • I just reused the name $tiddler$ to Create <<tiddler>> with emptyValue <<currentTiddler>>
  • When you have replaceable values you can make a detailed tooltip and keep the button name shorter.
  • The button is a user function description rather than detailing what happens, the tooltip does that.
Regards
Tones

Mohammad Rahmani

unread,
Jun 6, 2021, 12:37:38 AM6/6/21
to tiddl...@googlegroups.com
On Sun, Jun 6, 2021 at 12:34 AM Charlie Veniot <cj.v...@gmail.com> wrote:
The simplest combo of filters and transclusions?  That could be wildly different for each person.

For each person, It would be what is easiest to understand and maintain for that person, based on each person's intertwingled way of seeing things, based on each person's experiences (how he/she has done things before, with the features/tool he/she is familiar with, etc. etc. etc.).  So done in a way that is likely easily recognisable long after initially written.

Likely done à-la "git 'er done" with what one knows right away, maybe with what one knows to look for without ever having worked with, maybe refactored later with newly learned things (say listops, for example), or things with which one now feels comfortable using.

There is no one simplest solution for all.  There are a plethora of solutions, one being the "simplest" for one group of people, another solution being the best for another group of people, and another for another group, ad infinitum/nauseum..  What you may consider the simplest, I consider too complex.  What I consider the simplest, you might consider too complex.

but one can learn from others! that is why we have schools, teachers, universities, books, papers, ... you may find your solution is the best, but see other solutions and learn!


Yeah, I just went philosophical.  Too hungry for supper at the moment to get cracking on some code.  But I am mentally chewing on it, while also thinking about chowing down on some literal food...

somethies discussing things and having different ideas from different people helps to find better solutions!

 

Mohammad Rahmani

unread,
Jun 6, 2021, 12:43:20 AM6/6/21
to tiddl...@googlegroups.com
Hi Tones

Thank you for your solution! That solution in TW-Scripts actually belongs to Eric and based on the question and answer I kept the
original one! Yes, we can improve or add another one with your name and based on this thread!


Best wishes
Mohammad


Yes, nice! If you search the TW-Script, you see such a solution which is documented in your name! 

 
  • I just reused the name $tiddler$ to Create <<tiddler>> with emptyValue <<currentTiddler>>
  • When you have replaceable values you can make a detailed tooltip and keep the button name shorter.
  • The button is a user function description rather than detailing what happens, the tooltip does that.

We can add more examples to have such options!


 

Charlie Veniot

unread,
Jun 6, 2021, 11:34:11 AM6/6/21
to TiddlyWiki
Hey, I totally agree with you, and if I sound unappreciative, then I totally apologize.  I do very much appreciate.

Each one of us learns within the confines of our own abilities, learning by maximizing those things that play to our strengths and minimizing those things that emphasize our weaknesses.

I've got ADHD (attention regulation challenges), and I go into dysfunction when I'm overstimulated by sensory overload and/or cognitive overload.

My safe place is immersing myself in the details of a complex and very focused problem/project.  I'm at my happiest when hyper-focused on all of the intertwingled/hyperlinked intricacies of a problem/project scope and the tools I know for working things out.  When I hit a wall because what I am familiar does not work, then I go seeking out the new things I need, within the safe boundaries of the problem/project scope.

It does tickle me silly to know that there are other approaches to handling a problem.  It is a huge benefit.  But I can't study that new thing right away, because I'm hyperfocused (like a dog chewing on a bone) on churning code for the current problem with a keen desire to master a particular thing (in this case: filtering.)

As keen as I am for folk to contribute their knowledge of alternative ways of doing things for everybody's benefit (I encourage that something silly), the best I can do is simply take note of that, and park it into a recess of my sponge for later reference when I need it.  Back to the dog chewing on a bone: everything else is a squirrel.  I get easily distracted, but unlike the dog who can forget about the bone and see just the squirrel, I'm more like a kid in a candy+toy store, and I don't know where to look: too much to process.

So I take note that there are awesome alternatives out there (features in TiddlyWiki, plugin's, macros/scripts, upcoming new stuff, whatever), and I quickly park that note in subconscious memory for when I hit a wall or want to just enjoy learning something new.  When I'm in the midst of trying to figure out how I can solve something with the things I've learned so far, trying to process alternative ways of doing things when I'm banging my head against a wall is like having a bunch of people talking to me at the same time:  immediate over-stimulation and I shut right down.

Most folk don't have this disability (they can easily pause something, and transition from one thing to another), hence my standing ovation for anything and everything educative.  I just usually find myself having to ignore the discussion, because I'm already fully engaged in some pretty deep bush-whacking.

So that long-winded diatribe just to say the stuff you're contributing (that everybody contributes, whenever/wherever/however) is awesome.  I'm exceedingly appreciative.  It is just hard for me to show that appreciation by adopting/discussing the idea because I can't cope with competing thoughts.

Well, I also find writing a great exercise to understand oneself, too.  Not just how I function/dysfunction, but also how it impacts others.  Which has me on regular guilt-trips.  Trying to stay in a safe place cognitively, while trying to be respectful/appreciative of others.  Not so easy to focus on both when the disability is attention regulation.

I can pat my head and rub my belly at the same time, so I like to think it is possible.  Then again, show me a dog that doesn't like to have belly rubbed and a pat on the head ...

Mohammad Rahmani

unread,
Jun 6, 2021, 11:47:19 AM6/6/21
to tiddl...@googlegroups.com
Hi Charlie,

You are great and I learn from you and what you publish in the forum!
There is no need to apologize as we discussed something technically! and many times disagreement helps to improve things!
We have a Perdian proverb: differences make beauty!

So, I appreciate your efforts and thoughts shared with us here!

Best wishes
Mohammad


CJ Veniot

unread,
Jun 6, 2021, 1:10:04 PM6/6/21
to tiddl...@googlegroups.com
Well said and totally agree (well, everybody is great), and any slow down of good information and conversation is to me the worst thing that can happen in a community. 

I just want to clearly state that if I'm not showing appreciation, not adopting something, or not engaging: I'm just not ready to process the info, I can't transition out of current thought processes, and I'm just trying to stay in a cognitively safe place.

The beauty of differences can be overwhelming to this kid.  You should see me struggle at a buffet...



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/tF2MvRO8WJY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/CAAV1gMCiyNEdTEQ1zhV1-KZqw4bm1m1HCjS3tEBVQbLAFLv9FQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages