Skip to content

Commit

Permalink
Replaced all dict['alphanum_key'] with dict.alphanum_key
Browse files Browse the repository at this point in the history
  • Loading branch information
ZyX-I committed Oct 28, 2012
1 parent 8629be7 commit 92bb1bd
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 84 deletions.
68 changes: 35 additions & 33 deletions autoload/vam.vim
Expand Up @@ -18,61 +18,63 @@ endfor
let g:is_win = g:os[:2] == 'win'

exec vam#DefineAndBind('s:c','g:vim_addon_manager','{}')
let s:c['auto_install'] = get(s:c,'auto_install', 0)
let s:c.auto_install = get(s:c,'auto_install', 0)
" repository locations:
let s:c['plugin_sources'] = get(s:c,'plugin_sources', {})
let s:c.plugin_sources = get(s:c,'plugin_sources', {})
" if a plugin has an item here the dict value contents will be written as plugin info file
" Note: VAM itself may be added after definition of vam#PluginDirFromName
" function
let s:c['activated_plugins'] = get(s:c,'activated_plugins', {})
let s:c.activated_plugins = get(s:c,'activated_plugins', {})

let s:c['create_addon_info_handlers'] = get(s:c, 'create_addon_info_handlers', 1)
let s:c.create_addon_info_handlers = get(s:c, 'create_addon_info_handlers', 1)

" Users may install VAM system wide. In that case s:d is not writeable.
let s:d = expand('<sfile>:h:h:h')
let s:c['plugin_root_dir'] = get(s:c, 'plugin_root_dir', filewritable(s:d) ? s:d : '~/.vim/vim-addons' )
let s:c.plugin_root_dir = get(s:c, 'plugin_root_dir', filewritable(s:d) ? s:d : '~/.vim/vim-addons')
unlet s:d

if s:c['plugin_root_dir'] == expand('$HOME')
echoe "VAM: Don't install VAM into ~/.vim the normal way. See docs -> SetupVAM function. Put it int ~/.vim/vim-addons/vim-addon-manager for example."
if s:c.plugin_root_dir == expand('~')
echohl Error
echomsg "VAM: Don't install VAM into ~/.vim the normal way. See docs -> SetupVAM function. Put it int ~/.vim/vim-addons/vim-addon-manager for example."
echohl None
finish
endif

" ensure we have absolute paths (windows doesn't like ~/.. ) :
let s:c['plugin_root_dir'] = expand(s:c['plugin_root_dir'])
let s:c['dont_source'] = get(s:c, 'dont_source', 0)
let s:c['plugin_dir_by_name'] = get(s:c, 'plugin_dir_by_name', 'vam#DefaultPluginDirFromName')
let s:c['addon_completion_lhs'] = get(s:c, 'addon_completion_lhs', '<C-x><C-p>')
let s:c['debug_activation'] = get(s:c, 'debug_activation', 0)
let s:c['pool_item_check_fun'] = get(s:c, 'pool_item_check_fun', 'none')
let s:c['no_activate_hack'] = get(s:c, 'no_activate_hack', 0)
let s:c.plugin_root_dir = expand(s:c.plugin_root_dir)
let s:c.dont_source = get(s:c, 'dont_source', 0)
let s:c.plugin_dir_by_name = get(s:c, 'plugin_dir_by_name', 'vam#DefaultPluginDirFromName')
let s:c.addon_completion_lhs = get(s:c, 'addon_completion_lhs', '<C-x><C-p>')
let s:c.debug_activation = get(s:c, 'debug_activation', 0)
let s:c.pool_item_check_fun = get(s:c, 'pool_item_check_fun', 'none')
let s:c.no_activate_hack = get(s:c, 'no_activate_hack', 0)

