Development :  K-Meleon Forum
K-Meleon development related discussions. 
Pages: 12Next
Current Page: 1 of 2
Macrolanguage usage questions
Posted by: rodocop
Date: April 29, 2017 07:47AM

Folks!
Trying to upgrade my skills in KMM I found many things that I cannot understand or that aren't clearly descripted or need illustration in examples.

So I want to start the thread for usage questions (including DUMB ones, sure!). It can be useful not only for novices but also to more experienced users going mad sometime because of their dumbness!

1) I've created some child submenu.
setmenu("Parent",inline,child,-1);
What should be the code to delete it?
Can it be deleted during the current KM session?
I want this menu to be shown only when needed (checking some conditions)

2) $ARG - what is it really and how to use it? I saw some threads where it was used in macros but cannot understand it even with those examples.

More dumb questions to come... ;)


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)



Edited 1 time(s). Last edit at 04/29/2017 07:49AM by rodocop.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: rodocop
Date: April 29, 2017 07:52AM

3) rebuildmenu statement
ML2 page says 'Rebuildmenu is deprecated in later versions of K-Meleon'. What version it was deprecated from?

What should I use instead?


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 29, 2017 02:22PM

Great topic! Thanx smiling smiley
Just recently thought about creating something like it too, but got interrupted (by lack of time and/or lack of hope for interested readers ;-)

Let me add some links first (but switch to ENGLISH version, others too outdated)
http://kmeleonbrowser.org/wiki/MacroLanguage2&switchlang=en
http://kmeleonbrowser.org/wiki/CommandIds&switchlang=en
http://kmeleonbrowser.org/wiki/PluginCommands&switchlang=en

Basic overview for beginners, slightly outdated but best intro:
in the KM menu, open your local commands.html by
Edit > Configuration > Commands List

Catching errors: (not all, but most)
Most important: Error console!! By button "javascript console" (slightly misleading named for macro beginners) or in Tools>Error Console or direct link urlbar:
chrome://console2/content/console2.xul

Also extremely helpful to catch lots of syntax errors, although just Notepad can be used for plain editing too:
an editor with syntax highlighting for kmm-macros!
the one I use is an updated variation of kko's old Scite version. Was a nightmare for configuration, but luckily already finished (see attachment)

Also a little trap if unaware: kmm-files should be UTF-8 encoded.



Edited 1 time(s). Last edit at 04/29/2017 02:28PM by siria.

Attachments: editor_scite_kko-modsiria_2016.7z.001.7z (488.5 KB)   editor_scite_kko-modsiria_2016.7z.002.7z (163.1 KB)  
Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 29, 2017 02:33PM

Quote
rodocop
3) rebuildmenu statement
ML2 page says 'Rebuildmenu is deprecated in later versions of K-Meleon'. What version it was deprecated from?
What should I use instead?

No idea which version, and was also riddling long and hard about this, long ago! But the answer is simple:
setmenu smiling smiley
Just use the same commands and macros as for first creation were used. Or later, doesn't matter.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 29, 2017 02:42PM

Quote
rodocop
1) I've created some child submenu.
setmenu("Parent",inline,child,-1);
What should be the code to delete it?
Can it be deleted during the current KM session?
I want this menu to be shown only when needed (checking some conditions)

Hm... some years ago Dorian posted a trick to delete popup menus again: just treat it as if they were a macro or command line! By giving only the name but no action for it, or vice versa. Not sure if this works for inline menus too, but chances are probably good. Test?

created with:
setmenu("parentmenu",popup,"submenu");
can be deleted with:
setmenu("parentmenu",command,"submenu");

PS: to show "only when needed", my macro permdefs uses own little popup menus, just as another possibility.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 29, 2017 02:51PM

Quote
rodocop
2) $ARG - what is it really and how to use it? I saw some threads where it was used in macros but cannot understand it even with those examples.

