diff --git a/src/misc2.c b/src/misc2.c
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -4679,8 +4679,52 @@
     }
     STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir);
     add_pathsep(ff_expand_buffer);
-    STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path);
-    add_pathsep(ff_expand_buffer);
+    {
+	char_u *buf = alloc(STRLEN(ff_expand_buffer) + STRLEN(search_ctx->ffsc_fix_path));
+
+	STRCPY(buf, ff_expand_buffer);
+	STRCAT(buf, search_ctx->ffsc_fix_path);
+	if (mch_isdir(buf))
+	{
+	    STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path);
+	    add_pathsep(ff_expand_buffer);
+	}
+#ifdef FEAT_PATH_EXTRA
+	else
+	{
+	    char_u *p =  vim_strrchr(search_ctx->ffsc_fix_path, PATHSEP);
+	    char_u *wc_path = NUL;
+	    char_u *temp = NUL;
+	    int len = 0;
+
+	    if (p != NULL)
+	    {
+		len = p - search_ctx->ffsc_fix_path;
+		STRNCAT(ff_expand_buffer, search_ctx->ffsc_fix_path, len);
+		add_pathsep(ff_expand_buffer);
+	    }
+	    else
+		len = STRLEN(search_ctx->ffsc_fix_path);
+
+	    if (search_ctx->ffsc_wc_path != NULL)
+	    {
+		wc_path = vim_strsave(search_ctx->ffsc_wc_path);
+		temp = alloc(STRLEN(search_ctx->ffsc_wc_path) + 
+		    (STRLEN(search_ctx->ffsc_fix_path) - len));
+	    }
+
+	    if (temp == NULL || wc_path == NULL)
+		goto error_return;
+
+	    STRCPY(temp, search_ctx->ffsc_fix_path + len);
+	    STRCAT(temp, search_ctx->ffsc_wc_path);
+	    vim_free(search_ctx->ffsc_wc_path);
+	    vim_free(wc_path);
+	    search_ctx->ffsc_wc_path = temp;
+	}
+#endif
+	vim_free(buf);
+    }
 
     sptr = ff_create_stack_element(ff_expand_buffer,
 #ifdef FEAT_PATH_EXTRA
diff --git a/src/testdir/test89.in b/src/testdir/test89.in
--- a/src/testdir/test89.in
+++ b/src/testdir/test89.in
@@ -1,6 +1,7 @@
-Some tests for setting 'number' and 'relativenumber'
-This is not all that useful now that the options are no longer reset when
-setting the other.
+- Some tests for setting 'number' and 'relativenumber'
+  This is not all that useful now that the options are no longer reset when
+  setting the other.
+- Some tests for findfile() function
 
 STARTTEST
 :so small.vim
@@ -49,6 +50,17 @@
 :$put g
 :$put h
 :"
+:let cwd=getcwd()
+:cd ../..
+:$put =''
+:$put ='Testing findfile'
+:$put =''
+:$put =findfile('test19.in','src/test*')
+:exe "cd" cwd
+:cd ..
+:$put =findfile('test19.in','test*')
+:$put =findfile('test19.in','testdir')
+:exe "cd" cwd
 :/^results/,$w! test.out
 :q!
 ENDTEST
diff --git a/src/testdir/test89.ok b/src/testdir/test89.ok
--- a/src/testdir/test89.ok
+++ b/src/testdir/test89.ok
@@ -20,3 +20,9 @@
   number
 
   relativenumber
+
+Testing findfile
+
+src/testdir/test19.in
+testdir/test19.in
+testdir/test19.in
On Fr, 21 Jun 2013, Christian Brabandt wrote:
> On Do, 20 Jun 2013, Markus Braun wrote:
> 
> > I have a question about using wildcards in the path argument to findfile()
> > function. When running these commands
> > 
> >   mkdir -p "test/dir-1/" && touch "test/dir-1/foo"
> >   mkdir -p "test/dir-2/" && touch "test/dir-2/foo"
> >   mkdir -p "test/dir-3/" && touch "test/dir-3/foo"
> >   vim -u NONE -c "echo string(findfile('foo', 'test/*', -1))|call input('press ENTER to exit')|q"
> >   vim -u NONE -c "echo string(findfile('foo', 'test/dir-*', -1))|call input('press ENTER to exit')|q"
> > 
> > I would expect vim to output both times the same output of
> > 
> >   ['test/dir-1/foo', 'test/dir-2/foo', 'test/dir-3/foo']
> > 
> > but the second vim instance only gives
> > 
> >   []
> > 
> > I don't understand this behavior. What am I doing wrong here?
> 
> Looks like a bug. I almost have a working patch. I need to test it some 
> more...
Bram,
here is a patch, that makes findfile() behave as expected. Problem is, 
findfile() currently expects wildcards to be only after a valid 
directory name and for cases like findfile('test19.in', 'src/test*') (in 
Vim source directory), it tries to find a file 'test19.in' in a 
directory vim/src/test/ which doesn't exists and therefore fails.
Patch contains a test.
regards,
Christian
-- 
"Sie servieren heute Hasenbraten, las ich draußen", sagte der Beamte der
Gewerbeaufsicht. "Reiner Hasenbraten?"
"Mit etwas Pferd", gestand der Gastronom.
"In welchem Verhältnis?"
"50 zu 50: Ein Hase, ein Pferd."
-- 
-- 
You received this message from the "vim_use" 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
--- 
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Saturday, June 22, 2013
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment