Skip to content

Instantly share code, notes, and snippets.

@lislon
Created October 23, 2015 09:57
Show Gist options
  • Select an option

  • Save lislon/d5c82c9f77c1b24d8219 to your computer and use it in GitHub Desktop.

Select an option

Save lislon/d5c82c9f77c1b24d8219 to your computer and use it in GitHub Desktop.
;; Google translate interactive mode
(define-derived-mode google-translate-interactive-mode
text-mode "Google Translate"
(defun my/next-line-empty-p ()
"Check if next line empty"
(save-excursion
(beginning-of-line 2)
(save-match-data
(looking-at "[ \t]*$"))))
(defun my/translate-word-and-next-line ()
"Shows translation of current line in help buffer and inserts
new line after it"
(interactive)
(let ((buffer (current-buffer)) )
(move-beginning-of-line nil)
(set-mark-command nil)
(move-end-of-line nil)
(google-translate-at-point)
(switch-to-buffer buffer)
(if (eq (point) (point-max))
(newline-and-indent)
(end-of-line 2))
))
(use-local-map (make-sparse-keymap))
(local-set-key (kbd "RET") 'my/translate-word-and-next-line)
(define-key evil-normal-state-map (kbd "RET") 'my/translate-word-and-next-line))
(defun my/google-translate-repl ()
"Interactive major mode for translating multiply words"
(interactive)
(let ((buffer (get-buffer-create "Google Translate REPL")))
(switch-to-buffer buffer)
(google-translate-interactive-mode)
(evil-insert-state)
(goto-char (buffer-end 1))))
(evil-leader/set-key "x g i" 'my/google-translate-repl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment