用 eldoc + bing-dict 自动翻译光标下的单词

接近一年过去了,又突然想起这个主意来,可能是由于英文依旧没什么长进。

为了方便使用,把原来的 setq 整理成了一个 Minor Mode:

(defun bing-dict-eldoc-documentation-function ()
  (let ((word (word-at-point)))
    ;; 太短的单词不查
    (when (and word (> (length word) 4))
      (bing-dict-brief word))
    nil))

;; 注意一次只有一个 eldoc mode backend 生效
(define-minor-mode bing-dict-eldoc-mode
  "Use bing-dict as backend of eldoc."
  :lighter " Bing Dict"
  (if bing-dict-eldoc-mode
      (progn (setq-local eldoc-documentation-function
                         #'bing-dict-eldoc-documentation-function)
             (eldoc-mode +1))
    (setq-local eldoc-documentation-function #'ignore)
    (eldoc-mode -1)))
4 个赞