Love $ARG!! Baby simple, just a bit hard to explain...
Had also struggled forever to figure out what it's about at all, finding not even 1 example macro at the time sad smiley

But $ARG is simply a little piece of free text! Like, for example, a user agent string line.
It works by putting brackets around it and calling it directly with a macro command, then automatically gets usable as variable $ARG in this macro:
mymacroname(blabla)
example:
setmenu($_menu,macro,"set UA bla bla blup","setmyUA(bla bla blup)");

There are a few catches:
- it must not contain commas
- the length is limited. Depending from how many special characters are used, perhaps about 100-252 characters
- if called in a setmenu line, there must be quotes around the "macro(x)"
- it automatically gets "inherited" by other macros, which the first macro may call. But cannot be modified in that chain action. In such cases simply copy $ARG to an own variable like $_x. Actually that's always a good idea, probably also for use in alerts or other "modal windows"



Edited 1 time(s). Last edit at 04/29/2017 02:59PM by siria.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: JamesD
Date: April 30, 2017 01:46AM

I did some little work on $ARG in macros in the macrolibrary here:
http://kmeleonbrowser.org/wiki/KmmTraining

I always meant to go further with training(x) series, but never found the time.

Yes, Siria is correct. Always assign the value in $ARG to a variable as soon as possible.

Have you considered this for your menu which is to go away later?

   $RETURN = popupmenu( MENU NAME, VALUE ) ;                                    Since version 75.0

Displays the named menu in actionable or view-only mode.
If VALUE is true, then $RETURN is 1 if successful or 0 if not. (see false below)
Value 	Results
true (1) 	The menu is shown in actionable mode.
false (0) 	The menu is shown in view-only mode and $RETURN will have the menu's numeric id.

Note: A menu's numeric id may be used in the id() statement.

I am trying to find my test macro code now, but have so much old stuff in which I must look. Maybe I will get lucky and find it soon.

Edit:: Some menu stuff in training3.kmm



Edited 1 time(s). Last edit at 04/30/2017 01:50AM by JamesD.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: rodocop
Date: April 30, 2017 04:49AM

You can call me SUPERDUMB but I failed to understand the $ARG even after all these explanations ;-)
(I see how we've got values for most KMM-variables, but not for $ARG - even if I see the code, I cannot realize what exactly is the value of $ARG - and why it's exactly that?! - Sorry, I cannot explain my troubles better )

Also, James, I thought about popupmenu, but stuck with the point that I should create the menu previously with setmenu, but doing so I'm forced to add my new menu to some 'parent' - and... what?

You see, I have some basic 'algorhitmic' problems with some parts of Macrolanguage...


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)



Edited 2 time(s). Last edit at 04/30/2017 04:54AM by rodocop.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: JohnHell
Date: April 30, 2017 05:14AM

I totally forgot $ARG. Maybe I can use to clean code of some of my personal macros


Before macro functions (since K-meleon 75.1), this is, a macro with parameters, there was $ARG.

So, if you call the macro "test" with an $ARG, you are passing parameters to the macro.

Let's see:

test{
     alert($ARG);
}

If you call that macro with test("hello") will bring an alert with the text "hello":

macros(test("hello"))
&test("hello");

As $ARG may be used in several macros as a Global variable, it is recommended to pass it to a variable:
test{
$test_parameter = $ARG;
     alert($test_parameter);
}


About popmenu, I have no idea, but for deleting menus, it was me who asked a couple of years back and Dorian came to help. Here I found it smiling smiley

http://kmeleonbrowser.org/forum/read.php?2,133142

Dorian answer:
http://kmeleonbrowser.org/forum/read.php?2,133142#msg-133158



Edited 3 time(s). Last edit at 04/30/2017 05:46AM by JohnHell.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: rodocop
Date: April 30, 2017 05:17AM

I should describe my particular issue:

I work on creating Pocket button (add page contents to Pocket collection, like in Firefox)

