Extensions :  K-Meleon Web Browser Forum
All about K-Meleon extensions. 
Macro: searchkeywords
Posted by: Borut
Date: June 12, 2019 08:54PM

Description - why this macro:

Support for search from the URL bar, using search keywords, like:
g cookbook
where g is a keyword (for instance for Google) and cookbook is a phrase which is being searched for. Easy way for users to define search keywords.

Installation:

Decide if you want one definition for all K-M user profiles, or separate definitions in each profile. In the first case copy the attached kmm-file into K-M's subdirectory "macros". In the second case copy the kmm-file into "macros" subdirectory located under your wished profile directory (create "macros" subdirectory if not yet existing).

Background:

This is about using search engines directly from the URL bar, via search keywords (like in old Opera Presto, for example).

In http://kmeleonbrowser.org/forum/read.php?19,143253,145560#msg-145560 hermes published a small macro _TEXT_SEARCH_.KMM for using search keywords in URL bar. That macro was the inspiration for searchkeywords.kmm.

However, K-M has in fact a built in support for that, albeit a bit hidden one, as siria explained in: http://kmeleonbrowser.org/forum/read.php?9,149424#msg-149434

So, you may choose. If you do not want to use any of the above, then you might want to try searchkeywords and read further...

Usage:

This macro makes it possible to easily define, change, add, delete and use search keywords. Its definitions can be copied between the profiles too.

First you have to define the keywords. There are two ways to do that. You can use one or the other, or both. If some keywords are the same, those defined in a later way will take precedence.



1) You add something like [kwd] to existing search engine captions. Click on 'Add [keyword] to Search Engine Names', which will bring you to 'Finding Websites'. Select the tab 'Search Engines' there. Then select a line and click on Edit... Add your wished keyword inside [] in the caption text.

2) You define a list of keyword-URL pairs. To do that, click on 'Define Additional Search Keywords' and edit your definitions there. So defined search engines will be accessible only from the URL bar. Remember: Each URL should end with a place where the search phrase will later be inserted.

Finally, click on 'Update Search Keywords (based on the above)' to activate your definitions.

Changelog:
# 2019-06-15 Borut    Two needed prefs; Help; No luck with opentab.
# 2019-06-12 Borut    Alpha

Thanks to:

hermes, siria, JohnHell

This macro is in the alpha phase (as of June 2019). Please try/evaluate at your own risk (well, this is always so) and report problems here.



Edited 1 time(s). Last edit at 06/15/2019 05:07PM by Borut.

Attachments: searchkeywords.jpg (88.5 KB)   searchkeywords.kmm (24.5 KB)  
Options: ReplyQuote
Re: Macro: searchkeywords
Posted by: Borut
Date: June 12, 2019 09:17PM

Here is an example of additional search keywords definition file:

Attachments: keywords_from_user.txt (1.7 KB)  
Options: ReplyQuote
Re: Macro: searchkeywords
Posted by: siria
Date: June 13, 2019 02:26AM

Whoa, congratulations! It shows there went lots and LOTS of work into this sophisticated macro - and even with Help text. Great smiling smiley
Your new menu looks very nice and handy. And your example list too, all keywords together, and easy to copy from one profile to another. What a work...

Perhaps also include the necessary min KM-version, for users of older systems? (Like me, that means I haven't tried that macro in action yet, only taken a deeper look inside the file)

Regarding this main function: searchkeywords_DoSearch
Looks like it's always opening results in the same tab? Some users prefer new tabs, there's a setting somewhere too in F2... or perhaps just add a hint in the help text, for users to change open(url) into opentab(url) if they prefer.

Just one thing... That sentence is misleading:
Quote
Borut
"In K-M no web search keywords are initially defined - using search engines directly from the URL bar is not possible."

They are not initially defined, but that doesn't mean it were impossible. In fact K-Meleon always had a native way to define such search keywords, by adding them as "Nick" name to a bookmark or hotlist entry. The prob is of course, KM doesn't give users any hint about this, or other important things it can do! So everyone just believes it were impossible sad smiley I think those Nick-tricks are explained somewhere in the FAQ, but who studies that endless page (and partly obsolete anyway). And occasionally was mentioned in the forum.
But it must finally be made more obvious in the browser itself. It's overdue since ages that KM includes a few default keywords in the default bookmarks, for users to discover intuitively. BUT: it's 'only' GUI, not engine, sigh. That means no chance in KM. Just one of those age old probs, so unnecessary, so easy to fix, but never done just because it's 'only' GUI stuff and KM has no GUI-dev long since sad smiley And those default bookmarks are only a start, in a second step a hint in the bookmarks editor should be added too somehow, because most users import their own bookmarks and all defaults get lost. But that's more complicated. The extremely easy part is to just add a few search engines with nicks in the default bookmarks.html Or at the very least just the g-Nick to the already existing google search in there.

That's how this native but hidden gem works: the search engines must be defined as bookmarks, or as opera hotlist. And with %s as placeholder for the search terms. And with the keyword in the "Nick" field. That's all. Then typing e.g. "g xxxx" in the urlbar will open a google search for "xxxx"
There are no limits to such Nick shortcuts. Any web address can be opened with a shortcut this way, with or without additional text, not just search engines.
Also any bookmarks/hotlist Folders can get a Nick name too, that will open all bookmarks in that folder at once, just by typing the Nick keyword in the urlbar and hit enter.


(_howto_ search keywords like opera urlbar nick folder)

Anyway, back to your macro.
This is the first (or second?) macro I'm aware of that makes full use of the 'new' functions methods. Am not familiar with this yet, so was very surprised to now discover code inside that looks like pure macrolanguage. So far had assumed 'functions' take only normal javascript. Intriguing that this works (You're now my expert for function macros grinning smiley)

