Writting an index macro

218 views
Skip to first unread message

Luis Gonzalez

unread,
Apr 26, 2017, 8:25:17 AM4/26/17
to TiddlyWikiDev
I am a newcomer in TW and  I want to start writting macros.

¿How can I access to the content of the caller tiddler in a javascript or text macro?
I want to make a macro that prints a index of the tiddler headers so if the tiddler is


----
!Introduction
This is the introduction

!Phases
!!First phase
This is the first phase

!!Second Phase
This is the second fase
---

My macro would print in a small green letter:

Introduction
Phases
  First phase
  Second phase


Mat

unread,
Apr 26, 2017, 8:47:52 AM4/26/17
to TiddlyWikiDev
Warmly welcome Luis!


¿How can I access to the content of the caller tiddler in a javascript or text macro?

WikiText filters exracts the text with the get filter operator, like so get[text]

Example:

<$list filter="[[Foo]get[text]]">

</$list>


You can also use a transclusion {{Foo}} which, when used in a filter omits the outer curls:

<$list filter="[{Foo}]">

</$list>

To extract the headlines you can use filter operator splitbefore - or, probably better, some of Tobias Beer split operator variants.

I made the CherryPicker plugin (and the followup variant @ttention which might be less relevant here) that has many similarities to this. It is done in pure WikiText. But it is possibly not the best implementation. For one thing, Cherrypicker was made before I knew of Tobias' variants.

If you find TW cool, make sure to tell your friends so they get happy too ;-)


<:-)

Luis Gonzalez

unread,
Apr 26, 2017, 8:58:50 AM4/26/17
to TiddlyWikiDev
I like TW. It is wonderfull but I am a little lost because I can't find where I can look for information about writting macros.


Thanks !!!!

Mat

unread,
Apr 26, 2017, 10:55:00 AM4/26/17
to TiddlyWikiDev
This is probably the best doc tiddler on it but if you search there for "marcos" you'll also find other tiddlers.

Can I ask how/where you have looked for info thus far? I ask purely from a constructive perspective because there are for sure others who also do not find the info and we should do something about it. For example;

- did you know that tiddlywiki.com is the main place for documentation on TW?
- did you do any searches there? what search terms in that case?
- btw, how did you find out that one can write macros in TW?
...

Thanks!

<:-)

Luis Gonzalez

unread,
Apr 27, 2017, 4:45:19 AM4/27/17
to tiddly...@googlegroups.com
I am a java and python programmer.


I have various places I look for information:
http://tiddlywiki.com/
http://tiddlywiki.com/dev/
And many of the samples in http://tiddlywiki.com/static/Examples.html


The learning curve of tiddlywiki is very high, so if we want to make tiddlywiki better known we have to reduce the learnig phase. Let's look at python language for example. Its quick expansion is mainly due of its easy or learning.

I am gattering all docs I can find to sort an classify it in a way that all people can learn it as fast as we can.

For example, it's not clear the way we can access all tiddlywiki elements in a macro (filters, fileds, tags...)



I continue seeking for information. At this time I am documenting the macro's way of life in TW5. My intention is to share it with all of you. Maybe you can help me.




--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywikidev/oRoRA78XzTw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywikidev+unsubscribe@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/633c5d36-91be-4a78-9a60-efde46c9b947%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

PMario

unread,
Apr 27, 2017, 7:50:28 AM4/27/17
to TiddlyWikiDev
On Thursday, April 27, 2017 at 10:45:19 AM UTC+2, Luis Gonzalez wrote:
I have various places I look for information:
http://tiddlywiki.com/
http://tiddlywiki.com/dev/
And many of the samples in http://tiddlywiki.com/static/Examples.html

have closer look at: http://tiddlywiki.com/#%22Filter%20Examples%22%20by%20Tobias%20Beer:%5B%5B%22Filter%20Examples%22%20by%20Tobias%20Beer%5D%5D%20%5B%5B%22TB5%20-%20a%20pocket%20full%20of%20tips%22%20by%20Tobias%20Beer%5D%5D

Tobias adds more info to his TWs when he builds stuff, that was inspired by google groups discussions.

have fun!
mario

Mat

unread,
Apr 27, 2017, 9:03:08 AM4/27/17
to TiddlyWikiDev
Luis,