" experimental: will be documented when its tested
" don't echo lines, add them to a buffer to prevent those nasty "Press Enter"
" to show more requests by Vim
" TODO: move log code into other file (such as utils.vim) because its not used on each startup
" TODO: think about autowriting it
let s:c['log_to_buf'] = get(s:c, 'log_to_buf', 0)
let s:c['log_buffer_name'] = get(s:c, 'log_buffer_name', s:c.plugin_root_dir.'/VAM_LOG.txt')
let s:c.log_to_buf = get(s:c, 'log_to_buf', 0)
let s:c.log_buffer_name = get(s:c, 'log_buffer_name', s:c.plugin_root_dir.'/VAM_LOG.txt')

" More options that are used for plugins’ installation are listed in
" autoload/vam/install.vim

if g:is_win
if g:is_win && has_key(s:c, 'binary_utils')
" if binary-utils path exists then add it to PATH
let s:c['binary_utils'] = get(s:c,'binary_utils',s:c['plugin_root_dir'].'\binary-utils')
let s:c['binary_utils_bin'] = s:c['binary_utils'].'\dist\bin'
if isdirectory(s:c['binary_utils'])
let $PATH=$PATH.';'.s:c['binary_utils_bin']
let s:c.binary_utils = get(s:c,'binary_utils', s:c.plugin_root_dir.'\binary-utils')
let s:c.binary_utils_bin = s:c.binary_utils.'\dist\bin'
if isdirectory(s:c.binary_utils)
let $PATH=$PATH.';'.s:c.binary_utils_bin
endif
endif

" additional plugin sources should go into your .vimrc or into the repository
" called "vim-addon-manager-known-repositories" referenced here:
if executable('git')
let s:c['plugin_sources']["vim-addon-manager-known-repositories"] = { 'type' : 'git', 'url': 'git://github.com/MarcWeber/vim-addon-manager-known-repositories' }
let s:c.plugin_sources["vim-addon-manager-known-repositories"] = {'type' : 'git', 'url': 'git://github.com/MarcWeber/vim-addon-manager-known-repositories'}
else
let s:c['plugin_sources']["vim-addon-manager-known-repositories"] = { 'type' : 'archive', 'url': 'http://github.com/MarcWeber/vim-addon-manager-known-repositories/tarball/master', 'archive_name': 'vim-addon-manager-known-repositories-tip.tar.gz' }
let s:c.plugin_sources["vim-addon-manager-known-repositories"] = {'type' : 'archive', 'url': 'http://github.com/MarcWeber/vim-addon-manager-known-repositories/tarball/master', 'archive_name': 'vim-addon-manager-known-repositories-tip.tar.gz'}
endif

if s:c.create_addon_info_handlers
Expand Down Expand Up @@ -127,12 +129,12 @@ fun! vam#PluginDirFromName(...)
endfun
fun! vam#PluginRuntimePath(name)
let info = vam#AddonInfo(a:name)
return vam#PluginDirFromName(a:name).(has_key(info, 'runtimepath') ? '/'.info['runtimepath'] : '')
return vam#PluginDirFromName(a:name).(has_key(info, 'runtimepath') ? '/'.info.runtimepath : '')
endfun

