Hi,
On Mon, Jul 25, 2016 at 11:28 AM, Yegappan Lakshmanan
<[email protected]> wrote:
> Hi,
>
> On Mon, Jul 25, 2016 at 10:42 AM, chdiza <[email protected]> wrote:
>>
>> The new getcompletion() function is of limited usefulness if one wants to
>> use it for any "type" that might return directory names. That's because it
>> doesn't append the trailing slash to dir names. That means that
>> getcompletion()'s results don't actually match what you would get at the
>> command line by pressing .
>>
>> For example: from the command line, :cd myd<TAB> yields :cd mydir/. Yet
>> echo getcompletion('myd', 'dir') yields mydir.
>>
>> This could be worked around by calling map() on the result of
>> getcompletion() to append the slashes. But that only works for the type
>> "dir". For "file", one can't just append slashes because some of
>> getcompletion()'s matches will be file names, not dir names.
>>
>> Example: Suppose in the cwd I have a dir names "mydir" and a file named
>> "myfile".
>>
>> At the command line, :e my<TAB> will show mydir/ and then myfile if you
>> hit again. But :echo getcompletion("my", "file") will show a list containing
>> mydir and myfile. A blanket use of map() to append trailing slashes would
>> result in myfile/ which is wrong.
>>
>> In short, getcompletion() should return a list that shows what would
>> actually be presented at the command line. If that list contains dirnames,
>> they should end in a slash. Otherwise, it isn't very useful in helping to
>> define custom completion for files and dirs.
>>
> This is easy to fix (need to add WILD_ADD_SLASH to options in
> f_getcompletion()).
> I will send out a patch later.
>
A patch to fix this problem is attached. I have updated the test case
to test for backslash or forward slash depending on the system
(Unix/Windows). I have tested this on a Mac system. I haven't tested
this on MS-Windows to make sure the test passes.
- Yegappan
--
--
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/evalfunc.c b/src/evalfunc.c
index ae17038..160213b 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -4165,7 +4165,7 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
char_u *pat;
expand_T xpc;
int options = WILD_KEEP_ALL | WILD_SILENT | WILD_USE_NL
- | WILD_LIST_NOTFOUND | WILD_NO_BEEP;
+ | WILD_ADD_SLASH | WILD_LIST_NOTFOUND | WILD_NO_BEEP;
if (p_wic)
options |= WILD_ICASE;
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 0ddbcec..8b5ebea 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -61,7 +61,11 @@ func Test_getcompletion()
call assert_true(index(l, 'sleep') >= 0)
let l = getcompletion('', 'dir')
- call assert_true(index(l, 'samples') >= 0)
+ if has('unix')
+ call assert_true(index(l, 'samples/') >= 0)
+ else
+ call assert_true(index(l, 'samples\') >= 0)
+ endif
let l = getcompletion('exe', 'expression')
call assert_true(index(l, 'executable(') >= 0)