Instantly share code, notes, and snippets.

Embed
What would you like to do?
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