[Top][All Lists]

[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: Tue, 09 Jun 2020 21:32:47 +0200
User-agent: mu4e 1.1.0; emacs 27.0.50

On 2020-06-08, at 22:44, Emanuel Berg via Users list for the GNU Emacs text 
editor <> wrote:

> Marcin Borkowski wrote:
>> What I want is this: I have the source in, say,
>> buffer A, and I perform the translation in, say,
>> buffer B. The overlay is in buffer A, and I want to
>> move it to the next sentence (in buffer A) _without
>> moving the point away from buffer B_.
> Well, technically, there is a point in every buffer
> (and window, so there can be several for one buffer
> even), but I understand what you mean:

Well, if that code works for you, then great.  But it has two issues
from my POV.

1. It is inefficient, in the sense that every overlay belongs to some
buffer.  No need to keep the variable `source-buffer'.

2. Your code seems to assume that the point in the source buffer lies
within the highlighted sentence, no?  This need not be true, since

3. the source buffer may be (in my use-case) the same as the destination
buffer, i.e., I sometimes keep both the English and Polish (let's say)
versions in the same file.  My code covers that case as well as two
separate buffers.

BTW, I like the trick with negative one as argument to
`forward-sentence'.  I didn't think about it, I guess that may be
exactly the missing piece I looked for when I suspected my code has too
much repetition.  Thanks!


> ;;; -*- lexical-binding: t -*-
> ;;;
> ;;; this file:
> ;;;
> ;;;
> (defvar sentence-overlay nil)
> (defvar source-buffer nil)
> (defun set-source-buffer ()
>   (interactive)
>   (setq source-buffer (current-buffer)) )
> (defun remove-highlight ()
>   (interactive)
>   (when (overlayp sentence-overlay)
>     (delete-overlay sentence-overlay) ))
> (defun highlight-sentence ()
>   (let ((beg (progn (forward-sentence)    (point)))
>         (end (progn (forward-sentence -1) (point))) )
>     (if (overlayp sentence-overlay)
>         (move-overlay sentence-overlay beg end)
>       (let ((overlay (make-overlay beg end)))
>         (overlay-put overlay 'face 'font-lock-comment-face)
>         (setq sentence-overlay overlay) ))))
> (defun highlight-sentence-move (next)
>   (if (bufferp source-buffer)
>       (with-current-buffer source-buffer
>         (forward-sentence (if next 1 -1))
>         (highlight-sentence) )
>     (error "source-buffer not set") ))
> (defun highlight-sentence-next ()
>   (interactive)
>   (highlight-sentence-move t) )
> (defun highlight-sentence-prev ()
>   (interactive)
>   (highlight-sentence-move nil) )

Marcin Borkowski

reply via email to

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