From: Daniel Carl Date: Mon, 12 Nov 2012 18:38:21 +0000 (+0100) Subject: Allow to set mode after command. X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=e4972e2c5dbb1512ad19abb4a621b90136d46e2e;p=vimb.git Allow to set mode after command. Now we can set the mode to switch to, for every command. Doing this allows to use commands like :input also from inputbox. --- diff --git a/src/command.c b/src/command.c index f6a59ac..c5699b9 100644 --- a/src/command.c +++ b/src/command.c @@ -27,37 +27,37 @@ extern const char *inputbox_fg[2]; extern const char *inputbox_bg[2]; static CommandInfo cmd_list[] = { - /* command function arg */ - {"open", command_open, {VP_MODE_NORMAL, ""}}, - {"input", command_input, {0, ":"}}, - {"inputopen", command_input, {0, ":open "}}, - {"inputopencurrent", command_input, {VP_INPUT_CURRENT_URI, ":open "}}, - {"quit", command_close, {0}}, - {"source", command_view_source, {0}}, - {"back", command_navigate, {VP_NAVIG_BACK}}, - {"forward", command_navigate, {VP_NAVIG_FORWARD}}, - {"reload", command_navigate, {VP_NAVIG_RELOAD}}, - {"reload!", command_navigate, {VP_NAVIG_RELOAD_FORCE}}, - {"stop", command_navigate, {VP_NAVIG_STOP_LOADING}}, - {"jumpleft", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_LEFT}}, - {"jumpright", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_RIGHT}}, - {"jumptop", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_TOP}}, - {"jumpbottom", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_DOWN}}, - {"pageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_PAGE}}, - {"pagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_PAGE}}, - {"halfpageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_HALFPAGE}}, - {"halfpagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_HALFPAGE}}, - {"scrollleft", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_LEFT | VP_SCROLL_UNIT_LINE}}, - {"scrollright", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_RIGHT | VP_SCROLL_UNIT_LINE}}, - {"scrollup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_LINE}}, - {"scrolldown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_LINE}}, - {"nmap", command_map, {VP_MODE_NORMAL}}, - {"imap", command_map, {VP_MODE_INSERT}}, - {"cmap", command_map, {VP_MODE_COMMAND}}, - {"nunmap", command_unmap, {VP_MODE_NORMAL}}, - {"iunmap", command_unmap, {VP_MODE_INSERT}}, - {"cunmap", command_unmap, {VP_MODE_COMMAND}}, - {"set", command_set, {0}}, + /* command function arg mode */ + {"open", command_open, {VP_MODE_NORMAL, ""}, VP_MODE_NORMAL}, + {"input", command_input, {0, ":"}, VP_MODE_COMMAND}, + {"inputopen", command_input, {0, ":open "}, VP_MODE_COMMAND}, + {"inputopencurrent", command_input, {VP_INPUT_CURRENT_URI, ":open "}, VP_MODE_NORMAL}, + {"quit", command_close, {0}, VP_MODE_NORMAL}, + {"source", command_view_source, {0}, VP_MODE_NORMAL}, + {"back", command_navigate, {VP_NAVIG_BACK}, VP_MODE_NORMAL}, + {"forward", command_navigate, {VP_NAVIG_FORWARD}, VP_MODE_NORMAL}, + {"reload", command_navigate, {VP_NAVIG_RELOAD}, VP_MODE_NORMAL}, + {"reload!", command_navigate, {VP_NAVIG_RELOAD_FORCE}, VP_MODE_NORMAL}, + {"stop", command_navigate, {VP_NAVIG_STOP_LOADING}, VP_MODE_NORMAL}, + {"jumpleft", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_LEFT}, VP_MODE_NORMAL}, + {"jumpright", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_RIGHT}, VP_MODE_NORMAL}, + {"jumptop", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_TOP}, VP_MODE_NORMAL}, + {"jumpbottom", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_DOWN}, VP_MODE_NORMAL}, + {"pageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_PAGE}, VP_MODE_NORMAL}, + {"pagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_PAGE}, VP_MODE_NORMAL}, + {"halfpageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_HALFPAGE}, VP_MODE_NORMAL}, + {"halfpagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_HALFPAGE}, VP_MODE_NORMAL}, + {"scrollleft", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_LEFT | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL}, + {"scrollright", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_RIGHT | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL}, + {"scrollup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL}, + {"scrolldown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_LINE}, VP_MODE_NORMAL}, + {"nmap", command_map, {VP_MODE_NORMAL}, VP_MODE_NORMAL}, + {"imap", command_map, {VP_MODE_INSERT}, VP_MODE_NORMAL}, + {"cmap", command_map, {VP_MODE_COMMAND}, VP_MODE_NORMAL}, + {"nunmap", command_unmap, {VP_MODE_NORMAL}, VP_MODE_NORMAL}, + {"iunmap", command_unmap, {VP_MODE_INSERT}, VP_MODE_NORMAL}, + {"cunmap", command_unmap, {VP_MODE_COMMAND}, VP_MODE_NORMAL}, + {"set", command_set, {0}, VP_MODE_NORMAL}, }; void command_init(void) @@ -99,6 +99,7 @@ gboolean command_run(const gchar* name, const gchar* param) /* if command was run, remove the modkey and count */ vp.state.modkey = vp.state.count = 0; + vp.state.mode = c->mode; vp_update_statusbar(); return result; diff --git a/src/command.h b/src/command.h index 5cb7d8b..25a8616 100644 --- a/src/command.h +++ b/src/command.h @@ -25,7 +25,8 @@ typedef gboolean (*Command)(const Arg* arg); typedef struct { const gchar* name; Command function; - const Arg arg; + const Arg arg; /* arguments to call the command with */ + const Mode mode; /* mode to set after running the command */ } CommandInfo; diff --git a/src/main.c b/src/main.c index 49407cd..3418ecc 100644 --- a/src/main.c +++ b/src/main.c @@ -113,13 +113,11 @@ static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data) completion_clean(); success = vp_process_input((text + 1)); if (!success) { - /* switch to normal mode after running command */ + /* switch to normal mode after running command without success the + * mode after success is set by command_run to the value defined + * for the command */ Arg a = {VP_MODE_NORMAL}; vp_set_mode(&a); - } else { - /* switch to normal mode after running command and clean input */ - Arg a = {VP_MODE_NORMAL, ""}; - vp_set_mode(&a); } } } diff --git a/src/main.h b/src/main.h index a0592c0..48542fc 100644 --- a/src/main.h +++ b/src/main.h @@ -45,6 +45,7 @@ #define GET_TEXT() (gtk_entry_get_text(GTK_ENTRY(vp.gui.inputbox))) #define CLEAN_MODE(mode) ((mode) & ~(VP_MODE_COMPLETE)) +#define CLEAR_INPUT() (vp_echo(VP_MSG_NORMAL, "")) /* enums */ typedef enum _vp_mode {