Eric Arnold wrote:

> This seems like a klunky way of getting a value from getbufvar().
> 
>                       let attach_to = {}
>                       if len( getbufvar( bufnr, 'attach_to' ) ) > 0
>                               let attach_to = getbufvar( bufnr, 'attach_to' )
>                       endif
>                       if len( attach_to ) > 0
> 
> If I simply use
> 
>                       let attach_to = {}
>                       let attach_to = getbufvar( bufnr, 'attach_to' )
>                       if len( attach_to ) > 0
>                                  .......
> it will fail on variable type when the target for getbufvar(), i.e.
> b:attach_to  doesn't exist.  Fortunately,  len()  is smart enough to
> take different types, so there is a workaround.
> 
> I don't know if there's a good way around this without easing up on
> the variable type-checking, and [re-]initialize variables to the
> correct type upon assignment.  This would make life soooooo much
> easier with Vim 7 script.

I assume you have used the "attach_to" variable somewhere before.  Then
this should work fine:

                unlet! attach_to
                let attach_to = getbufvar( bufnr, 'attach_to' )
                if len(attach_to) > 0

Obviously getbufvar() cannot use a default type (empty list, empty
dictionary, zero...) when a variable does not exist.

-- 
Vi beats Emacs to death, and then again!
                        http://linuxtoday.com/stories/5764.html

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

Reply via email to