Thanks for your responce. How do you include groups or individual macros as needed?
If we define global macros vs local it sounds like you are proposing mostly local?
Your answers are very helpful to keep this clear, but I wonder about performance?
thanks in advance
Tony
I think it depends, what your macros do. .. Eg. If they define global functionality, which is useful for every "user" tiddler, or used in the ViewTemplate, you pretty much have to make them global, tagging them $:/tags/Macro
If you use them in something like a Dashboard tiddler, it can make sense, to \import them in the Dashboard itself. .. It limits the scope of the macros, so you won't have problems with "name collisions", which can be an issue for global macros.
There are some differences in macro/variable lookup performance, but I think you can safely ignore them. If your application uses a filter somewhere, they will outweigh the js macro/variable lookup by far. JS variable lookup is highly optimized by browsers.
-------------I personally have several macro definitions in 1 tiddler. IMO this makes debugging much easier. It also makes it easier to convert a macro definition tiddler into a template, which isn't tagged or imported at, but transcluded.
Transcluding macros uses more memory, since every transclusion defines new macro variables. Calling those macros = variables, has a very minimal performance advantage, since the variable lookup is faster. ... BUT every transclusion needs time to build those variables. ... So in the end the penalties will compensate the advantages.
Global macros are imported in $:/core/ui/PageTemplate ... So those variables will only be built, if the page template or one of the macros are changed.
\define wiki-mode() {{$:/config/wiki-mode}}$:/tags/Macro/View variables will be built everytime the ViewTemplate is shown. On the other hand you can use the same macro name per tiddler view. This gives you the possibility to change macro behavior per tiddler view in the story river.So again ... It depends, on what you want to do. ...
I think $:/tags/Macro/View is only needed for very special cases. I would go with a global macro definition. It makes them simple to use.-------------
Having every macro in 1 tiddler can improve the possibility to document them. The text below a macro definitions is ignored by the \import process. So it doesn't have any memory or performance penalty if there is a lot of text there.
But .. I personally think, it makes debugging more complex.
\define first-tiddler(filter:"[tag<currentTiddler>]") {{{ $filter$ +[first[]] }}}
\define last-tiddler(filter:"[tag<currentTiddler>]") {{{ $filter$ +[last[]] }}}
\define next-tiddler(filter:"[tag<currentTiddler>]") {{{ $filter$ +[after[]] }}}
\define prev-tiddler(filter:"[tag<currentTiddler>]") {{{ $filter$ +[before[]] }}}
<h2>Macro definition tiddler</h2>
;Obtain the first/last/next/prev member in a list defined by filter
:Defaults to tiddlers tagged with the current tiddler, `[tag<currentTiddler>]`
*`<<first-tiddler [filter]>>`
*`<<last-tiddler [filter]>>`
*`<<next-tiddler [filter]>>`
*`<<prev-tiddler [filter]>>`
<!-- comment here ok? search keywords etc... -->
Adding comments like <!-- comment --> inside the macro body, _will_ negatively impact macro performance, since the comment is processed everytime the macro is executed. (... we should try to improve this )
The [tag[abcd]] filter index does speed up finding tiddlers tagged "abcd" quite a bit. So yes. \import filter is improved since the indexing exists.
mymacro1(size of tiddler, name of field)
Since your question seems to be mainly about documenting macros, why not put your macro definitions in a data tiddler. Then as you edit, if you need a reminder just type{{macs##mymacro1}}and see something likemymacro1(size of tiddler, name of field)
over in the preview window.
Putting all the definitions in one place also has the advantage that you can quickly test at any time to make sure you're not accidentally creating a tiddler with the same name as an existing one.
I personally have several macro definitions in 1 tiddler. IMO this makes debugging much easier. It also makes it easier to convert a macro definition tiddler into a template, which isn't tagged or imported at, but transcluded.I would love an example of this if possible. That is convert a macro definition tiddler into a template.
Global macros are imported in $:/core/ui/PageTemplate ... So those variables will only be built, if the page template or one of the macros are changed.So this makes them quite efficient, but some of my macros refer to another value egso will all the the page macros be built every time $:/config/wiki-mode changes.\define wiki-mode() {{$:/config/wiki-mode}}
{{$:/config/wiki-mode}} ... as a string
You can see all variables if you use: <<dumpvariables>> macro see: https://tiddlywiki.com/#dumpvariables%20Macro%20(Examples)
-mario
Having every macro in 1 tiddler can improve the possibility to document them. The text below a macro definitions is ignored by the \import process. So it doesn't have any memory or performance penalty if there is a lot of text there.But .. I personally think, it makes debugging more complex.Good to know, So If I placed in the body macro documentation is will be visible on the macro tiddler but not add too much to slow down?For example?\define first-tiddler(filter:"[tag<currentTiddler>]") {{{ $filter$ +[first[]] }}}
\define last-tiddler(filter:"[tag<currentTiddler>]") {{{ $filter$ +[last[]] }}}
\define next-tiddler(filter:"[tag<currentTiddler>]") {{{ $filter$ +[after[]] }}}
\define prev-tiddler(filter:"[tag<currentTiddler>]") {{{ $filter$ +[before[]] }}}
<h2>Macro definition tiddler</h2>
;Obtain the first/last/next/prev member in a list defined by filter
:Defaults to tiddlers tagged with the current tiddler, `[tag<currentTiddler>]`
*`<<first-tiddler [filter]>>`
*`<<last-tiddler [filter]>>`
*`<<next-tiddler [filter]>>`
*`<<prev-tiddler [filter]>>`
<!-- comment here ok? search keywords etc... -->
Adding comments like <!-- comment --> inside the macro body, _will_ negatively impact macro performance, since the comment is processed everytime the macro is executed. (... we should try to improve this )But if I understand correctly it is ok as in the example above?
The [tag[abcd]] filter index does speed up finding tiddlers tagged "abcd" quite a bit. So yes. \import filter is improved since the indexing exists.
This is when the filters are used in the import widget and pragma?