Skip to content
Browse files

Name rewriting fixes:

- removed a:repos argument
- made name_rewriting option be a list instead of dictinary
- added vam#install#RewriteName documentation
- added sane name_rewriting documentation
Other changes:
- Replaced input()'s with confirm()'s
- Replaced s:reply with reply
  • Loading branch information...
1 parent 5f8d50a commit d013fb8b7ef5841e4afddc6e55c7ddd08d4bbec7 @ZyX-I ZyX-I committed with ZyX-I Mar 20, 2011
Showing with 53 additions and 57 deletions.
  1. +33 −31 autoload/vam/install.vim
  2. +20 −26 doc/vim-addon-manager.txt
View
64 autoload/vam/install.vim
@@ -3,19 +3,21 @@
let s:curl = exists('g:netrw_http_cmd') ? g:netrw_http_cmd : 'curl -o'
exec vam#DefineAndBind('s:c','g:vim_addon_manager','{}')
-let s:c.name_rewriting = get(s:c,'name_rewriting',{})
-let s:nr = s:c.name_rewriting
-let s:nr.vam_defaults = get(s:nr,'git', function('vam#install#RewriteName'))
+let s:c.name_rewriting = get(s:c, 'name_rewriting', {})
+call extend(s:c.name_rewriting, {'99git+github': 'vam#install#RewriteName'})
-fun! vam#install#RewriteName(name, repos)
- if a:name =~ '^github:'
+fun! s:confirm(msg, ...)
+ return confirm(a:msg, a:0 ? "&No\n&Yes" : "&Yes\n&No") == 1+a:0
+endfun
+
+fun! vam#install#RewriteName(name)
+ if a:name[:6]==#'github:'
let rest = a:name[len('github:'):]
- call add(a:repos, {'type' : 'git', 'url' : 'git://github.com/'.(rest =~ '/' ? rest : rest.'/vim-addon-'.rest)})
- endif
- if a:name =~ '^git:'
- call add(a:repos, {'type' : 'git', 'url' : a:name[len('git:'):]})
+ return {'type' : 'git', 'url' : 'git://github.com/'.(rest =~ '/' ? rest : rest.'/vim-addon-'.rest)}
+ elseif a:name[:3]==#'git:'
+ return {'type' : 'git', 'url' : a:name[len('git:'):]}
endif
-endf
+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
@@ -27,7 +29,7 @@ fun! vam#install#ReplaceAndFetchUrls(list)
silent! unlet t
let n = l[idx]
" assume n is either an url or a path
- if n =~ '^http://' && 'y' == input('Fetch plugin info from url '.n.' [y/n]')
+ if n =~ '^http://' && s:confirm('Fetch plugin info from URL '.n.'?')
let t = tempfile()
exec '!'.s:curl.' '.t.' > '.s:shellescape(t)
elseif n =~ '[/\\]' && filereadable(n)
@@ -62,23 +64,23 @@ fun! vam#install#Install(toBeInstalledList, ...)
let repository = get(s:c['plugin_sources'], name, get(opts, name,0))
if type(repository) == type(0) && repository == 0
- " try rewriting plugin names. See vam#install#RewriteName
- let r =[]
- for [k,F] in items(s:nr)
- call call(F,[name, r])
- unlet k F
- endfor
- if len(r) > 0
+ unlet repository
+ for key in sort(keys(s:c.name_rewriting))
+ let repository=call(s:c.name_rewriting[key], [name], {})
+ if type(repository) == type({})
+ break
+ endif
unlet repository
- let repository = r[0]
+ endfor
+ if exists('repository')
echom 'name '.name.' expanded to :'.string(repository)
else
echoe "No repository location info known for plugin ".name."! (typo?)"
continue " due to abort this won't take place ?
endif
endif
- let confirmed = ''
+ let confirmed = 0
" tell user about target directory. Some users don't get it the first time..
let pluginDir = vam#PluginDirByName(name)
@@ -89,16 +91,16 @@ fun! vam#install#Install(toBeInstalledList, ...)
echom "!> Deprecation warning package ".name. ":"
echom d
" even for auto_install make user confirm the deprecation case
- if 'y' == input('Plugin '.name.' is deprecated. See warning above. Install it? [y/n]','')
- let confirmed = 'y'
+ if s:confirm('Plugin '.name.' is deprecated, see warning above. Install it?', 1)
+ let confirmed = 1
else
continue
endif
endif
" ask user for to confirm installation unless he set auto_install
- if auto_install || confirmed == 'y' || 'y' == input('Install plugin "'.name.'" ? [y/n]:','')
+ if auto_install || confirmed || s:confirm("Install plugin `".name."'?")
let infoFile = vam#AddonInfoFile(name)
call vam#install#Checkout(pluginDir, repository)
@@ -147,7 +149,7 @@ fun! vam#install#UpdateAddon(name)
" move plugin to backup destination:
let pluginDirBackup = pluginDir.'-'.oldVersion
if isdirectory(pluginDirBackup) || filereadable(pluginDirBackup)
- if "y" == input("old plugin backup directory found: ".pluginDirBackup.", remove? [y/n]")
+ if s:confirm("Remove old plugin backup directory (".pluginDirBackup.")?")
call vam#utils#RmFR(pluginDirBackup)
else
throw "user abort: remove ".pluginDirBackup." manually"
@@ -222,7 +224,7 @@ endf
fun! vam#install#Update(list)
let list = a:list
- if empty(list) && input('Update all loaded plugins? [y/n] ','y') == 'y'
+ if empty(list) && s:confirm('Update all loaded plugins?')
call vam#install#LoadKnownRepos(' so that its updated as well')
" include vim-addon-manager in list
if !s:c['system_wide']
@@ -300,7 +302,7 @@ fun! vam#install#UninstallAddons(list)
return
endif
call map(list, 'vam#PluginDirByName(v:val)')
- if input('Confirm running rm -fr on directories: '.join(list,", ").'? [y/n]') == 'y'
+ if s:confirm('Confirm running rm -fr on directories: '.join(list,", ").'?')
call map(list, 'vam#utils#RmFR(v:val)')
endif
endf
@@ -393,14 +395,14 @@ fun! vam#install#LoadKnownRepos(...)
if 0 == get(s:c['activated_plugins'], known, 0)
let policy=get(s:c, 'known_repos_activation_policy', 'autoload')
if policy==?"ask"
- let s:reply = input('Activate plugin '.known.' to '.reason."? [y/n/N=don't ask again this (session)]:",'')
+ let reply = confirm('Activate plugin '.known.' to '.reason."?", "&Yes\n&No\nN&ever (during session)")
elseif policy==?"never"
- let s:reply="n"
+ let reply=2
else
- let s:reply='y'
+ let reply=1
endif
- if s:reply ==# 'N' | let s:c.known_repos_activation_policy = "never" | endif
- if s:reply ==? 'y'
+ if reply == 3 | let s:c.known_repos_activation_policy = "never" | endif
+ if reply == 1
call vam#ActivateAddons([known])
" This is not done in .vimrc because Vim loads plugin/*.vim files after
" having finished processing .vimrc. So do it manually
View
46 doc/vim-addon-manager.txt
@@ -9,9 +9,6 @@ CONTENTS *vim-addon-manager-contents*
3. Functionality provided |vim-addon-manager-functionality|
3.1. Commands |vim-addon-manager-commands|
3.2. Functions |vim-addon-manager-functions|
- 3.3. name rewriting |vim-addon-manager-name-rewriting|
- (keeping track of your
- personal vim configuration)
4. Options |vim-addon-manager-options|
5. Installing plugins |vim-addon-manager-install-plugins|
6. Addon-info file |vim-addon-manager-addon-info|
@@ -93,7 +90,7 @@ manually:
call SetupVAM()
" experimental: run after gui has been started [3]
" option1: au VimEnter * call SetupVAM()
- " option2: au GUIEnter * call SetupVAM()
+ " option2: au GUIEnter * call SetupVAM()
" See BUGS sections below [*]
< Note: Depending on the way you choose to run ActivateAddons Vim may not be
@@ -103,7 +100,6 @@ manually:
4. Optionally generate helptags: >
UpdateAddon vim-addon-manager
-<
Continue reading |vim-addon-manager-install-plugins|.
@@ -217,27 +213,14 @@ vam#install#MergePluginFiles([{name}] [, blacklist-regex ])
Yes, the info files should be cached as well (TODO)
-------------------------------------------------------------------------------
-3.3. name rewriting / personal Vim config *vim-addon-manager-name-rewriting*
-
- We all have our custom config - and maybe we all think that our setup is
- interesting - but not interesting enough to tell everybody about the url.
-
- For this reason name rewriting has been introduced:
- Whenever a name is unkown rewriting is tried. >
- g:vim_addon_manager.name_rewriting
-< contains a dict of functions rewriting names. The default implementation is
- |vam#install#RewriteName| which allows following shortcuts: >
-
- github:YourName -> {'type':'git', 'url': 'git://github.com/YourName/vim-addon-YourName'}
- github:Name/Repo -> {'type':'git', 'url': 'git://github.com/Name/Repo'}
-
- git:URL -> {'type':'git', 'url': 'URL'} (experimental, is vam#PluginDirByName used everywhere?)
-
-< Thus using the addon name github:YourName is enough to install your personal
- Vim config whose plugin/*.vim files can call ActivateAddons again to load
- additional plugins.
- Of course patches for additional rewritings will be accepted
+vam#install#RewriteName({name}) *vam#install#RewriteName()*
+ Returns a dictionary if {name} matches one of the following patterns:
+ Pattern Dictionary ~
+ github:{Name} {"type": "git",
+ "url": "git://github.com/{Name}/vim-addon-{Name}}
+ github:{N}/{Repo} {"type": "git",
+ "url": "git://github.com/{N}/{Repo}"}
+ git:{URL} {"type": "git", "url": {URL}} (experimental)
==============================================================================
4. Options *vim-addon-manager-options*
@@ -295,6 +278,17 @@ do_diff *vim-addon-manager-do_diff*
If this option is true (default), then try to retain user changes to
installed plugins (unless they are under SCM control). Requires diff
and patch programs installed.
+name_rewriting *vim-addon-manager-name_rewriting*
+ Set this to a dictionary with functions each taking a plugin name and
+ returning either a dictionary with repository location (see
+ |addon-info-repository|) for given name or zero. Location will be set
+ to the first non-zero value, functions are executed in order
+ determined by |sort()|ing |keys()| of the dictionary. These functions
+ will be called when repository location for requested plugin is not
+ found.
+ Value will be extended with >
+ {"99git+github": "vam#install#RewriteName"}
+< after it is read (see |vam#install#RewriteName()|).
==============================================================================
5. Installing plugins *vim-addon-manager-install-plugins*

0 comments on commit d013fb8

Please sign in to comment.
Something went wrong with that request. Please try again.