diff --git a/autoload/vivify.vim b/autoload/vivify.vim index 3a7f331..23d3963 100644 --- a/autoload/vivify.vim +++ b/autoload/vivify.vim @@ -2,8 +2,8 @@ let s:viv_url = 'http://localhost:' . ($VIV_PORT == '' ? '31622' : $VIV_PORT) " Note: nvim's jobstart isn't exactly a drop-in replacement for vim's job_start " See here: https://stackoverflow.com/questions/74999614/difference-between-vims-job-start-function-and-neovims-jobstart-functi -if has("nvim") - let s:job_start = function("jobstart") +if has('nvim') + let s:job_start = function('jobstart') " job is job_id as returned from jobstart() function! s:stdin_send_and_close(job, data) @@ -18,16 +18,30 @@ else call ch_close_in(l:channel) endfunction - let s:job_start = function("job_start") + let s:job_start = function('job_start') endif +function! s:percent_encode(path) + if has('python3') + " With python3 support, do proper percent encoding of url + " Vim needs to be compiled with +python3 (check `vim --version`) + " Neovim needs pynvim installed + py3 from urllib.parse import quote + return py3eval('quote("' . a:path . '")') + else + " If no python3 support, still handle the biggest problem + " which is spaces in filenames + return substitute(a:path, ' ', '%20', 'g') + endif +endfunction + function! s:post(data) let l:job = s:job_start([ \ 'curl', \ '-X', 'POST', \ '-H', 'Content-type: application/json', \ '--data', '@-', - \ s:viv_url . '/viewer' . expand('%:p') + \ s:viv_url . '/viewer' . s:percent_encode(expand('%:p')) \]) call s:stdin_send_and_close(l:job, json_encode(a:data)) endfunction @@ -44,6 +58,6 @@ function! vivify#open() " Note: nvim's jobstart doesn't use these opt keys call s:job_start( \ ['viv', expand('%:p')->substitute(':', '\\:', 'g') . ':' . getpos('.')[1]], - \ {"in_io": "null", "out_io": "null", "err_io": "null"} + \ {'in_io': 'null', 'out_io': 'null', 'err_io': 'null'} \) endfunction