Hello,
--> The issue
While in Command-line-mode, entering <Tab> for the :find command to
complete a directory's name does not append the ending slash.
Example:
vim -N -u NONE
:find dir<Tab>
" Observe that while the name is completed, no slash is appended.
This is inconsistent with :edit, :cd, etc.. It is also inconsistent
with :find ./dir<Tab>, which is explained below.
Besides consistency, appending the slash for you makes it easier to
proceed finding a file inside that directory. I couldn't think of any
downside of changing this behavior, but let me know if I've missed
something.
--> The fix
The reason this happens is that in gen_expand_wildcards() -- called
indirectly from ExpandFromContext() -- we do a branch. If it is of
format :find path-without-leading-dot-slash<Tab>, we call
expand_in_path(). Though expand_in_path() does proceed to call
globpath() and then ExpandFromContext() recursively, it only
propagates the WILD_ICASE flag, but not the WILD_ADD_SLASH flag.
This patch fixes that.
As suggested by CONTRIBUTING.md, I have attached a unified-diff format
patch, along with an accompanying test. Specifically, I modified
test_find_complete.vim to check both relative and non-relative cases
of the :find command mentioned above.
Let me know if anything else needs to be done.
Thanks,
Genki
--
--
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
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/misc1.c b/src/misc1.c
index 2d635d677..428740217 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -10761,6 +10761,7 @@ expand_in_path(
char_u *curdir;
garray_T path_ga;
char_u *paths = NULL;
+ int new_flags = 0;
if ((curdir = alloc((unsigned)MAXPATHL)) == NULL)
return 0;
@@ -10777,7 +10778,11 @@ expand_in_path(
if (paths == NULL)
return 0;
- globpath(paths, pattern, gap, (flags & EW_ICASE) ? WILD_ICASE : 0);
+ if (flags & EW_ICASE)
+ new_flags |= WILD_ICASE;
+ if (flags & EW_ADDSLASH)
+ new_flags |= WILD_ADD_SLASH;
+ globpath(paths, pattern, gap, new_flags);
vim_free(paths);
return gap->ga_len;
diff --git a/src/testdir/test_find_complete.vim b/src/testdir/test_find_complete.vim
index 4732109ed..a258f289c 100644
--- a/src/testdir/test_find_complete.vim
+++ b/src/testdir/test_find_complete.vim
@@ -86,6 +86,12 @@ func Test_find_complete()
call feedkeys(":find f\t\n", "xt")
call assert_equal('Holy Grail', getline(1))
+ " Test find completion on directories appends ending slash
+ call feedkeys(":find in/pa\tfile.txt\n", "xt")
+ call assert_equal('E.T.', getline(1))
+ call feedkeys(":find ./i\tstuff.txt\n", "xt")
+ call assert_equal('Another Holy Grail', getline(1))
+
" Test shortening of
"
" foo/x/bar/voyager.txt