[Demo] Inspect macro definitions

225 views
Skip to first unread message

clutterstack

unread,
Feb 26, 2021, 3:17:25 PM2/26/21
to TiddlyWiki
Hi all,

I was playing with dropdowns and...things...and I built something that I wished I had last summer, and which will help me keep track of current variable and macro definitions/values.


It's not perfect, but I'm kind of pleased. Also not documented or packaged.

I ended up writing two javascript macros to access variables and their properties -- if I could have done this using filters, I'd love to know what I missed! I didn't just want to search tiddlers for "\define" etc, because sometimes I put that stuff in code blocks as content.

Also, if there was a pre-existing public solution for this, I'd also like to see it. There must be a few out there, at least in private wikis.

Best,
Chris

Mohammad Rahmani

unread,
Feb 26, 2021, 11:51:10 PM2/26/21
to tiddl...@googlegroups.com
Hi Chris,
Inspect is a very useful addition both for developers and users.

Few suggestions (ignore them if not relevant)

1. find macros in tiddlers not tagged with $:/tags/Macro (e.g. non-global variable). For example I can search in all tiddlers tagged with $:/tags/Macro/Commander
2. limit the search to a plugin or filtered list only  


Best wishes
Mohammad


--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/b24fbec3-5b12-4610-9778-3633be89af4bn%40googlegroups.com.

clutterstack

unread,
Feb 27, 2021, 10:14:59 AM2/27/21
to TiddlyWiki
Hi Mohammad,

Thanks for checking it out. To your points:

1. I thought this looked tricky, but I guess by importing variables from each candidate tiddler in turn, we can examine non-global macros in the same way. Local macros will often have non-unique names, so that would have to be taken into account.

In practical terms, Mat's solution shared here (https://groups.google.com/g/tiddlywiki/c/NgFPRM1fFCw) works pretty well for finding local macros and linking to their source tiddlers, and is a lot simpler.

2. This should be possible...it's all just filters, except the two JavaScript macros that find out what TiddlyWiki considers the definition text of a macro to be, and what its parameter names and defaults are.

Best,
Chris

Mohammad Rahmani

unread,
Feb 27, 2021, 10:47:15 AM2/27/21
to tiddl...@googlegroups.com

On Sat, Feb 27, 2021 at 6:45 PM clutterstack <bee...@gmail.com> wrote:
Hi Mohammad,

Hi Chris,

Thanks for checking it out. To your points:

1. I thought this looked tricky, but I guess by importing variables from each candidate tiddler in turn, we can examine non-global macros in the same way. Local macros will often have non-unique names, so that would have to be taken into account.

In practical terms, Mat's solution shared here (https://groups.google.com/g/tiddlywiki/c/NgFPRM1fFCw) works pretty well for finding local macros and linking to their source tiddlers, and is a lot simpler.

Thank you! I used the solution by Mat's with my show-macro (https://kookma.github.io/TW-Utility/#demo%2Fshow-macro) in Utility plugin and I got nice results.

something line below in on https://tiddlywiki.com/ (assuming you have utility installed)

<table>
<$list filter="""[all[tiddlers]!has[plugin-type]!tag[$:/tags/Macro]search[\define]]""">
<tr>
<td><$link/></td>
<td>
<<show-macro>>
</td>
</tr>
</$list>
</table>


 

2. This should be possible...it's all just filters, except the two JavaScript macros that find out what TiddlyWiki considers the definition text of a macro to be, and what its parameter names and defaults are.


Yes, sometime you want to inspect a plugin for macros and variables.

Anyway I enjoy using your great solution!

Thank you!

 

Mohammad Rahmani

unread,
Feb 27, 2021, 10:54:18 AM2/27/21
to tiddl...@googlegroups.com

clutterstack

unread,
Feb 27, 2021, 5:06:33 PM2/27/21
to TiddlyWiki
Mohammad,

Haha, sorry for not making sure to reference solutions you've already released! I have tried out the find macro, which is a very neat tool. I was tired when I replied, and Mat's post was the thing I remembered first, because it was the first one I saw when I started to want to look at the source of macros a lot.

I am still running into formatting issues trying to make codeblocks with a combination of JS and WikiText, so I am replacing one of my JS macros with a widget.

...I am trying to make a wiki to use, not a plugin, but I keep opening parentheses...

Mohammad Rahmani

unread,
Feb 27, 2021, 10:44:41 PM2/27/21
to tiddl...@googlegroups.com
On Sun, Feb 28, 2021 at 1:36 AM clutterstack <bee...@gmail.com> wrote:
Mohammad,

Haha, sorry for not making sure to reference solutions you've already released!

No problem, ;-) I myself forgot what I have done before :-) :-)

 
I have tried out the find macro, which is a very neat tool. I was tired when I replied, and Mat's post was the thing I remembered first, because it was the first one I saw when I started to want to look at the source of macros a lot.

One minore issue with find macro is it needs both starting and ending delimiters! but I noticed Mats solution also uses the send delimiter (end of the line char)


 

I am still running into formatting issues trying to make codeblocks with a combination of JS and WikiText, so I am replacing one of my JS macros with a widget.

