On Wed, Jul 21, 2010 at 12:10 AM, Bram Moolenaar <b...@moolenaar.net> wrote:
>
> Nazri Ramliy wrote:
>
>> On Tue, Jul 20, 2010 at 8:06 AM, Nazri Ramliy <ayieh...@gmail.com> wrote:
>> Attached patch solves the duplicate entry.
>>
>> While fixing this bug I found another:

[snipped description of bug due to ...]

>> The function uniquefy_paths in misc1.c shortens the list of full path
>> file names without taking into account the values in 'path' option.
>>
>> I'll look into fixing this too.
>
> Thanks, this works better.  I included this patch and made a few
> cosmetical changes.
>
> I also see duplicates in the form "./term.h" and "term.h".  The "./" has
> no effect, thus these two names are the same.  The complete list is:
>
>        ./term.h        include/term.h  term.h

Attached are four patches that fix the above problem and refine the behavior of
the find/sfind/tabfind completion. Also I've added note to the documentation on
the limitation of the completion when 'path' has url and directory limiter
(/usr/**2) and upward search (;) notations.

Note that with this patch, the previous (duplicate) completions (done
in vim's src
directory with default 'path' setting):

>        ./term.h        include/term.h  term.h

are now "reduced" to:

        term.h

and it does not differentiate between "include/term.h" and "./term.h" due to
because doing ":find include/term.h" would fail with the default 'path' setting
(".,/usr/include,,").

nazri.

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
From bf06811c40d383a940d72f8784815f5fa62f6b00 Mon Sep 17 00:00:00 2001
From: nazri <ayieh...@gmail.com>
Date: Fri, 23 Jul 2010 12:37:29 +0800
Subject: [PATCH 1/4] Fix ./foo and foo duplication for find/sfind/tabfind completion

This is achieved by trimming the corresponding 'path' portion from each
matching filenames.
---
 src/ex_getln.c |   29 +++++++++++++++++++++++++++++
 src/misc1.c    |    6 +++---
 src/vim.h      |    1 +
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/ex_getln.c b/src/ex_getln.c
index 153271b..e00d8d9 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -3402,6 +3402,7 @@ nextwild(xp, type, options)
  * options = WILD_KEEP_ALL:	    don't remove 'wildignore' entries
  * options = WILD_SILENT:	    don't print warning messages
  * options = WILD_ESCAPE:	    put backslash before special chars
+ * options = WILD_TRIM_PREFIX:	    trim the 'path' part used as glob prefix
  *
  * The variables xp->xp_context and xp->xp_backslash must have been set!
  */
@@ -5016,11 +5017,19 @@ globpath(path, file, expand_options)
     int		num_p;
     char_u	**p;
     char_u	*cur = NULL;
+    char_u	*trim;
 
     buf = alloc(MAXPATHL);
     if (buf == NULL)
 	return NULL;
 
+    if (WILD_TRIM_PREFIX|expand_options)
+    {
+	trim = alloc(MAXPATHL);
+	if (trim == NULL)
+	    return NULL;
+    }
+
     ExpandInit(&xpc);
     xpc.xp_context = EXPAND_FILES;
 
@@ -5034,13 +5043,31 @@ globpath(path, file, expand_options)
 	if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL)
 	{
 	    add_pathsep(buf);
+	    if (WILD_TRIM_PREFIX|expand_options)
+		STRCPY(trim, buf);
 	    STRCAT(buf, file);
 	    if (ExpandFromContext(&xpc, buf, &num_p, &p,
 			     WILD_SILENT|expand_options) != FAIL && num_p > 0)
 	    {
 		ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options);
 		for (len = 0, i = 0; i < num_p; ++i)
+		{
+		    if (WILD_TRIM_PREFIX|expand_options)
+		    {
+			char_u *p1 = p[i];
+			int c = 0;
+
+			while(p1[c] == trim[c] &&
+					    (p1[c] != '\n' || p1[c] != '\0') &&
+								trim[c] != '\0')
+			    c++;
+			while(vim_ispathsep(p1[c]))
+			    c++;
+			STRMOVE(p[i], &p[i][c]);
+		    }
+
 		    len += (int)STRLEN(p[i]) + 1;
+		}
 
 		/* Concatenate new results to previous ones. */
 		if (ga_grow(&ga, len) == OK)
@@ -5061,6 +5088,8 @@ globpath(path, file, expand_options)
     if (cur != NULL)
 	*--cur = 0; /* Replace trailing newline with NUL */
 
+    if (WILD_TRIM_PREFIX|expand_options)
+	vim_free(trim);
     vim_free(buf);
     return (char_u *)ga.ga_data;
 }
