Use constructing backend function name to invoke the function.
[emacs-translate.git] / ui.el
blob9b443defaa4fc3ce0a30af3b238511d5e6c642f6
1 ;;; ui.el --- Provides UI framework for translating. -*- lexical-binding: t; -*-
2 ;; -*- coding: utf-8 -*-
4 ;; Copyright (C) 2020-2021 Free Software Foundation, Inc.
6 ;;; Commentary:
10 ;;; Code:
12 (defun emacs-translate.ui/translate-at-point (&optional backend)
13 (interactive "p")
14 (if current-prefix-arg
15 (setq backend (intern (completing-read "Select emacs-translate.el translating backend: "
16 emacs-translate-backends-list))))
17 (if-let ((text (thing-at-point 'word)))
18 (emacs-translate.core/translate text backend)
19 (error "Nothing at point.")))
21 (defun emacs-translate.ui/translate-region (&optional backend)
22 (interactive "p")
23 (if current-prefix-arg
24 (setq backend (intern (completing-read "Select emacs-translate.el translating backend: "
25 emacs-translate-backends-list))))
26 (if (region-active-p)
27 (let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
28 (emacs-translate.core/translate text backend))
29 (error "No region selected!")))
31 (defun emacs-translate.ui/translate-buffer (&optional backend)
32 (interactive "p")
33 (if current-prefix-arg
34 (setq backend (intern (completing-read "Select emacs-translate.el translating backend: "
35 emacs-translate-backends-list))))
36 (if-let ((text (buffer-substring-no-properties (point-min) (point-max))))
37 (emacs-translate.core/translate text backend)
38 (error "Buffer is empty!")))
40 (defun emacs-translate.ui/translate-paragraph-by-paragraph-overlay (&optional backend)
41 (interactive "p")
42 (if current-prefix-arg
43 (setq backend (intern (completing-read "Select emacs-translate.el translating backend: "
44 emacs-translate-backends-list))))
47 (defun emacs-translate.ui/translate-paragraph-by-paragraph-insert (&optional backend)
48 (interactive "p")
49 (if current-prefix-arg
50 (setq backend (intern (completing-read "Select emacs-translate.el translating backend: "
51 emacs-translate-backends-list))))
56 (provide 'ui)
58 ;;; ui.el ends here