[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs as a translator's tool
From: |
Emanuel Berg |
Subject: |
Re: Emacs as a translator's tool |
Date: |
Wed, 10 Jun 2020 03:02:44 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Marcin Borkowski wrote:
> 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'.
Ah, now I understand what I mean, well, I don't know
if it really makes it more efficient to extract it
every time (depends on definition of efficiency) but
maybe the code gets prettier that way, so OK:
;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;; http://user.it.uu.se/~embe8573/emacs-init/incal-ecat.el
;;; https://dataswamp.org/~incal/emacs-init/incal-ecat.el
(defvar sentence-overlay nil)
(defun remove-highlight ()
(interactive)
(when (overlayp sentence-overlay)
(delete-overlay sentence-overlay) ))
(defun highlight-sentence ()
(interactive)
(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) ))))
(defalias 'hs-init #'highlight-sentence)
(defun highlight-sentence-move (next)
(if (overlayp sentence-overlay)
(with-current-buffer (overlay-buffer sentence-overlay)
(forward-sentence (if next 1 -1))
(highlight-sentence) )
(highlight-sentence) ))
(defun highlight-sentence-next ()
(interactive)
(highlight-sentence-move t) )
(defun highlight-sentence-prev ()
(interactive)
(highlight-sentence-move nil) )
> BTW, I like the trick with negative one as argument
> to `forward-sentence'.
Right, its cool :)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
- recentering another window (was: Re: Emacs as a translator's tool), (continued)
- recentering another window (was: Re: Emacs as a translator's tool), Emanuel Berg, 2020/06/10
- Re: Emacs as a translator's tool, Marcin Borkowski, 2020/06/10
- Re: Emacs as a translator's tool, Emanuel Berg, 2020/06/10
- Re: Emacs as a translator's tool, Marcin Borkowski, 2020/06/12
- Re: Emacs as a translator's tool, Emanuel Berg, 2020/06/12
- Re: Emacs as a translator's tool, Marcin Borkowski, 2020/06/12
- Re: Emacs as a translator's tool, Emanuel Berg, 2020/06/19
- Re: Emacs as a translator's tool, Emanuel Berg, 2020/06/19
- Re: Emacs as a translator's tool, Emanuel Berg, 2020/06/10
- Re: Emacs as a translator's tool, Emanuel Berg, 2020/06/09
- Re: Emacs as a translator's tool,
Emanuel Berg <=
Re: Emacs as a translator's tool, Emanuel Berg, 2020/06/01
Re: Emacs as a translator's tool, Emanuel Berg, 2020/06/05
- Re: Emacs as a translator's tool, Jean-Christophe Helary, 2020/06/05
- Re: Emacs as a translator's tool, Emanuel Berg, 2020/06/05
- Re: Emacs as a translator's tool, Jean-Christophe Helary, 2020/06/05
- Re: Emacs as a translator's tool, Marcin Borkowski, 2020/06/05
- Re: Emacs as a translator's tool, Yuri Khan, 2020/06/05
- Re: Emacs as a translator's tool, Marcin Borkowski, 2020/06/06
- Re: Emacs as a translator's tool, Jean-Christophe Helary, 2020/06/05