From 0db2111a2506d2e4ba0ffa2d48b842be0d0288fd Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Thu, 30 Jan 2014 14:45:48 +0900 Subject: [PATCH] add prefs for google-translate --- emacs.el | 165 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 93 insertions(+), 72 deletions(-) diff --git a/emacs.el b/emacs.el index 22b3c80..92d3a42 100644 --- a/emacs.el +++ b/emacs.el @@ -1285,6 +1285,7 @@ found, otherwise returns nil." (let ((iswitchb-default-method 'display)) (call-interactively 'iswitchb-buffer))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; sdic @@ -1314,6 +1315,98 @@ found, otherwise returns nil." (setq sdic-disable-select-window t) (setq sdic-window-height 7)) + +;;;;;;;;;;;;;;;;;;;;;;;; +;; ilookup + +(when (fetch-library + "https://raw.github.com/10sr/emacs-lisp/master/ilookup.el" + t) + (lazy-load-eval 'ilookup + '(ilookup-open) + (setq ilookup-dict-alist + '( + ("en" . (lambda (word) + (shell-command-to-string + (format "sdcv -n -u dictd_www.dict.org_gcide '%s'" + word)))) + ("ja" . (lambda (word) + (shell-command-to-string + (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'" + word)))) + ("jaj" . (lambda (word) + (shell-command-to-string + (format "sdcv -n -u jmdict-en-ja '%s'" + word)))) + ("jag" . + (lambda (word) + (with-temp-buffer + (insert (shell-command-to-string + (format "sdcv -n -u 'Genius English-Japanese' '%s'" + word))) + (html2text) + (buffer-substring (point-min) + (point-max))))) + ("alc" . (lambda (word) + (shell-command-to-string + (format "alc '%s' | head -n 20" + word)))) + ("app" . (lambda (word) + (shell-command-to-string + (format "dict_app '%s'" + word)))) + ;; letters broken + ("ms" . + (lambda (word) + (let ((url (concat + "http://api.microsofttranslator.com/V2/Ajax.svc/" + "Translate?appId=%s&text=%s&to=%s")) + (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51") + (target "ja") + (eword (url-hexify-string word))) + (with-current-buffer (url-retrieve-synchronously + (format url + apikey + eword + target)) + (message "") + (goto-char (point-min)) + (search-forward-regexp "^$" + nil + t) + (url-unhex-string (buffer-substring-no-properties + (point) + (point-max))))))) + )) + ;; (funcall (cdr (assoc "ms" + ;; ilookup-alist)) + ;; "dictionary") + + ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja")) + + ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com")) + + (setq ilookup-default "ja") + (when (locate-library "google-translate") + (add-to-list 'ilookup-dict-alist + '("gt" . + (lambda (word) + (save-excursion + (google-translate-translate "auto" + "ja" + word)) + (with-current-buffer "*Google Translate*" + (buffer-substring-no-properties (point-min) + (point-max))))))) + )) + + +(when (lazy-load-eval 'google-translate '(google-translate-translate + google-translate-at-point)) + (setq google-translate-default-source-language "auto") + (setq google-translate-default-target-language "ja")) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; vc ;; (require 'vc) @@ -2371,77 +2464,5 @@ this is test, does not rename files." ;; (my-real-function-subr-p 'my-real-function-subr-p) -;;;;;;;;;;;;;;;;;;;;;;;; -;; ilookup - -(when (fetch-library - "https://raw.github.com/10sr/emacs-lisp/master/ilookup.el" - t) - (lazy-load-eval 'ilookup - '(ilookup-open) - (setq ilookup-dict-alist - '( - ("en" . (lambda (word) - (shell-command-to-string - (format "sdcv -n -u dictd_www.dict.org_gcide '%s'" - word)))) - ("ja" . (lambda (word) - (shell-command-to-string - (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'" - word)))) - ("jaj" . (lambda (word) - (shell-command-to-string - (format "sdcv -n -u jmdict-en-ja '%s'" - word)))) - ("jag" . - (lambda (word) - (with-temp-buffer - (insert (shell-command-to-string - (format "sdcv -n -u 'Genius English-Japanese' '%s'" - word))) - (html2text) - (buffer-substring (point-min) - (point-max))))) - ("alc" . (lambda (word) - (shell-command-to-string - (format "alc '%s' | head -n 20" - word)))) - ("app" . (lambda (word) - (shell-command-to-string - (format "dict_app '%s'" - word)))) - ;; letters broken - ("ms" . - (lambda (word) - (let ((url (concat - "http://api.microsofttranslator.com/V2/Ajax.svc/" - "Translate?appId=%s&text=%s&to=%s")) - (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51") - (target "ja") - (eword (url-hexify-string word))) - (with-current-buffer (url-retrieve-synchronously - (format url - apikey - eword - target)) - (message "") - (goto-char (point-min)) - (search-forward-regexp "^$" - nil - t) - (url-unhex-string (buffer-substring-no-properties - (point) - (point-max))))))) - )) - ;; (funcall (cdr (assoc "ms" - ;; ilookup-alist)) - ;; "dictionary") - - ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja")) - - ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com")) - - (setq ilookup-default "ja"))) - ;;; emacs.el ends here