MarcWeber / vim-addon-manager

manage and install vim plugins (including their dependencies) in a sane way. If you have any trouble contact me. Usually I reply within 24 hours
Other
660 stars 59 forks source link

Documentation example replaces g:vim_addon_manager while it should just add property. #64

Closed kyrisu closed 11 years ago

kyrisu commented 12 years ago

In the example in the documentation there is something like:

let g:vim_addon_manager = {'scms': {'git': {}}}

I'm not a git expert but shouldn't there be something like:

let g:vim_addon_manager.scms = {'git': {}}

The first assignment replaces the entire vim_addon_manager object (at least for me) and I'm unable to override the settings. The second option works perfectly.

MarcWeber commented 12 years ago

The first assignment replaces the entire vim_addon_manager object (at least for me) and I'm unable to override the settings. The second option works perfectly.

Depends on where you add it to .vimrc. Have a look at the get( usage in the autolad/vam.vim file to see how it could be proberly done. (-> DefineAndBind ..) I don't want to repeat myself - neither do I want to write a DSL.

If somebody has trouble understanding this issue he should just ask. We can't make everything foolproof.

Anyway I've added comments to the SetupVAM sample function illustrating how to use g:vim_addon_manager

ZyX-I commented 12 years ago

The first assignment replaces the entire vim_addon_manager object (at least for me) and I'm unable to override the settings. The second option works perfectly.

It was assuming that user knows what he is doing. That example works perfectly at the very top of the vimrc and also works in any other place before calling VAM, though having undesired side-effect of unsetting all previously set options. I was thinking of adding either vam#Setoption function or adding a possibility of using g:vam_{option_name} in addition with adding vam#Addoption(option, default) because in this case expressions populating s:c and keeping backwards compatibility grow too complex for repeating them every time option is set.

function s:Setoption(var, option, value)
    if !exists(a:var)
        execute 'let '.a:var.'={}'
    endif
    let idx=stridx(a:option, '.')
    if idx==-1
        execute 'let '.a:var.'['.string(a:option).']=a:value'
    else
        return s:Setoption(a:var.'['.string(a:option[:(idx-1)]).']', a:option[idx+1:], a:value)
    endif
endfunction
function vam#Setoption(option, value)
    return s:Setoption('g:vim_addon_manager')
endfunction

function vam#Addoption(option, default)
    if has_key(g:vim_addon_manager, a:option)
        " Old-style sets have priority
        return
    elseif exists('g:vam_'.tr(a:option, '-', '_'))
        let g:vim_addon_manager[a:option]=g:vam_{tr(a:option, '-', '_')}
    else
        let g:vim_addon_manager[a:option]=a:default
    endif
endfunction