From: Daniel Carl Date: Sat, 27 Oct 2012 11:21:37 +0000 (+0200) Subject: Use commands to add and remove keybindings. X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=6843d09111711002dfc51144ed984f2e9fc76bb0;p=vimb.git Use commands to add and remove keybindings. Doing it in this way, it is possible to easily set keybindings from input line and we have a single logic to read imput line and config files. --- diff --git a/src/command.c b/src/command.c index 2764bd2..ca0e46d 100644 --- a/src/command.c +++ b/src/command.c @@ -27,6 +27,12 @@ static CommandInfo cmd_list[] = { {"scrollright", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_RIGHT | VP_SCROLL_UNIT_LINE}}, {"scrollup", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_LINE}}, {"scrolldown", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_LINE}}, + {"nmap", vp_map, {VP_MODE_NORMAL}}, + {"imap", vp_map, {VP_MODE_INSERT}}, + {"cmap", vp_map, {VP_MODE_COMMAND}}, + {"nunmap", vp_unmap, {VP_MODE_NORMAL}}, + {"iunmap", vp_unmap, {VP_MODE_INSERT}}, + {"cunmap", vp_unmap, {VP_MODE_COMMAND}}, }; void command_init() diff --git a/src/main.c b/src/main.c index 0de0f8b..e6bd1fa 100644 --- a/src/main.c +++ b/src/main.c @@ -48,9 +48,8 @@ static void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec, gp static void vp_webview_load_commited_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data) { - /* unset possible set modkey and counts if loading a new page */ - vp.state.modkey = vp.state.count = 0; - vp_update_statusbar(); + Arg a = {VP_MODE_NORMAL}; + vp_set_mode(&a); } static void vp_destroy_window_cb(GtkWidget* widget, GtkWidget* window, gpointer user_data) @@ -236,6 +235,16 @@ void vp_view_source(const Arg* arg) webkit_web_view_reload(vp.gui.webview); } +void vp_map(const Arg* arg) +{ + keybind_add_from_string(arg->s, arg->i); +} + +void vp_unmap(const Arg* arg) +{ + keybind_remove_from_string(arg->s, arg->i); +} + void vp_set_mode(const Arg* arg) { vp.state.mode = arg->i; @@ -376,7 +385,6 @@ static void vp_read_config(void) { FILE* fp; gchar line[255]; - gchar** string = NULL; if (access(vp.files[FILES_CONFIG], F_OK) != 0) { fprintf(stderr, "Could not find config file"); @@ -391,23 +399,7 @@ static void vp_read_config(void) if (!g_ascii_isalpha(line[0])) { continue; } - g_strstrip(line); - - /* split into command and params */ - string = g_strsplit(line, " ", 2); - if (g_strv_length(string) != 2) { - g_strfreev(string); - continue; - } - - /* delegate the different commands */ - if (g_ascii_strcasecmp(string[0], "nmap") == 0) { - keybind_add_from_string(string[1], VP_MODE_NORMAL); - } else if (g_ascii_strcasecmp(string[0], "unmap") == 0) { - keybind_remove_from_string(string[1], VP_MODE_NORMAL); - } - - g_strfreev(string); + vp_process_input(line); } fclose(fp); diff --git a/src/main.h b/src/main.h index 692354b..33be7f3 100644 --- a/src/main.h +++ b/src/main.h @@ -145,6 +145,8 @@ void vp_scroll(const Arg* arg); void vp_close_browser(const Arg* arg); void vp_clean_up(void); void vp_view_source(const Arg* arg); +void vp_map(const Arg* arg); +void vp_unmap(const Arg* arg); void vp_set_mode(const Arg* arg); void vp_input(const Arg* arg); void vp_open(const Arg* arg);