Skip to content

Commit

Permalink
Rebranding
Browse files Browse the repository at this point in the history
  • Loading branch information
ZyX-I committed Jan 20, 2014
1 parent 4709ec9 commit 79e0548
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 228 deletions.
@@ -1,9 +1,9 @@
{
"name" : "vim-addon-manager-known-repositories",
"version" : "0.0",
"name" : "vim-pi",
"version" : "undefined",
"author" : "Marc Weber <marco-oweber@gmx.de>",
"maintainer" : "Marc Weber <marco-oweber@gmx.de>",
"repository" : {"type": "git", "url": "git://github.com/MarcWeber/vim-addon-manager-known-repositories.git"},
"repository" : {"type": "git", "url": "https://bitbucket.org/vimcommunity/vim-pi"},
"dependencies" : {},
"description" : "this repository contains a list of known other repositories only"
}
12 changes: 6 additions & 6 deletions autoload/vam_known_repositories.vim
Expand Up @@ -11,8 +11,8 @@ let s:c['MergeSources']=get(g:vim_addon_manager, 'MergeSources', 'vam_known_repo
" If you have custom packages overwrite this function and patch whatever you
" want to patch...
"
" arg www_vim_org: See vamkr#www_vim_org_generated#Sources() (result is patched vamkr#patch#Patch)
" arg scm_plugin_sources: See vamkr#scm#Sources() (vim_script_nr_X is replaced by plugin's name in keys)
" arg www_vim_org: See vimpi#www_vim_org_generated#Sources() (result is patched vamkr#patch#Patch)
" arg scm_plugin_sources: See vimpi#scm#Sources() (vim_script_nr_X is replaced by plugin's name in keys)
fun! vam_known_repositories#MergeSources(plugin_sources, www_vim_org, scm_plugin_sources, patch_function, snr_to_name)

let merge_strategy = get(s:c, 'scm_merge_strategy', 'force')
Expand Down Expand Up @@ -49,16 +49,16 @@ endf
" Its the default implementation for the one function returning the pool of
" known addons.
fun! vam_known_repositories#Pool()
let www_vim_org = vamkr#LoadDBFile('vimorgsources.json')
let snr_to_name = vamkr#GetNrToNameMap(www_vim_org)
let scm = vamkr#GetSCMSources(snr_to_name, www_vim_org)
let www_vim_org = vimpi#LoadDBFile('vimorgsources.json')
let snr_to_name = vimpi#GetNrToNameMap(www_vim_org)
let scm = vimpi#GetSCMSources(snr_to_name, www_vim_org)

" start from scratch adding plugin sources to pool:
let pool = copy(get(s:c, 'plugin_sources', {}))

" now call MergeSources merge function so that user can pick scm over
" www_vim_org sources as she desires.
call call(s:c['MergeSources'], [pool, www_vim_org, scm, 'vamkr#PatchSources', snr_to_name], {})
call call(s:c['MergeSources'], [pool, www_vim_org, scm, 'vimpi#PatchSources', snr_to_name], {})

return pool
endf
162 changes: 16 additions & 146 deletions autoload/vamkr.vim
@@ -1,147 +1,17 @@
if exists('g:vam_kr_running_hook_test')
function s:Log(message)
throw a:message
endfunction
elseif exists('g:vam_kr_silent')
function! s:Log(message)
endfunction
else
let s:Log=function('vam#Log')
endif

if !exists('g:vam_kr_database_directory')
let s:dbdir = expand('<sfile>:h:h').'/db'
else
let s:dbdir = g:vam_kr_database_directory
endif

function! vamkr#LoadDBFile(file) abort
let ext=fnamemodify(a:file, ':e')
let file=s:dbdir.'/'.a:file
if ext is# 'vim'
" The following code executes content of a .vim file returning the r var
" which should be defined. Its similar to using autoload functions.
" However autoload functions would not be garbage collected. Whether its
" insane to think about this small details - I don't know. Its ZyX idea
" and gets the job done. Little bit uncommon :)
"
" limitations: You can’t use line continuation here
execute "function! s:Vim()\n".join(readfile(file, 'b'), "\n")."\nreturn r\nendfunction"
try
let r=s:Vim()
catch /.*/
throw "error: ".v:exception.' real error location ('.a:file.'): '.v:throwpoint
endtry
delfunction s:Vim
return r
elseif ext is# 'json'
try
return eval(join(readfile(file, 'b'), ''))
catch /.*/
throw 'Failed to read json file “'.file.'”: '.v:exception.' '.v:throwpoint
endtry
else
throw 'Unknown file type: '.ext
endif
endfunction

function! vamkr#SuggestNewName(name)
let messages = []
for [nr, names] in items(vamkr#LoadDBFile('script-id-to-name-log.json'))
if index(names, a:name) > 0
call add(messages, a:name." was renamed to ".names[0])
endif
endfor
return messages
endfunction

function! s:FilterConflicts(from, with, bang)
let r=[]
call filter(a:from, a:bang.'has_key(a:with, v:key) ? 1 : [0, add(r, v:key)][0]')
return r
endfunction

function! vamkr#GetSCMSources(snr_to_name, www_vim_org)
let [scm, scmnr]=vamkr#LoadDBFile('scmsources.vim')
let scmnr_generated=vamkr#LoadDBFile('scm_generated.json')
call extend(scmnr, scmnr_generated, 'keep')
let scmvoconflicts=s:FilterConflicts(scm, a:www_vim_org, '!')
if !empty(scmvoconflicts)
call s:Log('The following scm keys are the same as vim.org ones: '.join(scmvoconflicts, ', ').".\n".
\'These plugins should either be renamed or put into scmnr dictionary.')
endif
let missingscmnr=s:FilterConflicts(scmnr, a:snr_to_name, '')
if !empty(missingscmnr)
call s:Log('The following scmnr keys are not known: '.join(missingscmnr, ', ').'.')
runtime autoload/vimpi.vim

redir => s:funcs
" Do not make it indent: use :execute to hide :function
silent execute 'function /^vimpi#'
redir END

for s:fname in map(split(s:funcs, "\n"), 'matchstr(v:val, ''\v%(vimpi#)@<=[^(]*'')')
if !empty(s:fname)
execute "function vamkr#".s:fname."(...)"
\."\n echohl WarningMsg"
\."\n echomsg 'Function vamkr#".s:fname." is deprecated, use vimpi#".s:fname."'"
\."\n echohl None"
\."\n return call('vimpi#".s:fname."', a:000)"
\."\nendfunction"
endif
" Merge scmnr sources into scm, rewriting numbers as names. But first add
" vim_script_nr key so that AddonInfo still finds the plugin even if scm
" overwrites www_vim_org sources
call map(scmnr, 'extend(scm, {a:snr_to_name[v:key] : extend(v:val, {"vim_script_nr": v:key})})')
unlet scmnr
" Transform names like %{snr} in dependencies dictionary into names used by
" VAM
for repository in filter(values(scm), 'has_key(v:val, "addon-info") && has_key(v:val["addon-info"], "dependencies")')
let depdict=repository['addon-info'].dependencies
for depname in filter(keys(depdict), 'v:val[0] is# "%"')
call remove(depdict, depname)
let depdict[a:snr_to_name[depname[1:]]]={}
endfor
endfor
return scm
endfunction

function! vamkr#PatchSources(sources, snr_to_name)
let [patch_repo, addon_info, addon_info_deps, renamings]=vamkr#LoadDBFile('patchinfo.vim')
" short documentation see patchinfo.vim

for [snr, deps] in items(addon_info_deps)
if !has_key(addon_info, snr)
let addon_info[snr]={}
endif
let ms = addon_info[snr]
let ms.dependencies = get(addon_info, 'dependencies', {})
call map(deps, 'extend( ms.dependencies, {(type(v:val) == type(0) ? a:snr_to_name[v:val] : v:val) : {}})')
endfor
call filter(addon_info, 'has_key(a:snr_to_name, v:key)')
call map(addon_info, 'extend(patch_repo, {v:key : extend(get(patch_repo, v:key, {}), {"addon-info": v:val})})')
let add_by_name={}
call map(patch_repo, 'extend(add_by_name, {a:snr_to_name[v:key] : v:val})')
call map(filter(add_by_name, 'has_key(a:sources, v:key)'), 'extend(a:sources[v:key], v:val)')

for [from, to_] in items(renamings)
if has_key(a:sources, to_) | throw "cannot rename ".from.' to '.to_ | endif
let a:sources[to_] = a:sources[from]
call remove(a:sources, from)
let a:sources[to_].old_title = from
unlet from to_
endfor

return a:sources
endfunction

function! vamkr#AddCopyHook(repository, files)
let hook=[]
let dirs={}
for [file, dir] in items(a:files)
let dirs[dir]=1
" Assuming that no one is crazy enough to really have newlines in
" filename
let hook+=['call vam#utils#CopyFile(%d.'.string('/'.file).', %d.'.string('/'.dir.'/'.file).')']
endfor
let a:repository['addon-info']={}
let a:repository['addon-info']['post-install-hook']=join(map(keys(dirs), '"call mkdir(%d.".string("/".v:val).(stridx(v:val, "/")==-1 ? "" : ", ''p''").")"')+hook, ' | ')
let a:repository['addon-info']['post-scms-update-hook']=join(hook, ' | ')
return a:repository " Make it possible to use let scmnr.XXXX = vamkr#AddCopyHook({...}, {...})
endfunction

function! vamkr#GetNrToNameMap(www_vim_org)
" build vim_script_nr to name lookup dictionary:
" nr_to_name is not exposed to the user (can only be accessed via function
" arg) because running #Pool() is expensive. That's why its done only when
" installing or upgrading plugins ..
let snr_to_name={}
call map(copy(a:www_vim_org), 'extend(snr_to_name, {v:val.vim_script_nr : v:key})')
return snr_to_name
endfunction
" vim: ft=vim ts=4 sts=4 sw=4 et fmr=▶,▲
endfor
147 changes: 147 additions & 0 deletions autoload/vimpi.vim
@@ -0,0 +1,147 @@
if exists('g:vim_pi_running_hook_test')
function s:Log(message)
throw a:message
endfunction
elseif exists('g:vim_pi_silent')
function! s:Log(message)
endfunction
else
let s:Log=function('vam#Log')
endif

if !exists('g:vim_pi_database_directory')
let s:dbdir = expand('<sfile>:h:h').'/db'
else
let s:dbdir = g:vim_pi_database_directory
endif

function! vimpi#LoadDBFile(file) abort
let ext=fnamemodify(a:file, ':e')
let file=s:dbdir.'/'.a:file
if ext is# 'vim'
" The following code executes content of a .vim file returning the r var
" which should be defined. Its similar to using autoload functions.
" However autoload functions would not be garbage collected. Whether its
" insane to think about this small details - I don't know. Its ZyX idea
" and gets the job done. Little bit uncommon :)
"
" limitations: You can’t use line continuation here
execute "function! s:Vim()\n".join(readfile(file, 'b'), "\n")."\nreturn r\nendfunction"
try
let r=s:Vim()
catch /.*/
throw "error: ".v:exception.' real error location ('.a:file.'): '.v:throwpoint
endtry
delfunction s:Vim
return r
elseif ext is# 'json'
try
return eval(join(readfile(file, 'b'), ''))
catch /.*/
throw 'Failed to read json file “'.file.'”: '.v:exception.' '.v:throwpoint
endtry
else
throw 'Unknown file type: '.ext
endif
endfunction

function! vimpi#SuggestNewName(name)
let messages = []
for [nr, names] in items(vimpi#LoadDBFile('script-id-to-name-log.json'))
if index(names, a:name) > 0
call add(messages, a:name." was renamed to ".names[0])
endif
endfor
return messages
endfunction

function! s:FilterConflicts(from, with, bang)
let r=[]
call filter(a:from, a:bang.'has_key(a:with, v:key) ? 1 : [0, add(r, v:key)][0]')
return r
endfunction

function! vimpi#GetSCMSources(snr_to_name, www_vim_org)
let [scm, scmnr]=vimpi#LoadDBFile('scmsources.vim')
let scmnr_generated=vimpi#LoadDBFile('scm_generated.json')
call extend(scmnr, scmnr_generated, 'keep')
let scmvoconflicts=s:FilterConflicts(scm, a:www_vim_org, '!')
if !empty(scmvoconflicts)
call s:Log('The following scm keys are the same as vim.org ones: '.join(scmvoconflicts, ', ').".\n".
\'These plugins should either be renamed or put into scmnr dictionary.')
endif
let missingscmnr=s:FilterConflicts(scmnr, a:snr_to_name, '')
if !empty(missingscmnr)
call s:Log('The following scmnr keys are not known: '.join(missingscmnr, ', ').'.')
endif
" Merge scmnr sources into scm, rewriting numbers as names. But first add
" vim_script_nr key so that AddonInfo still finds the plugin even if scm
" overwrites www_vim_org sources
call map(scmnr, 'extend(scm, {a:snr_to_name[v:key] : extend(v:val, {"vim_script_nr": v:key})})')
unlet scmnr
" Transform names like %{snr} in dependencies dictionary into names used by
" VAM
for repository in filter(values(scm), 'has_key(v:val, "addon-info") && has_key(v:val["addon-info"], "dependencies")')
let depdict=repository['addon-info'].dependencies
for depname in filter(keys(depdict), 'v:val[0] is# "%"')
call remove(depdict, depname)
let depdict[a:snr_to_name[depname[1:]]]={}
endfor
endfor
return scm
endfunction

function! vimpi#PatchSources(sources, snr_to_name)
let [patch_repo, addon_info, addon_info_deps, renamings]=vimpi#LoadDBFile('patchinfo.vim')
" short documentation see patchinfo.vim

for [snr, deps] in items(addon_info_deps)
if !has_key(addon_info, snr)
let addon_info[snr]={}
endif
let ms = addon_info[snr]
let ms.dependencies = get(addon_info, 'dependencies', {})
call map(deps, 'extend( ms.dependencies, {(type(v:val) == type(0) ? a:snr_to_name[v:val] : v:val) : {}})')
endfor
call filter(addon_info, 'has_key(a:snr_to_name, v:key)')
call map(addon_info, 'extend(patch_repo, {v:key : extend(get(patch_repo, v:key, {}), {"addon-info": v:val})})')
let add_by_name={}
call map(patch_repo, 'extend(add_by_name, {a:snr_to_name[v:key] : v:val})')
call map(filter(add_by_name, 'has_key(a:sources, v:key)'), 'extend(a:sources[v:key], v:val)')

for [from, to_] in items(renamings)
if has_key(a:sources, to_) | throw "cannot rename ".from.' to '.to_ | endif
let a:sources[to_] = a:sources[from]
call remove(a:sources, from)
let a:sources[to_].old_title = from
unlet from to_
endfor

return a:sources
endfunction

function! vimpi#AddCopyHook(repository, files)
let hook=[]
let dirs={}
for [file, dir] in items(a:files)
let dirs[dir]=1
" Assuming that no one is crazy enough to really have newlines in
" filename
let hook+=['call vam#utils#CopyFile(%d.'.string('/'.file).', %d.'.string('/'.dir.'/'.file).')']
endfor
let a:repository['addon-info']={}
let a:repository['addon-info']['post-install-hook']=join(map(keys(dirs), '"call mkdir(%d.".string("/".v:val).(stridx(v:val, "/")==-1 ? "" : ", ''p''").")"')+hook, ' | ')
let a:repository['addon-info']['post-scms-update-hook']=join(hook, ' | ')
return a:repository " Make it possible to use let scmnr.XXXX = vimpi#AddCopyHook({...}, {...})
endfunction

function! vimpi#GetNrToNameMap(www_vim_org)
" build vim_script_nr to name lookup dictionary:
" nr_to_name is not exposed to the user (can only be accessed via function
" arg) because running #Pool() is expensive. That's why its done only when
" installing or upgrading plugins ..
let snr_to_name={}
call map(copy(a:www_vim_org), 'extend(snr_to_name, {v:val.vim_script_nr : v:key})')
return snr_to_name
endfunction
" vim: ft=vim ts=4 sts=4 sw=4 et fmr=▶,▲
2 changes: 1 addition & 1 deletion db/patchinfo.vim
@@ -1,7 +1,7 @@
" This file is the "patch" to modify the repository informations retrieved
" from vim.sf.net
" Most numbers represent vim-script numbers
" See vamkr#PatchSources
" See vimpi#PatchSources
let patch_repo = {}
let addon_info = {}
let addon_info_deps = {}
Expand Down

0 comments on commit 79e0548

Please sign in to comment.