On Thu, Feb 26, 2009 at 10:38:21PM -0800, Sean wrote:
>
> Hi,
>
> All global variables can be found through g: which is a hash table
> itself. It might be good to hide those variable from outside and
> limit its use only to the plugin itself.
>
> I found a way to do it:
>
> " ------------------------------------------------
> let G = []
> call add(G, "g:vimim_datafile")
> call add(G, "g:vimim_signature")
> " ...
> " ------------------------------------------------
> for variable in G
> let s_variable = substitute(variable,"g:","s:",'')
> if !exists(variable)
> exe 'let '. s_variable . '=0'
> else
> exe 'let '. s_variable .'='. variable
> exe 'unlet! ' . variable
> endif
> endfor
> " ------------------------------------------------
>
> This enables
>
> (1) global variables can be defined in vimrc as usual
> (2) no global variables can be accessed outside the plugin
I've used something similar in tovl:
let s:loaded = config#GetG('tovl#plugins#loaded', {'set' : 1, 'default' : {}})
^^^^^^^^^^^^^^^^^^ plugin name
^^^^ GetG = get global var
it defines a file local var by getting the dict from a global dict.
This way can still access (and debug) everything from the outside and
its somewhat hidden as well.
You can even use the line in multiple files. The first call will create
the dict and it will be shared.
Marc Weber
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---