On Wed, 7 Jun 2006 at 8:16pm, A.J.Mechelynck wrote:

> Hari Krishna Dara wrote:
> > On Wed, 7 Jun 2006 at 8:10am, Jürgen Krämer wrote:
> >
> >
> >> Hi,
> >>
> >> Hari Krishna Dara wrote:
> >>
> >>> I am trying to use the new vim7 "object-based" features and am stuck
> >>> with an issue in using autoload style variables. Save the below as t.vim
> >>> in your autoload directory and execute it (:runtime autoload/t.vim).
> >>>
> >>> let t#var = 'something'
> >>>
> >>> let s:hash = {}
> >>> function! s:hash.func()
> >>>   echomsg 'from numbered function scope: '. g:t#var
> >>> endfunction
> >>>
> >>> echomsg 'from global scope: '. t#var
> >>> call s:hash.func()
> >>> <<<<
> >>>
> >>> you get the below output:
> >>>
> >>> from global scope: something
> >>> Error detected while processing function 3:
> >>> line    1:
> >>> E121: Undefined variable: t#var
> >>> E15: Invalid expression: 'from numbered function scope: '. t#var
> >>>
> >>> Is there something wrong that I am doing or is this a bug?
> >>>
> >> inside a function you have to reference global variables with the "g:"
> >> prefix even if it's an autoload variable, i.e.
> >>
> >>   function! s:hash.func()
> >>     echomsg 'from numbered function scope: '. g:t#var
> >>   endfunction
> >>
> >> Regards,
> >> Jürgen
> >>
> >
> > Strange... according to the documentation at |autoload|, you can access
> > them without the g: prefix.
> >
>
> According to the documentation at |global-variables|, omitting g: within
> a function definition gives you a variable local to the function:
>
>                         *global-variable* *g:var*
> Inside functions global variables are accessed with "g:".  Omitting this
> will
> access a variable local to a function.  But "g:" can also be used in any
> other
> place if you like.
>

Sorry, I wasn't clear. I knew about this difference. What I was trying
to say was that the variables and functions that have an autoload prefix
should by default be global. Why would anyone want to create a script
local variable with autoload prefix? a script local variables can only
be accessed from with in the same script, but then if the script is
already loaded, you don't need to autoload it anymore. All the autloader
ids can and should safely be considered as global. I hope I make sense
at least for someone.

-- 
Thanks,
Hari

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to