Last active
May 5, 2023 14:07
-
-
Save mattn/5457352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. You should submit this to vim.org/scripts