代码在这: https://gist.github.com/VitoVan/16e8c7ac31a01c02cebdb33cd896b874
拷贝粘贴到你的 .emacs 里就好了。
默认快捷键: C-c C-f
效果图:
给打不开 gist 的朋友:
(defvar base-youdao-url "http://fanyi.youdao.com/openapi.do?keyfrom=emacs-yd-pub&key=527593631&type=data&doctype=json&version=1.1&q=")
;; Get yourself an API KEY here: http://fanyi.youdao.com/openapi?path=data-mode
(defun youdao-fanyi ()
"Translate current word (en->cn, cn->en), prompt to input if no word here"
(interactive)
(let* ((word (or (thing-at-point 'word) (read-string "Translate> ")))
(full-url (concat base-youdao-url word)))
(with-current-buffer (url-retrieve-synchronously full-url)
(unwind-protect
(progn
(goto-char (point-min))
(re-search-forward "^$")
(delete-region (point) (point-min)) ;strip headers
(message
(elt (cdar ;we just want the straight one
(json-read-from-string
(decode-coding-string
(buffer-string) 'utf-8)))
0)))
(kill-buffer)))))
(global-set-key "\C-c\ \C-f" 'youdao-fanyi)
最好自己去申请一个 API KEY: http://fanyi.youdao.com/openapi?path=data-mode
1
scnace 2016-08-16 12:16:58 +08:00 via Android
写过个跑在终端里的 现在看英文文档一直在用 https://github.com/scbizu/yddict_cli (API key 都懒得 remove 掉了)
|
4
yuuko 2016-08-16 19:24:16 +08:00 via Android
下面是 vim 版, https://github.com/iamcco/dict.vim ,手动斜眼
|