(_HowTo_ macrolanguage Bugs beginner tips etc)
Quote
Borut
The macro language does not provide for some kind of functions/function calls, does it? The only way of "calling" is like &somemacro?
The only way for data exchange, when "calling", is via variables?
Sounds like you're seriously working with macros now, great!
Don't know which skills you already have, but just a few tips I wished someone had told clueless me in the first years:
Tips and HowTo for anyone interested in macro building:
Most errors are listed in the
Error Console. It's found in the
Tools menu, or enable the existing toolbar button (View > Toolbars > Javascript Console ), or open directly the URL "chrome
://console2/content/console2.xul". By default Macro errors are OFF, click on button "ALL" to see them too.
Create this Bool pref in aboutconfig, by right-click:
kmeleon.plugins.macros.debug = true
After a restart the Error Console will complain not only about "KMM errors", but also tell you WHICH macro is
broken and in which LINE!
Sadly the downside is a
new debugging bug, introduced somewhere along the KM7X versions: after enabling this pref KM will show an
error that the old "compat" macro is now broken, and it was automatically disabled. But as far as I know the purpose of this "compat.kmm" macro is only to convert extremely ancient macros written for KM1.1 or older! Really no prob But if you want to keep that macro and you're only occasionally writing macros, just toggle off that debug pref again and enable the compat-macro again, when finished.
Prob: another
new debugging bug in error console, this one since
KM-Goanna:
script errors now show only an extremely short javascripts extract, about 100 characters only, and the supposed "column" position is all wrong, for example 1145! But at least the tiny script extract does contain the complained error position in it somewhere.
Look into
main.kmm to find tons of real expert macros as examples. Some of it's scripts are far too much "expert" for me, but in general have discovered a lot of interesting methods and insights in there.
Use an
editor with syntax highlighting for macrolanguage, that helps **enourmously** to catch errors already while typing, for example to easily see which opened brackets are ending where exactly, etc. In the beginning I was so clueless and didn't even know such magical things like syntax highlighting exist! The prob is, I only have the very, very old inherited Scite version once customized by kko, where I've dabbled along the years to add some newer 7X macrocommands to the syntax, but overall customizing this app (or its ancient version) is far too complicated for me. Other macro editors (do a forum search) are far easier to customize, but I personally find the hightlighting syntax much better in old Scite, especially that it also shows if string quotes are not closed correctly or span aross several editor linebreaks.
Somewhere in the forum I've uploaded my slightly adjusted Scite version too, years ago, but over the years Dorian created yet more new commands.
And especially the "
direct JS functions" since KM75.1 those now do allow for strings to span across several editor linebreaks, and of course old Scite still shows that as interrupted "...string...." errors.
But oh well, I can't use those 'modern' functions anyway if I want my macros to remain compatible with old KM1.x, so I still need those errors shown.
The big revolution is that
since KM75.1 pure javascript functions can now be defined directly in kmm-files, which John mentioned above. That means no complicated wrapping of JS into KM-variables necessary anymore. I guess that makes writing and debugging 100x easier (if javascript is involved), and completely turns everything upside down debuggingwise.
Just not for myself, being stuck with KM1.6 on old OS, and of course want to use my macros too So have zero experience with that method. Please keep that in mind when reading my tips, they are mainly for old complicated way of handling JS in macro variables.
And there are also
magical javascript formatting tools out there! Another miracle thing I discovered many years too late since I'm not a coder and no one told me those tricks :-( When knitting together endless javascript code by macro, like in my current aboutconfig_exporter macro again (still the old var-wrapping method), I'm always forced to merge the final code into a single JS line again before injecting it into *old* KM1.x-versions, and that giant pile becomes just one big code mess. For debugging, it helps to copy that final pure JS line into the clipboard before injecting it (setclipboard($_js)), that allows to investigate the pure JS.
That's where a fantastic NotepadPlus Plugin now comes to the rescue:
JSTool with JSFormat. Out of that endless 1-liner it automatically creates pretty JS code with automatic linebreaks everywhere
But also great in general for everything dealing with JS, for bookmarklets, investigating scripts in webpage source codes etc.
In general, for big and complicated macros it helps to keep backups after every successful new step, in case the macro breaks later and then not knowing where to start searching. What exactly where those last edits again??
And to figure out which macro parts may cause any probs, little test alerts can be injected. To indicate if those specific parts are even running, and which value the variables have at that point.
When creating
javascript snippets by macro variables, stuff like linebreaks must be escaped twice in it. That means \\n instead of \n, and \\\" instead of \", in file paths double backslashes \\ etc
Since KM1.6 there's also an
extremely bad macro bug:
macro lines are not executed in order anymore, if any javascript code gets injected in between!
Especially its not possible anymore to toggle a pref by macro, inject a bit JS, and then toggle that pref back again by macro. The JS in between will work with the restored pref already! Somehow the following
macro lines are now completely detached from any javascript that gets injected before them. That has caused me endless headaches, gray hair and wasted time over the years, and still all futile, no real solution
The only lousy workaround is to open some alert popup in the middle, that will keep the following macro lines at bay while the JS is executed. But horrible GUI of course. One day finally Dorian created a timeout command in macrolanguage, which would be a better workaround. Except that it only works with FULL seconds, far too long for that purpose! Especially if several such pause-breaks are needed.
Oh well, sorry for the novel. No clue if it helps you or anyone, of course not everybody is such a bloody coding beginner as I was at first. And still am when it comes to JS. Or to yet more gruelsome xpcom stuff for addons (which of course won't stop me when there's no other chance, but still an endless waste of struggling time!)
Edited 4 time(s). Last edit at 08/19/2019 03:26PM by siria.