Re: [vim/vim] getcompletion() fails to append slashes to dirnames (#947)

2016-07-27 Fir de Conversatie Yegappan Lakshmanan
Hi,

On Wed, Jul 27, 2016 at 9:13 AM, chdiza  wrote:

> Right, sorry, I forgot to mention that "Desktop" is the only thing in the
> dir that starts with "De". :)
>

The attached patch fixes this problem.

- 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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index ae17038..53783af 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -4164,8 +4164,8 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
 {
 char_u *pat;
 expand_T   xpc;
-intoptions = WILD_KEEP_ALL | WILD_SILENT | WILD_USE_NL
- | WILD_LIST_NOTFOUND | WILD_NO_BEEP;
+intoptions = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
+   | WILD_NO_BEEP;
 
 if (p_wic)
options |= WILD_ICASE;
@@ -4194,7 +4194,7 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
 pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
 if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL))
 {
-   int i;
+   int i;
 
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
 
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 0ddbcec..5bc28a8 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -61,7 +61,7 @@ func Test_getcompletion()
   call assert_true(index(l, 'sleep') >= 0)
 
   let l = getcompletion('', 'dir')
-  call assert_true(index(l, 'samples') >= 0)
+  call assert_true(index(l, 'samples/') >= 0)
 
   let l = getcompletion('exe', 'expression')
   call assert_true(index(l, 'executable(') >= 0)


Re: [vim/vim] getcompletion() fails to append slashes to dirnames (#947)

2016-07-27 Fir de Conversatie Bram Moolenaar

Yegappan wrote:

> On Mon, Jul 25, 2016 at 11:28 AM, Yegappan Lakshmanan
>  wrote:
> > Hi,
> >
> > On Mon, Jul 25, 2016 at 10:42 AM, chdiza  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 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 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.

The tests are run with 'shellslash' set, thus I suspect the text fails.

-- 
To the optimist, the glass is half full.
To the pessimist, the glass is half empty.
To the engineer, the glass is twice as big as it needs to be.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] getcompletion() fails to append slashes to dirnames (#947)

2016-07-27 Fir de Conversatie Yegappan Lakshmanan
Hi,

On Tue, Jul 26, 2016 at 2:17 PM, chdiza  wrote:

> Actually, I seem to have found a problem with it.
>
> Suppose I have a dir named "Desktop" in my $HOME. From a Vim whose cwd is
> $HOME:
>
> echo getcompletion("de", "dir")
>
> Gives ['Desktop/*']. Note the asterisk, which messes things up if you
> want to use getcompletion() to soup-up ordinary dirname completion. For
> example, compare :cd De to
>

The getcompletion() function adds a star to the supplied pattern to get
all the matches. If the expansion fails, then the star is not removed.
The expansion may fail if the directory doesn't exist or if there are no
sub-directories under the specified directory. That is why you are seeing
a star at the end of the returned match. I will see how this can be fixed.

- Yegappan


> ec getcompletion(getcompletion("Desktop/", "dir")[0], "dir")
>
> The former has no asterisk, the latter has one. That means that using call
> input("CD to: ", "", "customlist,Foo"), where the function Foo is defined
> thus
>
> func Foo(A,L,P)
>   return getcompletion(a:A, "dir")
> endfunc
>
> will be such that hitting twice after "D" at the prompt will give
> Desktop/*, when it should just give Desktop/.
>
>
>

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [vim/vim] getcompletion() fails to append slashes to dirnames (#947)

2016-07-25 Fir de Conversatie Yegappan Lakshmanan
Hi,

On Mon, Jul 25, 2016 at 11:28 AM, Yegappan Lakshmanan
 wrote:
> Hi,
>
> On Mon, Jul 25, 2016 at 10:42 AM, chdiza  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 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 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 vim_dev+unsubscr...@googlegroups.com.
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;
 intoptions = 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)


Re: [vim/vim] getcompletion() fails to append slashes to dirnames (#947)

2016-07-25 Fir de Conversatie Yegappan Lakshmanan
Hi,

On Mon, Jul 25, 2016 at 10:42 AM, chdiza  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 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 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.

- 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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.