Scope of Variables Operator: How can I display variables come from certain namespace or scope?

Looking in https://tiddlywiki.com/prerelease/#variables%20Operator
The variables operator is a neat operator allowing you to debug your code.

One question is, how can display the variables come from a certain scope? For example all variables related to highlight.js or codemirror plugins? Or the only variables come from a certain namespace or tiddler.

You can use the actionlog-widget, that can be placed within the scope that you want to see. eg: currentTiddler is changed all the time, but it has a scope.

In the following code the variable name is always the same myVar but has 2 different values, depending on the scope of the let-widgets.

\define actions()
<$let myVar="outer">
  <$action-log myVar=<<myVar>>/>
  <$let myVar="inner">
    <$action-log myInnerVar=<<myVar>>/>
  </$let>
  <$action-log myVar=<<myVar>>/>
</$let>
\end

<$button actions=<<actions>>>click me!</$button>

You can’t see any variables which are private to libraries. By intention they are “scoped” in a way, that their variables are private, so they don’t produce js-variable conflicts.

What do you want to see?

1 Like

Thank you Mario! Seems the $action-log is a good widget here.

Actually I was curious to know what variables come from certain scope like a tiddler, or a plugin or bunch of tiddler in a namespace.

@Mohammad I am not sure an actual scope is available for variables but if you know a variable exists and is in use such as through variables operator and dumpvariables macro or the actionlog to peek inside variables, within in actions, there are other searches you can undertake to find where they are defined. More often than not the name of the variable itself will be the clue as to where it originated.

I can help a lot here but must ask why you ask this question, what do you hope to achieve?

  • I have built other tools that specifically search for macro/variable definitions

See my-custom-dumpvariables.json (672 Bytes) that collapses the dumpvariables and provides a subfilter this is more practical than the dumpvrariables macro on its own to insert in code. This along with the actionlog should give you visibility of variables in most places.

However as you know variables can be defined as needed such as in a recursive process it may be defined and set for each recursion, in which arguably the scope is within the DOM or virtual DOM (not that I am expert here) that tiddlywiki uses such that you may be able to get some information using the Internals plugin and Previews Parse and Widget trees.

Thank you. I did not understand the length[] you used where it returns the length of wikitext defines the variable.
Also the subfilter here seems to only work on the name of variables like +[prefix[.a]] but not on the scope.

I was looking for to see what variables come from a tiddler? or variables inside a long nested structure. I do not know the name of variables in advance.

Actually before you open the first details “MyDumpVariables” it basically sums the byte length of all the variables.

My reply suggested I have no way to determine the scope. If you know how let me know.

Actually I am not totally sure what you mean by scope.

  • Alternatively I could use another macro for each variable to then search for where the variable is defined, if defined like \define varname() but to then sort based on definition gets tricky.
    • I have one already if that would help

For example;
Here I include my search for a definition inside mydumpvariables macro, I open .attr and it tells me where it is defined.

Scope means a tiddler, a name space!
Assume you have a tiddler called myTiddler, the first question is what variables are working only in this tiddler?

The code you provided does not show for me where the macro is defined see:

May be your own code is different!

Yes my code is different, I included in mydumpvariables another macro I have not yet shared.

macro-help.json (2.8 KB) see usage tiddler

$ _PSaT_macros_mydumpvariables.json (777 Bytes) updated to use above “?” macro.

Of course the macro-help could then be extended to find/search all tiddlers in which varname is present, in addition to its definition.

That is contextual, just place <<mydumpvariables>> in the tiddler and it will show you the variables available to that tiddler when displayed in the story in view mode. But place it in side some other list it will show the variables available in that part of the list.

1 Like

Nice! now I can find the variables come from a tiddler!
Example:

  1. I define a helper parameter/variable to store all global vars at the very beginning of tiddler Like gv
  2. Then I use variables operator and store all vars in another helper var, like lv
  3. Last, I subtract the lv from gv

Its fine but I do not understand your example. I just hope I have helped :nerd_face:

I like to note that, the Utility 2.2.0 — utility kit for authors and developers (kookma.github.io) has a show-macro to list all macros from a scope like current tiddler or [tag[myscope]] but it cannot find other vars like those defined by $let and works in part of tiddler.

1 Like

I am reviewing your utility tools again and once again wow. I will play a little and see if I can build something to go part of the way to exposing more info in code tiddlers, like listing the macros there in and other intelligence, does that fit with your objective?

  • Once again thank you for your contributions to the community, they are brilliant.
  • They are so feature rich, the question is for me when to build my own, when to leverage yours or others tools and how to know when to go where. In some ways we need a registry of features from all sources we can search - just dreaming.

Thank you Tony!
I will update the announce of Utility, as 2.2.0 is new!

Go ahead and lets discuss your hacks one by one!

This is a very good question. We need a TW store, library or what else you like it! links.tiddlywiki.org is great but it cannot acts as a store or plugin library!

I think we can go with CPL from Chinese community (@linonetwo). It has potential to acts as the universal community plugins and tools library!

To be honest, you did created very good tools but they are buried inside GG and Talk and you need to put them together in a central place and lets people know about them. I think you may learn form webpage like TW-Scripts and publish your useful tools there.

1 Like

To @TW_Tones

I agree with @Mohammad. I don’t give much. You do and deserve to be more widely used.

IMO, of all the methods for dissemination TW has, I think “Plugin Libraries” are the most efficient, both for the end-user and the maker?

Just an opinion, TT

That’s not really possible from wikitext, because “nested” variables like “currentTiddler” do have a scope as I’ve shown in my last post. …

So you will need a possibility in the widgets to “expose” debugging info. There is a discussion at GitHub https://github.com/Jermolene/TiddlyWiki5/issues/6345 which has a slightly different scope.

But Jeremy’s last post suggested:

… It would also be an interesting challenge to unpack the data in a usable form. …

Which would / could contain variables, that are newly defined in that scope. … So it should be possible to see the scope. … BUT … That’s a challange, to present that info in a human consumable way.

I think, it would be worth to suggest a similar behaviour as an improvement for the core. … DETAILS would be needed to be implemented in the TW way, with persistent states.

I think every author should be able to build their own “store” without the need of middle-men.

I think, if we tell our plugin authors, how they can create their own libraries, that can be used by the default TW “import plugins” mechanism, it would be a big win.

1 Like

I have been asking for help constructing libraries in a zip tiddler in single file wiki for some time. Libraries can be used for test data repositories and a lot more.