From: Daniel Carl Date: Mon, 25 Mar 2013 20:35:38 +0000 (+0100) Subject: Allow to set a default search engine. X-Git-Url: https://git.owens.tech/rss.xml/rss.xml/git?a=commitdiff_plain;h=e14fd191d7223805ffd870e06d8e32d9589381da;p=vimb.git Allow to set a default search engine. Added command searchengine-default to set the handle of the default search engine. --- diff --git a/doc/vimb.1.txt b/doc/vimb.1.txt index 7aa0a49..85d1598 100644 --- a/doc/vimb.1.txt +++ b/doc/vimb.1.txt @@ -255,6 +255,14 @@ Adds a searchengine with the \fISHORTCUT\fP and search \fIURI\fP. The uri must not contain more than one '%s' placeholder. Example: searchengine-add dl=https://duckduckgo.com/lite/?q=%s +.TP +.BI "searchengine-remove " "SHORTCUT" +Remove the search engine to the given \fISHORTCUT\fP. +.TP +.BI "searchengine-default " "SHORTCUT" +Set the search engine for given \fISHORTCUT\fP as the default search engine. +It doesn't metter if the \fISHORTCUT\fP is already in use or not to be able to +set the default search engine. .SS Configuration .TP .BI "set " VAR = VALUE diff --git a/src/command.c b/src/command.c index 89b6b13..09c5766 100644 --- a/src/command.c +++ b/src/command.c @@ -88,6 +88,7 @@ static CommandInfo cmd_list[] = { {"search-backward", command_search, {VB_SEARCH_BACKWARD}}, {"searchengine-add", command_searchengine,{1}}, {"searchengine-remove", command_searchengine,{0}}, + {"searchengine-default", command_searchengine_default,{0}}, {"zoomin", command_zoom, {COMMAND_ZOOM_IN}}, {"zoomout", command_zoom, {COMMAND_ZOOM_OUT}}, {"zoominfull", command_zoom, {COMMAND_ZOOM_IN | COMMAND_ZOOM_FULL}}, @@ -474,6 +475,13 @@ gboolean command_searchengine(const Arg* arg) return result; } +gboolean command_searchengine_default(const Arg* arg) +{ + vb_set_mode(VB_MODE_NORMAL, FALSE); + + return searchengine_set_default(arg->s); +} + gboolean command_zoom(const Arg* arg) { float step, level; diff --git a/src/command.h b/src/command.h index a2aeee2..15e8e1f 100644 --- a/src/command.h +++ b/src/command.h @@ -67,6 +67,7 @@ gboolean command_yank(const Arg* arg); gboolean command_paste(const Arg* arg); gboolean command_search(const Arg* arg); gboolean command_searchengine(const Arg* arg); +gboolean command_searchengine_default(const Arg* arg); gboolean command_zoom(const Arg* arg); gboolean command_history(const Arg* arg); diff --git a/src/config.h b/src/config.h index 7341f9b..16853dd 100644 --- a/src/config.h +++ b/src/config.h @@ -94,6 +94,7 @@ const struct { {"hmap =hint-focus-prev"}, {"searchengine-add dl=https://duckduckgo.com/lite/?q=%s"}, {"searchengine-add dd=https://duckduckgo.com/?q=%s"}, + {"searchengine-default dl"}, {"set images=on"}, {"set cursivfont=serif"}, {"set defaultencondig=utf-8"}, diff --git a/src/main.h b/src/main.h index 76f3829..bb9fd9e 100644 --- a/src/main.h +++ b/src/main.h @@ -258,6 +258,7 @@ typedef struct { GSList* keys; GString* modkeys; GSList* searchengines; + char* searchengine_default; /* handle of the default search engine */ } Behaviour; typedef struct { diff --git a/src/searchengine.c b/src/searchengine.c index a19e076..9eb07cb 100644 --- a/src/searchengine.c +++ b/src/searchengine.c @@ -22,6 +22,11 @@ extern VbCore vb; +typedef struct { + char* handle; + char* uri; +} Searchengine; + static GSList* searchengine_find(const char* handle); static gboolean searchengine_is_valid_uri(const char* uri); static void searchengine_free(Searchengine* se); @@ -64,12 +69,24 @@ gboolean searchengine_remove(const char* handle) return FALSE; } +gboolean searchengine_set_default(const char* handle) +{ + /* do not check if the search engin exists to be able to set the default + * before defining the search engines */ + OVERWRITE_STRING(vb.behave.searchengine_default, handle); + + return TRUE; +} + char* searchengine_get_uri(const char* handle) { - GSList* list = searchengine_find(handle); + char* def = vb.behave.searchengine_default; + GSList* l = searchengine_find(handle); - if (list) { - return ((Searchengine*)list->data)->uri; + if (l) { + return ((Searchengine*)l->data)->uri; + } else if (def && (l = searchengine_find(def))) { + return ((Searchengine*)l->data)->uri; } return NULL; diff --git a/src/searchengine.h b/src/searchengine.h index d9079cc..4645c66 100644 --- a/src/searchengine.h +++ b/src/searchengine.h @@ -20,14 +20,10 @@ #ifndef _SEARCHENGINE_H #define _SEARCHENGINE_H -typedef struct { - char* handle; - char* uri; -} Searchengine; - void searchengine_cleanup(void); gboolean searchengine_add(const char* handle, const char* uri); gboolean searchengine_remove(const char* handle); +gboolean searchengine_set_default(const char* handle); char* searchengine_get_uri(const char* handle); #endif /* end of include guard: _SEARCHENGINE_H */