From: Daniel Carl Date: Sun, 7 Dec 2014 22:12:24 +0000 (+0100) Subject: Don't save mapped commands in history (#130). X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=3a1519ac58c8c62c73eb72fbc657855f80ead19d;p=vimb.git Don't save mapped commands in history (#130). If a map causes vimb to run various ex commands or too do a search it's irritating when these resolved commands are written into history. So a command is only be written to history, if it's built from typed chars. At the time the whole history recording is toggled on and off, which is not what vim does. Maybe it would be better to allow fine gained control which types of history and also registers are enabled or not. Now also the command triggered from remote are recorded into history. This makes sense, because the remote is assumed as normal user input. --- diff --git a/src/autocmd.c b/src/autocmd.c index 4ac3569..e4548de 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -256,9 +256,6 @@ gboolean autocmd_run(AuEvent event, const char *uri, const char *group) return true; } - /* don't record commands in history runed by autocmd */ - vb.state.enable_history = false; - /* loop over the groups and find matching commands */ for (lg = groups; lg; lg = lg->next) { grp = lg->data; @@ -283,7 +280,6 @@ gboolean autocmd_run(AuEvent event, const char *uri, const char *group) ex_run_string(cmd->excmd); } } - vb.state.enable_history = true; return true; } diff --git a/src/history.c b/src/history.c index 9883d8d..9035baf 100644 --- a/src/history.c +++ b/src/history.c @@ -77,9 +77,9 @@ void history_add(HistoryType type, const char *value, const char *additional) { const char *file; - /* don't write a history entry to the file if history is disabled or - * history max size is set to 0 */ - if (!vb.state.enable_history || !vb.config.history_max) { + /* Don't write a history entry to the file if the commands where not typed + * by the user or the history max size is set to 0. */ + if (!vb.config.history_max || !vb.state.typed) { return; } @@ -204,7 +204,7 @@ static const char *get_file_by_type(HistoryType type) } /** - * Loads history items form file but eliminate duplicates in FIFO order. + * Loads history items form file but eleminate duplicates in FIFO order. * * Returned list must be freed with (GDestroyNotify) free_history. */ diff --git a/src/io.c b/src/io.c index 5fbfc29..3603c0d 100644 --- a/src/io.c +++ b/src/io.c @@ -101,14 +101,14 @@ static gboolean fifo_watch(GIOChannel *gio, GIOCondition condition) g_error_free(err); } - /* don't recore remote commands in history */ - vb.state.enable_history = false; + /* simulate the typed flag to allow to record the commands in history */ + vb.state.typed = true; map_handle_string(line, true); g_free(line); - /* reenable history recording */ - vb.state.enable_history = true; + /* unset typed flag */ + vb.state.typed = false; return true; } diff --git a/src/main.c b/src/main.c index 00a72da..2cc16cd 100644 --- a/src/main.c +++ b/src/main.c @@ -1600,7 +1600,6 @@ int main(int argc, char *argv[]) /* init some state variable */ vb.state.enable_register = false; - vb.state.enable_history = false; vb.state.uri = g_strdup(""); init_core(); @@ -1612,7 +1611,6 @@ int main(int argc, char *argv[]) /* active the registers and writing of command history */ vb.state.enable_register = true; - vb.state.enable_history = true; /* open uri given as last argument */ if (argc <= 1) { diff --git a/src/main.h b/src/main.h index e2e606a..fc84612 100644 --- a/src/main.h +++ b/src/main.h @@ -308,7 +308,7 @@ typedef struct { char *reg[VB_REG_SIZE]; /* holds the yank buffer */ gboolean enable_register; /* indicates if registers are filled */ char current_register; /* holds char for current register to be used */ - gboolean enable_history; /* indicates if history entries are written */ + gboolean typed; /* indicates if th euser type the keys processed as command */ #ifdef FEATURE_SEARCH_HIGHLIGHT int search_matches; /* number of matches search results */ #endif diff --git a/src/map.c b/src/map.c index 081f772..4d273ca 100644 --- a/src/map.c +++ b/src/map.c @@ -159,9 +159,15 @@ gboolean map_keypress(GtkWidget *widget, GdkEventKey* event, gpointer data) return false; } + /* set flag to notify that the key was typed by the user */ + vb.state.typed = true; vb.state.processed_key = true; + map_handle_keys(string, len, true); + /* reset the typed flag */ + vb.state.typed = false; + return vb.state.processed_key; } @@ -319,6 +325,10 @@ MapState map_handle_keys(const guchar *keys, int keylen, gboolean use_map) ) { map.resolved = match->inlen; } + /* Unset the typed flag - if there where keys replaced by a + * mapping the resulting key string is considered as not typed by + * the user. */ + vb.state.typed = false; } else { /* first char is not mapped but resolved */ map.resolved = 1;