Skip to content

Instantly share code, notes, and snippets.

@bamanzi
Created November 19, 2013 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bamanzi/7545133 to your computer and use it in GitHub Desktop.
Save bamanzi/7545133 to your computer and use it in GitHub Desktop.
[emacs] translate/dictionary with online services (youdao/google)
(defun youdao (words)
"Use cmd line `translate' to translate selection, and show result in popup tip.
google translate:
http://code.google.com/p/tranny/
http://www.commandlinefu.com/commands/view/5034/google-translate
youdao: http://hexlee.iteye.com/blog/1442506
"
(interactive
(list (read-string "Translate: "
(if (and transient-mark-mode mark-active)
(buffer-substring-no-properties (region-beginning) (region-end))
((thing-at-point 'word))))))
(let ((result (shell-command-to-string (concat "youdao '" words "'"))))
(if (fboundp 'pos-tip-show)
(pos-tip-show result)
(popup-tip result))))
;;FIXME: not work
(defun google-translate-at-point-popup (&optional override-p)
(interactive "P")
(%google-translate-at-point override-p nil)
(let ((result (with-current-buffer "*Google Translate*"
(buffer-string))))
(when (or (fboundp 'popup-tip)
(fboundp 'pos-tip-show))
(bury-buffer "*Google Translate*")
(if (fboundp 'pos-tip-show)
(pos-tip-show result)
(popup-tip result)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment