Add submodules and my wornik stuff

master
Jacopo De Simoi 12 years ago
parent f5336944e6
commit b18062cae7
  1. 9
      .gitmodules
  2. 1
      ace-jump-mode
  3. 1
      emacs-no-easy-keys
  4. 1
      multiple-cursors.el
  5. 47
      wordnik-synonym.el

9
.gitmodules vendored

@ -0,0 +1,9 @@
[submodule "ace-jump-mode"]
path = ace-jump-mode
url = https://github.com/winterTTr/ace-jump-mode.git
[submodule "emacs-no-easy-keys"]
path = emacs-no-easy-keys
url = https://github.com/danamlund/emacs-no-easy-keys.git
[submodule "multiple-cursors.el"]
path = multiple-cursors.el
url = https://github.com/magnars/multiple-cursors.el.git

@ -0,0 +1 @@
Subproject commit 07b713792aec8cfb1bed7e1effaa9bf2b1cf3282

@ -0,0 +1 @@
Subproject commit 90f44351c28a0d9c8206f60f0bef02ae9c0c9733

@ -0,0 +1 @@
Subproject commit a3e6ec7c93c376f35c9add3ff8d155bdf2e079a4

@ -0,0 +1,47 @@
(require 'json)
(require 'thingatpt)
(setq wordnik-api-key "fa815fa92045b7fa23699014d0a01c081b3d9c3c761292bf3")
(defun wordnik-get-syn-buffer-for-word (word)
(url-retrieve-synchronously (concat "http://api.wordnik.com//v4/word.json/" word "/relatedWords?relationshipTypes=synonym&limitPerRelationshipType=25&api_key=" wordnik-api-key)))
(defun thesaurus-process-http-headers ()
"In the buffer created by `url-retrieve-synchronously',
there are HTTP headers, and content. This fn removes the headers
from the buffer, parsing the Content-Length header to verify that
a substantive response was received.
This implementation deletes each line until finding a blank line,
which in correctly-formatted HTTP messages signals the end of the
headers and the beginning of the message content.
"
(let ((clength -1))
(while (/= (point) (line-end-position))
(when (and (< clength 0)
(re-search-forward "^[Cc]ontent-[Ll]ength ?: *\\(.*\\)$" (line-end-position) t))
(setq clength (string-to-number (match-string 1)))
(goto-char (line-beginning-position)))
(delete-region (point) (line-end-position))
(delete-char 1))
(delete-char 1)
clength))
(defun wn/synonym-list (word)
"Look up synonyms for (word) on wordnik and return them as an array of strings"
(let ((buf (wordnik-get-syn-buffer-for-word word)))
(if buf
(progn
(with-current-buffer buf
(goto-char (point-min))
(thesaurus-process-http-headers)
(let ((json-object-type 'alist))
(cdr (assoc 'words (elt (json-read-from-string (buffer-substring-no-properties (point) (line-end-position))) 0)))))))))
(defun wn/synonym-at-point ()
(interactive)
(let ((word (word-at-point)))
(message "Synonyms for %s: %S" word (wn/synonym-list word))))
(provide 'wordnik-synonym)
Loading…
Cancel
Save