From 73072c673dcfa0b486f1c31e57e30fdb7551f464 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sun, 29 Sep 2013 01:02:54 +0200 Subject: [PATCH] Used typed input for completions. No the completion does not write the full command name into inputbox if the command was found. Instead write the prefix like it was typed by the user like in vim. That means if an abbreviated command is completed, the abbreviated version is shown for example for ':o !'. --- src/ex.c | 49 +++++++++++++++++++++++-------------------------- src/main.h | 1 + 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/ex.c b/src/ex.c index 212186e..3946970 100644 --- a/src/ex.c +++ b/src/ex.c @@ -836,7 +836,6 @@ static gboolean ex_shortcut(const ExArg *arg) */ static gboolean ex_complete(short direction) { - char prefix[2] = {0}; char *input; /* input read from inputbox */ const char *in; /* pointer to input that we move */ gboolean found = false; @@ -886,31 +885,31 @@ static gboolean ex_complete(short direction) before_cmdname = in; if (parse_command_name(&in, arg) && *in == ' ') { + OVERWRITE_NSTRING(excomp.prefix, input, in - input + 1); + skip_whitespace(&in); - if (arg->code == EX_SET) { - if (setting_fill_completion(store, in)) { - /* TODO calculate the prefix automatically */ - OVERWRITE_STRING(excomp.prefix, ":set "); - sort = true; - found = true; - } - } else if (arg->code == EX_OPEN || arg->code == EX_TABOPEN) { - OVERWRITE_STRING(excomp.prefix, arg->code == EX_OPEN ? ":open " : ":tabopen "); - if (*in == '!') { - if (bookmark_fill_completion(store, in + 1)) { - found = true; + switch (arg->code) { + case EX_OPEN: + case EX_TABOPEN: + if (*in == '!') { + found = bookmark_fill_completion(store, in + 1); + } else { + found = history_fill_completion(store, HISTORY_URL, in); } - } else { - if (history_fill_completion(store, HISTORY_URL, in)) { - found = true; - } - } - } else if (arg->code == EX_BMA) { - if (bookmark_fill_tag_completion(store, in)) { - OVERWRITE_STRING(excomp.prefix, ":bma "); + break; + + case EX_SET: + sort = true; + found = setting_fill_completion(store, in); + break; + + case EX_BMR: sort = true; - found = true; - } + found = bookmark_fill_tag_completion(store, in); + break; + + default: + break; } } else { /* complete command names */ /* restore the 'in' pointer after try to parse command name */ @@ -927,10 +926,8 @@ static gboolean ex_complete(short direction) } free_cmdarg(arg); } else if (*in == '/' || *in == '?') { - prefix[0] = *in; - if (history_fill_completion(store, HISTORY_SEARCH, in + 1)) { - OVERWRITE_STRING(excomp.prefix, prefix); + OVERWRITE_NSTRING(excomp.prefix, in, 1); sort = true; found = true; } diff --git a/src/main.h b/src/main.h index aa53829..89edfd0 100644 --- a/src/main.h +++ b/src/main.h @@ -66,6 +66,7 @@ #define SECONDARY_CLIPBOARD() gtk_clipboard_get(GDK_NONE) #define OVERWRITE_STRING(t, s) {if (t) {g_free(t); t = NULL;} t = g_strdup(s);} +#define OVERWRITE_NSTRING(t, s, l) {if (t) {g_free(t); t = NULL;} t = g_strndup(s, l);} #define FILE_LOCK_SET(fd, cmd) \ { \ -- 2.20.1