Pass macro to widget attribute: Create new tiddler with specified title

301 views
Skip to first unread message

brorgschlr85

unread,
Oct 9, 2015, 1:05:58 PM10/9/15
to TiddlyWiki
I am trying to create a button with an accompanying edit-text widget that will (a) create a new tiddler with the title entered in the edit-text widget box, (b) edit the description field of the new tiddler as specified below, (c) assign multiple tags to the new tiddler (as below), and (d) append the current date to the title of the new tiddler.

The following macro achieves objective (a) through (c):

\define newentry()
\define tmp() {{$:/temp/newtitle}} <<now>>
<$button>
<$action-sendmessage $message="tm-new-tiddler" title={{$:/temp/newtitle}} description=<<now "ddd, mmm DD, YYYY - 0hh:0mm $(currentTiddler)$">> tags="BM GL [[Hello World]]"/>
New Entry:
</$button>
<$edit-text tiddler="$:/temp/newtitle" tag="input" default=""/>
\end  

However, (d) is proving very difficult. I've tried passing a macro to the title attribute of the action-sendmessage widget, but the result is the literal string of the macro call, e.g.:

\define newentry()
\define newtitlemacro() {{:/tempnewtitle}} <<now YY-MM-DD>>
\define tmp() {{$:/temp/newtitle}} <<now>>
<$button>
<$action-sendmessage $message="tm-new-tiddler" title=<<newtitlemaro>> description=<<now "ddd, mmm DD, YYYY - 0hh:0mm $(currentTiddler)$">> tags="BM GL [[Hello World]]"/>
New Entry:
</$button>
<$edit-text tiddler="$:/temp/newtitle" tag="input" default=""/>
\end  

but the resulting button/text field creates a new macro entitled "<<newtitlemacro>>"). As seen above, I'm able to pass macros to the description attribute of the action-sendmessage widget, so I'm not sure why the title attribute takes literal strings only.

Mark S.

unread,
Oct 9, 2015, 2:16:43 PM10/9/15
to tiddl...@googlegroups.com
Hello,

First, there were some lexical mistakes in your text. Maybe the UTF got mangled by copy/paste?

Second, I'm not sure if you can actually define a macro inside a macro. I've always kept definitions separate. So, humor me, I separated them.

Finally, whenever I find that literal text is popping up where I expect transcluded (wikified) text, I'm pretty sure I need the <$set> to set up the variables for me.

The code below is what came up with. I ditched the <<tmp>> macro since it didn't seem to be doing anything. The following code seems to work.

Good luck!
Mark


\define newtitlemacro() $(mytitle)$ $(rightnow)$
\define newentry()
<$button>
<$action-sendmessage $message="tm-new-tiddler" title=<<newtitlemacro>> description=<<now "ddd, mmm DD, YYYY - 0hh:0mm $(currentTiddler)$">> tags="BM GL [[Hello World]]"/>

New Entry:
</$button>
<$edit-text tiddler="$:/temp/newtitle" tag="input" default=""/>
\end 

<$set name="rightnow" value=<<now YY-MM-DD>> >
<$set name="mytitle" value={{$:/temp/newtitle}} >
<<newentry>>
</$set></$set>


Evolena

unread,
Oct 9, 2015, 2:22:40 PM10/9/15
to tiddl...@googlegroups.com
I was trying to send a similar solution for 15 minutes but that dummy Publication button doesn't seem to want to make something apart frozing the subject...

I was wondering for the nested macro too... Nested macro definitions seems to work outside of the outer macro definition, but not inside. The same code with the newtitlemacro definition inside the newentry macro definition instead of outside doesn't work:

\define newentry()
\define newtitlemacro() $(v-title)$ $(v-now)$
<$vars v-title={{$:/temp/newtitle}} v-now=<<now YY-MM-DD>>>

<$button>
<$action-sendmessage $message="tm-new-tiddler" title=<<newtitlemacro>> description=<<now "ddd, mmm DD, YYYY - 0hh:0mm $(currentTiddler)$">> tags="BM GL [[Hello World]]"/>
New Entry:
<
/$button>
</
$vars>

<$edit-text tiddler="$:/temp/newtitle" tag="input" default=""/>
\end
[Edit] warning, this is the non-working example, invert the first two lines to make it work)

Jed Carty

unread,
Oct 9, 2015, 2:31:44 PM10/9/15
to TiddlyWiki
I put some information about why this happens here if you are interested. It comes up more often than I would have expected.

Jed Carty

unread,
Oct 9, 2015, 2:57:15 PM10/9/15
to TiddlyWiki
Sorry, that last one was about passing macros as parameters to other things.

Evolena,

