I have a need to read all the tiddler names from $:/HistoryList in 5.2.3. Unfortunately it appears there are no filter operators available to work with JSON files, so my current solution is this rather verbose filter using regular expressions:
It’ll break if there is a tiddler with ~~ in its name
It’ll break if there is a tiddler with a quote character in its name (This I can fix by encoding those escapes and decoding them later, but it has the same vulnerability)
It’ll break if there is a tiddler with any other character that is escaped in JSON – to some extent I can handle that but only to some extent
I recall that the next version of TW will give some facilities to improve interfacing with JSON but I am interested in making it work in 5.2.3 or even 5.2.2. I could also just write a custom filter but it’s something that’ll ultimately land in a plugin so I am not sure that’s the direction I want to go just yet.
I have done something very similar to @EricShulman solution but be aware there is value also not displaying tiddlers (found in history) who no longer have a “title” otherwise you may provide “historical links to tiddlers now deleted”.
I also want to point out this approach is what I refer to as “parsing the content of a tiddler” to extract information separately from the “Parsing to render content that TiddlyWiki” does for us.
understanding the splitregexp[\n] which splits on each line is key to opening a lot of powerful solutions.
This is one approach I use to do “sophisticated things” in tiddlywiki overlooked by many.
I also use the following macro when listing the items in the history list \define close-if-open-button() <$list filter="[list<tv-story-list>match<currentTiddler>]" variable=nul>{{||$:/core/ui/Buttons/close}}</$list>
Then when listing each tiddler <<close-if-open-button>> <$link/> displays the X icon when open in the story and allows you to close it, from the history list like the Open tab.
I actually introduce other “by tiddler” buttons to lists as needed, eg add {{||$:/core/ui/Buttons/edit}} in the above.
The history information being JSON formatted, it is sensible to use JavaScript to access it. Hence, Ittayd wrote a filter operator to get the history, which is basically a one-liner and thus quite beautiful and robust at the same time. While I strongly tend to do things in WikiText if possible, I do use his filter operator in my wikis for that reason.
When the JSON filter operators will be available with the next release, I’ll probably change back to a WikiText solution, though.
That’s much more graceful, thank you! I think I might be tad neurotic when it comes to catching all possible edge cases and don’t have much trust in the format of the input I get.
Only two changes I’d make is:
add is[tiddler] somewhere in there to remove non-existing tiddlers
replace !prefix[Draft] with !is[draft] to be clearer – I am guessing you used prefix because !is[draft] won’t detect deleted draft tiddlers
I see you don’t bother with unescaping things other than quote character which I suppose is fair. I like your solution very much!
Yup, it already stabbed me in the butt as I was working out my solution hence the inclusion of is[tiddler]
I agree it would be more graceful solution but I specifically want to avoid adding a custom filter so I’ll stick to the solution @EricShulman provided. But thanks nonetheless!
Using is[tiddler] will ignore any shadow tiddlers in the history. Perhaps you can use has[title], which will match existing tiddlers AND shadows, but not a non-existent tiddler.
Just drag an drop this into a TW and a history button will appear in the PageControls.
For currently open tiddlers, it shows an eye icon. For my workflow that’s better than leaving open tiddlers out completely, as then I might have to scan two lists (history and open) for what I’m looking for.
If you don’t want shadow tiddlers to show up then just delete [is[shadow]] from tiddler-or-shadow.
IMO you should use a different icon. The icon is used for the core “Timestamp is ON/OFF” switch which has a very high potential to cause confusion and trouble. eg: If the timestamp is switched off and the setting is forgotten it will cause trouble with the recent list.
So I would strongly recommend to use a different icon for your history functionality.