Skip to content

Commit

Permalink
Put last used translation direction on top.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorniu committed Aug 8, 2020
1 parent 619d318 commit 2910a97
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions google-translate-smooth-ui.el
Expand Up @@ -120,7 +120,7 @@
;; `google-translate-core-ui' and thus it could be customized via this
;; package's variables. Please read documentation for the
;; `google-translate-core-ui' package.
;;
;;

;;; Code:

Expand Down Expand Up @@ -157,6 +157,10 @@ As example, this alist could looks like the following:
keeps current translation direction while changing translation
directions.")

(defvar google-translate-last-translation-direction nil
"The last used translation direction.
Points to nth element of `google-translate-translation-directions-alist' variable.")

(defvar google-translate-translation-direction-query ""
"Temporal variable which keeps a minibuffer text while
switching translation directions.")
Expand Down Expand Up @@ -219,7 +223,7 @@ C-n - to select next direction."
(interactive)
(let ((text ""))
(setq google-translate-try-other-direction nil)
(setq text
(setq text
(if google-translate-input-method-auto-toggling
(minibuffer-with-setup-hook
(lambda ()
Expand Down Expand Up @@ -250,7 +254,7 @@ C-n - to select next direction."

(defun google-translate--read-from-minibuffer ()
"Read string from minibuffer."
(let* ((source-language
(let* ((source-language
(google-translate--current-direction-source-language))
(target-language
(google-translate--current-direction-target-language))
Expand Down Expand Up @@ -299,7 +303,7 @@ A current translation direction could be changed directly in the
minibuffer by means of key bindings such as C-n and C-p for
changing to the next translation direction and to the previous
one respectively."
(interactive)
(interactive)

(setq google-translate-translation-direction-query
(if (use-region-p)
Expand All @@ -308,7 +312,8 @@ one respectively."
(unless current-prefix-arg
(current-word t t))))

(setq google-translate-current-translation-direction 0)
(setq google-translate-current-translation-direction
(or google-translate-last-translation-direction 0))

(let* ((text (google-translate-query-translate-using-directions))
(source-language (google-translate--current-direction-source-language))
Expand All @@ -317,7 +322,9 @@ one respectively."
(setq source-language (google-translate-read-source-language)))
(when (null target-language)
(setq target-language (google-translate-read-target-language)))
(google-translate-translate source-language target-language text)))
(google-translate-translate source-language target-language text)
(setq google-translate-last-translation-direction
google-translate-current-translation-direction)))


(provide 'google-translate-smooth-ui)
Expand Down

0 comments on commit 2910a97

Please sign in to comment.