[Top][All Lists]

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

Re: Emacs as a translator's tool

From: Eric Abrahamsen
Subject: Re: Emacs as a translator's tool
Date: Sun, 07 Jun 2020 14:37:13 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Emanuel Berg via Users list for the GNU Emacs text editor
<> writes:

> Marcin Borkowski wrote:
>> If you find a good way to refactor it so that it is
>> more DRY, I'd love to see it.
> ;;; -*- lexical-binding: t -*-
> ;;;
> ;;; this file:
> ;;;
> ;;;
> (defvar sentence-overlay nil)
> (defun remove-highlight ()
>   (interactive)
>   (when (overlayp sentence-overlay)
>     (delete-overlay sentence-overlay) ))
> (defun highlight-sentence ()
>   (interactive)
>   (remove-highlight)
>   (let ((overlay (make-overlay (progn (forward-sentence)  (point))
>                                (progn (backward-sentence) (point)) )))
>     (overlay-put overlay 'face 'font-lock-function-name-face)
>     (setq sentence-overlay overlay) ))

You don't need to delete the overlay and make it again each time, just
use `move-overlay'. You can also move an overlay that's been deleted,
essentially recreating it, so long as you still have a reference to it.

How do I know? Because this thread finally motivated me to finish the
translation environment package I've been thinking of for a while, and I
just wrote pretty much the same code a couple of days ago :)

reply via email to

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