V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
vitovan
V2EX  ›  分享创造

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

  •  
  •   vitovan · 2016-08-16 12:07:11 +08:00 · 2890 次点击
    这是一个创建于 2803 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码在这: 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 条回复    2016-08-16 20:11:40 +08:00
    scnace
        1
    scnace  
       2016-08-16 12:16:58 +08:00 via Android
    写过个跑在终端里的 现在看英文文档一直在用 https://github.com/scbizu/yddict_cli (API key 都懒得 remove 掉了)
    vitovan
        2
    vitovan  
    OP
       2016-08-16 12:34:47 +08:00
    r#1 @scnace 哈~ Go 语言~
    scnace
        3
    scnace  
       2016-08-16 13:32:58 +08:00 via Android
    @vitovan 😂😂😂
    yuuko
        4
    yuuko  
       2016-08-16 19:24:16 +08:00 via Android
    下面是 vim 版, https://github.com/iamcco/dict.vim ,手动斜眼
    vitovan
        5
    vitovan  
    OP
       2016-08-16 20:11:40 +08:00
    r#4 @yuuko 这是要挑起圣战呀 😬😬😬😬
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2753 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 02:07 · PVG 10:07 · LAX 19:07 · JFK 22:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.