Loading ...
Sorry, an error occurred while loading the content.
 

Re: buf*() functions and symbolic links

Expand Messages
  • Yegappan Lakshmanan
    Bram, ... Thanks. This patch fixes the problem. Now the bufnr() function correctly handles symbolic links. - Yegappan ...
    Message 1 of 3 , Aug 30, 2002
      Bram,

      --- Bram Moolenaar <Bram@...> wrote:
      >
      > Yegappan Lakshmanan wrote:
      >
      > > I have the following two files in a Unix system:
      > >
      > > dir/file1
      > > file2
      > >
      > > where file2 is a symbolic link to dir/file1. I have loaded
      > > dir/file1 in Vim. Look at the return values from the different
      > > buf*() functions:
      > >
      > > :echo bufexists("dir/file1")
      > > :echo bufexists("file2")
      > > :echo bufloaded("dir/file1")
      > > :echo bufloaded("file2")
      > > :echo buflisted("dir/file1")
      > > :echo buflisted("file2")
      > >
      > > All of the above functions return 1. According to the help for
      > > bufexists(), buflisted() and bufloaded() functions the specified
      > > name must match a buffer name exactly. This is not correct. As
      > > shown above, for symbolic links, these functions will still
      > > work, even though the specified name is different from any
      > > of the loaded buffer names.
      > >
      > > Now, look at the return value for bufnr():
      > >
      > > :echo bufnr("dir/file1")
      > > :echo bufnr("file2")
      > >
      > > For the symbolic link, bufnr() returns -1. How do you get the
      > > buffer number given the symbolic name of a file, when the
      > > original file is loaded in Vim? Using the above example, when
      > > the dir/file1 file is loaded in Vim, given the symbolic link
      > > file2, how do you get the buffer number?
      >
      > The functions bufexists() and bufnr() indeed use a different method to
      > obtain the buffer. The intention was that bufnr() finds a buffer in
      > more ways, since it allows using a regexp. But bufexists() expands the
      > name to a full path name and in that way also resolves symbolic links.
      >
      > Try this patch, it should make finding a buffer more consistent:
      >

      Thanks. This patch fixes the problem. Now the bufnr() function
      correctly handles symbolic links.

      - Yegappan

      > *** ../../vim61.166/src/eval.c Sun Aug 4 21:51:53 2002
      > --- eval.c Thu Aug 29 21:09:09 2002
      > ***************
      > *** 2944,2949 ****
      > --- 2944,2954 ----
      >
      > p_magic = save_magic;
      > p_cpo = save_cpo;
      > +
      > + /* If not found, try expanding the name, like done for bufexists(). */
      > + if (buf == NULL)
      > + buf = find_buffer(avar);
      > +
      > return buf;
      > }

      __________________________________________________
      Do You Yahoo!?
      Yahoo! Finance - Get real-time stock quotes
      http://finance.yahoo.com
    Your message has been successfully submitted and would be delivered to recipients shortly.