Skip to content

Commit

Permalink
Allow passing dictionaries instead of names to ActivateAddons
Browse files Browse the repository at this point in the history
reasons:
- allow completing vundle emulation {rtp keys}
- allow version locking, eg user can do
   call ActivateAddons([{name: "foo", tag: "bar"}])
- If vim-pi switches format so that each repository can contain multiple sources
  users can pass 'source-from': "github" or "vim" like hints per package.
  (future story)
- patching the pool is no longer neccessary, you can just pass repository
  information to ActivateAddons.

Nicer vundle like api could be introduced such as VAMActivateWithOptions
command (arg and options)
  • Loading branch information
MarcWeber committed Feb 13, 2014
1 parent c5a2c91 commit a59d517
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
38 changes: 33 additions & 5 deletions autoload/vam.vim
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,18 @@ endfun
" 'auto_install': when 1 overrides global setting, so you can autoinstall
" trusted repositories only
" }
fun! vam#ActivateRecursively(list_of_names, ...)
fun! vam#ActivateRecursively(list_of_scripts, ...)
let opts = extend({'run_install_hooks': 1}, a:0 == 0 ? {} : a:1)

for name in a:list_of_names
for script_ in a:list_of_scripts
let name = script_.name
if !has_key(s:c.activated_plugins, name)
" break circular dependencies..
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))
if empty(vam#install#Install([script_], opts))
unlet s:c.activated_plugins[name]
continue
endif
Expand Down Expand Up @@ -243,10 +244,33 @@ fun! s:ResetVars(buf)
endif
endfun

fun! vam#PreprocessScriptIdentifier(list)
" turn name into dictionary
for i in range(0, len(a:list)-1)
" 1 is string
if type(a:list[i]) == 1
let a:list[i] = {'name': a:list[i]}
endif
endfor

" Merging with the pool will be done in install.vim because that's only
" sourced when installations take place
" only be loaded when installations take place
endf

" see also ActivateRecursively
" Activate activates the plugins and their dependencies recursively.
" I sources both: plugin/*.vim and after/plugin/*.vim files when called after
" .vimrc has been sourced which happens when you activate plugins manually.
"
" The script names will be turned into {'name': name}. Dictionaries can
" contain additional keys. Which ones depends also on future usage. Use cases
" - vundle emualtion ('rtp' key)
" - version locking
"
" Additional keys from pool or name rewriting will be merged unless keys exist
" and unless 'type' key exists (which signals that the data is already complete)
" This happens in vam#install#CompleteRepoData
fun! vam#ActivateAddons(...) abort
let args = copy(a:000)
if a:0 == 0 | return | endif
Expand Down Expand Up @@ -283,8 +307,12 @@ fun! vam#ActivateAddons(...) abort
let opts = args[1]
let topLevel = !has_key(opts, 'new_runtime_paths')

let to_activate = args[0]

call vam#PreprocessScriptIdentifier(args[0])

if exists('g:vam_plugin_whitelist') && topLevel
call filter(args[0], 'index(g:vam_plugin_whitelist, v:val) != -1')
call filter(args[0], 'index(g:vam_plugin_whitelist, v:val.name) != -1')
endif

" add new_runtime_paths state if not present in opts yet
Expand All @@ -296,7 +324,7 @@ fun! vam#ActivateAddons(...) abort
let opts.to_be_activated = to_be_activated

for a in args[0]
let to_be_activated[a] = 1
let to_be_activated[a.name] = a
endfor

call call('vam#ActivateRecursively', args)
Expand Down
40 changes: 27 additions & 13 deletions autoload/vam/install.vim
Original file line number Diff line number Diff line change
Expand Up @@ -73,49 +73,61 @@ fun! vam#install#RewriteName(name)
endif
endfun

fun! vam#install#GetRepo(name, opts)
if a:name isnot# s:c.known | call vam#install#LoadPool() |endif
fun! vam#install#CompleteRepoData(repository, opts)
if has_key(a:repository, 'type')
" looks like repository is already complete ..
return a:repository
endif

" add missing information by
" 1) lookup in pool
" 2) try turning name into source by s:c.name_rewriting
let name = a:repository.name
if 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, name, get(get(a:opts, 'plugin_sources', {}), name, 0))
if repository is 0
unlet repository
for key in sort(keys(s:c.name_rewriting))
let repository=call(s:c.name_rewriting[key], [a:name], {})
let repository=call(s:c.name_rewriting[key], [name], {})
if type(repository) == type({})
break
endif
unlet repository
endfor
if exists('repository')
echom 'Name '.a:name.' expanded to :'.string(repository)
echom 'Name '.name.' expanded to :'.string(repository)
else
" try to find typos and renamings. Tell user about failure
let maybe_fixes = []
let name_ = vam#utils#TypoFix(a:name)
let name_ = vam#utils#TypoFix(name)
for x in keys(s:c.plugin_sources)
if vam#utils#TypoFix(x) == name_
call add(maybe_fixes, a:name.' might be a typo, did you mean: '.x.' ?')
call add(maybe_fixes, name.' might be a typo, did you mean: '.x.' ?')
endif
endfor
" try finding new name (vim-pi only)
try
" using try because pool implementations other then vim-pi could be
" used
call extend(maybe_fixes, vimpi#SuggestNewName(a:name))
call extend(maybe_fixes, vimpi#SuggestNewName(name))
catch /Vim(call):E117:/
" If vim-pi activation policy is never, then the above will yield
" unknown function error
endtry
call vam#Log(join(["No repository location info known for plugin ".a:name."."] + maybe_fixes,"\n"))
call vam#Log(join(["No repository location info known for plugin ".name."."] + maybe_fixes,"\n"))
return 0
endif
endif
call extend(repository, a:repository)
return repository
endfun

" Install let's you install plugins by passing the url of a addon-info file
" This preprocessor replaces the urls by the plugin-names putting the
" repository information into the global dict
"
" TODO: Does anybody use this? Is it worth keeping?
fun! vam#install#ReplaceAndFetchUrls(list)
let l = a:list
let idx = 0
Expand All @@ -139,7 +151,6 @@ fun! vam#install#ReplaceAndFetchUrls(list)
let l[idx] = info.name
endif
endfor
return l
endfun

fun! vam#install#RunHook(hook, info, repository, pluginDir, opts)
Expand All @@ -162,12 +173,15 @@ endfun

" opts: same as ActivateAddons
fun! vam#install#Install(toBeInstalledList, ...)
let toBeInstalledList = vam#install#ReplaceAndFetchUrls(a:toBeInstalledList)
let toBeInstalledList = a:toBeInstalledList
call vam#PreprocessScriptIdentifier(toBeInstalledList)
call vam#install#ReplaceAndFetchUrls(map(copy(a:toBeInstalledList),'v:val.name'))
let opts = a:0 == 0 ? {} : a:1
let auto_install = get(opts, 'auto_install', s:c.auto_install)
let installed = []
for name in filter(copy(toBeInstalledList), '!vam#IsPluginInstalled(v:val)')
let repository = vam#install#GetRepo(name, opts)
for to_install in filter(copy(toBeInstalledList), '!vam#IsPluginInstalled(v:val.name)')
let repository = vam#install#CompleteRepoData(to_install, opts)
let name = repository.name
" make sure all sources are known
if repository is 0
continue
Expand Down

0 comments on commit a59d517

Please sign in to comment.