Created
November 19, 2013 13:11
-
-
Save bamanzi/7545133 to your computer and use it in GitHub Desktop.
[emacs] translate/dictionary with online services (youdao/google)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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