Skip to content

Commit 9be2366

Browse files
committed
Check the shortener and playpen urls at calltime
1 parent 67a8ff1 commit 9be2366

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

autoload/rust.vim

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,6 @@ endfunction
363363
" Parts of gist.vim by Yasuhiro Matsumoto <[email protected]> reused
364364
" gist.vim available under the BSD license, available at
365365
" http://github.com/mattn/gist-vim
366-
if !exists('g:rust_playpen_url')
367-
let g:rust_playpen_url = 'https://play.rust-lang.org/'
368-
endif
369-
if !exists('g:rust_shortener_url')
370-
let g:rust_shortener_url = 'https://is.gd/'
371-
endif
372-
373366
function! s:has_webapi()
374367
if !exists("*webapi#http#post")
375368
try
@@ -383,6 +376,17 @@ endfunction
383376
function! rust#Play(count, line1, line2, ...) abort
384377
redraw
385378

379+
if !exists('g:rust_playpen_url')
380+
let l:rust_playpen_url = 'https://play.rust-lang.org/'
381+
else
382+
let l:rust_playpen_url = g:rust_playpen_url
383+
endif
384+
if !exists('g:rust_shortener_url')
385+
let l:rust_shortener_url = 'https://is.gd/'
386+
else
387+
let l:rust_shortener_url = g:rust_shortener_url
388+
endif
389+
386390
if !s:has_webapi()
387391
echohl ErrorMsg | echomsg ':RustPlay depends on webapi.vim (https://github.com/mattn/webapi-vim)' | echohl None
388392
return
@@ -399,15 +403,15 @@ function! rust#Play(count, line1, line2, ...) abort
399403
call setreg('"', save_regcont, save_regtype)
400404
endif
401405

402-
let body = g:rust_playpen_url."?code=".webapi#http#encodeURI(content)
406+
let body = l:rust_playpen_url."?code=".webapi#http#encodeURI(content)
403407

404408
if strlen(body) > 5000
405409
echohl ErrorMsg | echomsg 'Buffer too large, max 5000 encoded characters ('.strlen(body).')' | echohl None
406410
return
407411
endif
408412

409413
let payload = "format=simple&url=".webapi#http#encodeURI(body)
410-
let res = webapi#http#post(g:rust_shortener_url.'create.php', payload, {})
414+
let res = webapi#http#post(l:rust_shortener_url.'create.php', payload, {})
411415
let url = res.content
412416
redraw | echomsg 'Done: '.url
413417
endfunction

0 commit comments

Comments
 (0)