Record command history and register after command.
authorDaniel Carl <danielcarl@gmx.de>
Thu, 11 Dec 2014 20:45:39 +0000 (21:45 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Thu, 11 Dec 2014 20:45:39 +0000 (21:45 +0100)
The command to run was written to history and ':' register right before it was
run. This caused :register to show always the register command as last ex
command. Now the command is written to history and register after attempt to
run it.

src/ex.c

index 1290df2..e207c13 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -475,20 +475,23 @@ static void input_activate(void)
 
 VbCmdResult ex_run_string(const char *input)
 {
+    /* copy to have original command for history */
+    const char *in  = input;
     VbCmdResult res = VB_CMD_ERROR;
     ExArg *arg = g_slice_new0(ExArg);
     arg->lhs   = g_string_new("");
     arg->rhs   = g_string_new("");
 
-    vb_register_add(':', input);
-    history_add(HISTORY_COMMAND, input, NULL);
-
-    while (input && *input) {
-        if (!parse(&input, arg) || !(res = execute(arg))) {
-            free_cmdarg(arg);
-            return VB_CMD_ERROR | VB_CMD_KEEPINPUT;
+    while (in && *in) {
+        if (!parse(&in, arg) || !(res = execute(arg))) {
+            res = VB_CMD_ERROR | VB_CMD_KEEPINPUT;
+            break;
         }
     }
+
+    history_add(HISTORY_COMMAND, input, NULL);
+    vb_register_add(':', input);
+
     free_cmdarg(arg);
 
     return res;