I like the idea of allowing comments within filters, but I am not sure that this is the right approach.
The advantage of this proposal is that it doesn’t introduce any new syntax to filters, reusing the existing syntax. The fairly devastating disadvantage is that comments need terminating, which doesn’t match the user experience of most other languages.
Given that nowadays filters are often written across multiple lines, I think it would be worth exploring comment syntax that is terminated by the end of the line.
The most obvious approach would be to use //
as the comment start symbol, ignoring all characters up to and including the following line break. A necessary subtlety would be that the character sequence would only be recognised in between filter runs.
It might be used like this:
\function edit-preview-state()
[{$:/config/ShowEditPreview/PerTiddler}!match[yes]then[$:/state/showeditpreview]] // Use per-tiddler state tiddler if present
:else[<qualified-preview-state>] // Otherwise use the qualified state
+[get[text]] // Get the text of the state tiddler
:else[[no]] // Default to "no" if not present
\end
The syntax could still be used with single line filters, but would require the comment to be at the end of the filter:
<$list filter="[[HelloThere]] // This is a comment" />
This syntax is not strictly backwards compatible. In current versions of TiddlyWiki, the example above evaluates to “HelloThere”, “//”, “This”, “is”, “a”, “comment”.
Note that with this proposal there would be no comment recognised in the filter [[HelloThere]] [[//]]
, so it would not break our ability to include “//” in filters.