Hi tejjyid > I've managed to update many of my simpler macros, but now I'm moving on to > the more complicated ones. > > There are two scenarios that I used to have: > > 1.) a list of words stored in one tiddler that I would highlight in a range > of texts stored in other tiddlers. That list of words would be converted into > a regex via some inline js, and I could then use that regex in other macros, > because once created the regex variable was "visible" everywhere. From my > point of view, this was an easy option because I could update the list of > words to be annotated easily.
The simplest type of JavaScript module to write for TiddlyWiki5 is a JS macro. The semantics are extremely simple: the macro defines the names of its parameters, and exports a handler function that is called when the macro is invoked. Here’s a simple example from the core: https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/macros/makedatauri.js <https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/macros/makedatauri.js> There are quite a few restrictions and limitations with macros, though. Firstly, a macro is not supposed to have any side effects (it cannot create or modify tiddlers, for example), and is supposed to return the same result every time it is called with a given set of parameters. Secondly, they don’t participate in the refresh mechanism (which is one of the things that makes them simple to write). This means that you can’t easily arrange for them to automatically refresh if underlying data should change. Nonetheless, in many situations, writing a macro is adequate. There is some documentation here: http://tiddlywiki.com/dev/#JavaScript%20Macros In your case, you could write a macro <<extract-regexp filter>> that would retrieve the tiddlers matching a filter, and retrieve the highlights from inside them, and then return the resulting regexp. Then, you could use an action-setfield widget within a button to allow the user to manually trigger the assignment of the regular expression to a tiddler. > 2.) I had a library of functions stored in one tiddler that I could use in > varying combinations in different macros. > > I can't work out to do either thing in the TW5 framework. I don't mind doing > it a better way, if the better way doesn't involve complex code. Or > alternatively, how do I make the same arrangement work? TiddlyWiki 5 provides a Common/JS compatible module loader that makes it easy to require() other modules and access their exports. Here’s an example from one of the core plugins: https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/widgets/button.js#L15 > Something else - I used to be able to get tiddlers into my macros with code > like "store.getTiddlerText" - does that functionality still exist? Can > someone point me to where it's documented? Within a macro, you can obtain the text of a tiddler with: this.wiki.getTiddlerText("HelloThere") TiddlyWiki’s internal APIs are only documented within the source. Most of the TiddlyWiki Classic store.*() functions will be found in: https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/wiki.js <https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/wiki.js> Generally, the trick with TiddlyWiki 5 development is to find an existing plugin or module that you can use as a starting point. Best wishes Jeremy > If anyone feels they need to look at old code to answer the questions: the > attached has everything. But probably some ideas on how to do it & pointers > to useful documentation would be enough. > > Thanks > > -- > 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 [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at https://groups.google.com/group/tiddlywiki > <https://groups.google.com/group/tiddlywiki>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/tiddlywiki/2d4f51a2-bc48-489f-ae41-90c018d01429%40googlegroups.com > > <https://groups.google.com/d/msgid/tiddlywiki/2d4f51a2-bc48-489f-ae41-90c018d01429%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. > <andrewsimon(1).html> -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/743A3483-D3C1-456F-89F5-D537D92DB545%40gmail.com. For more options, visit https://groups.google.com/d/optout.

