爱意满满的作品展示区。
vitovan

Emacs - 有道词典 - 快捷查询 ( C-c C-f)

  •  
  •   vitovan · Aug 16, 2016 · 3395 views
    This topic created in 3557 days ago, the information mentioned may be changed or developed.

    代码在这: 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

    5 replies    2016-08-16 20:11:40 +08:00
    scnace
        1
    scnace  
       Aug 16, 2016 via Android
    写过个跑在终端里的 现在看英文文档一直在用 https://github.com/scbizu/yddict_cli (API key 都懒得 remove 掉了)
    vitovan
        2
    vitovan  
    OP
       Aug 16, 2016
    r#1 @scnace 哈~ Go 语言~
    scnace
        3
    scnace  
       Aug 16, 2016 via Android
    @vitovan 😂😂😂
    yuuko
        4
    yuuko  
       Aug 16, 2016 via Android
    下面是 vim 版, https://github.com/iamcco/dict.vim ,手动斜眼
    vitovan
        5
    vitovan  
    OP
       Aug 16, 2016
    r#4 @yuuko 这是要挑起圣战呀 😬😬😬😬
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2995 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 15:20 · PVG 23:20 · LAX 08:20 · JFK 11:20
    ♥ Do have faith in what you're doing.