" adding VAM, so that its contained in list passed to :UpdateActivatedAddons
if filewritable(vam#PluginDirFromName('vim-addon-manager'))==2
let s:c['activated_plugins']['vim-addon-manager']=1
let s:c.activated_plugins['vim-addon-manager']=1
endif

" doesn't check dependencies!
Expand Down Expand Up @@ -172,14 +174,14 @@ fun! vam#ActivateRecursively(list_of_names, ...)
let opts = extend({'run_install_hooks': 1}, a:0 == 0 ? {} : a:1)

for name in a:list_of_names
if !has_key(s:c['activated_plugins'], name)
if !has_key(s:c.activated_plugins, name)
" break circular dependencies..
let s:c['activated_plugins'][name] = 0
let s:c.activated_plugins[name] = 0

let infoFile = vam#AddonInfoFile(name)
if !filereadable(infoFile) && !vam#IsPluginInstalled(name)
if empty(vam#install#Install([name], opts))
unlet s:c['activated_plugins'][name]
unlet s:c.activated_plugins[name]
continue
endif
endif
Expand All @@ -196,13 +198,13 @@ fun! vam#ActivateRecursively(list_of_names, ...)

" source plugin/* files ?
let rtp = vam#PluginRuntimePath(name)
call add(opts['new_runtime_paths'], rtp)
call add(opts.new_runtime_paths, rtp)
let opts.path_plugins[rtp] = name
if !empty(get(opts, 'requested_by'))
let opts.are_dependencies[name] = 1
endif

let s:c['activated_plugins'][name] = 1
let s:c.activated_plugins[name] = 1

if s:c.debug_activation
" activation takes place later (-> new_runtime_paths), but messages will be in order
Expand Down Expand Up @@ -355,11 +357,11 @@ fun! vam#DisplayAddonInfoLines(name, repository)
endfun

fun! vam#DisplayAddonInfo(name)
let repository = get(g:vim_addon_manager['plugin_sources'], a:name, {})
let repository = get(g:vim_addon_manager.plugin_sources, a:name, {})
let name = a:name
if empty(repository) && a:name =~ '^\d\+$'
" try to find by script id
let dict = filter(copy(g:vim_addon_manager['plugin_sources']), 'get(v:val,"vim_script_nr","")."" == '.string(1*a:name))
let dict = filter(copy(g:vim_addon_manager.plugin_sources), 'get(v:val,"vim_script_nr","")."" == '.string(1*a:name))
if (empty(dict))
throw "unknown script ".a:name
else
Expand Down Expand Up @@ -515,7 +517,7 @@ command! -nargs=* -bar -complete=customlist,vam#install#AddonCompletion Activate
command! -nargs=* -bar -complete=customlist,vam#install#AddonCompletion AddonsInfo :call vam#DisplayAddonsInfo([<f-args>])
command! -nargs=* -bar -complete=customlist,vam#install#InstalledAddonCompletion ActivateInstalledAddons :call vam#ActivateAddons([<f-args>])
command! -nargs=* -bar -complete=customlist,vam#install#UpdateCompletion UpdateAddons :call vam#install#Update([<f-args>])
command! -nargs=0 -bar UpdateActivatedAddons exec 'UpdateAddons '.join(keys(g:vim_addon_manager['activated_plugins']),' ')
command! -nargs=0 -bar UpdateActivatedAddons exec 'UpdateAddons '.join(keys(g:vim_addon_manager.activated_plugins),' ')
command! -nargs=* -bar -complete=customlist,vam#install#UninstallCompletion UninstallNotLoadedAddons :call vam#install#UninstallAddons([<f-args>])

command! -nargs=* -complete=customlist,vam#bisect#BisectCompletion AddonsBisect :call vam#bisect#Bisect(<f-args>)
Expand Down
66 changes: 33 additions & 33 deletions autoload/vam/install.vim
Expand Up @@ -2,16 +2,16 @@

exec vam#DefineAndBind('s:c','g:vim_addon_manager','{}')

let s:c['change_to_unix_ff'] = get(s:c, 'change_to_unix_ff', (g:os=~#'unix'))
let s:c['do_diff'] = get(s:c, 'do_diff', 1)
let s:c['known'] = get(s:c,'known','vim-addon-manager-known-repositories')
let s:c['MergeSources'] = get(s:c, 'MergeSources', 'vam_known_repositories#MergeSources')
let s:c['pool_fun'] = get(s:c, 'pool_fun', 'vam#install#Pool')
let s:c['name_rewriting'] = get(s:c, 'name_rewriting', {})
let s:c['pre_update_hook_functions'] = get(s:c, 'pre_update_hook_functions', ['vam#install#CreatePatch'])
let s:c['post_update_hook_functions'] = get(s:c, 'post_update_hook_functions', ['vam#install#ApplyPatch'])
let s:c['post_scms_update_hook_functions'] = get(s:c, 'post_scms_update_hook_functions', ['vam#install#ShowShortLog'])
let s:c['pool_item_check_funs'] = get(s:c, 'pool_item_check_funs', ['vam#install#CheckPoolItem'])
let s:c.change_to_unix_ff = get(s:c, 'change_to_unix_ff', (g:os=~#'unix'))
let s:c.do_diff = get(s:c, 'do_diff', 1)
let s:c.known = get(s:c, 'known', 'vim-addon-manager-known-repositories')
let s:c.MergeSources = get(s:c, 'MergeSources', 'vam_known_repositories#MergeSources')
let s:c.pool_fun = get(s:c, 'pool_fun', 'vam#install#Pool')
let s:c.name_rewriting = get(s:c, 'name_rewriting', {})
let s:c.pre_update_hook_functions = get(s:c, 'pre_update_hook_functions', ['vam#install#CreatePatch'])
let s:c.post_update_hook_functions = get(s:c, 'post_update_hook_functions', ['vam#install#ApplyPatch'])
let s:c.post_scms_update_hook_functions = get(s:c, 'post_scms_update_hook_functions', ['vam#install#ShowShortLog'])
let s:c.pool_item_check_funs = get(s:c, 'pool_item_check_funs', ['vam#install#CheckPoolItem'])

call extend(s:c.name_rewriting, {'99git+github': 'vam#install#RewriteName'})

Expand Down Expand Up @@ -71,9 +71,9 @@ fun! vam#install#RewriteName(name)
endfun

fun! vam#install#GetRepo(name, opts)
if a:name isnot# s:c['known'] | call vam#install#LoadPool() |endif
if a:name isnot# s:c.known | call vam#install#LoadPool() |endif

let repository = get(s:c['plugin_sources'], a:name, get(get(a:opts, 'plugin_sources', {}), a:name, 0))
let repository = get(s:c.plugin_sources, a:name, get(get(a:opts, 'plugin_sources', {}), a:name, 0))
if repository is 0
unlet repository
for key in sort(keys(s:c.name_rewriting))
Expand Down Expand Up @@ -126,14 +126,14 @@ fun! vam#install#ReplaceAndFetchUrls(list)
let t = n
endif
if exists('t')
let dic = vam#ReadAddonInfo(t)
let info = vam#ReadAddonInfo(t)
unlet t
if !has_key(dic,'name') || !has_key(dic, 'repository')
if !has_key(info, 'name') || !has_key(info, 'repository')
call vam#Log( n." is no valid addon-info file. It must contain both keys: name and repository")
continue
endif
let s:c['plugin_sources'][dic['name']] = dic['repository']
let l[idx] = dic['name']
let s:c.plugin_sources[info.name] = info.repository
let l[idx] = info.name
endif
endfor
return l
Expand Down Expand Up @@ -266,7 +266,7 @@ fun! vam#install#CreatePatch(info, repository, pluginDir, hook_opts)
call mkdir(a:pluginDir.'/archive', 'p')

let rep_copy = deepcopy(a:repository)
let rep_copy['url'] = 'file://'.expand(archiveFileBackup)
let rep_copy.url = 'file://'.expand(archiveFileBackup)
call vam#install#Checkout(a:pluginDir, rep_copy)
silent! call delete(a:pluginDir.'/version')
try
Expand Down Expand Up @@ -332,7 +332,7 @@ fun! vam#install#UpdateAddon(name)

" we have to find out whether there is a new version:
call vam#install#LoadPool()
let repository = get(s:c['plugin_sources'], a:name, {})
let repository = get(s:c.plugin_sources, a:name, {})
if empty(repository)
call vam#Log("Don't know how to update ".a:name." because it is not contained in plugin_sources")
return 'failed'
Expand Down Expand Up @@ -392,7 +392,7 @@ fun! vam#install#Update(list)
call vam#install#LoadPool(1)

if empty(list) && s:confirm('Update all loaded plugins?')
let list = keys(s:c['activated_plugins'])
let list = keys(s:c.activated_plugins)
endif
let by_reply = {}
for p in list
Expand Down Expand Up @@ -563,7 +563,7 @@ endfun
fun! vam#install#ArchiveNameFromDict(repository)
let archiveName = fnamemodify(substitute(get(a:repository,'archive_name',''), '\.\@<=VIM$', 'vim', ''),':t')
if empty(archiveName)
let archiveName = fnamemodify(a:repository['url'],':t')
let archiveName = fnamemodify(a:repository.url,':t')
endif
return archiveName
endfun
Expand Down Expand Up @@ -592,7 +592,7 @@ fun! vam#install#Checkout(targetDir, repository) abort
" archive will be downloaded to this location
let archiveFile = a:targetDir.'/archive/'.archiveName

call vam#utils#Download(a:repository['url'], archiveFile)
call vam#utils#Download(a:repository.url, archiveFile)

call vam#utils#Unpack(archiveFile, a:targetDir,
\ {'strip-components': get(a:repository,'strip-components',-1),
Expand Down Expand Up @@ -637,7 +637,7 @@ fun! vam#install#MergePluginFiles(plugins, skip_pattern)
let target = vam#install#MergeTarget()

for r in a:plugins
if !has_key(s:c['activated_plugins'], r)
if !has_key(s:c.activated_plugins, r)
throw "JoinPluginFiles: all plugins must be activated (which ensures that they have been installed). This plugin is not active: ".r
endif
endfor
Expand Down Expand Up @@ -753,9 +753,9 @@ endfun
" one of those commands. Read doc/vim-addon-manager.txt to learn about the
" pool of plugin sources. Also see option "known_repos_activation_policy"
fun! vam#install#LoadKnownRepos()
let known = s:c['known']
let known = s:c.known
let reason = a:0 > 0 ? a:1 : 'get more plugin sources'
if get(s:c['activated_plugins'], known, 0)
if get(s:c.activated_plugins, known, 0)
return 1
else
let policy=get(s:c, 'known_repos_activation_policy', 'autoload')
Expand Down Expand Up @@ -810,8 +810,8 @@ endfun

if g:is_win
fun! vam#install#FetchAdditionalWindowsTools() abort
if !isdirectory(s:c['binary_utils'].'\dist')
call mkdir(s:c['binary_utils'].'\dist','p')
if !isdirectory(s:c.binary_utils.'\dist')
call mkdir(s:c.binary_utils.'\dist','p')
endif
" we have curl, so we can fetch remaining deps using Download and Unpack
let tools = {
Expand All @@ -827,18 +827,18 @@ if g:is_win
for ex in v[2]
if executable(ex) | continue | endif
endfor
if !filereadable(s:c['binary_utils'].'\'.v[1])
call vam#utils#DownloadFromMirrors(v[0].v[1], s:c['binary_utils'])
if !filereadable(s:c.binary_utils.'\'.v[1])
call vam#utils#DownloadFromMirrors(v[0].v[1], s:c.binary_utils)
endif
endfor

if !executable('unzip')
" colorize this?
echo "__ its your turn: __"
echom "__ move all files of the zip directory into ".s:c['binary_utils'].'/dist . Close the Explorer window and the shell window to continue. Press any key'
echom "__ move all files of the zip directory into ".s:c.binary_utils.'/dist . Close the Explorer window and the shell window to continue. Press any key'
call getchar()
exec "!".expand(s:c['binary_utils'].'/'. tools.zip[1])
let $PATH=$PATH.';'.s:c['binary_utils_bin']
exec "!".expand(s:c.binary_utils.'/'. tools.zip[1])
let $PATH=$PATH.';'.s:c.binary_utils_bin
if !executable('unzip')
throw "can't execute unzip. Something failed!"
endif
Expand All @@ -847,7 +847,7 @@ if g:is_win
" now we have unzip and can do rest
for k in ["gzip","bzip2","tar","diffutils","patch"]
if !executable(tools[k][2])
call vam#utils#Unpack(s:c['binary_utils'].'\'.tools[k][1], s:c['binary_utils'].'\dist')
call vam#utils#Unpack(s:c.binary_utils.'\'.tools[k][1], s:c.binary_utils.'\dist')
endif
endfor

Expand All @@ -856,7 +856,7 @@ if g:is_win
"return
"endif
"let _7zurl = 'mirror://sourceforge/sevenzip/7-Zip/4.65/7z465.exe'
"call vam#utils#DownloadFromMirrors(_7zurl, s:c['binary_utils'].'/7z.exe')
"call vam#utils#DownloadFromMirrors(_7zurl, s:c.binary_utils.'/7z.exe')

endfun
endif
Expand Down
16 changes: 8 additions & 8 deletions autoload/vam/test.vim
Expand Up @@ -10,12 +10,12 @@ fun! vam#test#Test()
exec '!cp -r' s:plugin_root_dir test_dir

" keep it simple:
let g:vim_addon_manager['activated_plugins']['vim-addon-manager-known-repositories'] = 1
let plugin_sources = g:vim_addon_manager['plugin_sources']
let g:vim_addon_manager.activated_plugins['vim-addon-manager-known-repositories'] = 1
let plugin_sources = g:vim_addon_manager.plugin_sources

" test mercurial
call feedkeys("y")
let plugin_sources['vimstuff'] = { 'type': 'hg', 'url': 'http://vimstuff.hg.sourceforge.net:8000/hgroot/vimstuff/vimstuff' }
let plugin_sources.vimstuff = {'type': 'hg', 'url': 'http://vimstuff.hg.sourceforge.net:8000/hgroot/vimstuff/vimstuff'}
call vam#ActivateAddons(["vimstuff"])

" test git
Expand Down Expand Up @@ -54,7 +54,7 @@ fun! vam#test#TestUnpack(test) abort
for [k,v] in items(tests)
if k !~ a:test | continue | endif
call vam#utils#RmFR(tmpDir)
let dict = g:vim_addon_manager['plugin_sources'][v[0]]
let dict = g:vim_addon_manager.plugin_sources[v[0]]
call vam#install#Checkout(tmpDir, dict)
let files = vam#GlobInDir(tmpDir, '**')
" replace \ by / on win and remove tmpDir prefix
Expand All @@ -79,7 +79,7 @@ fun! vam#test#TestUpdate(case) abort
let plugin_source_file = tmpDir.'/'.plugin_name.'.vim'
let installDir = vam#PluginDirByName(plugin_name)
let installCompareDir = vam#PluginDirByName(plugin_name.'-1.0')
silent! unlet g:vim_addon_manager['activated_plugins'][plugin_name]
silent! unlet g:vim_addon_manager.activated_plugins[plugin_name]
for dir in [tmpDir, installDir, installCompareDir]
if isdirectory(dir) | call vam#utils#RmFR(dir) | endif
endfor
Expand All @@ -95,7 +95,7 @@ fun! vam#test#TestUpdate(case) abort

" install v1
call writefile( file_v1, plugin_source_file, 1)
let g:vim_addon_manager['plugin_sources'][plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '1.0' , 'script-type': 'plugin' }
let g:vim_addon_manager.plugin_sources[plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '1.0' , 'script-type': 'plugin' }
exec 'ActivateAddons '.plugin_name

" patch
Expand All @@ -105,7 +105,7 @@ fun! vam#test#TestUpdate(case) abort

" update to v2
call writefile( file_v2, plugin_source_file, 1)
let g:vim_addon_manager['plugin_sources'][plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '2.0' , 'script-type': 'plugin' }
let g:vim_addon_manager.plugin_sources[plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '2.0' , 'script-type': 'plugin' }
exec 'UpdateAddons '.plugin_name

" verify that the patch is still present
Expand All @@ -117,7 +117,7 @@ fun! vam#test#TestUpdate(case) abort
" manual test: diff file should be kept
" update to v2 conflict
call writefile( file_v2_conflict, plugin_source_file, 1)
let g:vim_addon_manager['plugin_sources'][plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '2.0' , 'script-type': 'plugin' }
let g:vim_addon_manager.plugin_sources[plugin_name] = {'type': 'archive', 'url': 'file://'.plugin_source_file, 'version' : '2.0' , 'script-type': 'plugin' }
exec 'UpdateAddons '.plugin_name
else
throw "unknown case"
Expand Down

0 comments on commit 92bb1bd

Please sign in to comment.