-
Notifications
You must be signed in to change notification settings - Fork 391
/
google-translate-mode.el
74 lines (60 loc) · 2.09 KB
/
google-translate-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;;; google-translate-mode.el --- Google Translate minor mode
;; This file is distributed as part of translate-shell
;; URL: https://github.com/soimort/translate-shell
;; Last-Updated: 2015-04-08 Wed
;; This is free and unencumbered software released into the public domain.
;;; Code:
(defcustom trans-command "trans"
"trans command name."
:type 'string
:group 'google-translate-mode)
(defcustom trans-verbose-p nil
"Is in verbose mode. (default: nil)"
:type 'boolean
:group 'google-translate-mode)
(defcustom trans-source "auto"
"Source language. (default: auto)"
:type 'string
:group 'google-translate-mode)
(defcustom trans-target "en"
"Target language. (default: en)"
:type 'string
:group 'google-translate-mode)
(defun trans (verbose source target text)
(shell-command-to-string
(concat trans-command
(if verbose "" " -b")
(if source (concat " -s " source) "")
(if target (concat " -t " target) "")
" " text)))
(defun show-translation ()
"Show translation of the current word in message buffer."
(interactive)
(message
(trans trans-verbose-p trans-source trans-target (current-word))))
(defun view-translation ()
"View verbose translation of the current word in popup dialog."
(interactive)
(let ((translation
(trans t trans-source trans-target (current-word))))
(x-popup-menu t (list "Translation"
(list "PANE"
(list translation nil))))))
(defun insert-translation ()
"Insert translation of the current word right after."
(interactive)
(insert " ")
(insert
(trans trans-verbose-p trans-source trans-target (current-word))))
(defvar google-translate-mode-keymap
(let
((map (make-sparse-keymap)))
(define-key map (kbd "C-c -") 'show-translation)
(define-key map (kbd "C-c =") 'view-translation)
(define-key map (kbd "C-c +") 'insert-translation)
map)
"Keymap for Google Translate minor mode.")
(define-minor-mode google-translate-mode
"Google Translate"
:keymap google-translate-mode-keymap)
(provide 'google-translate-mode)