Skip to content
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

gts-kill-ring-render saves both input & output #20

Closed
strikerlulu opened this issue Oct 29, 2021 · 6 comments
Closed

gts-kill-ring-render saves both input & output #20

strikerlulu opened this issue Oct 29, 2021 · 6 comments

Comments

@strikerlulu
Copy link

In v1 i think go-translate-kill-ring-save only saved the output(target lang)
but now gts-kill-ring-render saves both input & output
I see an option to create my own render but how do i just get the result of translated text from result ?

@lorniu
Copy link
Owner

lorniu commented Oct 29, 2021

Different parser makes different result.

This will cause all (both input & output & more) copied to kill ring:

(setq gts-default-translator
      (gts-translator
       :picker (gts-prompt-picker)
       :engines (gts-google-engine)
       :render (gts-kill-ring-render)))

While this will only copy the brief result:

(setq gts-default-translator
      (gts-translator
       :picker (gts-prompt-picker)
       :engines (gts-google-engine :parser (gts-google-summary-parser))
       :render (gts-kill-ring-render)))

@strikerlulu
Copy link
Author

Thx :)

(gts-translate (gts-translator
                  :picker (gts-prompt-picker)
                  :engines (gts-google-rpc-engine)
                  :render (gts-posframe-pop-render))))

is there any way to speak the input in background while its rendering in posframe popup ?
like pressing y to speak on the gts-buffer-render

@lorniu
Copy link
Owner

lorniu commented Oct 30, 2021

Same keybinds as in gts-buffer-render. Focus and click the pop-up frame window, and then use y to play the sound.

@strikerlulu
Copy link
Author

strikerlulu commented Oct 30, 2021

i don't wanna use mouse :(
so i think I've to create a new render and use go-tts function to speak

;; A method
(cl-defmethod gts-out ((_ your-render) result)
  (deactivate-mark)
  (insert result))

and in the README instead of result shouldn't it be task ? how do i get the insert-able text from the task ?

@strikerlulu
Copy link
Author

strikerlulu commented Oct 30, 2021

Ah got it...
i just override the gts-postframe-pop-render's gts-out method for the ease :P

(cl-defmethod gts-out ((_ gts-posframe-pop-render) task)
  (when-let ((buf (gts-render-buffer gts-posframe-pop-render-buffer task)))
    (posframe-refresh buf)
    (add-hook 'post-command-hook #'gts-posframe-render-auto-close-handler))
  (with-slots (text from engine) task
    (gts-tts engine text from)))

and i think in README it should be

(cl-defmethod gts-out ((_ your-render) task)
  (deactivate-mark)
  (with-slots (result) task
    (insert result)))

@lorniu
Copy link
Owner

lorniu commented Oct 30, 2021

Thanks for correcting.

And, with eieio you can write shorter:

(cl-defmethod gts-out :after ((_ gts-posframe-pop-render) task)
  (with-slots (text from engine) task
    (gts-tts engine text from)))

Also you can write another render instead:

(defclass your-posframe-pop-with-tts-render (gts-posframe-pop-render) ())

(cl-defmethod gts-out ((_ your-posframe-pop-with-tts-render) task)
  (cl-call-next-method)
  (with-slots (text from engine) task
    (gts-tts engine text from)))

;; then use `your-posframe-pop-with-tts-render' in your command.
  :render (your-posframe-pop-with-tts-render)

lorniu added a commit that referenced this issue Oct 30, 2021
lorniu added a commit that referenced this issue Oct 30, 2021
lorniu added a commit that referenced this issue Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants