Skip to content

Commit

Permalink
feat(jannis-baum#20): percent-encode paths
Browse files Browse the repository at this point in the history
The primary intention is to fix the case where filenames have spaces in
them and this plugin doesn't encode the URL properly so it appears as if
vivify can't refresh

We do this whether (n)vim has python3 support or not, but with python3
support do a proper encoding with a library to handle more esoteric
cases, for example curly brackets in filenames.

We found that even without the library, characters such as ä, á, ñ, €
already work, so it's probably a very rare case where you need any more
meticulous encoding for filenames. And then even if that occurs,
enabling python3 support will solve it :)
  • Loading branch information
tuurep committed Sep 16, 2024
1 parent ef13132 commit 8e9c411
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion autoload/vivify.vim
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,27 @@ else
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 +python
" 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
Expand Down

0 comments on commit 8e9c411

Please sign in to comment.