Use constructing backend function name to invoke the function.
[emacs-translate.git] / emacs-translate.el
blob2fc2bb2ee96efb15f69b1353d246d6ecd0073e85
1 ;;; emacs-translate.el --- Emacs translate front-end framework supports customize variant translating backends. -*- lexical-binding: t; -*-
2 ;; -*- coding: utf-8 -*-
4 ;; Copyright (C) 2020-2021 Free Software Foundation, Inc.
6 ;;; Commentary:
8 ;; This extension provides a UI front-end for variant translating backends.
10 ;;; Code:
12 (require 'core)
13 (require 'ui)
15 (defgroup emacs-translate nil
16 "Emacs translate front-end framework supports customize variant translating backends."
17 :prefix "emacs-translate-"
18 :group 'emacs-translate)
20 (defcustom emacs-translate-backends-list '("youdao" "baidu-translate" "bing-translate" "google-translate" "DeepL")
21 "A list of translating backend strings."
22 :type 'list
23 :safe #'listp
24 :group 'emacs-translate)
26 (defcustom emacs-translate-default-backend 'bing-translate
27 "Specify the default translating backend."
28 :type 'symbol
29 :safe #'symbolp
30 :group 'emacs-translate)
32 (defcustom emacs-translate-mode-map-prefix (kbd "C-c C-t")
33 "Specify emacs-translate keybindings prefix before loading."
34 :type 'kbd
35 :group 'emacs-translate)
37 (defvar emacs-translate-mode-map
38 (let ((map (make-sparse-keymap)))
39 (unless (keymapp map)
40 (global-set-key emacs-translate-mode-map-prefix map)
41 (define-key emacs-translate-mode-map-prefix (kbd "t") 'emacs-translate.ui/translate-at-point)
42 (define-key emacs-translate-mode-map-prefix (kbd "r") 'emacs-translate.ui/translate-region)
43 (define-key emacs-translate-mode-map-prefix (kbd "b") 'emacs-translate.ui/translate-buffer)
44 (define-key emacs-translate-mode-map-prefix (kbd "p") 'emacs-translate.ui/translate-paragraph-by-paragraph-overlay)
45 (define-key emacs-translate-mode-map-prefix (kbd "P") 'emacs-translate.ui/translate-paragraph-by-paragraph-insert)
46 (define-key emacs-translate-mode-map-prefix (kbd "C-p") 'emacs-translate.ui/translate-popup))
47 map)
48 "emacs-translate-mode map.")
50 (define-minor-mode emacs-translate-mode
51 "A global minor mode to toggle extension `emacs-translate'."
52 :require 'emacs-translate
53 :init-value nil
54 :lighter " emacs-translate"
55 :group 'emacs-translate
56 :keymap emacs-translate-mode-map
57 (if emacs-translate-mode
58 (progn
59 (dolist (backend emacs-translate-backends-list)
60 (require (intern (concat "backend-" backend)))))))
64 (provide 'emacs-translate)
66 ;;; emacs-translate.el ends here