You could use :exe
, but this is extremely cumbersome to use and you'll need to escape a few things.
I used to use my own path fixing function. It looked like:
exe 'set rtp+='.lh#path#fix(somevariable)
" with standard tools, may be it'd be (untested)
exe 'set rtp+='.escape(somevariable, ' \|,')
let &rtp = expression
is really our friend.
But indeed, it doesn't play well with +=
. That's why I've came up with lh#path#munge()
that relies on another function lh#list#add_if_new()
. Strictly speaking set +=
is emulated by lh#list#add_if_new()
. munge()
keeps pathnames that do exist, or actually globbing patterns that match things.
" Function: lh#path#munge(pathlist, path) {{{3
function! lh#path#munge(pathlist, path) abort
if type(a:pathlist) == type('str')
let pathlist = split(a:pathlist, ',')
return join(lh#path#munge(pathlist, a:path), ',')
else
" if filereadable(a:path) || isdirectory(a:path)
if ! empty(glob(a:path)) " support '/**' for &tags
call lh#list#push_if_new(a:pathlist, a:path)
endif
return a:pathlist
endif
endfunction
" Function: lh#list#push_if_new(list, value) {{{3
function! lh#list#push_if_new(list, value) abort
if index(a:list, a:value) < 0
call add (a:list, a:value)
endif
return a:list
endfunction
They are defined and maintained in lh-vim-lib.