From e3076a24f280663c88fa58ef5facdf14544a2830 Mon Sep 17 00:00:00 2001 From: Ezequiel Valenzuela Date: Sat, 9 Nov 2013 17:47:48 +0000 Subject: [PATCH 1/6] improved compatibility: it now supports vim version 7.0 * added new functions to detach caller from having to call fnameescape() (which isn't available until vim-7.2): * s:compat_rtp_rm_entry(dirs): abstracts 'set rtp-=LIST'; * s:compat_rtp_addset_entry(dirs, addset_operator): abstracts 'set rtp+=LIST', 'set rtp^=LIST', 'set rtp=LIST'; --- autoload/vundle/config.vim | 137 +++++++++++++++++++++++++++++++++---- 1 file changed, 125 insertions(+), 12 deletions(-) diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index 5bb6e3f..13a050e 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -67,30 +67,143 @@ 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') - let prepends = join(paths, ',') - let appends = join(paths, '/after,').'/after' - exec 'set rtp-='.fnameescape(prepends) - exec 'set rtp-='.fnameescape(appends) + 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) + endif endf func! s:rtp_add_a() let paths = map(copy(g:bundles), 'v:val.rtpath') - let prepends = join(paths, ',') - let appends = join(paths, '/after,').'/after' - exec 'set rtp^='.fnameescape(prepends) - exec 'set rtp+='.fnameescape(appends) + 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,'+') + endif endf func! s:rtp_rm(dir) abort - exec 'set rtp-='.fnameescape(expand(a:dir, 1)) - exec 'set rtp-='.fnameescape(expand(a:dir.'/after', 1)) + 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)) + endif endf func! s:rtp_add(dir) abort - exec 'set rtp^='.fnameescape(expand(a:dir, 1)) - exec 'set rtp+='.fnameescape(expand(a:dir.'/after', 1)) + 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), '+') + endif endf func! s:expand_path(path) abort From ca9044cc6091c9d487530268654ef7161dff8099 Mon Sep 17 00:00:00 2001 From: Ezequiel Valenzuela Date: Sun, 10 Nov 2013 13:19:54 +0000 Subject: [PATCH 2/6] 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; --- autoload/vundle/compat.vim | 161 ++++++++++++++++++++++++++++++++++ autoload/vundle/config.vim | 121 ++----------------------- autoload/vundle/installer.vim | 8 +- autoload/vundle/scripts.vim | 8 +- test/vimrc | 2 +- 5 files changed, 178 insertions(+), 122 deletions(-) create mode 100644 autoload/vundle/compat.vim diff --git a/autoload/vundle/compat.vim b/autoload/vundle/compat.vim new file mode 100644 index 0000000..145a2b6 --- /dev/null +++ b/autoload/vundle/compat.vim @@ -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 + diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index 13a050e..06adf36 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -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 diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index bc807c3..287b8a3 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -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 diff --git a/autoload/vundle/scripts.vim b/autoload/vundle/scripts.vim index ded6a46..d31cae6 100644 --- a/autoload/vundle/scripts.vim +++ b/autoload/vundle/scripts.vim @@ -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) diff --git a/test/vimrc b/test/vimrc index 662709f..68df310 100644 --- a/test/vimrc +++ b/test/vimrc @@ -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 From 0859aebe7f17d12e42bf1d3873cb82c3c1dfc4c2 Mon Sep 17 00:00:00 2001 From: Ezequiel Valenzuela Date: Sun, 10 Nov 2013 13:35:58 +0000 Subject: [PATCH 3/6] tidied up (comment changes, dead code removal) --- autoload/vundle/compat.vim | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/autoload/vundle/compat.vim b/autoload/vundle/compat.vim index 145a2b6..2a5c2dc 100644 --- a/autoload/vundle/compat.vim +++ b/autoload/vundle/compat.vim @@ -1,3 +1,6 @@ +" MAYBE: also provide fnameescape() +" (first appeared in a major release in vim-7.2) + " this abstracts the operation: " exec 'set runtimepath-='.fnameescape(LIST) " @@ -132,11 +135,6 @@ 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() From 61d6f00ea6d966d0a4909fb9d55b928dcc6d077d Mon Sep 17 00:00:00 2001 From: Ezequiel Valenzuela Date: Mon, 11 Nov 2013 16:36:10 +0000 Subject: [PATCH 4/6] actioned review comments (github.com/jdevera) * use local variable in filter expression (filter()); * moved comments regarding future changes to the bottom of the file; --- autoload/vundle/compat.vim | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/autoload/vundle/compat.vim b/autoload/vundle/compat.vim index 2a5c2dc..1df1fe6 100644 --- a/autoload/vundle/compat.vim +++ b/autoload/vundle/compat.vim @@ -1,5 +1,4 @@ -" MAYBE: also provide fnameescape() -" (first appeared in a major release in vim-7.2) +" vundle - vim compatibility support module " this abstracts the operation: " exec 'set runtimepath-='.fnameescape(LIST) @@ -45,11 +44,9 @@ func! vundle#compat#rtp_rm_entry(dirs) " 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') + for l:entry_dir in split(a:dirs, l:elem_separator, 1) + let l:runtimepath_list = filter(l:runtimepath_list, 'v:val != l: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 @@ -108,11 +105,9 @@ func! vundle#compat#rtp_addset_entry(dirs, addset_operator) 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') + for l:entry_dir in split(&rtp, l:elem_separator, 1) + let l:dirs_list = filter(l:dirs_list, 'v:val != l: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 @@ -157,3 +152,6 @@ func! vundle#compat#shellescape(string_value) endif endf +" MAYBE: also provide fnameescape() +" (first appeared in a major release in vim-7.2) + From 6be36c757bf5c50112e636e717932e5999df81b2 Mon Sep 17 00:00:00 2001 From: Ezequiel Valenzuela Date: Tue, 19 Jul 2016 21:03:26 +0100 Subject: [PATCH 5/6] autoload/vundle/compat.vim: added function 'vundle#compat#fnameescape()' --- autoload/vundle/compat.vim | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/autoload/vundle/compat.vim b/autoload/vundle/compat.vim index 55ffcae..ea9b69a 100644 --- a/autoload/vundle/compat.vim +++ b/autoload/vundle/compat.vim @@ -1,19 +1,16 @@ " vundle - vim compatibility support module " this abstracts the operation: -" exec 'set runtimepath-='.fnameescape(LIST) -" -" ... even when fnameescape() is not available (on vim-7.0, for example) +" exec 'set runtimepath-='.vundle#compat#fnameescape(LIST) " " notes: -" * it attempts to do the "real thing", if it can -" (if 'fnameescape()' is available); +" * it attempts to do the "real thing", if it can; " * 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). +" exec 'set runtimepath-='.vundle#compat#fnameescape(LIST) +" first. " if that does not alter &runtimepath, then it tries to remove a:dirs " elements individually; " @@ -33,12 +30,10 @@ func! vundle#compat#rtp_rm_entry(dirs) 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 + exec 'set rtp-='.vundle#compat#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 ) ) elseif ( l:process_stage == 2 ) if exists('*split') && exists('*filter') && exists('*join') " a bit costly, but more compatible @@ -73,11 +68,9 @@ func! vundle#compat#rtp_rm_entry(dirs) 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) +" exec 'set runtimepath^='.vundle#compat#fnameescape(LIST) +" exec 'set runtimepath+='.vundle#compat#fnameescape(LIST) +" exec 'set runtimepath='.vundle#compat#fnameescape(LIST) " " args: " dirs [string]: described as 'LIST' above; @@ -152,6 +145,11 @@ func! vundle#compat#shellescape(string_value) endif endf -" MAYBE: also provide fnameescape() " (first appeared in a major release in vim-7.2) +let s:vundle_compat_has_fnameescape = exists( '*fnameescape' ) +function vundle#compat#fnameescape( fname ) + " from documentation: it escapes: " \t\n*?[{`$\\%#'\"|!<" + " plus, depending on 'isfname', other characters. + return ( s:vundle_compat_has_fnameescape ? fnameescape( a:fname ) : escape( a:fname, " \t\n*?[{`$\\%#'\"|!<" ) ) +endfunction From d661e168cdb07911a136ada4ac089e7f3bb4e814 Mon Sep 17 00:00:00 2001 From: Ezequiel Valenzuela Date: Tue, 19 Jul 2016 21:04:15 +0100 Subject: [PATCH 6/6] autoload/vundle/config.vim: use 'compat' module for 'fnameescape()' --- autoload/vundle/config.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index 105ab48..8612639 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -171,7 +171,7 @@ func! s:rtp_add_defaults() let &rtp = current let default_rtp_items = split(default, ',') if !empty(default_rtp_items) - let first_item = fnameescape(default_rtp_items[0]) + let first_item = vundle#compat#fnameescape(default_rtp_items[0]) exec 'set rtp-=' . first_item exec 'set rtp^=' . first_item endif