help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs as a translator's tool


From: Marcin Borkowski
Subject: Re: Emacs as a translator's tool
Date: Fri, 29 May 2020 08:35:38 +0200
User-agent: mu4e 1.1.0; emacs 27.0.50

On 2020-05-29, at 07:55, Marcin Borkowski <mbork@mbork.pl> wrote:

> Hi all,
>
> does anyone here perform translations within Emacs?  Do you know of any
> tools facilitating that?  There exist a few CATs, or Computer Aided
> Translation systems, but - AFAIK - they are all proprietary and closed
> source.  Emacs seems capable of implementing at least a simple CAT, but
> I could not find any existing solutions for that.  (I skimmed through
> the answers here:
> https://www.reddit.com/r/emacs/comments/a35bs2/emacs_for_translations/,
> but did not find anything useful.)
>
> The first thing I would need is a way to highlight the "currently
> translated sentence" in the other window, where I would keep the
> original text, with an easy way to highlight the next/previous one -
> this seems very easy to do, but did anyone actually code anything like
> this?

OK, so I assumed nobody did it, so here's my take.  Probably not
extremely well-done, but I just coded it in 15 minutes, so there you go.
Comments welcome.

--8<---------------cut here---------------start------------->8---
(defface ecat-highlight-face '((t :background "#e7ede7"))
  "Face for highlighting the currently translated sentence.")

(defvar ecat-sentence-overlay nil
  "The overlay to highlight the currently translated sentence.")

(defun ecat-highlight-this-sentence ()
  "Highlight the sentence at point using an overlay."
  (interactive)
  (delete-overlay ecat-sentence-overlay)
  (save-excursion
    (let ((sentence-end (progn (forward-sentence)
                               (point)))
          (sentence-beginning (progn (backward-sentence)
                                     (point))))
      (setq ecat-sentence-overlay
            (make-overlay sentence-beginning sentence-end))))
  (overlay-put ecat-sentence-overlay 'face 'ecat-highlight-face))

(defun ecat-highlight-next-sentence ()
  "Move the highlight to the next sentence."
  (interactive)
  (save-excursion
    (set-buffer (overlay-buffer ecat-sentence-overlay))
    (goto-char (overlay-end ecat-sentence-overlay))
    (let ((sentence-end (progn (forward-sentence)
                               (point)))
          (sentence-beginning (progn (backward-sentence)
                                     (point))))
      (move-overlay ecat-sentence-overlay sentence-beginning sentence-end))))

(defun ecat-highlight-previous-sentence ()
  "Move the highlight to the previous sentence."
  (interactive)
  (save-excursion
    (set-buffer (overlay-buffer ecat-sentence-overlay))
    (goto-char (overlay-start ecat-sentence-overlay))
    (let ((sentence-beginning (progn (backward-sentence)
                                     (point)))
          (sentence-end (progn (forward-sentence)
                               (point))))
      (move-overlay ecat-sentence-overlay sentence-beginning sentence-end))))

(defun ecat-disable-sentence-highlighting ()
  "Disable sentence highlighting."
  (interactive)
  (delete-overlay ecat-sentence-overlay))
--8<---------------cut here---------------end--------------->8---

Best,

--
Marcin Borkowski
http://mbork.pl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]