And thanks for teaching me a new syntax trick smiling smiley Wasn't aware that even ancient KM1.x could already glue strings together across linebreaks, by simply using dots. Now seeing this method used in your macro over and over, finally got me wondering, and just tried it with a little test macro - bingo! Works great. So far always thought linebreaks in strings were only possible since KM75.



Edited 1 time(s). Last edit at 06/13/2019 02:29AM by siria.

Attachments: BOOKMARK-keywords_howto.png (11.4 KB)  
Options: ReplyQuote
Re: Macro: searchkeywords
Posted by: hermes
Date: June 13, 2019 07:20AM

@siria

Other way: (macro)
http://kmeleonbrowser.org/forum/read.php?19,143253,145560#msg-145560

Can be changed for any configuration.



Edited 1 time(s). Last edit at 06/13/2019 07:23AM by hermes.

Options: ReplyQuote
Re: Macro: searchkeywords
Posted by: Borut
Date: June 15, 2019 10:45PM

Quote
siria
Perhaps also include the necessary min KM-version, for users of older systems? (Like me, that means I haven't tried that macro in action yet, only taken a deeper look inside the file)
Would this mean no functions (I would not be happy to try that)? And regarding Macrolanguage, which "since version" would apply?

Quote
siria
Looks like it's always opening results in the same tab? Some users prefer new tabs, there's a setting somewhere too in F2... or perhaps just add a hint in the help text, for users to change open(url) into opentab(url) if they prefer.
In this new version I am selecting the open according to the setting, but this is not being obeyed. No idea why. If someone has a solution for that, please report it.

Quote
siria
In fact K-Meleon always had a native way to define such search keywords, by adding them as "Nick" name to a bookmark or hotlist entry. The prob is of course, KM doesn't give users any hint about this, or other important things it can do! So everyone just believes it were impossible sad smiley
Oh, i do not use Bookmarks at all, so I never even saw that dialogue. Otherwise probably would not start writing that macro at all. My starting point was _TEXT_SEARCH_.KMM by hermes. I now changed documentation/help accordingly.

Quote
siria
[...]functions methods. Am not familiar with this yet, so was very surprised to now discover code inside that looks like pure macrolanguage. So far had assumed 'functions' take only normal javascript.
Apparently one can not pass values out via arguments, so only one out-element, via function result itself. (My background is Pascal, so I am used to the possibility of "var" arguments also in functions.)

Options: ReplyQuote
Re: Macro: searchkeywords
Posted by: siria
Date: June 16, 2019 07:28AM

Quote
Borut
Oh, i do not use Bookmarks at all, so I never even saw that dialogue. Otherwise probably would not start writing that macro at all. My starting point was _TEXT_SEARCH_.KMM by hermes. I now changed documentation/help accordingly.

Thank you.
By the way if you're interested, take a look at the SearchDuo macro, one of my endless monstermacros. At the time I had studied intensely the native search functions. Half of it now forgotten again, but it still contains all search methods I know of in SearchOptions>Help

Quote
Borut
In this new version I am selecting the open according to the setting, but this is not being obeyed. No idea why.

Had a look, find nothing wrong with it either. Would it work without functions inside, just macro?

searchkeywords_DoSearch{
$_x=index($URLBAR," ");
if ($_x>0) {
	$_key=substr($URLBAR,0,$_x);
	$_url=iniread($_searchkeywords_cIniSection,$_key,"",$_searchkeywords_sMySettings_Path);
	if ($_url>"") {
		$OpenURL=sub($_key." ",$_url,$URLBAR);
		&_OpenURL_HowST;
}}
$_key=""; $_url="";
}

Quote
Borut
Apparently one can not pass values out via arguments, so only one out-element, via function result itself.

Normal macros have zero problems with vars, they are all shared. But looks like javascript-functions are very restrictive in that regard. Have just lately discovered that prob too, slightly shocked.
Oh... it dawns again... guess in pure JS it depends if the var is global or not? Not sure. Am mostly using trial&error and just look what works when struggling with JS, sigh.
Hmm... return($sResult);
return is usually without (), normal would be "return $sResult;"
Could it be with brackets it's returning "true" instead of the string...?

Thinking about this macro again, have started wondering what happens if a user searches without any keyword. Probably shows an error?



Edited 2 time(s). Last edit at 06/16/2019 08:06AM by siria.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.