One problem with nested macros like that is that unless the first non-whitespace text in the tiddler is \define... than the content isn't treated as a macro and any content between macro definitions (that isn't also a macro) will prevent any text below it from being parsed as a macro definition. Since macros just insert the contained text into the location they are called in the wiki the definition would be placed where the macro is called, this is probably what prevents it from working. At least that is what I think is happening, I am a bit confused about why '\define newtitlemacro() $(v-title)$ $(v-now)$' isn't rendered when newentrymacro is called but it still isn't treated as a macro.

There are some subtleties about the rendering process that still confuse me so I may be completely wrong here.

Evolena

unread,
Oct 9, 2015, 4:18:19 PM10/9/15
to TiddlyWiki
Maybe I've not been clear enough: the code I've posted (with nested macro) is the non working one, as Mark posted the working one while I was struggling with posting. One should invert the two first lines to make it work.

I thought that I had managed to use the tmp macro in brorgschlr85 first code outside the macros definition, but I can't reproduce, so maybe I've been confused too when experimenting.
Anyway, nesting macro is a bad idea, it can have side effects ^^

brorgschlr85

unread,
Oct 9, 2015, 4:57:06 PM10/9/15
to TiddlyWiki
We're getting closer, but using <$set> seems to introduce a problem. When I attempt to type a title in the resulting edit-text widget, I can only enter one character at a time. This is similar behavior as when edit-text is used to edit a field of the current tiddler. It appears that each time I type a character, $:/temp/newtitle is modified and updating the value of the "mytitle" variable requires the editor to lose focus of the edit-text widget.

Any suggestions?

Jed Carty

unread,
Oct 9, 2015, 5:19:19 PM10/9/15
to TiddlyWiki
Move the edit-text widget outside the set widget. What is happening is every time you type a character into the edit text widget it refreshes the set widget and all its children, which currently includes the edit text widget and it resets the focus so you aren't in the text box anymore.

Try this:


\define newtitlemacro() $(mytitle)$ $(rightnow)$
\define newentry()
<$button>
<$set name="rightnow" value=<<now YY-MM-DD>> >
<$set name="mytitle" value={{$:/temp/newtitle}} >

<$action-sendmessage $message="tm-new-tiddler" title=<<newtitlemacro>> description=<<now "ddd, mmm DD, YYYY - 0hh:0mm $(currentTiddler)$">> tags="BM GL [[Hello World]]"/>
</$set></$set>


New Entry:
</$button>
<$edit-text tiddler="$:/temp/newtitle" tag="input" default=""/>
\end 

<<newentry>>

Jed Carty

unread,
Oct 9, 2015, 5:19:25 PM10/9/15
to TiddlyWiki
Move the edit-text widget outside the set widget. What is happening is every time you type a character into the edit text widget it refreshes the set widget and all its children, which currently includes the edit text widget and it resets the focus so you aren't in the text box anymore.

Try this:

\define newtitlemacro() $(mytitle)$ $(rightnow)$
\define newentry()
<$button>
<$set name="rightnow" value=<<now YY-MM-DD>> >
<$set name="mytitle" value={{$:/temp/newtitle}} >

<$action-sendmessage $message="tm-new-tiddler" title=<<newtitlemacro>> description=<<now "ddd, mmm DD, YYYY - 0hh:0mm $(currentTiddler)$">> tags="BM GL [[Hello World]]"/>
</$set></$set>


New Entry:
</$button>
<$edit-text tiddler="$:/temp/newtitle" tag="input" default=""/>
\end 

<<newentry>>

brorgschlr85

unread,
Oct 9, 2015, 5:40:45 PM10/9/15
to TiddlyWiki
Excellent--this fixed the problem.

Thanks, all, for your thoughtful and timely help.

brorgschlr85

Tobias Beer

unread,
Oct 10, 2015, 10:06:54 AM10/10/15
to TiddlyWiki
Hi Mark, Jed, Evolena, brorgschlr85,

With this problem popping up ever so often,
I added some "lessons learned" on this here...


Best wishes,

— tb 

Mark S.

unread,
Oct 10, 2015, 3:02:27 PM10/10/15
to TiddlyWiki
Hi Tobias,

That looks good! I assume you plan to post it to the tiddlywiki.com documentation pool? Possibly with a link from the existing Macros tiddler?

Mark

Chris Nicoll

unread,
Oct 29, 2015, 4:54:26 PM10/29/15
to TiddlyWiki
Thanks to everyone on this thread. My new button just got even fancier than I'd planned.

Hegart Dmishiv

unread,
Apr 5, 2016, 7:43:26 AM4/5/16
to TiddlyWiki
Hi Jed,

Just wanted to let you know that your solution here was the last piece of the puzzle we needed to get the main functionality of our TiddlyCRM semester project for {{DesignWrite}} going. See this tiddler for a demo of how we used it. Thanks!

Hegart.
Reply all
Reply to author
Forward
0 new messages