Used typed input for completions.
authorDaniel Carl <danielcarl@gmx.de>
Sat, 28 Sep 2013 23:02:54 +0000 (01:02 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 28 Sep 2013 23:02:54 +0000 (01:02 +0200)
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 !<Tab>'.

src/ex.c
src/main.h

index 212186e..3946970 100644 (file)
--- 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;
         }
index aa53829..89edfd0 100644 (file)
@@ -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) \
 { \