Hi, I'd like to write a command handler function that changes a
certain macro parameter in all occurrences of that macro in the
current tiddler, and then saves the changed tiddler.

I'd like to use existing TiddlyWiki functions for that, but I can't
figure out how it would be done. Curently, I am trying to use the
macro formatter's lookaheadRegExp, but it doesn't return any matches,
though I am fairly sure that there should be some.

Can someone point me to a good example where a tiddler's text is
parsed for macros from within plugin code, or maybe find the mistake I
made in my code?

Many thanks in advance,
Gerrit


Here's my first try:

// Get the macro formatter. (Can this be done in an easier way?)
var macroFormatter = null;
for(i=0; i<config.formatters.length; i++) {
        if( config.formatters[i].name == 'macro' ) {
                macroFormatter = config.formatters[i];
                break;
        }
}
var tiddler = store.getTiddler(title);
// Search for the first occurrence. (Later, iterate over occurrences.)
lookaheadMatch = macroFormatter.lookaheadRegExp.exec(tiddler.text);
// Currently, lookaheadMatch is always null, even though the tiddler
contains macros.
var macroName = lookaheadMatch[1];
if( macroName == 'myMacro' ) {
        var params = lookaheadMatch[2].readMacroParams();
        for(paramKey in params) {
                if( paramKey == 'myParam' )
                        newMacroString += ' myParam:' + someNewValue;
                else
                        newMacroString += ' ' + paramKey + ':' + 
params[paramKey];
        }
        newMacroString += '>>';
}
// Now, somehow replace old macro ocurrence with newMacroString.

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/tiddlywikidev?hl=en.

Reply via email to