It turns out that whatever the text type, the changed it made. The changed was made by the _transform macro, which was only called if of the proper type.
Now, a question. I have concluded that the macro is always invoked when first encountered. Since mine had a side effect, it did its job even when not called. Am I right?
If I’m right, would it not be better to alert people on this? Could this behavior be corrected?
Look at my first code. I’m building a transform variable and then I invoke the <$macrocall> widget with that variable as $name parameter. Thus, the transform macro is called or not called.
It’s not all that new, and is actually quite useful.
For example, suppose you are writing a popup and want to have “ok” and “cancel” buttons, as well as handling keyboard “enter” and “escape”. You could write something like this:
Note that the definitions of <<done>> and <<close>> are local to the <<showpopup>> macro and are invoked for both <$keyboard> and <$button> actions. Similarly, <<init>> (defined using a $let widget) is scoped only surrounding the $button for invoking the popup.
Using these “macro definition inside another macro” and “macro defined as a variable” techniques avoids repeating code as well as keeping the code nice and compact. However, there are some limitations to using these code patterns:
The macro definitions must be one-liners, since you can’t use \end within the containing macro, or it would prematurely terminate that macro.
The macro definitions can’t use $param$ or $(variable)$ syntax, since those would be automatically substituted when the containing macro is processed. However, they can use <<variable>> or <<__param__>> syntax, since those are interpreted “on-the-fly” when the inner macros are invoked.
Or perhaps a generalised solution so we could make use of this nifty user interface element in your example?
Eg macro called with tiddlername/fieldname defaulting to current tiddler, to edit named tiddlername/fieldname
I now see how the use of the \whitespace trim works in this way.
As other may know things can break if you have empty macros of this form
\define dummy()
\end
or
\define dummy()
\end
Here is my minimal example of this pattern;
\define topmacro()
\define submacro() submacro output
\define submacro2() submacro output in <<currentTiddler>>
Internal of topmacro using '<<submacro>>' and '<<submacro2>>'
\end
<<topmacro>>
'<<submacro>>' not valid outside topmacro
It is important to note this could easily give rise to macro edits that break the code because we do not normally think that the following represents two different macros
\define submacro2() submacro output in <<currentTiddler>>
Internal of topmacro using '<<submacro>>' and '<<submacro2>>'