...I am trying to make a wiki to use, not a plugin, but I keep opening parentheses...

Great! good luck! I have an eye open for your further improvement to the code!

On Saturday, February 27, 2021 at 10:54:18 AM UTC-5 Mohammad wrote:

Cheers
Mohammad


 

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

David Gifford

unread,
Feb 28, 2021, 6:09:13 PM2/28/21
to TiddlyWiki
Added this to the toolmap, both in the "Understanding TiddlyWiki" section and the "Advanced / developer" section

clutterstack

unread,
Mar 2, 2021, 11:27:10 AM3/2/21
to TiddlyWiki
Thanks, David.

clutterstack

unread,
Mar 3, 2021, 5:36:32 PM3/3/21
to TiddlyWiki
For Mohammad: I am still wading through the mess I made, but I made a tab for Tiddler Commander you can try here. This is totally not ready for prime time and will probably not stay in this wiki but I'd be interested in your feedback as to how you'd like something like this to work.

There are two plugins at the moment, to make this work: "selector" and "showmacrodef". One gives me a macro for a dropdown selector. The other gives me a JavaScript widget and a JS macro, for displaying a variable's definition/value and a sample macrocall (if applicable), respectively, as well as a tool that makes a tab for Tiddler Commander to inspect for variable definitions within a filtered list of tiddlers. There is a tiddler that will do something similar without having Commander installed, but it's not finished.

The Commander tab does something like this, starting with the searchfilter from the top part of the Commander UI:

You type into the selector and it looks through those tiddlers for lines with "\define ", followed by something that contains the user input, followed by "(". From that, it rebuilds the macro name on that line. Each macro name it deduces from this, it lists in the dropdown as a selection option.

Once you select a macro name, it returns a list of the tiddlers that contain a "\define" line for that macro name. Note that it's possible for a tiddler to have a line like that, but NOT be defining anything (e.g. within a code block). To check, you choose the tiddler with a radio button, and the macro gives you a display.

Here's where it checks that there's a macro definition in the selected tiddler: it redefines that macro using a set widget, then imports the variables from the candidate source tiddler. If the macro now has a definition, then that tiddler had a real definition in it, and this is displayed using the aforementioned JS widget.

I note that the filter in the dropdown interface is pretty slow. Right now it's showing all candidate source tiddlers in the dropdown...maybe not a good tradeoff performance- and space-wise.

Any feedback welcome.

Best,
Chris

clutterstack

unread,
Mar 3, 2021, 11:37:32 PM3/3/21
to TiddlyWiki
I did some prefiltering and this seems to have sped things up by about a factor of 4-5 (counting seconds in my head, using [all[tiddlers+shadows]] as input and typing one letter into the search).

Mohammad Rahmani

unread,
Mar 4, 2021, 5:06:33 AM3/4/21
to tiddl...@googlegroups.com
Hi Chris,
 Great to see you are improving macro-variable !
 I tried to experiment with Sample you provided

To reproduce
1. In commander Combo Search I entered \define
2. Commander returned 60 matches
3. Under the Defs tab I entered testCreate
4. After a while I see the dropdown returns some outputs and let me choose a variable to show

Yes, as you wrote in your post it is pretty slow!



Best wishes
Mohammad


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

clutterstack

unread,
Mar 4, 2021, 8:57:12 AM3/4/21
to TiddlyWiki
Hi Mohammad,

Hmm. That is disappointing!

Did you try it after my last post here? The newer iteration is much faster than the first. (A peripheral lesson here is: update version numbers no matter what! I was in a rush to upload the faster version.)

I see my latest version is returning duplicate results in the dropdown though, so there's at least one major bug. Maybe it'll be fast after I fix that! Haha. I will look some more at this later.

Thanks for testing!

Best,
Chris

Mohammad Rahmani

unread,
Mar 4, 2021, 9:03:08 AM3/4/21
to tiddl...@googlegroups.com
Chris,
 Is there a new version? Is it in the same link?



Best wishes
Mohammad


clutterstack

unread,
Mar 4, 2021, 9:53:22 AM3/4/21
to TiddlyWiki
Hi Mohammad, I updated it sometime after 11pm EST yesterday, at the same link. It is faster, but also lists variables multiple times, so I made a mistake with my filters. I will look at it again today and post here when I update again.

Best,
Chris

Mohammad Rahmani

unread,
Mar 4, 2021, 11:23:28 AM3/4/21
to tiddl...@googlegroups.com
Thanks Chris! 

Wow, this is much faster! but multiple outputs of the same result!


Best wishes
Mohammad


clutterstack

unread,
Mar 4, 2021, 1:31:36 PM3/4/21
to TiddlyWiki
I've updated the demo with "version 0.1.2" of my showmacrodef plugin, which is still not finished, just improved (I hope). Fixing the duplicate entries was trivial (missed out a unique[] operator in a filter).

To speed things up and make them look tidier, I removed the preview of possible source tiddlers within the dropdown.

Best,
Chris
Reply all
Reply to author
Forward
0 new messages