Browse Source

improved vim-7.0 support: most (all?) operations work

* created autoload/vundle/compat.vim: "compatibility" module
    (implements functions not available in previous vim versions);
    (code taken from my previous commit in 'autoload/vundle/config.vim',
    then modified and extended);
  * added compatibility function for shellescape();
 * autoload/vundle/config.vim: tidied up so that it's a bit closer to
    the file upstream;
  * (previous commit) but added a few performance improvements (avoid
     unnecessary calls and/or operations);
 * altered other scripts to use 'vundle#compat#*()' functions instead of
    those not necessarily available in previous vim versions;
pull/354/head
Ezequiel Valenzuela 12 years ago
parent
commit
ca9044cc60
5 changed files with 178 additions and 122 deletions
  1. +161
    -0
      autoload/vundle/compat.vim
  2. +8
    -113
      autoload/vundle/config.vim
  3. +4
    -4
      autoload/vundle/installer.vim
  4. +4
    -4
      autoload/vundle/scripts.vim
  5. +1
    -1
      test/vimrc

+ 161
- 0
autoload/vundle/compat.vim View File

@ -0,0 +1,161 @@
" this abstracts the operation:
" exec 'set runtimepath-='.fnameescape(LIST)
"
" ... even when fnameescape() is not available (on vim-7.0, for example)
"
" notes:
" * it attempts to do the "real thing", if it can
" (if 'fnameescape()' is available);
" * otherwise, it has a number of fallback scenarios, ordered by
" reliability;
" * special case: if a:dirs contains a ',' (multiple entries), this function
" attempts the
" exec 'set runtimepath-='.fnameescape(LIST)
" first (if fnameescape() is available).
" if that does not alter &runtimepath, then it tries to remove a:dirs
" elements individually;
"
" args:
" dirs [string]: described as 'LIST' above;
"
" for now, it does not produce an explicit return value
"
func! vundle#compat#rtp_rm_entry(dirs)
" debug: echomsg '[debug] vundle#compat#rtp_rm_entry(): entered. rtp: ' . string(&rtp) . '; dirs: ' . string(a:dirs)
" optimisation: there seems to be a few of these cases
if empty(a:dirs)
return 0
endif
let l:runtimepath_orig = &rtp
let l:processed_flag = 0
let l:elem_separator = ','
for l:process_stage in range(1, 4)
if ( l:process_stage == 1 )
if exists('*fnameescape')
exec 'set rtp-='.fnameescape(a:dirs)
" if &rtp was altered, or a:dirs had only one element, we won't keep
" trying
let l:processed_flag = ( ( &rtp != l:runtimepath_orig ) || ( stridx(a:dirs, l:elem_separator) < 0 ) )
endif
elseif ( l:process_stage == 2 )
if exists('*split') && exists('*filter') && exists('*join')
" a bit costly, but more compatible
let l:runtimepath_list = split(&rtp, l:elem_separator, 1)
unlet! g:vundle_config_compat_rtp_rm_entry_dir
for g:vundle_config_compat_rtp_rm_entry_dir in split(a:dirs, l:elem_separator, 1)
let l:runtimepath_list = filter(l:runtimepath_list, 'v:val != g:vundle_config_compat_rtp_rm_entry_dir')
endfor
unlet! g:vundle_config_compat_rtp_rm_entry_dir
" assemble the runtime variable from the list
let &rtp = join(l:runtimepath_list, l:elem_separator)
let l:processed_flag = 1
endif
elseif ( l:process_stage == 3 )
if exists('*escape')
" from fnameescape() documentation:
" it escapes: " \t\n*?[{`$\\%#'\"|!<"
" plus, depending on 'isfname', other characters.
" (TODO: add those cases, if needed)
exec 'set rtp-='.escape(a:dirs, " \t\n*?[{`$\\%#'\"|!<")
let l:processed_flag = 1
endif
elseif ( l:process_stage == 4 )
" cheap and cheerful (but no escaping)
exec 'set rtp-='.a:dirs
let l:processed_flag = 1
endif
if l:processed_flag
break
endif
endfor
" debug: echomsg '[debug] vundle#compat#rtp_rm_entry(): exiting. rtp: ' . string(&rtp)
endf
" abstracts the following operations:
" exec 'set runtimepath^='.fnameescape(LIST)
" exec 'set runtimepath+='.fnameescape(LIST)
" exec 'set runtimepath='.fnameescape(LIST)
"
" ... even when fnameescape() is not available (on vim-7.0, for example)
"
" args:
" dirs [string]: described as 'LIST' above;
" addset_operator [string]: one of:
" '^': prepend ('set runtimepath^=');
" '+': append ('set runtimepath+=');
" '': set ('set runtimepath=');
"
" for now, it does not produce an explicit return value
"
func! vundle#compat#rtp_addset_entry(dirs, addset_operator)
" debug: echomsg '[debug] vundle#compat#rtp_addset_entry(): entered. rtp: ' . string(&rtp) . '; dirs: ' . string(a:dirs) . '; operator: ' . string( a:addset_operator )
if exists('*fnameescape')
exec 'set rtp'.a:addset_operator.'='.fnameescape(a:dirs)
else
" a bit costly, but more compatible
if ( a:addset_operator == '' ) && empty(&rtp)
" this should be quick
let &rtp = a:dirs
else
let l:elem_separator = ','
" only add the elements not already present in &runtimepath
if exists('*split') && exists('*filter') && exists('*join')
" a bit costly, but more compatible
let l:dirs_list = split(a:dirs, l:elem_separator, 1)
unlet! g:vundle_config_compat_rtp_addset_entry_dir
for g:vundle_config_compat_rtp_addset_entry_dir in split(&rtp, l:elem_separator, 1)
let l:dirs_list = filter(l:dirs_list, 'v:val != g:vundle_config_compat_rtp_addset_entry_dir')
endfor
unlet! g:vundle_config_compat_rtp_addset_entry_dir
let l:dirs = join(l:dirs_list, l:elem_separator)
else
" nothing we can do about this: we'll take the input as is
let l:dirs = a:dirs
endif
if !empty(l:dirs)
if a:addset_operator == '^'
let &rtp = l:dirs . l:elem_separator . &rtp
elseif a:addset_operator == '+'
let &rtp = &rtp . l:elem_separator . l:dirs
else
" FIXME: report internal error
endif
endif
endif
endif
" debug: echomsg '[debug] vundle#compat#rtp_addset_entry(): exiting. rtp: ' . string(&rtp)
endf
func! vundle#compat#has_dos_windows_paths()
return exists('+shellslash')
" previous implementation:
" return 0
" \ || has('win32') || has('win64')
" \ || has('win16') || has('win95')
" \ || has('dos16') || has('dos32')
endf
" provides the same functionality as shellescape()
" (even on vim versions that don't support it)
"
" note: behaviour taken from vim-7.1 documentation
func! vundle#compat#shellescape(string_value)
if vundle#compat#has_dos_windows_paths()
if &shellslash
" return as is?
return a:string_value
else
" double all double quotes within string,
" and enclose result in double quotes
return '"' . substitute(a:string_value,'"','""','g') . '"'
endif
else
" replace all "'" with "'\''"
return "'" . substitute(a:string_value,"'","'".'\\'."''",'g') . "'"
endif
endf

+ 8
- 113
autoload/vundle/config.vim View File

@ -67,118 +67,13 @@ func! s:parse_name(arg)
return {'name': name, 'uri': uri, 'name_spec': arg }
endf
" this abstracts the operation:
" 'set runtimepath-=LIST'
"
" notes:
" * it takes care of trailing '/' characters on each of the entries in LIST
" (it attempts to remove the entry with and without the trailing '/', just
" in case);
" * it attempts to do the "real thing", if it can
" (if 'fnameescape()' is available);
" * otherwise, it has a number of fallback scenarios, ordered by
" reliability;
"
" args:
" dirs [string]: described as 'LIST' above;
"
" for now, it does not produce an explicit return value
"
func! s:compat_rtp_rm_entry(dirs)
" debug: echomsg '[debug] s:compat_rtp_rm_entry(): entered. rtp: ' . string(&rtp) . '; dirs: ' . string(a:dirs)
" optimisation: there seems to be a few of these cases
if empty(a:dirs)
return 0
endif
if exists('*fnameescape')
exec 'set rtp-='.fnameescape(a:dirs)
elseif exists('*filter') && exists('*split') && exists('*join') " && ( stridx(a:dir, ',') < 0 )
" a bit costly, but more compatible
let l:runtimepath_list = split(&rtp, ',', 1)
unlet! g:vundle_config_compat_rtp_rm_entry_dir
for l:dir_now in split(a:dirs, ',', 1)
" FIXME: normalise path (think of win32 and other platforms)
" (fnamemodify()?)
" get rid of the last slash, if it's not a root directory
if ( strlen(l:dir_now) > 1 ) && ( l:dir_now[ -1: ] == '/' ) && ( l:dir_now[ -2:-2 ] != ':' )
let l:dir_now = l:dir_now [ :-2 ]
endif
" remove the directory as is (without a trailing '/'),
" and with a trailing '/', too.
for l:dir_suff in [ '', '/' ]
if ( empty(l:dir_now) && ( ! empty(l:dir_suff) ) )
continue
endif
let g:vundle_config_compat_rtp_rm_entry_dir = l:dir_now . l:dir_suff
let l:runtimepath_list = filter(l:runtimepath_list, 'v:val != g:vundle_config_compat_rtp_rm_entry_dir')
endfor
endfor
unlet! g:vundle_config_compat_rtp_rm_entry_dir
" assemble the runtime variable from the list
let &rtp = join(l:runtimepath_list, ',')
elseif exists('*escape')
" from fnameescape() documentation:
" it escapes: " \t\n*?[{`$\\%#'\"|!<"
" plus, depending on 'isfname', other characters.
" (TODO: add those cases, if needed)
exec 'set rtp-='.escape(a:dirs, " \t\n*?[{`$\\%#'\"|!<")
else
" cheap and cheerful (but no escaping)
exec 'set rtp-='.a:dirs
endif
" debug: echomsg '[debug] s:compat_rtp_rm_entry(): exiting. rtp: ' . string(&rtp)
endf
" abstracts the following operations:
" 'set runtimepath^=LIST'
" 'set runtimepath+=LIST'
" 'set runtimepath=LIST'
"
" args:
" dirs [string]: described as 'LIST' above;
" addset_operator [string]: one of:
" '^': prepend ('set runtimepath^=');
" '+': append ('set runtimepath+=');
" '': set ('set runtimepath=');
"
" for now, it does not produce an explicit return value
"
func! s:compat_rtp_addset_entry(dirs, addset_operator)
" debug: echomsg '[debug] s:compat_rtp_addset_entry(): entered. rtp: ' . string(&rtp) . '; dirs: ' . string(a:dirs) . '; operator: ' . string( a:addset_operator )
if exists('*fnameescape')
exec 'set rtp'.a:addset_operator.'='.fnameescape(a:dirs)
else
" almost as quick, but more compatible
if a:addset_operator == ''
let &rtp = a:dirs
else
let l:elem_separator = ( empty(&rtp) ? '' : ',' )
" note: ideally, we would want to
" do nothing if the value already exists
" (this is what the standard 'set {op}=' expressions do)
" but, for efficiency, we will let those elements
" through (besides, s:compat_rtp_rm_entry() would get rid of all
" matches if we want to do that before or after this operation)
if a:addset_operator == '^'
let &rtp = a:dirs . l:elem_separator . &rtp
elseif a:addset_operator == '+'
let &rtp = &rtp . l:elem_separator . a:dirs
else
" FIXME: internal error
endif
endif
endif
" debug: echomsg '[debug] s:compat_rtp_addset_entry(): exiting. rtp: ' . string(&rtp)
endf
func! s:rtp_rm_a()
let paths = map(copy(g:bundles), 'v:val.rtpath')
if !empty(paths)
let prepends = join(paths, ',')
let appends = join(paths, '/after,').'/after'
call s:compat_rtp_rm_entry(prepends)
call s:compat_rtp_rm_entry(appends)
call vundle#compat#rtp_rm_entry(prepends)
call vundle#compat#rtp_rm_entry(appends)
endif
endf
@ -187,22 +82,22 @@ func! s:rtp_add_a()
if !empty(paths)
let prepends = join(paths, ',')
let appends = join(paths, '/after,').'/after'
call s:compat_rtp_addset_entry(prepends,'^')
call s:compat_rtp_addset_entry(appends,'+')
call vundle#compat#rtp_addset_entry(prepends,'^')
call vundle#compat#rtp_addset_entry(appends,'+')
endif
endf
func! s:rtp_rm(dir) abort
if !empty(a:dir)
call s:compat_rtp_rm_entry(expand(a:dir, 1))
call s:compat_rtp_rm_entry(expand(a:dir.'/after', 1))
call vundle#compat#rtp_rm_entry(expand(a:dir, 1))
call vundle#compat#rtp_rm_entry(expand(a:dir.'/after', 1))
endif
endf
func! s:rtp_add(dir) abort
if !empty(a:dir)
call s:compat_rtp_addset_entry(expand(a:dir, 1), '^')
call s:compat_rtp_addset_entry(expand(a:dir.'/after', 1), '+')
call vundle#compat#rtp_addset_entry(expand(a:dir, 1), '^')
call vundle#compat#rtp_addset_entry(expand(a:dir.'/after', 1), '+')
endif
endf


+ 4
- 4
autoload/vundle/installer.vim View File

@ -174,7 +174,7 @@ func! vundle#installer#delete(bang, dir_name) abort
\ 'rm -rf'
let bundle = vundle#config#init_bundle(a:dir_name, {})
let cmd .= ' '.shellescape(bundle.path())
let cmd .= ' '.vundle#compat#shellescape(bundle.path())
let out = s:system(cmd)
@ -214,15 +214,15 @@ func! s:sync(bang, bundle) abort
let git_dir = expand(a:bundle.path().'/.git/', 1)
if isdirectory(git_dir) || filereadable(expand(a:bundle.path().'/.git', 1))
if !(a:bang) | return 'todate' | endif
let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull && git submodule update --init --recursive'
let cmd = 'cd '.vundle#compat#shellescape(a:bundle.path()).' && git pull && git submodule update --init --recursive'
let cmd = g:shellesc_cd(cmd)
let get_current_sha = 'cd '.shellescape(a:bundle.path()).' && git rev-parse HEAD'
let get_current_sha = 'cd '.vundle#compat#shellescape(a:bundle.path()).' && git rev-parse HEAD'
let get_current_sha = g:shellesc_cd(get_current_sha)
let initial_sha = s:system(get_current_sha)[0:15]
else
let cmd = 'git clone --recursive '.shellescape(a:bundle.uri).' '.shellescape(a:bundle.path())
let cmd = 'git clone --recursive '.vundle#compat#shellescape(a:bundle.uri).' '.vundle#compat#shellescape(a:bundle.path())
let initial_sha = ''
endif


+ 4
- 4
autoload/vundle/scripts.vim View File

@ -39,7 +39,7 @@ func! s:create_changelog() abort
let updated_sha = bundle_data[1]
let bundle = bundle_data[2]
let cmd = 'cd '.shellescape(bundle.path()).
let cmd = 'cd '.vundle#compat#shellescape(bundle.path()).
\ ' && git log --pretty=format:"%s %an, %ar" --graph '.
\ initial_sha.'..'.updated_sha
@ -155,10 +155,10 @@ func! s:fetch_scripts(to)
let l:vim_scripts_json = 'http://vim-scripts.org/api/scripts.json'
if executable("curl")
let cmd = 'curl --fail -s -o '.shellescape(a:to).' '.l:vim_scripts_json
let cmd = 'curl --fail -s -o '.vundle#compat#shellescape(a:to).' '.l:vim_scripts_json
elseif executable("wget")
let temp = shellescape(tempname())
let cmd = 'wget -q -O '.temp.' '.l:vim_scripts_json. ' && mv -f '.temp.' '.shellescape(a:to)
let temp = vundle#compat#shellescape(tempname())
let cmd = 'wget -q -O '.temp.' '.l:vim_scripts_json. ' && mv -f '.temp.' '.vundle#compat#shellescape(a:to)
if (has('win32') || has('win64'))
let cmd = substitute(cmd, 'mv -f ', 'move /Y ', '') " change force flag
let cmd = g:shellesc(cmd)


+ 1
- 1
test/vimrc View File

@ -12,7 +12,7 @@ let src = 'http://github.com/gmarik/vundle.git'
" let g:vundle_default_git_proto = 'git'
if !isdirectory(expand(root, 1).'/vundle')
exec '!git clone '.src.' '.shellescape(root, 1).'/vundle'
exec '!git clone '.src.' '.vundle#compat#shellescape(root, 1).'/vundle'
endif
filetype off


Loading…
Cancel
Save