On Monday, September 17, 2012 3:29:56 PM UTC-4, Christian Brabandt wrote:
> Hi Donald!
> 
> 
> 
> On Sa, 15 Sep 2012, Donald Allen wrote:
> 
> 
> 
> > I am running vim 7.3.659 on a 64-bit Arch Linux system. I am seeing
> 
> > what I believe to be a bug in the filename-completion logic as used in
> 
> > the :buffer command. To reproduce, do the following:
> 
> > 
> 
> > 1. mkdir /tmp/foo
> 
> > 2. cd /tmp/foo
> 
> > 3. Somehow, create two files in /tmp/foo -- foo.c and bar.c.
> 
> > 4. Start vim. Enter ':e bar' followed by <tab>. It will complete to
> 
> > 'bar.c'. Hit <enter> to load the file. Do the same for foo.c. Note
> 
> > that after typing ':e foo' and then <tab>, it will complete to
> 
> > 'foo.c'.
> 
> > 5. You will have foo.c displayed in the vim window. If you enter ':b
> 
> > ba' followed by <tab>, it will complete to 'bar.c'. Hit <enter>. Now
> 
> > the window displays bar.c.  Now type ':b fo' followed by <tab>; it
> 
> > will not complete. But if you hit <enter> at that point, the window
> 
> > will switch correctly to foo.c. I think the logic is getting confused
> 
> > by the directory name and the filename both being 'foo'. If you move
> 
> > the directory to /tmp/baz, the problem will not occur.
> 
> 
> 
> Hm, that might be a bug. The problem is, that :b fo uses a different 
> 
> algorithm for determining the buffer, than the completion function. 
> 
> 
> 
> That is not the bug, so. Anyhow, I think ExpandBufnames can try to first 
> 
> match files explicitly, before falling back to the old behaviour. But I 
> 
> am not sure, this is useful.
> 
> Something like this:
> 
> 
> 
> diff --git a/src/buffer.c b/src/buffer.c
> 
> --- a/src/buffer.c
> 
> +++ b/src/buffer.c
> 
> @@ -2236,24 +2236,29 @@
> 
>      /* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */
> 
>      if (*pat == '^')
> 
>      {
> 
> -       patc = alloc((unsigned)STRLEN(pat) + 11);
> 
> +       patc = alloc((unsigned)STRLEN(pat) + 29);
> 
>         if (patc == NULL)
> 
>             return FAIL;
> 
>         STRCPY(patc, "\\(^\\|[\\/]\\)");
> 
>         STRCPY(patc + 11, pat + 1);
> 
> +       /* Make sure, patc only matches files for 1st attempt */
> 
> +       STRCPY(patc + STRLEN(patc), "[^\\/]*\\([\\/]\\)\\@!$");
> 
>      }
> 
>      else
> 
>         patc = pat;
> 
>  
> 
>      /*
> 
> -     * attempt == 0: try match with    '\<', match at start of word
> 
> +     * attempt == 0: try match with    '\<', match at start of word and 
> force a match of a file
> 
>       * attempt == 1: try match without '\<', match anywhere
> 
>       */
> 
>      for (attempt = 0; attempt <= 1; ++attempt)
> 
>      {
> 
>         if (attempt > 0 && patc == pat)
> 
>             break;      /* there was no anchor, no need to try again */
> 
> -       prog = vim_regcomp(patc + attempt * 11, RE_MAGIC);
> 
> +       else if (attempt > 0)
> 
> +           STRCPY(patc, pat + 1);
> 
> +
> 
> +       prog = vim_regcomp(patc, RE_MAGIC);
> 
>         if (prog == NULL)
> 
>         {
> 
>             if (patc != pat)
> 
> 
> 
> 
> 
> regards,
> 
> Christian
> 
> -- 
> 
> Das Menschenleben ist seltsam eingerichtet: Nach den Jahren der Last
> 
> hat man die Last der Jahre.
> 
>               -- Johann Wolfgang von Goeth

Thanks for the response and the patch. I will give it a try and report back.

/Don Allen 

-- 
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

Raspunde prin e-mail lui