Instantly share code, notes, and snippets.

What would you like to do?
ginger API from Emacs
(require 'request) ;;
(require 'json)
(defvar ginger-end-point
"" )
(defun ginger-region (beg end)
(interactive "r")
(lexical-let* ((text (buffer-substring-no-properties beg end))
(results nil))
:params `((lang . "US")
(clientVersion . "2.0")
(apiKey . "6ae0c3a0-afdc-4532-a810-82ded0054236")
(text . ,text))
:parser 'json-read
:success (function*
(lambda (&key data &allow-other-keys)
(loop with elems = (assoc-default 'LightGingerTheTextResult data)
with i = 0
for elem across elems
for from = (assoc-default 'From elem)
for to = (assoc-default 'To elem)
for suggest = (assoc-default
'Text (aref (assoc-default 'Suggestions elem) 0))
(when (< i from)
(push (substring text i from) results))
(push (propertize suggest
'face 'error) results)
(setq i (1+ to)))
(when (< i (length text))
(push (substring text i) results)))
(pop-to-buffer (get-buffer-create "*ginger*"))
(insert (concat "[Original]\n" text "\n\n"))
(insert (concat "[Fixed]\n"
(mapconcat 'identity (reverse results) "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment