filenameescape()
is supposed to be the solution. And yet, I've cooked my own solution 2 decades ago and it's still working fine so far.
function! lh#path#fix(pathname, ...) abort
" Parameters {{{4
" Ignore the last slash or backslash character, if any
let pathname = matchstr(a:pathname, '^.*[^/\\]')
" Default value for the quote character
let quote_char = ''
" Determine if 'shellslash' exists (dos-like platforms)
if lh#os#OnDOSWindows()
if lh#os#system_detected() == 'msdos'
let shellslash = 0
else
let shellslash = &shellslash
endif
else "unix
let shellslash = 1
endif
" Determine if we will use slashes or backslashes to distinguish directories
if a:0 >= 1 "
let shellslash = a:1
if a:0 >= 2
let quote_char = a:2
endif
endif
" Smart definition of quote chars for $COMSPEC
if (lh#os#system_detected() == 'msdos') && !shellslash && (''==quote_char)
if (&shell =~ 'command\.com')
if pathname =~ ' '
" should also test long directory-names...
" Best: AVOID command.com !!!
if &verbose >= 1
call lh#common#error_msg('lh#path#fix: '.
\ 'Problem expected because of the space in <'.pathname.'>')
endif
else
let quote_char = ''
endif
else
let quote_char = '"'
endif
endif
" Fix the pathname {{{4
if shellslash
let res = substitute(
\ substitute(pathname, '\\\([^ ]\|$\)', '/\1', 'g'),
\ '\(^\|[^\\]\) ', '\1\\ ', 'g')
else
let res = substitute(
\ substitute(pathname, '\\ ', ' ', 'g'),
\ '/', '\\', 'g')
endif
" Note: problem to take care (that explains the complex substition schemes):
" sometimes the path passed to the function mix the two writtings, e.g.:
" "c:\Program Files/longpath/some\ spaces/foo"
" }}}4
return quote_char . res . quote_char
endfunction
Yeah. It's horrible. I should probably simplify it but... it works!
a:file
and notg:file
expand('%:p')
should work, according to eval.txt, but the quotemarks in"C:\...\manager check "
don't make sense. Do you see any error messages when you try to run the plugin?