Hi,

for some time now I've wanted to be able easily to search in text files
without caring about whitespace much: 
when I look for "foo bar" it should match "foo   bar" as well as "foo
bar" (with the new line there).

Basically, I'd like an option that transforms a space in search into
"\_s+".

Attached is an svn diff of a quick and dirty hack that introduces the
option 'magicspace' to do the above. I won't pretend I understand the
machinery of regexp.c, but it seems to work for me.

I'll be happy to learn if there's already a way to do it. Otherwise, I'd
suggest that this might be a useful feature, and I'm willing to add
documentation if pointed to where to do so; but I'd appreciate help with
cleaning up the code if necessary.

Have fun,
Jacek Kopecky

-- 
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
Index: src/option.c
===================================================================
--- src/option.c	(revision 1716)
+++ src/option.c	(working copy)
@@ -1655,6 +1655,10 @@
     {"magic",	    NULL,   P_BOOL|P_VI_DEF,
 			    (char_u *)&p_magic, PV_NONE,
 			    {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
+    /* magicspace means to pretend in patterns that ' ' is '\_s*' */
+    {"magicspace",  "ms",   P_BOOL|P_VI_DEF,
+			    (char_u *)&p_magicspace, PV_NONE,
+			    {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
     {"makeef",	    "mef",  P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
 #ifdef FEAT_QUICKFIX
 			    (char_u *)&p_mef, PV_NONE,
Index: src/option.h
===================================================================
--- src/option.h	(revision 1716)
+++ src/option.h	(working copy)
@@ -585,6 +585,7 @@
 EXTERN int	p_macatsui;	/* 'macatsui' */
 #endif
 EXTERN int	p_magic;	/* 'magic' */
+EXTERN int	p_magicspace;	/* 'magicspace' */
 #ifdef FEAT_QUICKFIX
 EXTERN char_u	*p_mef;		/* 'makeef' */
 EXTERN char_u	*p_mp;		/* 'makeprg' */
Index: src/regexp.c
===================================================================
--- src/regexp.c	(revision 1716)
+++ src/regexp.c	(working copy)
@@ -405,6 +405,8 @@
 static char_u	*skip_anyof __ARGS((char_u *p));
 static void	init_class_tab __ARGS((void));
 
+static int      reg_magicspace; /* True when the current caracter is space and magicspace is on */
+
 /*
  * Translate '\x' to its control character, except "\n", which is Magic.
  */
@@ -1430,7 +1432,10 @@
     if (ret == NULL)
 	return NULL;
 
-    op = peekchr();
+    if (!reg_magicspace)
+        op = peekchr();
+    else
+        op = Magic('+');
     if (re_multi_type(op) == NOT_MULTI)
     {
 	*flagp = flags;
@@ -1439,7 +1444,10 @@
     /* default flags */
     *flagp = (WORST | SPSTART | (flags & (HASNL | HASLOOKBH)));
 
-    skipchr();
+    if (!reg_magicspace)
+        skipchr();
+    else
+        reg_magicspace = FALSE;
     switch (op)
     {
 	case Magic('*'):
@@ -1602,6 +1610,11 @@
 	ret = regnode(EOW);
 	break;
 
+      case Magic(' '):
+        c = Magic('s');
+        reg_magicspace = TRUE;
+        goto addnlclass;
+
       case Magic('_'):
 	c = no_Magic(getchr());
 	if (c == '^')		/* "\_^" is start-of-line */
@@ -1618,6 +1631,7 @@
 	    break;
 	}
 
+addnlclass:
 	extra = ADD_NL;
 	*flagp |= HASNL;
 
@@ -2611,6 +2625,11 @@
     {
 	switch (curchr = regparse[0])
 	{
+        case ' ':
+            /* magic only if 'magicspace' is on */
+            if (p_magicspace)
+                curchr = Magic(' ');
+            break;
 	case '.':
 	case '[':
 	case '~':
@@ -2791,6 +2810,7 @@
     prevchr = curchr;
     curchr = nextchr;	    /* use previously unget char, or -1 */
     nextchr = -1;
+    reg_magicspace = FALSE;
 }
 
 /*

Raspunde prin e-mail lui