Please wrap my macro in another macro?

Okay, guys, last request of the weekend.

I figured out the following, and it works:

\define timestamp() @@.donotprint &nbsp;&nbsp;[[(c)|$(datetime)$]] <<modal "$(datetime)$">>@@
<$vars datetime=<<now "YYYY-0MM-0DD 0hh:0mm:0ss">>
>
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="insert-text"
	text=<<timestamp>>
/>			
			
</$vars>

But this adds a long snippet to every line of text I add it to. So, being greedy and lazy as I am, I would like to have the entire thing be part of a global macro, so I can just hit an editortoolbar button and have it insert <<datetime tid:“2025-05-25 16:14:33”>>, nice and concise, but which is the equivalent of the code above. I tried about 8 different ways, but every time I am getting the red screen of death.

Can anyone show one last bit of love? I promise, in return, to make the final result available for anyone to use…The basic idea is to be able to insert both a link and a modal button after or within any line of text, to a tiddler with a datetimestamp as a title. That would serve as a footnote to additional content. One could navigate to the tiddler or view it in place with a modal.

As I read it;

The above would be in a tiddler with a global tag providing timestap macro

Then the following inside the editor toolbar button;

<$vars datetime=<<now "YYYY-0MM-0DD 0hh:0mm:0ss">>
>
<$action-sendmessage
	$message="tm-edit-text-operation"
	$param="insert-text"
	text=<<timestamp>>
/>			
			
</$vars>

Or is there something else?

But it seems like the vars should be in the macro tiddler, not the editor toolbar button? How does the vars get applied to the timestamp if all that is being inserted is the text <<timestamp>>? Doesn’t there need to be the equivalent of a $tid$ in the text=<<timestamp>> part of the toolbar code?

Anyway, what it is pasting is the long text, which is what I am trying to avoid…

The Timestamp macro, when used should make use of the value set in the current vars statement, however in this case, vars may be set when the button is rendered not when it is clicked :frowning:

We may need to design it differently to address this. I will give it more consideration.

Create a tiddler (e.g., “DateTimeMacro”), tagged with $:/tags/Global, containing:

\define datetime(tid) @@.donotprint &nbsp;&nbsp;[[(c)|$tid$]] <<modal "$tid$">>@@

Then, create an Editor Toolbar Button (e.g., “TimeStampButton”), tagged with $:/tags/EditorToolbar, containing:

<$let stamp=<<now "YYYY-0MM-0DD 0hh:0mm:0ss">>>
<$action-sendmessage $message="tm-edit-text-operation"
	$param="insert-text" text=`<<datetime "$(stamp)$">>`/>
</$let>

As with all Editor Toolbar Button definitions, also give this tiddler caption, condition, description, and icon fields.

Notes:

  • The TimeStampButton tiddler first gets the current time stamp value (a date/time string)
  • It then performs an Editor Toolbar tm-edit-text-operation to insert the <<datetime ...>> macro into the tiddler being edited (the “target” tiddler).
  • Note how the <<datetime ...>> text that is being inserted is enclosed in backticks. This causes it to perform a substitution of the current time stamp value into the text parameter value that is then inserted into the target tiddler.
  • Also note that the $(stamp)$ syntax is enclosed by literal double-quote characters. This is necessary since the stamp text contains a space. Otherwise, the stamp text would be seen as two separate macro parameter values.
  • When the target tiddler is rendered, the global <<datetime>> macro then shows the (c) link and the <<modal ...>> macro (which I assume is defined elsewhere)

Also note that prior to the introduction of the backtick “substitution” syntax, this could have been written using a “filtered transclusion” to construct the text parameter value, like this:

<$action-sendmessage $message="tm-edit-text-operation" $param="insert-text"
   text={{{ [[<<datetime "]] [<now "YYYY-0MM-0DD 0hh:0mm:0ss">] [[">>]] +[join[]] }}}/>

enjoy,
-e

1 Like

Thanks Eric! That was quite a thorough explanation. Thanks for that and for the solution itself.

For the datetime macro contents, I added the modal part:

\define datetime(tid) @@.donotprint &nbsp;&nbsp;[[(c)|$tid$]] <$button class="tc-btn-invisible"><$action-sendmessage $message="tm-modal" $param="$tid$" />(v)</$button>@@

The timestamp editortoolbar contents are identical yours, plus the condition and icon fields.

addendum:

  • While not strictly required, you should give your editor toolbar button caption and description fields. The caption field is used as the mouseover tooltip for the button when displayed in the Tiddler editor, and both fields are used when showing your toolbar button in the $:/ControlPanel > Appearance > Toolbars > Editor Toolbar list.

  • The modal button in your <<timestamp>> macro can be shortened a bit by using the message and param parameters directly in the $button widget, instead of using a separate $action-sendmessage, like this:

<$button class="tc-btn-invisible" message="tm-modal" param="$tid$">(v)</$button>

-e

1 Like

Just made these changes. Thanks Eric!

If anyone wants to see the final results, check out More info!

2 Likes