-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for vim and other emacs flavours #444
Comments
I think the best is to create custom commands in editors to use a shell command more or less interactively, but editors will have different ways to do that. I was using Kakoune some time ago and did that for some Markdown live preview mode for example. Here is something I came up with for Emacs, which seems to work nicely so far (it should support multiline source text containing quotes and backticks): ;; Translate text using github.com/soimort/translate-shell
;; The selected text will be used as source and be replaced
;; by the translation. If no text is selected, the user will
;; be prompted to enter the source text.
(defun trans-text (from-lang to-lang text)
"Translate TEXT from FROM-LANG to TO-LANG using the 'trans' command (translate-shell)."
(interactive
(list (let ((input (read-string "Translate from (default: auto): ")))
(if (string-empty-p input)
""
input))
(read-string "Translate to language: ")
(if (use-region-p)
(buffer-substring (region-beginning) (region-end))
(read-string "Text to translate: "))))
;; Escape the text for proper shell quoting
(setq text (shell-quote-argument text))
(let* ((from-option (if (string-empty-p from-lang) "" (format "-s '%s'" from-lang)))
(command (format "trans -no-warn -b %s -t '%s' <<< %s" from-option to-lang text))
(translated-text (shell-command-to-string command)))
(if (use-region-p)
(delete-region (region-beginning) (region-end))
(delete-region (point) (point)))
(insert translated-text)))
(global-set-key (kbd "C-c M-t") 'trans-text) https://asciinema.org/a/2bGCV9FI0Fisgf1BIFbqmL0YV It could be shortened but I wanted it to use the current selection as input text, if any, and to support automatic language detection. I wouldn't know how to achieve the same in |
Wonderful function! Thx a lot! |
Could you also add a shortcut for using translate-shell with vim, neovim, and other Emacs flavours when using chemacs?
say:
trans -V - for Vim
trans -NV - for neovim
trans -Sc - for Scimax
trans -ED - for Emacs Doom
trans -EnG - Emacs no-GUI
or give us an example on how to set them up in a initiation
config file...
https://github.com/plexus/chemacs
https://github.com/jkitchin/scimax
https://github.com/hlissner/doom-emacs
https://github.com/neovim/neovim
https://github.com/vim/vim
The text was updated successfully, but these errors were encountered: