Skip to content

Instantly share code, notes, and snippets.

@chemzqm
Created September 13, 2016 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chemzqm/f155aec0eff3d09b31eb0f502b7b7934 to your computer and use it in GitHub Desktop.
Save chemzqm/f155aec0eff3d09b31eb0f502b7b7934 to your computer and use it in GitHub Desktop.
load lorem from web API
command! -nargs=* Lorem :call s:LoadLorem(<f-args>)
" load lorem with number and optional tag name
function! s:LoadLorem(...)
let num = get(a:, 1, 1)
let html_tag = exists('a:2') ? a:2 : ''
let url = 'https://devlorem.kovah.de/api/'.num.'/json'
let output = system('curl -s '.url)
if v:shell_error && output !=# ""
echohl Error | echon output | echohl None
return
endif
let line = getcurpos()[1]
let list = copy(webapi#json#decode(output))
if !empty(html_tag)
call append(line, map(list, '"<'.html_tag.'>".v:val."</'.html_tag.'>"'))
else
call append(line, list)
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment