[tw5]Macro interactions

193 views
Skip to first unread message

admls

unread,
Feb 12, 2019, 7:58:14 PM2/12/19
to TiddlyWiki
Hi Folks,

I'm trying to populate a stylesheet, but I'm having trouble getting these macros to work together. The concatStateTiddler macro is supposed to give me the name of a state tiddler tacked composed of a prefix and the name of the currentTiddler. The backup macro is supposed to fetch some value from the state tiddler if it is present. And if it is not present, it should fetch it from a set of backup values.

\define concatStateTiddler()
<$set filter="[all[current]get[draft.of]] [all[current]!has[draft.of]]">
"$:/state/<<currentTiddler>>"
</$set>
\end

\define backup(value)
<$view tiddler=$(concatStateTiddler)$ field="""$value$""">
 <$view tiddler="$:/
config/backup-values" field="""backup-$value$""">
    </$view>
</$view>
\end

I can get it to work if concatStateTiddler looks like this:
\define concatStateTiddler()
"$:/state/$(currentTiddler)$"
\end

But I want the view and edit mode versions of the tiddler to use the same state tiddler. Hence the first version of concatStateTiddler. But the first version doesn't play nice with the backup macro. Any ideas of what I'm doing wrong here?

The only thing I can think is that the set widget is creating a list, even if it is a list consisting of only one element (on account of the use of [all[current]]). That list format may be playing havoc with the backup macro. But I really don't have any idea beyond that. Any help would be greatly appreciated.

Best regards,

Adam

TonyM

unread,
Feb 12, 2019, 10:13:56 PM2/12/19
to TiddlyWiki
Adam,

I do not understand the Question, Others may, However in your set statement you are not providing or using the name= parameter so I am not sure what is happening other than in your second example.

Regards
Tony

Mark S.

unread,
Feb 12, 2019, 11:02:42 PM2/12/19
to TiddlyWiki
Hello Adam,

The following version works.

\define concatStateTiddler()
<$set filter="[all[current]get[draft.of]] [all[current]!has[draft.of]] +[addprefix[$:/state/]]" name="kitty"><$text text=<<kitty>>/></$set>
\end

\define backup(value)
<$wikify text=<<concatStateTiddler>> name=cst>
<$view tiddler=<<cst>> field="""$value$"""/>
</$wikify>
\end


You can't concatenate a <<variable>> inside text like that ... well ... maybe with a lot of patient application of wikify (which I needed anyways). Instead, I used the "addprefix" operator to do the concatenation, following up on a suggestion by Jeremy in an earlier post today.

Note, all the extra space and line feeds had to be squeezed out of concatStateTiddler -- if GG puts them back in ... take them out.

The <$text> widget was used to convert the resulting item (which would otherwise have been a link because filter generates a title list) into plain text, and <$wikify> was used to make the entire result of concatStateTiddler into a single variable.

Hope this was something like what you wanted!

-- Mark

admls

unread,
Feb 13, 2019, 2:35:44 AM2/13/19
to TiddlyWiki
Hi Tony,

My understanding is that if the name parameter is left out of the set widget, the variable name defaults to "currentTiddler". I could be mistaken, of course.


Hi Mark,

That doesn't seem to be working for me. It's acting like there is nothing at those fields, but I've made sure that there are some values there.


Best wishes,
Adam

Mal

unread,
Feb 13, 2019, 2:42:11 AM2/13/19
to TiddlyWiki
Hi Adam,

I think you might be getting the set widget confused with the list widget. With the list widget, there is a parameter called "variable" that defaults to "currentTiddler".

Regards,

Mal

TonyM

unread,
Feb 13, 2019, 2:44:51 AM2/13/19
to TiddlyWiki
As mal says, If you use set you are defining a value/variable you must name it name=myvar you can give it a value=<<currentTiddler>>

Regards
tony

admls

unread,
Feb 13, 2019, 3:04:47 AM2/13/19
to TiddlyWiki
The tiddlywiki.com documentation on the set widget says this about the name parameter: 'The name of the variable to assign (defaults to "currentTiddler")'.

Does that just need updated or something? Or am I misunderstanding it?

Jeremy Ruston

unread,
Feb 13, 2019, 3:11:19 AM2/13/19
to tiddl...@googlegroups.com
Hi Adam

The docs are correct, the "name" attribute of the <$set> widget defaults to "currentTiddler" if not present.

Best wishes

Jeremy

--
Jeremy Ruston
jer...@jermolene.com
https://jermolene.com

> On 13 Feb 2019, at 08:04, admls <adam.the...@gmail.com> wrote:
>
> The tiddlywiki.com documentation on the set widget says this about the name parameter: 'The name of the variable to assign (defaults to "currentTiddler")'.
>
> Does that just need updated or something? Or am I misunderstanding it?
>
> --
> 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 https://groups.google.com/group/tiddlywiki.
> To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/44695e55-ac26-430b-8d06-5846fd008970%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

TonyM

unread,
Feb 13, 2019, 3:54:46 AM2/13/19
to TiddlyWiki
Thanks Jeremy,

Similer to other widgets, I suppose this is a way to do the same as the tiddler widget but with the posibility of emptyvalue etc...

Tony

S. S.

unread,
Feb 13, 2019, 8:28:04 AM2/13/19
to TiddlyWiki
Adam, not sure if this is what you want.

In tiddler : NewTiddler
\define concatStateTiddler(value)
<$list filter="[all[current]get[draft.of]] [all[current]!has[draft.of]] +[addprefix[$:/state/]]">
<$view field=backup-$value$/>
</$list>
\end

In tiddler: $:/state/NewTiddler
has field: backup-1
field backup-1 has value : somevalue

When NewTiddler is being viewed or edited, this macro in its text field <<concatStateTiddler 1>>  should give a result of : somevalue

admls

unread,
Feb 13, 2019, 1:58:12 PM2/13/19
to TiddlyWiki
Hi S.S.,

I just got the chance to test out your code. I had to massage it just a smidge, but it works great! Thank you. I have bashed my head against this problem for too long. I'm always amazed at how concise well-written tiddlywiki code can be. The solution to my problems is often achieved in half the code I thought would be required. 

Thank you everybody!

Best wishes,
Adam

Mal

unread,
Feb 13, 2019, 10:59:20 PM2/13/19
to TiddlyWiki
Adam,

Sorry my response (above) was a bit off the mark.

This has taught me a couple of important lessons:
  1. I need to make sure to read and understand the documentation at tiddlywiki.com - It may not be particularly user-friendly, but it is accurate and concise.
  2. In Tiddlywiki there are usually many ways to achieve the same outcome.  Your use of the set widget is something I have not seen before and, after a bit of thought, I can see that the same could be achieved with other approaches, including the list, reveal or tiddler widgets and probably a few others.
All part of the fun with Tiddlywiki.

Regards,

Mal



Jeremy Ruston

unread,
Feb 14, 2019, 5:01:19 AM2/14/19
to tiddl...@googlegroups.com
Hi Mark


The following version works.

\define concatStateTiddler()
<$set filter="[all[current]get[draft.of]] [all[current]!has[draft.of]] +[addprefix[$:/state/]]" name="kitty"><$text text=<<kitty>>/></$set>
\end

\define backup(value)
<$wikify text=<<concatStateTiddler>> name=cst>
<$view tiddler=<<cst>> field="""$value$"""/>
</$wikify>
\end


I think that this can be done much more concisely and efficiently.

At the moment concatStateTiddler is using the "filter" attribute of the set widget. That means that the result of will be a list of titles, using double square brackets to quote titles containing spaces.

I don't fully understand the original problem, but unless you definitely need to have that quoting, it would be more concise to write this:

<$text text={{{ [all[current]get[draft.of]] ~[all[current]] +[addprefix[$:/state/]] }}}/>

In the backup macro you're using the wikify widget on the result of the  concatStateTiddler macro. Perhaps it's because you want to get the result of concatStateTiddler into a variable? But that doesn't make sense, because the substance of concatStateTiddler is to assign a value to a variable and then return it as text.

Stepping back, it looks like this should work:

\define backup(value)
<$view tiddler={{{ [all[current]get[draft.of]] ~[all[current]] +[addprefix[$:/state/]] }}} field=<<__value__>>/>
\end

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 https://groups.google.com/group/tiddlywiki.

admls

unread,
Feb 14, 2019, 12:19:48 PM2/14/19
to TiddlyWiki
Hi Jeremy,

Thanks! That's marvelously concise.
Reply all
Reply to author
Forward
0 new messages