Elilif / emacs-immersive-translate

Immersive-translate provides bilingual simultaneous display and translation of any text in Emacs.
GNU General Public License v3.0
72 stars 9 forks source link

[feature request] add support for copying the translated text #7

Open yuchen-lea opened 8 months ago

yuchen-lea commented 8 months ago

It would be very helpful for taking notes.

tasteSoGood commented 6 months ago

@yuchen-lea Modify the function immersive-translate-paragraph to:

(defun immersive-translate-paragraph ()
  "Translate the current paragraph."
  (interactive)
  (save-excursion
    (unless (immersive-translate-disable-p)
      (when-let* ((paragraph (immersive-translate-join-lin
                              (immersive-translate--get-paragraph)))
                  (content (if (eq immersive-translate-backend 'chatgpt)
                               (immersive-translate-chatgpt-create-prompt paragraph)
                             paragraph))
                  (ov t))
        (immersive-translate-end-of-paragraph)
        (if (immersive-translate--cache-p content)
            (let ((translation (immersive-translate--cache-get content)))
              (progn
                (kill-new translation) ;; copy the translated result to kill-ring
                (immersive-translate--add-ov translation)))
          (setq ov (make-overlay (1- (point)) (point)))
          (overlay-put ov
                       'after-string
                       immersive-translate-pending-message)
          (immersive-translate-do-translate content))))))

while overlay shows, the translation results will copy to the kill-ring instantly.

yuchen-lea commented 5 months ago

Thanks for the suggestion, but I prefer that the translated text could be manually selected and then copied like the original text