From c4f7a6e71d2050dc7d3bace8980a7da6eda9779a Mon Sep 17 00:00:00 2001
From: Robert Timm <mail@rtti.de>
Date: Sat, 8 Apr 2017 22:40:29 +0200
Subject: [PATCH] adds incsearch setting

---
 src/ex.c      | 15 ++++++++++++++-
 src/main.h    |  1 +
 src/setting.c |  1 +
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/ex.c b/src/ex.c
index cc4bdbe..46f02a7 100644
--- a/src/ex.c
+++ b/src/ex.c
@@ -348,6 +348,15 @@ VbResult ex_keypress(Client *c, int key)
         }
     }
 
+    if (c->config.incsearch && key != KEY_CR) {
+        gtk_text_buffer_get_bounds(buffer, &start, &end);
+        text = gtk_text_buffer_get_text(buffer, &start, &end, false);
+        if (text && (*text == '/' || *text == '?')) {
+            command_search(c, &((Arg){0, NULL})); /* stop last search */
+            command_search(c, &((Arg){*text == '/' ? 1 : -1, (char*)text + 1}));
+        }
+    }
+
     /* if the user deleted some content of the inputbox we check if the
      * inputbox is empty - if so we switch back to normal like vim does */
     if (check_empty) {
@@ -493,7 +502,11 @@ static void input_activate(Client *c)
         case '/': count = 1; /* fall through */
         case '?':
             vb_enter(c, 'n');
-            command_search(c, &((Arg){count, cmd}));
+
+            /* start search, if incsearch, it's done while typing */
+            if (!c->config.incsearch) {
+                command_search(c, &((Arg){count, cmd}));
+            }
             break;
 
         case ';': /* fall through */
diff --git a/src/main.h b/src/main.h
index 59e1fbb..9d016a5 100644
--- a/src/main.h
+++ b/src/main.h
@@ -226,6 +226,7 @@ struct Client {
         GHashTable              *settings;
         guint                   scrollstep;
         gboolean                input_autohide;
+        gboolean                incsearch;
         /* completion */
         GdkRGBA                 comp_fg[COMP_LAST];
         GdkRGBA                 comp_bg[COMP_LAST];
diff --git a/src/setting.c b/src/setting.c
index 59bf50a..9c5741f 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -140,6 +140,7 @@ void setting_init(Client *c)
     i = 100;
     setting_add(c, "default-zoom", TYPE_INTEGER, &i, default_zoom, 0, NULL);
     setting_add(c, "download-path", TYPE_CHAR, &"~", NULL, 0, NULL);
+    setting_add(c, "incsearch", TYPE_BOOLEAN, &off, internal, 0, &c->config.incsearch);
 
 #ifdef FEATURE_GUI_STYLE_VIMB2_COMPAT
     /* gui style settings vimb2 compatibility */
-- 
2.20.1