emacs-devel
[Top][All Lists]
Advanced

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

Tracking buffer positions across time, without markers (was Re: PL suppo


From: Clément Pit-Claudel
Subject: Tracking buffer positions across time, without markers (was Re: PL support)
Date: Sat, 9 May 2020 15:47:33 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

Hi João,

On 09/05/2020 13.08, João Távora wrote:
> Since exchanging information about source-file changes is largely a
> solved problem, as soon as servers start declaring support the new
> syntax highlighting extensions, it's is a question of applying the
> text properties in an efficient manner.


Can you clarify what you mean by 'a solved problem'?  One long-standing issue 
that I've had with Emacs is that I don't know of a way to track buffer 
positions without adding markers.  Here's a concrete example:

I start with a buffer that contains "int foo ()", and send that to a subprocess 
(say a syntax highlighter, for example).  It returns [0:3:type; 4:7:name].  In 
the meantime, the user has inserted more text in the buffer, which now contains 
"static int foo ()".  If I apply the highlighting as-is, it will be all wrong!

Visual Studio has a nice API for this: there is a way to snapshot a buffer, and 
to translate positions between two snapshots.  In my example, this allows you 
to translate 0:3 in the original buffer to 7:10 in the new one.

I don't think Emacs has such a facility at the moment — did I miss something?

I've been thinking of building one for a while.  I think it can be done 
entirely in ELisp, by using the undo list: snapshots would be pointers into the 
undo list, and positions could be translated by iterating over all undo list 
entries between two snapshots and adjusting positions according to each 
undo-list entry.

Are you using something different in eglot? Or are you assuming that calls are 
fast enough that this isn't a problem?  I ran into this problem with very slow 
subprocesses, like running an SMT solver.

Clément.



reply via email to

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