Last active
February 8, 2017 13:40
-
-
Save liiker/3ee7fd02c9694def8124579b92b6225f to your computer and use it in GitHub Desktop.
Revisions
-
liiker revised this gist
Feb 8, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,4 +22,3 @@ (interactive) (let ((word (read-string "要查询的单词: "))) (translate word)))) -
liiker created this gist
Feb 8, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ ;; send http get request (defun get-url (url) (with-current-buffer (url-retrieve-synchronously url) (buffer-string))) ;; get word translate origin data (defun get-translate-info (word) (decode-coding-string (get-url (format "http://fanyi.youdao.com/openapi.do?keyfrom=emacs-fanyi&key=830729599&type=data&doctype=json&version=1.1&q=%s" word)) 'utf-8)) ;; get chinese explain and send to the minibuffer (defun translate (word) (let (me-data pos-json json-str info) (setq me-data (get-translate-info word)) (setq pos-json (string-match-p "{.*}" me-data)) (setq json-str (substring me-data pos-json)) (setq info (json-read-from-string json-str)) (print (assoc 'explains (assoc 'basic info))))) ;; 绑定翻译快捷键 (global-set-key (kbd "C-c t n") (lambda () (interactive) (let ((word (read-string "要查询的单词: "))) (translate word)))) )