Can anyone fix my editortoolbar text?

Hi guys

The code at the bottom for an editortoolbar didn’t work. From the tiddler ‘New tiddler’, I want it to paste 4 macros, like this:

<<viewme tid:"New tiddler sources">><br><<viewme tid:"New tiddler output">><br><<viewme tid:"New tiddler defdescr">><br><<viewme tid:"New tiddler outline">><br>

Here is my attempt at coming up with a solution without bothering you guys first:

\define giffpre() <<viewme tid:"
\define giffpost() ">><br>
\define giffsuffix1() -sources
\define giffsuffix2() -output
\define giffsuffix3() -defdescr
\define giffsuffix4() -outline
\define addcurrent() $(realTarget)$
<$set name="realTarget" value={{{[<targetTiddler>get[draft.of]]}}}>
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="replace-selection"
	text={{{ [<giffpre><addcurrent><giffsuffix1><giffpost><giffpre><addcurrent><giffsuffix2><giffpost><giffpre><addcurrent><giffsuffix3><giffpost><giffpre><addcurrent><giffsuffix4><giffpost>] }}}
	suffix=""
/>
</$set>

What is the simplest way to do this?

Your wikitext code first defines a set of single-line macros containing pieces of the desired final result, which you will then assemble using “filtered transclusion” syntax (the tripled curly-braces stuff).

Here’s some (untested) code with a bit of cleanup and comments:

<!-- First, define macros for all the text pieces -->
\define giffpre() <<viewme tid:"
\define giffpost() ">><br>
\define giffsuffix1() -sources
\define giffsuffix2() -output
\define giffsuffix3() -defdescr
\define giffsuffix4() -outline

<!-- and define a macro that assembles the pieces (using simple macro parameter substitution syntax) -->
\define output()
$(giffpre)$$(realTarget)$$(giffsuffix1)$$(giffpost)$
$(giffpre)$$(realTarget)$$(giffsuffix2)$$(giffpost)$
$(giffpre)$$(realTarget)$$(giffsuffix3)$$(giffpost)$
$(giffpre)$$(realTarget)$$(giffsuffix4)$$(giffpost)$
\end

<!-- Next get the desired "Draft of ..." title from the target tiddler -->
<$let realTarget={{{ [<targetTiddler>get[draft.of]] }}}>

<!-- Then, send the message to perform the editor toolbar button action -->
<$action-sendmessage
   $message="tm-edit-text-operation" $param="replace-selection" text=<<output>> suffix=""/>
</$let>

Notes:

  • Instead of using “filtered transclusion” to assemble the output text, I used a macro with parameter substitution (the $(...)$ syntax), because it is easier to read and doesn’t require using filter syntax, which would involve more punctuation (i.e., angle brackets, square brackets, curly braces) plus a final +[join[]] operator to connect all the pieces together.

  • I also omitted the redundant addcurrent() macro, since the realTarget variable already contains the needed piece of text

Let me know how it goes…

enjoy,
-e

1 Like

Wow! Thank you @EricShulman for the snippet and the careful explanation! The only change I needed was to change your closing <$set/> to a </$let>.

I will no doubt be using variations of this for a number of longer editortoolbar buttons.

I will make a contribution to TW dev later today for your several helps lately. Thanks again.

1 Like

I would suggest inserting one macro or transclusion that generates the four different tiddler titles, rather than inserting 4 macros that use the same parameter.

  • This would allow future modifications to the single macro be reflected where ever it was used, rather having to change 4 macros everywhere they were used.
1 Like