Skip to content

Instantly share code, notes, and snippets.

@syohex
Created April 25, 2013 05:40
Show Gist options
  • Save syohex/5457732 to your computer and use it in GitHub Desktop.
Save syohex/5457732 to your computer and use it in GitHub Desktop.
ginger API from Emacs
(require 'request) ;; https://github.com/tkf/emacs-request
(require 'json)
(defvar ginger-end-point
"http://services.gingersoftware.com/Ginger/correct/json/GingerTheText" )
;;;###autoload
(defun ginger-region (beg end)
(interactive "r")
(lexical-let* ((text (buffer-substring-no-properties beg end))
(results nil))
(request
ginger-end-point
: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))
do
(progn
(when (< i from)
(push (substring text i from) results))
(push (propertize suggest
'face 'error) results)
(setq i (1+ to)))
finally
(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) "")
"\n")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment