[TW5] Tagging Macro Problems

111 views
Skip to first unread message

Tobias Beer

unread,
Nov 17, 2014, 7:41:26 AM11/17/14
to tiddl...@googlegroups.com
I was trying to create a simple tagging macro tagged  $:/tags/Macro , so I thought.

http://taggly5.tiddlyspot.com/#%24%3A%2Fmacros%2Ftagging
\define tagging()
<$list filter="[all[current]tagging[]]">

</$list>
\end
Any reason why it won't run at all?

See tiddler Class A for an example...




Also, if I wanted the tiddler title to be an optional parameter to the tagging macro, how would I go about doing that? The more alternative methods you can suggest, the better.

Best wishes, Tobias.

PMario

unread,
Nov 17, 2014, 7:54:01 AM11/17/14
to tiddl...@googlegroups.com

Tobias Beer

unread,
Nov 17, 2014, 8:11:17 AM11/17/14
to tiddl...@googlegroups.com
Thanks Mario,

Not sure what you're trying to say as it basically does the same, only that mine is not working.
Or are you suggesting I should use a transclusion template rather than an actual macro?

Best wishes, Tobias.

Tobias Beer

unread,
Nov 17, 2014, 8:20:47 AM11/17/14
to tiddl...@googlegroups.com
Or are you suggesting I should use a transclusion template rather than an actual macro?

Using a transclusion template appears to work, see...
However, I would still love to know...
  • why my macro implementation fails
  • how to ammend it so as to be able to do <<tagging "any tiddler">>.
Best wishes, Tobias.

PMario

unread,
Nov 17, 2014, 10:16:39 AM11/17/14
to tiddl...@googlegroups.com
\define tagging()
<$list filter="[all[current]tagging[]]"/>
\end

This works, because it uses the default "fallback" template.

see this description quote from: http://tiddlywiki.com/#ListWidget

The content of the <$list> widget is an optional template to use for rendering each tiddler in the list. Alternatively, the template can be specified as a tiddler title in the template attribute. As a fallback, the default template just displays the tiddler title.


Your first example did define an empty template <$list> your template comes here</$list>

hope that helps
mario

Evolena

unread,
Nov 17, 2014, 10:19:25 AM11/17/14
to tiddl...@googlegroups.com

Le lundi 17 novembre 2014 13:41:26 UTC+1, Tobias Beer a écrit :
I was trying to create a simple tagging macro tagged  $:/tags/Macro , so I thought.

http://taggly5.tiddlyspot.com/#%24%3A%2Fmacros%2Ftagging
\define tagging()
<$list filter="[all[current]tagging[]]">

</$list>
\end
Any reason why it won't run at all?

Because you defined your macro tiddler to be plain/text type, so it is not interpreted.

Tobias Beer

unread,
Nov 17, 2014, 10:30:48 AM11/17/14
to tiddl...@googlegroups.com
Thanks, Evolena, of course.
 
Because you defined your macro tiddler to be plain/text type, so it is not interpreted.

Although, I'd quite like macro code to be displayed.

Any hints on how I could make <<tagging "tiddler X">> work?

Best wishes, Tobias.

Evolena

unread,
Nov 17, 2014, 10:47:07 AM11/17/14
to tiddl...@googlegroups.com
There must be a smarter solution, but you can try this macro definition:

\define tagging(title:"<<currentTiddler>>")
<$set name="myTitle" value=$title$>

<<myTitle>>
<$list filter="[title<myTitle>tagging[]]">

</$list>
</
$set>
\end

However for it to work with a title, you need to use a trick:

All content for current tiddler...
<<tagging>>

All content for Class B...
<<tagging "'Class B'">>

