Re: Search from address bar
Johannes Hofmann <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, On Mon, Jun 17, 2013 at 03:16:09PM +0300, Aki Helin wrote: > Hi, > > Currently when using a window manager where focus follows mouse, making a > search usually requires you to reach for the mouse. One way to avoid this > would be to allow using search engine(s) directly from the address bar. > > Searches would have to be differentiated somehow from URLs. Dillo already > has a customizable list of engines in preferences, so one natural solution > would be to interpret url strings which start with the name of a search > engine as searches to be performed using it, so that e.g. 'wikipedia > slartibartfast', 'google foo' and 'weather oulu' do what you would expect. > > Below is a quick patch I've used to do this for a while, should anyone > else find this feature useful. This has been discussed before, but somehow wasn't completed. I like your idea to reuse the search engine name to derive the shortcut. However, I would allow arbitrary prefixes of the search engine name as in the slightly modified patch below. What do you think? Cheers, Johannes _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
loc_search.diff
(text/plain, 2.4 KB)
diff -r 2e5d8e14618c dillorc
--- a/dillorc Mon Jun 17 20:51:36 2013 +0200
+++ b/dillorc Mon Jun 17 21:34:09 2013 +0200
@@ -146,7 +146,7 @@
# Format: search_url="[<label> ]<url>"
# You can enable multiple search_url strings at once and select from among
# them at runtime, with the first being the default.
-search_url="http://duckduckgo.com/lite/?kp=-1&q=%s"
+search_url="DuckDuckGo http://duckduckgo.com/lite/?kp=-1&q=%s"
search_url="Wikipedia http://www.wikipedia.org/w/index.php?search=%s&go=Go"
search_url="Free Dictionary http://www.thefreedictionary.com/%s"
search_url="Google http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=%s"
diff -r 2e5d8e14618c src/uicmd.cc
--- a/src/uicmd.cc Mon Jun 17 20:51:36 2013 +0200
+++ b/src/uicmd.cc Mon Jun 17 21:34:09 2013 +0200
@@ -70,6 +70,7 @@
*/
static BrowserWindow *UIcmd_tab_new(CustTabs *tabs, UI *old_ui, int focus);
static void close_tab_btn_cb (Fl_Widget *w, void *cb_data);
+static char *UIcmd_make_search_str(const char *str);
//----------------------------------------------------------------------------
@@ -649,6 +650,29 @@
}
/*
+ * Return a search string of the suffix if str starts with a
+ * prefix of a search engine name and a blank
+ */
+static char *UIcmd_find_search_str(const char *str)
+{
+ int end = dList_length(prefs.search_urls);
+ int p = 0;
+ char *url = NULL;
+ int len = strcspn(str, " ");
+
+ while (len > 0 && str[len + 1] != '\0' && p < end && !url) {
+ char *search = (char *)dList_nth_data(prefs.search_urls, p);
+ int res = strncasecmp(str, search, len);
+ if (res == 0) {
+ prefs.search_url_idx = p;
+ url = UIcmd_make_search_str(str + len);
+ }
+ p++;
+ }
+ return url;
+}
+
+/*
* Open a new URL in the given browser window.
*
* our custom "file:" URIs are normalized here too.
@@ -656,10 +680,14 @@
void a_UIcmd_open_urlstr(void *vbw, const char *urlstr)
{
char *new_urlstr;
+ char *search_urlstr = NULL;
DilloUrl *url;
int ch;
BrowserWindow *bw = (BrowserWindow*)vbw;
+ if ((search_urlstr = UIcmd_find_search_str(urlstr))) {
+ urlstr = search_urlstr;
+ }
if (urlstr && *urlstr) {
/* Filter URL string */
new_urlstr = a_Url_string_strip_delimiters(urlstr);
@@ -680,6 +708,8 @@
url = a_Url_new(new_urlstr, NULL);
}
dFree(new_urlstr);
+ if (search_urlstr)
+ dFree(search_urlstr);
if (url) {
a_UIcmd_open_url(bw, url);