It would be more than easy: just wrap the bookmarklet code with standard macrolanguage shell like KM-firebug for example (or many other extensions made from bookmarklets) if not the one thing:

the Pocket user's bookmarklet is PERSONAL - you should be logged in to get your own unique JS-code.

Well, nothing special - the same problem was solved earlier by jsnj for the LastPassLite extension: there were command added to 'LinkSave' menu to add that bookmarklets (siria should recall - she helped me to get correct JS-code without that '%20'-chars).
And that menu items were grayed out unless the URL of page viewed wasn't equal to that containing personal bookmarklet-links.

What is the problem? That items are present and cluttering Link context menu always - while they are really needed once! (or may be rarely - to update bookmarklets code).

And I've got not single feedback that KM context menus are too bulky even in default config.

So my intention was to create the menu to show it only depending on some conditions

1) only on the page where it can be used
or
2) only if personal code is absent yet.

So I need the way to set and then delete the menu.


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)



Edited 1 time(s). Last edit at 04/30/2017 05:19AM by rodocop.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: rodocop
Date: April 30, 2017 05:29AM

Great, JohnHell!

I remember the thread linked but that time I was unable to understand it fully ;-)
It's sense was sliding away from me as well as the sense of $ARG.

Now I started to slightly understand things


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 30, 2017 05:32AM

Quote
rodocop
(I see how we've got values for most KMM-variables, but not for $ARG - even if I see the code, I cannot realize what exactly is the value of $ARG - and why it's exactly that?!

Also, James, I thought about popupmenu, but stuck with the point that I should create the menu previously with setmenu, but doing so I'm forced to add my new menu to some 'parent' - and... what?

LOL! I believe there exists an effect that something is just TOO easy, when people just cannot imagine this possible grinning smiley
Next try: $ARG is whatever text a MENU author or BUTTON author or SHORTCUT author adds in brackets directly after a macro command, for defining it. For later starting it. Whatever text YOU as author want (with above mentioned restrictions). Not anything from the depths of gecko or something. like $URL or $TITLE. When you create a menu line. Or create a shortcut. Or edit toolbars.cfg. You have to first hardcode it e.g. in the setmenu line. It becomes a fix part of the menu. Ah, now I have it (hopefully): consider it like a commandline in a desktop link! Or a batch command argument?

popupmenu: No. Menus do NOT need a parent for their creation smiling smiley They first exist by themselves, and if wished, can be inserted into a parent menu. OR can be started by popupmenu (or older KM versions rebarmenu-command). Then they popup out of nothing like an alert, just without a window frame around. Like in my permdefs macro.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: rodocop
Date: April 30, 2017 05:45AM

I should sleep on it all now, folks!

Thank you all! Now I really started to get into - for about 50%. Tomorrow things should be better! ;-)


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 30, 2017 05:58AM

BTW, don't mind me sitting here grinning, it's really goodnatured only. Know myself exactly how you feel - when it comes to stuff like javascript! Just a solid wall before me cool smiley

Quote
rodocop
So my intention was to create the menu to show it only depending on some conditions

1) only on the page where it can be used
or
2) only if personal code is absent yet.

So I need the way to set and then delete the menu.

Okay... so want it similar like LastPass? When the user right-clicks on a link, there shall be a new entry?
And your planning to call a checker macro after each page load, via $OnLoad?
- checking if personal code is already set
- if not, then checking if URL is right
- if yes: setmenu to add... / if no, but was created before: setmenu to remove...

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: JohnHell
Date: April 30, 2017 06:03AM

Quote
siria
No. Menus do NOT need a parent for their creation smiling smiley

Mind blowing :S

Now I see it

The commands were optional!!! LOL. I understand now how to create Holders automatically. I always had to add a menu holder (to be used as inline or popup) in menus.cfg for menu items

I suck.

Really, even though that thread I linked when I asked about menus a couple of years back, I still didn't get all the potential of some macro code.

