When a tiddler is tagged, you can click on the tag, which shows a dropdown. If the tiddler with the same name as the tag exists, the first line in the dropdown will link to it. If the tiddler doesn’t exist, the link will be italized, same as with links to non-existing tiddlers.
How do I list all tags (i.e. tags from all tiddlers), for which a corresponding tiddler with the same name as the tag doesn’t exist yet?
I know that the ListWidget can be used to list all tags (adapted from this answer):
<$list filter="[tags[]]" variable="thistag">
<$vars count={{{ [<thistag>tagging[]count[]] }}}>
<li>
<$link to=<<thistag>> tooltip=<<count>>>
<$text text=<<thistag>> />
</$link>
</li>
</$vars>
</$list>
I also know that the operator has can be used in filters to check if a tiddler exists.
But I don’t know how to apply operator has to <<thistag>> in the code above.
<$list filter="[tags[]sort[]is[missing]!is[shadow]]">
<<tag>>
</$list>
(EDITED to sort, and take out unnecessary :filter complexity)
should get you the list of tags where there’s no tiddler there at that logical “node” (assuming you don’t also want the missing shadow tags, take out the !is[shadow] otherwise).
(Note, I’ve been using the term “node” to mark the logical location in naming space where a tiddler may or may not exist. The node for a tag is an empty node if there’s no tiddler there. I suggest this term because “missing” has more specific uses elsewhere. (The “Missing” sidebar tab obviously can’t name all nodes where there isn’t a tiddler, but instead lists nodes where there is a hard-coded link pointing to a node where there’s no tiddler to land at. Notably, that “Missing” list also doesn’t include tag nodes that are empty either, though one could make a sidebar tab that does provides that list. Hm.
)
For exactly those tags, I also suggest a solution for making tag pills display in italics if missing. I think this may even make it into the core at some point, if I recall other discussions here.
Edited to incorporate updates from later replies.
For my purposes, I added formatting into a table:
<table>
<$list filter="[tags[]is[missing]!is[shadow]] +[sort[]]" variable="thistag">
<$vars count={{{ [<thistag>tagging[]count[]] }}}>
<tr>
<td><$macrocall $name="tag" tag=<<thistag>> /></td>
<td><$link to=<<thistag>> ><$text text=<<thistag>> /></$link></td>
<td><<count>> tiddlers</td>
</tr>
</$vars>
</$list>
</table>
Relevant documentation:
Old reply, before edits:
Still haven’t figured out how to add sort operator into the filter. All examples of sort operator are inside a single set of square brackets:
[list[Days of the Week]sort[]]
^ ^
but in my case, there are two sets:
[tags[]] :filter[is[missing]!is[shadow]]
^ ^ ^ ^
1 1 2 2
adding a third set seems to undo the second one. There’s no more filtering with the following:
[tags[]] :filter[is[missing]!is[shadow]] [sort[]]
^ ^ ^ ^ ^ ^
1 1 2 2 3 3
To be able to figure out where to put sort (as described above), I am trying to understand this filter:
[tags[]] :filter[is[missing]!is[shadow]]
^^^^^^^
I am struggling with the underlined part. Per Filter Step, the syntax is operator:suffix. I have found the filter Operator, but the syntax looks to my noob eyes to be backwards: the word filter appears to be the suffix, after the colon, with an empty operator name.
is this the suffix or the operator?
vvvvvv
:filter
^^^^^^
where is operator?
There’s obviously some conceptual gap in my understanding of the filter syntax, and I’d appreciate it if someone pointed it out.
Sorry for the extra noise in my code! It was hastily adapted from another use.
In this case, you can just use the compact form:
<$list filter="[tags[]sort[]is[missing]!is[shadow]]">
The word “filter” has many uses!
In this case, I had invoked it (unnecessarily) as a filter-run prefix
Sure, this works, but what if I don’t want to sort all tags? It seems wasteful (in the performance of software sense). Is it possible to sort after the filtering done via is[missing]?
I think the amount of calculation is not such a huge deal in this case, but in principle, your preference makes sense!
<$list filter="[tags[]is[missing]!is[shadow]] +[sort[]]">
Wonderful, thank you!
<$list filter="[tags[]is[missing]!is[shadow]] +[sort[]]">
^
Relevant documentation about the plus: it’s a shortcut to a Filter Run Prefix called :and:
- the prefix
+, it receives the filter output so far as its input; its output then replaces all filter output so far and forms the input for the next run
I was trying to use [sort[]] without the plus, like so:
filter="[tags[]is[missing]!is[shadow]] [sort[]]"
which is the same as :or (“de-duplicated union of sets”), and it means:
The following is speculation: it seems to me that because my [sort[]] didn’t specify any input, the input defaulted to all tiddlers, which made the output to be set union of:
[tags[]is[missing]!is[shadow]
- “all tiddlers, sorted”
P.S. Trying to learn all the syntaxes (macros, widgets, filters, procedures) makes my brain melt. For filters in particular I’m wishing for a plugin to just run SQL queries inside tiddlers.
Correct. There is an implied [all[tiddlers]] at the beginning of a filter run. So [[sort]] is equivalent to [all[tiddlers]sort[]]. Some filter steps will replace the input lists with their own, but the majority of them – including sort – work with the list they’ve been given.
Correct-ish. Because there is an intrinsic order to the lists that TW deals with, they are not true sets. But they are similar enough for many purposes; the documentation often refers to them that way.