emacs-devel
[Top][All Lists]
Advanced

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

Re: Syntactic fontification of diff hunks


From: Yuri Khan
Subject: Re: Syntactic fontification of diff hunks
Date: Fri, 17 Aug 2018 13:47:57 +0700

On Fri, Aug 17, 2018 at 12:57 PM Andreas Röhler
<address@hidden> wrote:

> > Also, it looks like it’s going to be somewhere between slightly and
> > horribly inaccurate depending on where the hunk starts (e.g. in the
> > middle of a string literal or comment)?
>
> Which probably thwarts the whole project.

Not necessarily; I think it might be good enough for a major part of
real-life use cases. Also, if the diff comes from an interactive tool,
the user can probably just increase context size a few times so as to
shift the balance towards “slightly inaccurate”.

> Theoretically if being behind
> the end or start of a string could be fetched from source files -

That condition is undecidable based on the hunk text alone.

An implementation that has access to at least one of the source files
could just fontify that whole file and extract fontification from that
using hunk line offsets (assuming they are accurate). This probably
covers Ediff, vc, and Magit, but not reading standalone patches.

There is also the theoretical issue of syntax being changed by the
patch — e.g. introducing an unbalanced multiline string or comment
opener or closer on a separate line.

     (defun foo ()
    +  "
       (bar baz)
    +  "
       (quux xyzzy))

The middle line here has (punctuation identifier identifier
punctuation) syntax according to the “before” file, but (string)
according to “after”.



reply via email to

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