If now I knew what macros could I edit to take benefit of this, I would start editing, but, as rodocop, is quite late and too much to inspect and edit.

(And as I told back in time, if we could change macro code without restarting K-meleon, that would be awesome. Would be time saving.)

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: JohnHell
Date: April 30, 2017 06:08AM

Oh, no, was using popupmenu, forget the above :S

I still don't get XD


Examples, please.



Edited 1 time(s). Last edit at 04/30/2017 06:08AM by JohnHell.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: rodocop
Date: April 30, 2017 06:23AM

Sorry for being that boring, but...
- am I right in the next statement:

if for usual variables we first fill them - and only then use
then for $ARG we first 'reserve the wish' to use it - and only then fill right
in the needed macro call
???

It seems to me that I almost understand JohnHell's example usage (I found the real usage in UndoClosedTabs.kmm)

But I still stay bewildered with such examples (most of them in real macros looks alike):
kmPrefs{
macroinfo=_("Change preferences and settings");
menugrayed=$ARG=="kgestures"?$_kmPrefs_GesturesAbsent:false;
opennew("chrome://kmprefs/content/pref.xul?".$ARG);
}

# PRIVATE
$_kmPrefs_GesturesAbsent=true;
(this is main.kmm)

or this one:
Proxy_Custom{
macroinfo=_("Connect to the Internet over the specified proxy");
menuchecked=(getpref(STRING,$_Proxy_Current)==$ARG)*(getpref(INT,$_Proxy_Type)!=0)*(getpref(INT,$_Proxy_Type)!=4);
menugrayed=!getpref(STRING,$macroPrefBranch.$ARG.".name");
$_proxy=$ARG; getpref(STRING,$macroPrefBranch.$ARG.".name")==""?0:&_Proxy_Custom;
&Proxy_Sync;
}
(proxy.kmm)

I cannot catch the point - what are real values of $ARG in these examples and where they came from?


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)



Edited 2 time(s). Last edit at 04/30/2017 06:25AM by rodocop.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: rodocop
Date: April 30, 2017 06:31AM

siria,

only BIG thanks to you and John and James! No any thought you are grinning! ;-)

Speaking about the macro, it would be enough to check it once for session OnSetup and only check URL OnLoad if personal code isn't there in place (once filled, it should be there all the time unless user wouldn't be forced to specially clear it and get new code).


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)



Edited 2 time(s). Last edit at 04/30/2017 06:34AM by rodocop.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 30, 2017 06:58AM

Quote
rodocop
But I still stay bewildered with such examples (most of them in real macros looks alike):
kmPrefs{
macroinfo=_("Change preferences and settings");
menugrayed=$ARG=="kgestures"?$_kmPrefs_GesturesAbsent:false;
opennew("chrome://kmprefs/content/pref.xul?".$ARG);
}

# PRIVATE
$_kmPrefs_GesturesAbsent=true;
(this is main.kmm)

or this one:
Proxy_Custom{
macroinfo=_("Connect to the Internet over the specified proxy");
menuchecked=(getpref(STRING,$_Proxy_Current)==$ARG)*(getpref(INT,$_Proxy_Type)!=0)*(getpref(INT,$_Proxy_Type)!=4);
menugrayed=!getpref(STRING,$macroPrefBranch.$ARG.".name");
$_proxy=$ARG; getpref(STRING,$macroPrefBranch.$ARG.".name")==""?0:&_Proxy_Custom;
&Proxy_Sync;
}
(proxy.kmm)

I cannot catch the point - what are real values of $ARG in these examples and where they came from?

Ok, those are REALLY harder to understand - even already knowing the basic concept!

kmprefs:
the $ARGs are created some 10 lines lower:
$kBookmarks?setmenu("&Bookmarks",macro,$__o,"kmPrefs(kbookmarks)","bookmarks(Config)"):0;
$kFavorites?setmenu("F&avorites",macro,$__o,"kmPrefs(kfavorites)","favorites(Config)"):0;
$kHotlist?setmenu("H&otlist",macro,$__o,"kmPrefs(khotlist)","hotlist(Config)"):0;
setmenu(Settings,macro,"Mouse &Gestures...","kmPrefs(kgestures)");

