This patch allows you to type something like:

ahu twit TAB

and get an auto-complete to:

https://twitter.com/_ahungry (assuming it was in your history).

Makes finding past pages when you only recall the general gist of what
was in the URL quite easy, for instance, you could find past programming
blogs with:

prog blog TAB

Let me know what you think!

(now if only I could get it to narrow down results as you type vs having
to press tab...)

diff --git a/utilities.c b/utilities.c
index 943b2e0..fe8c38d 100644
--- a/utilities.c
+++ b/utilities.c
@@ -21,6 +21,7 @@ extern Key keys[];
 extern gboolean complete_case_sensitive;
 static GList *dynamic_searchengines = NULL, *dynamic_uri_handlers = NULL;
 static int command_histsize = 50;
+int fuzzy_style_match(char *haystack, char *needle);
 
 void add_modkeys(char key);
 
@@ -550,6 +551,34 @@ echo_message(const MessageType type, const char *format, ...)
     va_end(ap);
 }
 
+int
+fuzzy_style_match (char *haystack, char *needle)
+{
+  char *subs;
+  char *next;
+  char word[1000];
+  int iter;
+
+  iter = 0;
+  subs = needle;
+  next = subs;
+
+  do
+    {
+      next = strstr(subs + 1 , " ");
+      strcpy(word, subs);
+      word[strlen(subs) - (next != NULL ? strlen(next) : 0)] = '\0';
+      if (strstr(haystack, word + iter) == NULL)
+        {
+          return 0;
+        }
+      iter = 1;
+    }
+  while ((subs = strstr(subs + 1, " ")) != NULL);
+
+  return 1;
+}
+
 static Listelement *
 complete_list_add_candidate(const char *s, const char *searchfor, const int mode, Listelement *elementlist)
 {
@@ -584,7 +613,7 @@ complete_list_add_candidate(const char *s, const char *searchfor, const int mode
         if (!complete_case_sensitive) {
             g_utf8_strdown(str, 255);
         }
-        if (!strlen(searchfor) || strstr(str, searchfor) != NULL) {
+        if (!strlen(searchfor) || fuzzy_style_match(str, (char *) searchfor)) {
             memset(readelement, 0, MAXTAGSIZE + 1);
             if (strchr(candidatepointer->element, ' ') != NULL && mode != CompleteModeBuffers) {
                 /* only use string up to the first space */

-- 
Matthew Carter ([email protected])
http://ahungry.com
------------------------------------------------------------------------------
_______________________________________________
Vimprobable-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vimprobable-users

Reply via email to