From b9c4133c6afc38485d76fcd8c2e9d130251d5a2e Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Sat, 28 Sep 2013 17:24:28 +0200
Subject: [PATCH] Allow to configure the timeoutlen.

Timeoutlen is  the time in milliseconds that is waited for a key code or
mapped key sequence to complete.
---
 src/default.h |  1 +
 src/main.h    |  1 +
 src/map.c     |  2 +-
 src/setting.c | 13 +++++++++++++
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/default.h b/src/default.h
index c0c029d..51d9305 100644
--- a/src/default.h
+++ b/src/default.h
@@ -65,6 +65,7 @@ static char *default_config[] = {
     "set insecure-content-show=off",
     "set insecure-content-run=off",
 #endif
+    "set timeoutlen=1000",
     "cmap <Up> <C-P>",
     "cmap <Down> <C-N>",
     NULL
diff --git a/src/main.h b/src/main.h
index 3488252..aa53829 100644
--- a/src/main.h
+++ b/src/main.h
@@ -281,6 +281,7 @@ typedef struct {
     char   *download_dir;
     guint  history_max;
     char   *editor_command;
+    guint  timeoutlen;      /* timeout for ambiguous mappings */
 } Config;
 
 typedef struct {
diff --git a/src/map.c b/src/map.c
index 07dcc3d..ee13214 100644
--- a/src/map.c
+++ b/src/map.c
@@ -167,7 +167,7 @@ MapState map_handle_keys(const char *keys, int keylen)
         if (map.timout_id) {
             g_source_remove(map.timout_id);
         }
-        map.timout_id = g_timeout_add(1000, (GSourceFunc)map_timeout, NULL);
+        map.timout_id = g_timeout_add(vb.config.timeoutlen, (GSourceFunc)map_timeout, NULL);
     }
 
     /* copy the keys onto the end of queue */
diff --git a/src/setting.c b/src/setting.c
index cfe8d63..fab9d19 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -44,6 +44,7 @@ static gboolean proxy(const Setting *s, const SettingType type);
 static gboolean user_style(const Setting *s, const SettingType type);
 static gboolean history_max_items(const Setting *s, const SettingType type);
 static gboolean editor_command(const Setting *s, const SettingType type);
+static gboolean timeoutlen(const Setting *s, const SettingType type);
 
 static Setting default_settings[] = {
     /* webkit settings */
@@ -89,6 +90,7 @@ static Setting default_settings[] = {
     {NULL, "status-sslinvalid-color-bg", TYPE_COLOR, status_color_bg, {0}},
     {NULL, "status-sslinvalid-color-fg", TYPE_COLOR, status_color_fg, {0}},
     {NULL, "status-sslinvalid-font", TYPE_FONT, status_font, {0}},
+    {NULL, "timeoutlen", TYPE_INTEGER, timeoutlen, {0}},
     {NULL, "input-bg-normal", TYPE_COLOR, input_style, {0}},
     {NULL, "input-bg-error", TYPE_COLOR, input_style, {0}},
     {NULL, "input-fg-normal", TYPE_COLOR, input_style, {0}},
@@ -700,3 +702,14 @@ static gboolean editor_command(const Setting *s, const SettingType type)
 
     return true;
 }
+
+static gboolean timeoutlen(const Setting *s, const SettingType type)
+{
+    if (type == SETTING_GET) {
+        print_value(s, &vb.config.timeoutlen);
+    } else {
+        vb.config.timeoutlen = abs(s->arg.i);
+    }
+
+    return true;
+}
-- 
2.20.1