Fixed none shown command error if used by :source command.
authorDaniel Carl <danielcarl@gmx.de>
Mon, 21 Sep 2015 09:00:45 +0000 (11:00 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 21 Sep 2015 09:01:11 +0000 (11:01 +0200)
Also clear the input after successful sourcing of a file.

src/ex.c
src/ex.h
src/main.c

index cbd1bd3..56634f2 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -504,29 +504,32 @@ VbCmdResult ex_run_string(const char *input, gboolean enable_history)
 /**
  * Run all ex commands in a file.
  */
-gboolean ex_run_file(const char *filename)
+VbCmdResult ex_run_file(const char *filename)
 {
     char *line, **lines;
+    VbCmdResult res = VB_CMD_SUCCESS;
 
     lines = util_get_lines(filename);
 
     if (!lines) {
-        return false;
+        return res;
     }
 
     int length = g_strv_length(lines) - 1;
     for (int i = 0; i < length; i++) {
         line = lines[i];
-        if (*line == '#') {
+        /* skip commented or empty lines */
+        if (*line == '#' || !*line) {
             continue;
         }
-        if (ex_run_string(line, false) & VB_CMD_ERROR) {
+        if ((ex_run_string(line, false) & ~VB_CMD_KEEPINPUT) == VB_CMD_ERROR) {
+            res = VB_CMD_ERROR | VB_CMD_KEEPINPUT;
             g_warning("Invalid command in %s: '%s'", filename, line);
         }
     }
     g_strfreev(lines);
 
-    return true;
+    return res;
 }
 
 /**
@@ -1018,7 +1021,7 @@ static VbCmdResult ex_shellcmd(const ExArg *arg)
 
 static VbCmdResult ex_source(const ExArg *arg)
 {
-    return ex_run_file(arg->rhs->str) ? VB_CMD_SUCCESS | VB_CMD_KEEPINPUT : VB_CMD_ERROR;
+    return ex_run_file(arg->rhs->str);
 }
 
 static VbCmdResult ex_handlers(const ExArg *arg)
index cd3dccb..cbd1281 100644 (file)
--- a/src/ex.h
+++ b/src/ex.h
@@ -29,6 +29,6 @@ VbResult ex_keypress(int key);
 void ex_input_changed(const char *text);
 gboolean ex_fill_completion(GtkListStore *store, const char *input);
 VbCmdResult ex_run_string(const char *input, gboolean enable_history);
-gboolean ex_run_file(const char *filename);
+VbCmdResult ex_run_file(const char *filename);
 
 #endif /* end of include guard: _EX_H */
index aec3276..94021cb 100644 (file)
@@ -114,7 +114,6 @@ static void set_uri(const char *uri);
 static void set_title(const char *title);
 static void init_core(void);
 static void marks_clear(void);
-static void read_config(void);
 static void setup_signals();
 static void init_files(void);
 static void session_init(void);
@@ -1080,7 +1079,8 @@ static void init_core(void)
     /* make sure the main window and all its contents are visible */
     gtk_widget_show_all(gui->window);
 
-    read_config();
+    /* read the config file */
+    ex_run_file(vb.files[FILES_CONFIG]);
 
     /* initially apply input style */
     vb_update_input_style();
@@ -1125,11 +1125,6 @@ static void marks_clear(void)
     }
 }
 
-static void read_config(void)
-{
-    ex_run_file(vb.files[FILES_CONFIG]);
-}
-
 static void setup_signals()
 {
     /* Set up callbacks so that if either the main window or the browser