Checking if global macro exists, and order or RawMarkup includes?

66 views
Skip to first unread message

Roel Vanhout

unread,
May 27, 2020, 9:01:39 PM5/27/20
to TiddlyWikiDev
Hi,

Is there a way to either check if a global macro with a certain name exists, or to loop over all existing macros? When I register a macro from a javascript plugin, it shows up in $tw.macros but it looks like macros \define'd from a tiddler tagged with $:/tags/Macro don't.

While I'm at it - are there any guarantees as to in what order content included through tagging tiddlers with $:/tags/RawMarkup will be included in the page? I have a 'plugin' for a javascript component that relies on being included after the main component, is there any way to specify an explicit order between two tiddlers? Right now I just copy/paste everything into one tiddler manually but that's more fragile of course. Thanks.

regards

Roel

TonyM

unread,
May 28, 2020, 2:14:23 AM5/28/20
to TiddlyWikiDev
Roel,

There is more than one raw tag no

SystemTag: $:/tags/RawMarkup
SystemTag: $:/tags/RawMarkupWikified
SystemTag: $:/tags/RawMarkupWikified/BottomBody
SystemTag: $:/tags/RawMarkupWikified/TopBody
SystemTag: $:/tags/RawMarkupWikified/TopHead
SystemTag: $:/tags/RawStaticContent


Perhaps this is enough?

Otherwise, setup your raw tiddlers, save the wiki and look at the html file to see where you find the content of your raw tiddlers appearing, and in what apparent order.

Regards
Tony

PMario

unread,
May 28, 2020, 3:17:02 AM5/28/20
to TiddlyWikiDev
Hi,

If you tag something and the tag-tiddler exists, it can have a field named: list. This field can define the order of tagged tiddlers.

So you can use the <<list-links-draggable "$:/tags/RawMarkup">> and it can be used to drag & drop order your code.

If a new tiddler is tagged, it will be listed as the "last element". So you have to define the order again.

-mario

PMario

unread,
May 28, 2020, 3:17:51 AM5/28/20
to TiddlyWikiDev

Roel Vanhout

unread,
May 28, 2020, 9:55:52 PM5/28/20
to tiddly...@googlegroups.com
Thanks, that's been useful. I had a wrong mental model of how macro storage worked which made me look in the wrong places. In case anyone ever happens to find this while doing the same in the future, I ended up writing this function (to be called from a widget's member function):

function getVariables(widget)
{
    var node = widget;
    var result = [];
    while (node) {
        if ($tw.utils.hop(node, "variables") ) {
            result = result.concat(Object.getOwnPropertyNames(node.variables));
        }
        node = node.parentWidget;
    }
    return result;
}

But the important realization is that macros/variables are not all stored in place but are rather context-dependent, i.e. are a collection of variables defined at any of the parents of the current context. Which is probably not news to any of you :) but it's what tripped me up.

cheers,

roel



On Thu, May 28, 2020 at 4:47 PM PMario <pmar...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/4df83c11-95fb-4336-b54a-48e420ea503c%40googlegroups.com.

PMario

unread,
May 29, 2020, 9:34:50 AM5/29/20
to TiddlyWikiDev

On Friday, May 29, 2020 at 3:55:52 AM UTC+2, Roel Vanhout wrote:

But the important realization is that macros/variables are not all stored in place but are rather context-dependent, i.e. are a collection of variables defined at any of the parents of the current context. Which is probably not news to any of you :) but it's what tripped me up.

That's true. Macros are internally stored as variables. _And_ they have a scope. This makes it possible to "reuse" or overwrite them. Eg: currentTiddler always points to the tiddler, which contains the "wiki text", if it was defined by a standard transclusion. Using the <$tiddler .. > widget also defines currentTiddler.

<$set ... and <$var ... widgets work in the same way. The variables, that they define or only valid inside the widget body.



-mario

PMario

unread,
May 29, 2020, 9:37:33 AM5/29/20
to TiddlyWikiDev
On Friday, May 29, 2020 at 3:55:52 AM UTC+2, Roel Vanhout wrote:
Thanks, that's been useful. I had a wrong mental model of how macro storage worked which made me look in the wrong places. In case anyone ever happens to find this while doing the same in the future, I ended up writing this function (to be called from a widget's member function):

function getVariables(widget)
{
    var node = widget;
    var result = [];
    while (node) {
        if ($tw.utils.hop(node, "variables") ) {
            result = result.concat(Object.getOwnPropertyNames(node.variables));
        }
        node = node.parentWidget;
    }
    return result;
}

That's OK, if you need it that way. .. But accessing variables, that are _not_ "own properties", should use the JavaScript prototype chain. So you should be able to directly access a given variable, if you want to. This should give you much faster access.

-m

Roel Vanhout

unread,
May 29, 2020, 9:59:23 AM5/29/20
to tiddly...@googlegroups.com
> On Fri, May 29, 2020 at 11:07 PM PMario <pmar...@gmail.com> wrote:
> That's OK, if you need it that way. .. But accessing variables, that are _not_ "own properties",
> should use the JavaScript prototype chain. So you should be able to directly access a given
> variable, if you want to. This should give you much faster access.

Just to check if I understand correctly - what you're saying is how to access a specific variable when you already know its name, right? To get all variables that are defined, the method I posted is the only way, right?

cheers,

roel


--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.

PMario

unread,
May 29, 2020, 3:42:54 PM5/29/20
to TiddlyWikiDev


On Friday, May 29, 2020 at 3:59:23 PM UTC+2, Roel Vanhout wrote:
> On Fri, May 29, 2020 at 11:07 PM PMario <pmar...@gmail.com> wrote:
> That's OK, if you need it that way. .. But accessing variables, that are _not_ "own properties",
> should use the JavaScript prototype chain. So you should be able to directly access a given
> variable, if you want to. This should give you much faster access.

Just to check if I understand correctly - what you're saying is how to access a specific variable when you already know its name, right?

Yes.
 
To get all variables that are defined, the method I posted is the only way, right?
 
Right.

TonyM

unread,
May 30, 2020, 5:31:10 AM5/30/20
to TiddlyWikiDev
Note

Outside java script there is now the Is variable operator.

Tony

Reply all
Reply to author
Forward
0 new messages