What the macro executes, when the user clicks on such a menu line:
opennew("chrome://kmprefs/content/pref.xul?kbookmarks);
opennew("chrome://kmprefs/content/pref.xul?kfavorites);
opennew("chrome://kmprefs/content/pref.xul?khotlist);

The gestures first get a startup check, if gestures-plugin is enabled or not. If not the menu line is grayed out, if yes the macro executes:
opennew("chrome://kmprefs/content/pref.xul?kgestures);

The lines menugrayed and menuchecked always check only if the right side of "=" gives a result of 1 or 0, that is "true" or "false".

Proxy: not 100% sure but think it's $ARGs are simply numbers.
pref: ...proxy1.name or proxy2.name etc.

Quote
rodocop
if for usual variables we first fill them - and only then use
then for $ARG we first 'reserve the wish' to use it - and only then fill right
in the needed macro call
???

Euh... now I am bewildered... cool smiley
Let me put it this way:
then for $ARG we first 'reserve the wish' to use it - and only then fill it right
in the needed macro call

Every macro can be called with an additional parameter in ()
It's optional to then do anything with it or not, when running that macro. To use such a given parameter inside the macro code sure makes sense of course, but it's not necessary for 'definition' or such...

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 30, 2017 07:21AM

Quote
JohnHell
Oh, no, was using popupmenu, forget the above :S
I still don't get XD
Examples, please.

Euh, for what exactly...? Popupmenu?
test{
popupmenu(&Zoom);
}


with or without quotes around menu name? Not sure, test required. Perhaps only if a blank is in the menu name...

Frankly, that thing with a "value" and "id" is too high for me yet.
But luckily not necessary for simple menu popups smiling smiley

Or did you mean setmenu...?

_DocInfoMore_BuildMenu{
$_menu="Images + Background";
setmenu($_menu,macro,"IMG Images",DocInfoMore_imgIMG);
setmenu($_menu,macro,"CSS images",DocInfoMore_imgCSS);
setmenu($_menu,macro,"ALL Images",DocInfoMore_imgALL);
#

setmenu(ImageProperties,popup,$_menu,-1);
setmenu("Page Pro&perties",popup,$_menu,-1);
}


(the last 2 green lines are optional, not necessary)



Edited 3 time(s). Last edit at 04/30/2017 07:37AM by siria.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: JohnHell
Date: April 30, 2017 07:28AM

EDIT: yes, menu creation without addressing it. Without a parent.


The menu creation without addressing.


Let's say we want to create a menu called "aaa" without address it. Is it being created by simply?

setmenu("aaa", macro, "menu item", "macroname");

Is this what it means that a menu is created without address it to another.

With that command is being created a menu item and a new menu "aaa" that later can be addressed to another menu. Is that the way?



Edited 3 time(s). Last edit at 04/30/2017 07:30AM by JohnHell.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 30, 2017 07:37AM

Yes exactly. Have added another example in my post above.
The example may look familiar to you cool smiley (but have it cropped to be an easier example)

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: JohnHell
Date: April 30, 2017 07:45AM

Ok, so no more use of menus.cfg first to create a menu holder for items

Thanks Siria.



Edited 1 time(s). Last edit at 04/30/2017 07:45AM by JohnHell.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: rodocop
Date: April 30, 2017 07:47AM

WOW!


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 30, 2017 08:09AM

Quote
rodocop
WOW!
ROFL!!! That reminds me - the forum could really use a few more default smilies if possible grinning smiley grinning smiley

Glad you're finding menus a bit easier now too! (until the next BUT...)

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: rodocop
Date: April 30, 2017 08:14AM

Quote
siria
ROFL!!! That reminds me - the forum could really use a few more default smilies if possible grinning smiley grinning smiley

Just due to JohnHell and his great macro!


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)



Edited 1 time(s). Last edit at 04/30/2017 08:14AM by rodocop.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 30, 2017 08:10PM

Let me catch the rare opportunity to mention a few other overly complicated constructions, looking like misunderstandings in recent macros, now getting copied again and again by other new macros cool smiley

setclipboard() Mostly not needed!
No need to silently delete a users clipboard contents IF the only purpose is to transfer some selected text on a webpage into a macro variable. There's already an automatically filled variable for this case: $SelectedText
There's still a need for clipboard commands in some cases, but only rarely, mostly to exchange text with other programs.

That flood of endless-long-name-variables! Ouuuff...
That's only necessary if they must be remembered again later during the session.
But in recent years bandworm-names are used even for the tiniest trash variables, a jungle which renders macros so complicated they are hardly readable anymore. At least to me - trees, trees, trees everywhere, nothing but trees, can see no forest anymore ;-)
But if a variable is only needed at the same moment when it's created, inside the same {...} macro module for a quick action, without a need to be remembered again some page loads later, then it's sufficient to use a trash var like $_x (judging from main.kmm, which was written by expert devs). Makes the code a LOT easier to read.
Especially safe for macros, which only get executed manually, when a user calls them actively by menu or button.
Just perhaps, if a macro is executed at the same time as many others, like $OnInit or $OnLoad, and to be absolutely sure newer KM versions don't accidentally confuse anything, it may (?) make sense to give it a more unique name, but for that purpose can be a very short one. And not sure at all if such accidents can even happen or not. Just in case. Also just if in doubt, I'd rather actively empty again such short variables at the end of a {macro} module than confuse myself with bandworm-names in the lines above. But since several years am just using $_menu for initial menu building for ALL my multiline-menus. Didn't notice any probs so far. And main.kmm also still uses simply $__m

togglepref:
Just a little trick for simplification: to get the changed setting into a variable again, instead of adding another getpref line, it can simply be combined to
$_x=togglepref... (see main.kmm)

$RETURN=....
If that result variable is not used for anything, it can just be omitted (popupmenu, injectJS etc.)

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: siria
Date: April 30, 2017 08:53PM

Can't resist posting a little example when it itches in all my 10 fingers to simplify, 4 lines like that:

id("editCopyImageLocation");
$searchimageURL=getclipboard();
$searchimageengineURL="https://domain.com/images/search?rpt=imagelike&url=";
opentab($searchimageengineURL.$searchimageURL);

it does work fine, but requires a lot of thinking. Easier would be:

opentab("https://domain.com/images/search?rpt=imagelike&url=".$ImageURL);

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: JohnHell
Date: May 01, 2017 01:58AM

Quote
siria
setclipboard() Mostly not needed!
No need to silently delete a users clipboard contents IF the only purpose is to transfer some selected text on a webpage into a macro variable. There's already an automatically filled variable for this case: $SelectedText
There's still a need for clipboard commands in some cases, but only rarely, mostly to exchange text with other programs.

Ok, ok, and you know the worst? That it exists since 1.0.

But you can't teach new tricks to an old dog, and with my first versions (0.8x, 0.9x) I started to use the get/set clipboard and... till today.

Another thing to take note to change in my macros.


About the smileys, the problem is that you need server access to upload more. But also I found that there are a few not assigned to any code. There are like 20 not initialized.

Options: ReplyQuote
Re: Macrolanguage usage questions
Posted by: JamesD
Date: May 01, 2017 03:31AM

Quote
JohnHell
(And as I told back in time, if we could change macro code without restarting K-meleon, that would be awesome. Would be time saving.)

Are you making use of Restart2 macro?

Attachments: Restart2.7z (6.4 KB)  
Options: ReplyQuote
Pages: 12Next
Current Page: 1 of 2


K-Meleon forum is powered by Phorum.