summaryrefslogtreecommitdiff
path: root/src/completion.c
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2013-08-14 20:15:06 +0200
committerDaniel Carl <danielcarl@gmx.de>2013-09-20 00:58:07 +0200
commit46f8678f4600ca7c1566f483cbee143ed6294772 (patch)
tree4510df6626f02e5b07e00331a3f81b034442001e /src/completion.c
parent6ae1f47d8eab6229c96f4ff0ec2a51b83aa1ab75 (diff)
Changed the way keys are processed.
Until today vimb mapped two-part keybindings to commands. This patch changed this paradigm into a more vi like way. The commands are separated into normal mode commands that mainly consists of a single char and ex commands that can by typed into the inputbox like ':open'. This change allows us to adapt also the way keypresses and mapping are handled. Now every keypress is converted into a unsigned char and collected into a typeahead queue. The mappings are applied on the queue. So now we can use also long keymaps and run multiple commands for different modes with them like ':nmap abcdef :set scripts!<CR>:open search query<CR>50G'.
Diffstat (limited to 'src/completion.c')
-rw-r--r--src/completion.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/completion.c b/src/completion.c
index 1f8aa14..d3e10df 100644
--- a/src/completion.c
+++ b/src/completion.c
@@ -25,6 +25,7 @@
#include "bookmark.h"
#include "command.h"
#include "setting.h"
+#include "ex.h"
#define TAG_INDICATOR '!'
@@ -54,10 +55,11 @@ gboolean completion_complete(gboolean back)
GtkListStore *store = NULL;
gboolean res = false, sort = true;
+ /* TODO give the type of completion to this function - because we have to
+ * handle also abreviated commands like ':op foo<tab>' */
input = vb_get_input_text();
type = vb_get_input_parts(input, VB_INPUT_ALL, &prefix, &suffix);
-
- if (vb.state.mode & VB_MODE_COMPLETE) {
+ if (vb.mode->flags & FLAG_COMPLETION) {
if (comp.text && !strcmp(input, comp.text)) {
/* step through the next/prev completion item */
move_cursor(back);
@@ -68,12 +70,6 @@ gboolean completion_complete(gboolean back)
completion_clean();
}
- /* don't disturb other command sub modes - complete only if no sub mode
- * is set before */
- if (vb.state.mode != VB_MODE_COMMAND) {
- return false;
- }
-
/* create the list store model */
store = gtk_list_store_new(COMPLETION_STORE_NUM, G_TYPE_STRING, G_TYPE_STRING);
if (type == VB_INPUT_SET) {
@@ -91,7 +87,10 @@ gboolean completion_complete(gboolean back)
/* remove counts before command and save it to print it later in inputbox */
comp.count = g_ascii_strtoll(suffix, &command, 10);
- res = command_fill_completion(store, command);
+ res = ex_fill_completion(store, command);
+ /* we have a special sorting of the ex commands so we don't should
+ * reorder them for the completion */
+ sort = false;
} else if (type == VB_INPUT_SEARCH_FORWARD || type == VB_INPUT_SEARCH_BACKWARD) {
res = history_fill_completion(store, HISTORY_SEARCH, suffix);
} else if (type == VB_INPUT_BOOKMARK_ADD) {
@@ -107,7 +106,8 @@ gboolean completion_complete(gboolean back)
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COMPLETION_STORE_FIRST, GTK_SORT_ASCENDING);
}
- vb_set_mode(VB_MODE_COMMAND | VB_MODE_COMPLETE, false);
+ /* set the submode flag */
+ vb.mode->flags |= FLAG_COMPLETION;
OVERWRITE_STRING(comp.prefix, prefix);
init_completion(GTK_TREE_MODEL(store));
@@ -118,16 +118,18 @@ gboolean completion_complete(gboolean back)
void completion_clean(void)
{
- if (comp.win) {
- gtk_widget_destroy(comp.win);
- comp.win = comp.tree = NULL;
- }
- OVERWRITE_STRING(comp.prefix, NULL);
- OVERWRITE_STRING(comp.text, NULL);
- comp.count = 0;
+ if (vb.mode->flags & FLAG_COMPLETION) {
+ /* remove completion flag from mode */
+ vb.mode->flags &= ~FLAG_COMPLETION;
- /* remove completion flag from mode */
- vb.state.mode &= ~VB_MODE_COMPLETE;
+ if (comp.win) {
+ gtk_widget_destroy(comp.win);
+ comp.win = comp.tree = NULL;
+ }
+ OVERWRITE_STRING(comp.prefix, NULL);
+ OVERWRITE_STRING(comp.text, NULL);
+ comp.count = 0;
+ }
}
static void init_completion(GtkTreeModel *model)