diff --git a/src/misc1.c b/src/misc1.c
index 8e2c656..d154662 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9416,7 +9416,7 @@ expand_in_path(gap, pattern, flags)
     char_u	*s;	/* start */
     char_u	*e;	/* end */
 
-    files = globpath(path_option, pattern, 0);
+    files = globpath(path_option, pattern, WILD_TRIM_PREFIX);
     if (files == NULL)
 	return 0;
 
@@ -9428,14 +9428,14 @@ expand_in_path(gap, pattern, flags)
 	    e++;
 	if (*e == '\0')
 	{
-	    addfile(gap, s, flags);
+	    addfile(gap, s, EW_NOTFOUND|flags);
 	    break;
 	}
 	else
 	{
 	    /* *e is '\n' */
 	    *e = '\0';
-	    addfile(gap, s, flags);
+	    addfile(gap, s, EW_NOTFOUND|flags);
 	    e++;
 	    s = e;
 	}
diff --git a/src/vim.h b/src/vim.h
index ce55514..051a4b2 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -797,6 +797,7 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
 #define WILD_KEEP_ALL		32
 #define WILD_SILENT		64
 #define WILD_ESCAPE		128
+#define WILD_TRIM_PREFIX	256
 
 /* Flags for expand_wildcards() */
 #define EW_DIR		0x01	/* include directory names */
-- 
1.7.2

From 46b01f72e0492bf1c9955fd4642aaa3854e8018d Mon Sep 17 00:00:00 2001
From: nazri <ayieh...@gmail.com>
Date: Fri, 23 Jul 2010 16:48:22 +0800
Subject: [PATCH 2/4] Support spaces in 'path' option for find/sfind/tabfind completion

---
 src/ex_getln.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/ex_getln.c b/src/ex_getln.c
index e00d8d9..57f4121 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -5039,7 +5039,7 @@ globpath(path, file, expand_options)
     while (*path != NUL)
     {
 	/* Copy one item of the path to buf[] and concatenate the file name. */
-	copy_option_part(&path, buf, MAXPATHL, ",");
+	copy_option_part(&path, buf, MAXPATHL, " ,");
 	if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL)
 	{
 	    add_pathsep(buf);
-- 
1.7.2

From 3174d9a929293b88423f85754b328900d0ab6986 Mon Sep 17 00:00:00 2001
From: nazri <ayieh...@gmail.com>
Date: Fri, 23 Jul 2010 16:44:57 +0800
Subject: [PATCH 3/4] Skip url path when doing completion for find/sfind/tabfind

---
 src/ex_getln.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/ex_getln.c b/src/ex_getln.c
index 57f4121..a694106 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -5040,6 +5040,12 @@ globpath(path, file, expand_options)
     {
 	/* Copy one item of the path to buf[] and concatenate the file name. */
 	copy_option_part(&path, buf, MAXPATHL, " ,");
+	if (path_with_url(buf))
+	    continue;
+	/*
+	 * FIXME: should we proactively skip 'path' with limiter (/usr/**N) and
+	 * upward search (;) notations, just like we did with url above?
+	 */
 	if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL)
 	{
 	    add_pathsep(buf);
-- 
1.7.2

From 789b79252665f464f1430aacce9146435baf2ad0 Mon Sep 17 00:00:00 2001
From: nazri <ayieh...@gmail.com>
Date: Fri, 23 Jul 2010 16:17:09 +0800
Subject: [PATCH 4/4] Add note on limitation of find/sfind/tabfind completion

---
 runtime/doc/editing.txt |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt
index 0d242ff..23e713e 100644
--- a/runtime/doc/editing.txt
+++ b/runtime/doc/editing.txt
@@ -1625,7 +1625,10 @@ There are three different types of searching:
 <   This searches: >
 	/u/user_x/work/release/**
 	/u/user_x/**
-<   This searches the same directories, but in a different order.
+<   This searches the same directories, but in a different order. >
 
+<  Note that completion for ":find", ":sfind", and ":tabfind" commands do not
+   currently work with 'path' settings that contain url or use the limiter
+   (/usr/**2) and upward search (;) notations. >
 
  vim:tw=78:ts=8:ft=help:norl:
-- 
1.7.2

Raspunde prin e-mail lui