Don't write register or history during setup.
authorDaniel Carl <danielcarl@gmx.de>
Tue, 3 Jun 2014 11:02:32 +0000 (13:02 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Tue, 3 Jun 2014 11:02:32 +0000 (13:02 +0200)
src/command.c
src/ex.c
src/history.c
src/main.c
src/main.h

index 5c85794..cdf0404 100644 (file)
@@ -51,6 +51,7 @@ gboolean command_search(const Arg *arg)
         query = arg->s;
         /* add new search query to history and search register */
         vb_register_add('/', query);
+        history_add(HISTORY_SEARCH, query, NULL);
     } else {
         /* no search phrase given - continue a previous search */
         query = vb_register_get('/');
index 26a56c4..0dd3fc4 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -432,17 +432,12 @@ static void input_activate(void)
     text = vb_get_input_text();
 
     /* skip leading prompt char like ':' or '/' */
-    /* TODO should we use a flag to determine if we should record the command
-     * into the history - maybe it's not good to save commands in history that
-     * where triggered by a map like ':name \, :set scripts!<cr>' - by the way
-     * does vim also skip history recording for such mapped commands */
     cmd = text + 1;
     switch (*text) {
         case '/': count = 1; /* fall through */
         case '?':
             mode_enter('n');
             command_search(&((Arg){count, cmd}));
-            history_add(HISTORY_SEARCH, cmd, NULL);
             break;
 
         case ';': /* fall through */
@@ -453,10 +448,6 @@ static void input_activate(void)
         case ':':
             mode_enter('n');
             ex_run_string(cmd);
-            /* TODO fill register and history in ex_run_string but not if this
-             * is called on reading the config file */
-            vb_register_add(':', cmd);
-            history_add(HISTORY_COMMAND, cmd, NULL);
             break;
 
     }
@@ -469,6 +460,9 @@ gboolean ex_run_string(const char *input)
     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) || !execute(arg)) {
             free_cmdarg(arg);
index c3cb17b..e3272ec 100644 (file)
@@ -68,8 +68,13 @@ void history_cleanup(void)
  */
 void history_add(HistoryType type, const char *value, const char *additional)
 {
-    const char *file = get_file_by_type(type);
+    const char *file;
+
+    if (!vb.state.enable_history) {
+        return;
+    }
 
+    file = get_file_by_type(type);
     if (additional) {
         util_file_append(file, "%s\t%s\n", value, additional);
     } else {
index 306d094..076a6ad 100644 (file)
@@ -652,7 +652,6 @@ static void set_status(const StatusType status)
 static void init_core(void)
 {
     Gui *gui = &vb.gui;
-    WebKitWebSettings *setting;
 
     if (vb.embed) {
         gui->window = gtk_plug_new(vb.embed);
@@ -737,6 +736,10 @@ static void init_core(void)
     gtk_box_pack_start(gui->box, gui->eventbox, false, false, 0);
     gtk_box_pack_end(gui->box, gui->input, false, false, 0);
 
+    /* init some state variable */
+    vb.state.enable_register = false;
+    vb.state.enable_history  = false;
+
     /* initialize the modes */
     mode_init();
     mode_add('n', normal_enter, normal_leave, normal_keypress, NULL);
@@ -760,11 +763,11 @@ static void init_core(void)
 
     setup_signals();
 
-    setting = webkit_web_view_get_settings(gui->webview);
-
     /* make sure the main window and all its contents are visible */
     gtk_widget_show_all(gui->window);
     if (vb.config.kioskmode) {
+        WebKitWebSettings *setting = webkit_web_view_get_settings(gui->webview);
+
         /* hide input box - to not create it would be better, but this needs a
          * lot of changes in the code where the input is used */
         gtk_widget_hide(vb.gui.input);
@@ -774,6 +777,8 @@ static void init_core(void)
     }
 
     /* enter normal mode */
+    vb.state.enable_register = true;
+    vb.state.enable_history  = true;
     mode_enter('n');
 
     vb.config.default_zoom = 1.0;
@@ -783,6 +788,7 @@ static void init_core(void)
     GdkScreen *screen = gdk_window_get_screen(gtk_widget_get_window(vb.gui.window));
     gdouble dpi = gdk_screen_get_resolution(screen);
     if (dpi != -1) {
+        WebKitWebSettings *setting = webkit_web_view_get_settings(gui->webview);
         webkit_web_view_set_full_content_zoom(gui->webview, true);
         g_object_set(G_OBJECT(setting), "enforce-96-dpi", true, NULL);
 
@@ -978,6 +984,10 @@ void vb_register_add(char buf, const char *value)
     char *mark;
     int idx;
 
+    if (!vb.state.enable_register) {
+        return;
+    }
+
     /* make sure the mark is a valid mark char */
     if ((mark = strchr(VB_REG_CHARS, buf))) {
         /* get the index of the mark char */
index 09bd81d..553f23a 100644 (file)
@@ -292,6 +292,8 @@ typedef struct {
     gdouble         marks[VB_MARK_SIZE];    /* holds marks set to page with 'm{markchar}' */
     char            *linkhover;             /* the uri of the curret hovered link */
     char            *reg[VB_REG_SIZE];      /* holds the yank buffer */
+    gboolean        enable_register;        /* indicates if registers are filled */
+    gboolean        enable_history;         /* indicates if history entries are written */
 } State;
 
 typedef struct {