From 2bf1f59c07642af9689b8b4ffa0debefd6b07a0e Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sat, 27 Apr 2013 18:06:56 +0200 Subject: [PATCH] Renamed searchengine to shortcut. The feature isn't only useful for searchengines but also in general for structured urls. An if the placeholder will be optional, we can use this to store also url quickmarks. --- README.md | 1 + doc/vimb.1.txt | 22 ++++++++------ src/command.c | 20 ++++++------- src/command.h | 4 +-- src/config.h | 6 ++-- src/main.c | 8 ++--- src/{searchengine.c => shortcut.c} | 48 +++++++++++++++--------------- src/{searchengine.h => shortcut.h} | 16 +++++----- 8 files changed, 65 insertions(+), 60 deletions(-) rename src/{searchengine.c => shortcut.c} (63%) rename src/{searchengine.h => shortcut.h} (67%) diff --git a/README.md b/README.md index 1c6a2ea..e58cc8b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ browsing-experience with low memory and cpu usage. - custom configuration files - tagged bookmarks - open input or teaxteaeas with configurable external editor +- user defined URL-shortcuts with placeholders ## Dependencies - libwebkit-1.0 diff --git a/doc/vimb.1.txt b/doc/vimb.1.txt index 18b1111..2ceffd6 100644 --- a/doc/vimb.1.txt +++ b/doc/vimb.1.txt @@ -1,3 +1,4 @@ +.\" vim: ft=groff .\" Process this file with .\" groff -man -Tascii vimb.1 .TH PROJECT 1 "06/04/2013" "PROJECT/VERSION" "Vimb Manual" @@ -249,21 +250,24 @@ Yank the current url to the primary and secondary clipboard. .TP .B yank-selection Yank the selected text into the primary and secondary clipboard. -.SS Searchengines -Searchengines allows to query a searchengine instead of typing a full url. If -a searchengine with shortcut 'dd' is defined you can use 'dd search terms' to -perform a search query. +.SS Shortcuts +Shortcuts allows to open URL build up from a named tamplate with additional +parameters. If a sortcut named 'dd' is defined, you can use it with `:open dd +list of parameters' to open the generated URL. + +Shortcuts are a good to use searchengines where the URL is nearly the same but +a single parameter is user diefined. .TP -.BI "searchengine-add " "SHORTCUT" "=" "URI" -Adds a searchengine with the \fISHORTCUT\fP and search \fIURI\fP. The uri must +.BI "shortcut-add " "SHORTCUT" "=" "URI" +Adds a shortcut 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 +Example: shortcut-add dl=https://duckduckgo.com/lite/?q=%s .TP -.BI "searchengine-remove " "SHORTCUT" +.BI "shortcut-remove " "SHORTCUT" Remove the search engine to the given \fISHORTCUT\fP. .TP -.BI "searchengine-default " "SHORTCUT" +.BI "shortcut-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. diff --git a/src/command.c b/src/command.c index 08bb8dd..0a62612 100644 --- a/src/command.c +++ b/src/command.c @@ -24,7 +24,7 @@ #include "completion.h" #include "hints.h" #include "util.h" -#include "searchengine.h" +#include "shortcut.h" #include "history.h" #include "bookmark.h" #include "dom.h" @@ -93,9 +93,9 @@ static CommandInfo cmd_list[] = { {"tabopen-clipboard", command_paste, {VB_CLIPBOARD_PRIMARY | VB_CLIPBOARD_SECONDARY | VB_TARGET_NEW}}, {"search-forward", command_search, {VB_SEARCH_FORWARD}}, {"search-backward", command_search, {VB_SEARCH_BACKWARD}}, - {"searchengine-add", command_searchengine, {1}}, - {"searchengine-remove", command_searchengine, {0}}, - {"searchengine-default", command_searchengine_default, {0}}, + {"shortcut-add", command_shortcut, {1}}, + {"shortcut-remove", command_shortcut, {0}}, + {"shortcut-default", command_shortcut_default, {0}}, {"zoomin", command_zoom, {COMMAND_ZOOM_IN}}, {"zoomout", command_zoom, {COMMAND_ZOOM_OUT}}, {"zoominfull", command_zoom, {COMMAND_ZOOM_IN | COMMAND_ZOOM_FULL}}, @@ -529,7 +529,7 @@ gboolean command_search(const Arg *arg) return true; } -gboolean command_searchengine(const Arg *arg) +gboolean command_shortcut(const Arg *arg) { gboolean result; if (arg->i) { @@ -538,13 +538,13 @@ gboolean command_searchengine(const Arg *arg) if ((handle = strchr(arg->s, '='))) { *handle = '\0'; handle++; - result = searchengine_add(arg->s, handle); + result = shortcut_add(arg->s, handle); } else { return false; } } else { - /* remove the search engine */ - result = searchengine_remove(arg->s); + /* remove the shortcut */ + result = shortcut_remove(arg->s); } vb_set_mode(VB_MODE_NORMAL, false); @@ -552,11 +552,11 @@ gboolean command_searchengine(const Arg *arg) return result; } -gboolean command_searchengine_default(const Arg *arg) +gboolean command_shortcut_default(const Arg *arg) { vb_set_mode(VB_MODE_NORMAL, false); - return searchengine_set_default(arg->s); + return shortcut_set_default(arg->s); } gboolean command_zoom(const Arg *arg) diff --git a/src/command.h b/src/command.h index a526e03..fb50ba7 100644 --- a/src/command.h +++ b/src/command.h @@ -69,8 +69,8 @@ gboolean command_hints_focus(const Arg *arg); 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_shortcut(const Arg *arg); +gboolean command_shortcut_default(const Arg *arg); gboolean command_zoom(const Arg *arg); gboolean command_history(const Arg *arg); gboolean command_bookmark(const Arg *arg); diff --git a/src/config.h b/src/config.h index 68d850c..838ffff 100644 --- a/src/config.h +++ b/src/config.h @@ -92,9 +92,9 @@ const char *default_config[] = { "cmap =hist-prev", "cmap =hist-next", "imap =editor", - "searchengine-add dl=https://duckduckgo.com/lite/?q=%s", - "searchengine-add dd=https://duckduckgo.com/?q=%s", - "searchengine-default dl", + "shortcut-add dl=https://duckduckgo.com/lite/?q=%s", + "shortcut-add dd=https://duckduckgo.com/?q=%s", + "shortcut-default dl", "set images=on", "set cursivfont=serif", "set defaultencondig=utf-8", diff --git a/src/main.c b/src/main.c index 2146103..862e29f 100644 --- a/src/main.c +++ b/src/main.c @@ -28,7 +28,7 @@ #include "completion.h" #include "dom.h" #include "hints.h" -#include "searchengine.h" +#include "shortcut.h" #include "history.h" #include "session.h" @@ -144,8 +144,8 @@ gboolean vb_load_uri(const Arg *arg) uri = g_strdup_printf("file://%s", rp); free(rp); } else if (!strchr(path, '.')) { - /* use a searchengine */ - uri = searchengine_get_uri(path); + /* use a shortcut */ + uri = shortcut_get_uri(path); } if (!uri) { @@ -1000,7 +1000,7 @@ static void destroy_client() command_cleanup(); setting_cleanup(); keybind_cleanup(); - searchengine_cleanup(); + shortcut_cleanup(); history_cleanup(); for (int i = 0; i < FILES_LAST; i++) { diff --git a/src/searchengine.c b/src/shortcut.c similarity index 63% rename from src/searchengine.c rename to src/shortcut.c index 0724dd6..1b22b03 100644 --- a/src/searchengine.c +++ b/src/shortcut.c @@ -18,7 +18,7 @@ */ #include "main.h" -#include "searchengine.h" +#include "shortcut.h" #include "util.h" extern VbCore vb; @@ -26,45 +26,45 @@ extern VbCore vb; typedef struct { char *handle; char *uri; -} Searchengine; +} Shortcut; -static GSList *searchengines; +static GSList *shortcuts; static char *default_handle = NULL; static GSList *find(const char *handle); -static void free_searchengine(Searchengine *se); +static void free_shortcut(Shortcut *se); -void searchengine_cleanup(void) +void shortcut_cleanup(void) { - if (searchengines) { - g_slist_free_full(searchengines, (GDestroyNotify)free_searchengine); + if (shortcuts) { + g_slist_free_full(shortcuts, (GDestroyNotify)free_shortcut); } } -gboolean searchengine_add(const char *handle, const char *uri) +gboolean shortcut_add(const char *handle, const char *uri) { /* validate if the uri contains only one %s sequence */ if (!util_valid_format_string(uri, 's', 1)) { return false; } - Searchengine *s = g_new0(Searchengine, 1); + Shortcut *s = g_new0(Shortcut, 1); s->handle = g_strdup(handle); s->uri = g_strdup(uri); - searchengines = g_slist_prepend(searchengines, s); + shortcuts = g_slist_prepend(shortcuts, s); return true; } -gboolean searchengine_remove(const char *handle) +gboolean shortcut_remove(const char *handle) { GSList *list = find(handle); if (list) { - free_searchengine((Searchengine*)list->data); - searchengines = g_slist_delete_link(searchengines, list); + free_shortcut((Shortcut*)list->data); + shortcuts = g_slist_delete_link(shortcuts, list); return true; } @@ -72,20 +72,20 @@ gboolean searchengine_remove(const char *handle) return false; } -gboolean searchengine_set_default(const char *handle) +gboolean shortcut_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 */ + /* do not check if the shotcut exists to be able to set the default + * before defining the shotcut */ OVERWRITE_STRING(default_handle, handle); return true; } /** - * Retrieves the search uri for given query string. - * Not that the memory of the returned uri must be freed. + * Retrieves the uri for given query string. Not that the memory of the + * returned uri must be freed. */ -char *searchengine_get_uri(const char *string) +char *shortcut_get_uri(const char *string) { GSList *l = NULL; char *p = NULL, *tmpl = NULL, *query = NULL, *uri = NULL; @@ -94,7 +94,7 @@ char *searchengine_get_uri(const char *string) *p = '\0'; /* is the first word the handle? */ if ((l = find(string))) { - tmpl = ((Searchengine*)l->data)->uri; + tmpl = ((Shortcut*)l->data)->uri; query = soup_uri_encode(p + 1, "&"); } else { *p = ' '; @@ -102,7 +102,7 @@ char *searchengine_get_uri(const char *string) } if (!tmpl && (l = find(default_handle))) { - tmpl = ((Searchengine*)l->data)->uri; + tmpl = ((Shortcut*)l->data)->uri; query = soup_uri_encode(string, "&"); } @@ -119,8 +119,8 @@ char *searchengine_get_uri(const char *string) static GSList *find(const char *handle) { GSList *s; - for (s = searchengines; s != NULL; s = s->next) { - if (!strcmp(((Searchengine*)s->data)->handle, handle)) { + for (s = shortcuts; s != NULL; s = s->next) { + if (!strcmp(((Shortcut*)s->data)->handle, handle)) { return s; } } @@ -128,7 +128,7 @@ static GSList *find(const char *handle) return NULL; } -static void free_searchengine(Searchengine *se) +static void free_shortcut(Shortcut *se) { g_free(se->uri); g_free(se->handle); diff --git a/src/searchengine.h b/src/shortcut.h similarity index 67% rename from src/searchengine.h rename to src/shortcut.h index a0b876b..f55de7f 100644 --- a/src/searchengine.h +++ b/src/shortcut.h @@ -17,13 +17,13 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -#ifndef _SEARCHENGINE_H -#define _SEARCHENGINE_H +#ifndef _SHORTCUT_H +#define _SHORTCUT_H -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); +void shortcut_cleanup(void); +gboolean shortcut_add(const char *handle, const char *uri); +gboolean shortcut_remove(const char *handle); +gboolean shortcut_set_default(const char *handle); +char *shortcut_get_uri(const char *handle); -#endif /* end of include guard: _SEARCHENGINE_H */ +#endif /* end of include guard: _SHORTCUT_H */ -- 2.20.1