sgur
4/25/2013 - 3:41 AM

ginger.vim

let s:endpoint = 'http://services.gingersoftware.com/Ginger/correct/json/GingerTheText'
let s:apikey = '6ae0c3a0-afdc-4532-a810-82ded0054236'
function! s:ginger(text)
  let res = webapi#json#decode(webapi#http#get(s:endpoint, {
  \ 'lang': 'US',
  \ 'clientVersion': '2.0',
  \ 'apiKey': s:apikey,
  \ 'text': a:text}).content)
  let i = 0
  let correct = ''
  echon "Mistake: "
  for rs in res['LightGingerTheTextResult']
    let [from, to] = [rs['From'], rs['To']]
    if i < from
      echon a:text[i : from-1]
      let correct .= a:text[i : from-1]
    endif
    echohl WarningMsg
    echon a:text[from : to]
	echohl None
    let correct .= rs['Suggestions'][0]['Text']
    let i = to + 1
  endfor
  if i < len(a:text)
    echon a:text[i :]
    let correct .= a:text[i :]
  endif
  echo "Correct: ".correct
endfunction

command! -nargs=+ Ginger call s:ginger(<q-args>)