20 08 2020
(bind-key "C-c t" 'chromium-translate) (require 'url-util) (defun chromium-translate () "Open google translate with chromium." (interactive) (if (use-region-p) (let ((string ;; 行頭、行末のホワイトスペースを削除し、文章の途中にある改行をスペースに変換してから翻訳する (replace-regexp-in-string "\\([^\n]\\)\n\\([^\n]\\)" "\\1 \\2" (replace-regexp-in-string "^\s*\\(.*?\\)\s*$" "\\1" (buffer-substring-no-properties (region-beginning) (region-end)) )) )) (deactivate-mark) (if (string-match (format "\\`[%s]+\\'" "[:ascii:]") string) (browse-url (concat "https://translate.google.com/?source=gtx#en/ja/" (url-hexify-string string))) (browse-url (concat "https://translate.google.com/?source=gtx#ja/en/" (url-hexify-string string))))) (let ((string (read-string "Google Translate: "))) (if (string-match (format "\\`[%s]+\\'" "[:ascii:]") string) (browse-url (concat "https://translate.google.com/?source=gtx#en/ja/" (url-hexify-string string))) (browse-url (concat "https://translate.google.com/?source=gtx#ja/en/" (url-hexify-string string)))))))便利!便利!
update: 2020/08/20 11:25 | path: /pub/software/emacs