Do you see it? The parameter with the title of the tiddler also contains ticks, so that the value of the set widget is interpreted correctly (it should be value=<<currentTiddler>> in one case and value="title" in the second, so the $title$ substitution can't do both at the same time).

Evolena

unread,
Nov 17, 2014, 10:48:34 AM11/17/14
to tiddl...@googlegroups.com
(you can get rid of the <<myTitle>> line, it was here for investigating purposes)

Tobias Beer

unread,
Nov 17, 2014, 12:09:35 PM11/17/14
to tiddl...@googlegroups.com
Thanks Evolena,
 
However for it to work with a title, you need to use a trick:

All content for Class B...
<<tagging "'Class B'">>

The parameter with the title of the tiddler also contains ticks, so that the value of the set widget is interpreted correctly (it should be value=<<currentTiddler>> in one case and value="title" in the second, so the $title$ substitution can't do both at the same time).

That's not pretty at all ...and I don't see how variable substitution would work that way.
Is <<currentTiddler>> something other than a plain string or is this a limitation in the execution order?

Unless there's a way around that I'd really prefer not to use it but rather a transclusion template instead. 

Anyhow, tested it and it works.

Best wishes, Tobias.

PMario

unread,
Nov 17, 2014, 1:26:29 PM11/17/14
to tiddl...@googlegroups.com
You may want to try this for tags with spaces:

As a user, I'd probably like to define a list with <ul> or <ol> ... similar to <<list-links>>

\define tagging(title, type:ul)
<$type$>
<$list filter="""[[$title$]tagging[]]"""><li><$link><<currentTiddler>></$link></li></$list>
</$type$>
\end


<<tagging "a b">>

tag a tiddler with: a"b  ... and try your macro with

<<
tagging 'a"b'>>

You may want to have a close look to: http://tiddlywiki.com/#Macros%20in%20WikiText for the tripple double quotes: """

have fun!
mario


Tobias Beer

unread,
Nov 17, 2014, 1:43:21 PM11/17/14
to tiddl...@googlegroups.com
Hi Mario,
 
You may want to try this for tags with spaces
 
Thanks for your reply. I believe, this leaves the problem of not being able leave out the tiddler parameter and just do...

<<tagging>>

Best wishes, Tobias.

PMario

unread,
Nov 17, 2014, 4:13:12 PM11/17/14
to tiddl...@googlegroups.com

Yes, I thought about this. ... but the tiddler where you don't have a parameter is the tag. You can use <<list-links filter:"[all[current]tagging[]]">>

Tobias Beer

unread,
Nov 17, 2014, 5:17:11 PM11/17/14
to tiddl...@googlegroups.com
Yes, I thought about this. ... but the tiddler where you don't have a parameter is the tag. 
You can use <<list-links filter:"[all[current]tagging[]]">>

Of course, that is possible and using the list widget or a transclusion template too, but that was not the purpose of the exercise.  ^_^

Best wishes, Tobias.

Jeremy Ruston

unread,
Nov 17, 2014, 5:36:02 PM11/17/14
to TiddlyWiki
Hi Tobias

If I understand correctly, the goal is to write a macro that lists the tiddlers that are tagged by a specified tiddler, and you'd like the ability to specify the the target tiddler, or leave it unspecified and default to the current tiddler.

The obvious way to accomplish it doesn't in fact work:

\define tagging(title:<<currentTiddler>>)
<$list filter="[[$title$]tagging[]]"/>
\end

The reason is that it is not possible to transclude a default macro parameter value; the default value has to be specified as a string.

I think it would be possible to extend the macro syntax to allow transcluded default values, but it's not something I've been planning. The approach the core uses in situations like this would be to have two macros:

\define tagging(title)
<$tiddler tiddler="""title""">
<<tagging-current>>
</$tiddler>
\end

\define tagging-current()
<$list filter="[all[current]tagging[]]"/>
\end

Then one could call <<tagging-current>> or <<tagging "HelloThere">>.

Best wishes

Jeremy.



--
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 post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com
Message has been deleted

Tobias Beer

unread,
Nov 17, 2014, 6:21:50 PM11/17/14
to tiddl...@googlegroups.com, jeremy...@gmail.com
The reason is that it is not possible to transclude a default macro parameter value; the default value has to be specified as a string.

I was wondering how difficult it might be to extend the set widget so as to allow a default value as a fallback for when the value is actually undefined:

\define tagging(title)
<$set name="tid" value=$title$ default="<<currentTiddler>>">
<$list filter="[[<<tid>>]tagging[]]"/>
\end

I am not sure if that would help or be the correct syntax, the latter mostly thanks to me not quite being able to decipher the documentation for variables on tiddlywiki.com.

Best wishes, Tobias.

Jeremy Ruston

unread,
Nov 17, 2014, 6:27:22 PM11/17/14
to Tobias Beer, TiddlyWiki
Hi Tobias
 
I was wondering how difficult it might be to extend the set widget so as to allow a default value as a fallback for when the value is actually undefined:

The trouble is that in many situations an empty string is a valid value that shouldn't be defaulted; what we really want here is a way to detect missing parameters.



\define tagging(title)
<$set name="tid" value=$title$ default="<<currentTiddler>>">
<$list filter="[[<<tid>>]tagging[]]"/>
\end

This example wouldn't work for a title containing spaces. Bear in mind that macro parameters are processed with text substitution, so passing "Hello There" as a title gives you value=Hello There, which won't work as expected. The fix is to use quotes; triple quotes are recommended because that allows titles to contain single or double quotes.

<$set name="tid" value="""$title$""">

Best wishes

Jeremy.




\define tagging(title)
<$set name="tid" value=$title$ default="<<currentTiddler>>">
<$list filter="[[<<tid>>]tagging[]]"/>
\end

I am not sure if that would help or be the correct syntax, the latter mostly thanks to me not quite being able to decipher the documentation for variables on tiddlywiki.com.

Best wishes, Tobias.

Tobias Beer

unread,
Nov 17, 2014, 6:50:12 PM11/17/14
to tiddl...@googlegroups.com, beert...@gmail.com, jeremy...@gmail.com
Hi Jeremy,
 
Bear in mind that macro parameters are processed with text substitution, so passing "Hello There" as a title gives you value=Hello There, which won't work as expected. The fix is to use quotes; triple quotes are recommended because that allows titles to contain single or double quotes.

<$set name="tid" value="""$title"""/>

Got it now. Good to know how to move in safe waters.

Best wishes, Tobias.

Tobias Beer

unread,
Nov 17, 2014, 7:12:46 PM11/17/14
to tiddl...@googlegroups.com, beert...@gmail.com, jeremy...@gmail.com
 
 This example wouldn't work for a title containing spaces.

Ok, so let's consider the hypothetical syntax fixed...

\define tagging(title)
<$set name="tid" value="""$title$""" default="<<currentTiddler>>"/>

<$list filter="[[<<tid>>]tagging[]]"/>
\end
The trouble is that in many situations an empty string is a valid value that shouldn't be defaulted; what we really want here is a way to detect missing parameters.

How and when are variables evaluated? Could the evaluation return some <<undefined>> or <<null>> value subsequently passed to the set widget in order to trigger using a default fallback?

Best wishes, Tobias.

Jeremy Ruston

unread,
Nov 18, 2014, 4:23:23 AM11/18/14
to Tobias Beer, TiddlyWiki
Hi Tobias

Ok, so let's consider the hypothetical syntax fixed...

\define tagging(title)
<$set name="tid" value="""$title$""" default="<<currentTiddler>>"/>
<$list filter="[[<<tid>>]tagging[]]"/>
\end

The trouble is that in many situations an empty string is a valid value that shouldn't be defaulted; what we really want here is a way to detect missing parameters.

How and when are variables evaluated? Could the evaluation return some <<undefined>> or <<null>> value subsequently passed to the set widget in order to trigger using a default fallback?

The trouble is that the macro parameter is inserted into the macro body using textual substitution. Thus if you don't pass the title parameter then the first line of the macro body will be:

<$set name="tid" value="""""" default="<<currentTiddler>>"/>

So, there's an empty string being passed as the attribute "value". There's no way for the set widget to distinguish that empty string as a missing value that needs to be defaulted unless it regarded all empty strings as missing values. The trouble with that is that often we want to be able to assign an empty string to a variable. That could be accomplished by assigning the empty string as expected if the "default" attribute is missing.

I think it's less complicated to fix the issue by introducing transcluded default values for macro definitions.

Best wishes

Jeremy.

 

Best wishes, Tobias.

Tobias Beer

unread,
Nov 18, 2014, 5:38:06 AM11/18/14
to tiddl...@googlegroups.com, beert...@gmail.com, jeremy...@gmail.com
<$set name="tid" value="""""" default="<<currentTiddler>>"/>

So, there's an empty string being passed as the attribute "value". There's no way for the set widget to distinguish that empty string as a missing value that needs to be defaulted unless it regarded all empty strings as missing values. The trouble with that is that often we want to be able to assign an empty string to a variable. That could be accomplished by assigning the empty string as expected if the "default" attribute is missing.

I totally understand that, my suggestion was to alter the actual text substitution so as to pass down a literal "<<underfined>>" or "<<null>>" or any appropriate flag as a string, which of course would not be possible for use as an actual value.

So, instead we would be left with...

<$set name="tid" value="""<<undefined>>""" default="<<currentTiddler>>"/>

...and the appropriate handling by the set widget.

Not if <<undefined>> provides for a naming convention but something that doesn't leave us with an empty string... and widgets by default treating all of <<underfined>>, <<null>> or <emptyString> the same, except for when explicitly declared otherwise.

Best wishes, Tobias.
Reply all
Reply to author
Forward
0 new messages