First, I'm sorry for hijacking your thread but I hope you feel you're also getting some answers. I agree with PMario that Tobias Beers stuff is top notch and a fantastic resource for learning about TW, especially if you have a coding background (which, incidentally, I don't really).



The learning curve of tiddlywiki is very high, so if we want to make tiddlywiki better known we have to reduce the learnig phase. Let's look at python language for example. Its quick expansion is mainly due of its easy or learning.

Surely, TW is a lot simpler to learn than a real coding language. Of course, TW is also more limited, unless you also include JS as part of "knowing" TW.
 

I am gattering all docs I can find to sort an classify it in a way that all people can learn it as fast as we can.

The "big picture solution" to this is IMO a kind of social TW system called TWederation. If you don't know about it: It is in its early stages but it actually works. The idea is to be able to import tiddlers from anyone elses public TW. This would enable us as a collective to refine data by; fetching, adding your own little bits to it and sharing. The key here is that "adding your own little bits to it" is incentive driven. You add bits because they are of value to you - tags, whatever. Or, like in your case, someone has a neat classification for TW resources... you fetch it, add your own stuff to it, remove a dead link,... and this is now a potenitally even better list. Or the mere nfo that you added some plugin (as evidenced in the plugin list). This is of potential value for everybody. It is a federated knowledge base that is refined based on incentives in ones own wikis! (at least the public ones... or, later on, public parts of ones private TW).

Sorry for the rant but your problems about the learning curve, the difficulty to find information and that the whole TW project suffers because of this is spot on. (It is especially disheartening, but valuable, to hear an actual coder and who even has seen the docs is expressing this. We're lucky that the existing docs DO hold a very high quality even if they are limited.)

...


For example, it's not clear the way we can access all tiddlywiki elements in a macro (filters, fileds, tags...)

A key to accessing at least tiddler elements (perhaps not TiddlyWiki elements... but then everything are tiddlers in TW) is by means of filters, at least in WikiText. There are a few widgets that use filters. The "tag" and "tags" fitler operators are a little special because the tags field is a bit special... at least I think so.

The easiest way to test fitlers, without special plugins, is to be in edit mode and use the preview feature there. And to use this short hand filter form:

{{{ [....] }}}


I continue seeking for information. At this time I am documenting the macro's way of life in TW5. My intention is to share it with all of you. Maybe you can help me.

Much appreciated. My faviourite way of sharing is to use TiddlySpot. To get an empty TW5 on it;

1. create a new tiddlyspot.com (you don't have to bother with "flavour" since they don't offer that right away. So after clicking "Create", don't bother going to the link.
2. go to http://tiddlywiki.com/empty.html and ...controlpanel > saving > tiddlyspot ...fill in info and save
3. now to your tiddlyspot which is now TW5

...and add your data. If your data is as tiddlers, you can drag'n drop those tiddlers right onto your tiddlyspot. (You drag by grabbing on a link for the tiddlers title).


<:-)




2017-04-26 16:55 GMT+02:00 Mat <matia...@gmail.com>:
This is probably the best doc tiddler on it but if you search there for "marcos" you'll also find other tiddlers.

Can I ask how/where you have looked for info thus far? I ask purely from a constructive perspective because there are for sure others who also do not find the info and we should do something about it. For example;

- did you know that tiddlywiki.com is the main place for documentation on TW?
- did you do any searches there? what search terms in that case?
- btw, how did you find out that one can write macros in TW?
...

Thanks!

<:-)

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywikidev/oRoRA78XzTw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywikide...@googlegroups.com.

Luis Gonzalez

unread,
Apr 27, 2017, 2:51:35 PM4/27/17
to TiddlyWikiDev
I wrote my two first macros.

The first is a WikiText macro, but I think we have no control sentences like if or for loop in WikiText macros. I access all the tiddler fields: title, text, created, modified, tags....

The second is a Javascript macro because I need control sentences. But in it I don't know how to access to the current tiddler fields.
I try:

 return "Title: " + this.getFieldString(title);


but it does not work.


This is the macro:
(function(){

"use strict";

exports
.name = "ahora";

exports
.params = [];

exports
.run = function() {
 
return "Title: " + this.getFieldString(title);
};

})();

and I call the macro in other tiddler in this way:

<$macrocall $name="ahora" />

I get: Title: undefined
    

: - (

Mat

unread,
Apr 27, 2017, 3:44:10 PM4/27/17
to TiddlyWikiDev
Luis Gonzalez wrote:
I wrote my two first macros.

Fantastic!!!
 

The first is a WikiText macro, but I think we have no control sentences like if or for loop in WikiText macros. I access all the tiddler fields: title, text, created, modified, tags....


Sure; the standard way is to use the listwidget with the condition in the filter. There is AFAIK no loop X times for a preset number but the list filter iterates for each element that comes out of the filter and that you might want to manipulate.

<$list filter="[all[]tag[foo]]">
{{!!myfield}}
</$list>

What is it you want to achieve?


 
The second is a Javascript macro because I need control sentences. But in it I don't know how to access to the current tiddler fields.

I'm too bad at real coding but I'm sure that if you just look at some of the other js modules, you'll find this right away. Just do a search for ".js" in advanced search.


<:-)

BJ

unread,
Apr 27, 2017, 7:04:38 PM4/27/17
to TiddlyWikiDev
Hi Luis,
the current tiddler name  is stored in a variable (usually), use

var currentTiddlerName = this.getVariable("currentTiddler");

then if you want data from a field

var currentTiddler = this.wiki.getTiddler(currentTiddler);

value
= currentTiddler.getFieldString("fieldname");

cheers

BJ

Luis Gonzalez

unread,
May 10, 2017, 8:35:20 AM5/10/17
to TiddlyWikiDev
I try and it runs ok.

Now I have to use regexp (for example) looking all occurrences of !, !! and !!! to produce the index.

I continue trying, Thanks....

Luis Gonzalez

unread,
May 11, 2017, 3:45:27 AM5/11/17
to TiddlyWikiDev
I got it!!!

I have finish my macro and it runs perfect.
It puts a little index with the heads of the current tiddler.

This is the code:

(function(){

"use strict"; exports.name = "index"; exports.params = [{name: "head"}]; exports.run = function(head) { var currentTiddlerName = this.getVariable("currentTiddler"); var currentTiddler = this.wiki.getTiddler(currentTiddlerName); var value = currentTiddler.getFieldString("text"); var result = "!!!" + head + "\n" + "<small>\n\n"; var partial; var pattern = /^(!+)(\w.+?)$/gm; while((partial = pattern.exec(value)) != null) { result = result + "*".repeat(partial[1].length) + " " + partial[2] + "\n"; } result = result + "</small>" return result; }; })();

And this is the way I use it:

<<index "In this tiddler:">>

Reply all
Reply to author
Forward
0 new messages