[Top][All Lists]

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

Re: Highlighting word diffs

From: Stefan Monnier
Subject: Re: Highlighting word diffs
Date: Sat, 18 Apr 2015 12:46:41 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

> I would expect the [-text-] bits to be coloured red, and {+text+} bits
> to be coloured green.  That's what I get in the terminal with:

>   $ git diff --word-diff

> Does that help?

Yes, thank you.

> Is there support for this?

No, there isn't so far.

> If not, would it be a valid feature request?

Of course.

Looking at your sample output I can't see any indication that diff-mode
could use to detect that "word-diff" was used.  Also "diff --word-diff
a b" tells me that this option is not supported, so either it's a new
feature in recent diffutils or (more likely) it's specific to Git.
Also "git diff --help" tells me:

               Show words as [-removed-] and {+added+}.  Makes no attempts to
               escape the delimiters if they appear in the input, so the
               output may be ambiguous.

so making diff-mode highlight [-<foo>-] specially might lead to
completely broken highlighting if the file contains "[-" or "-]".

So, the best options to get reliable highlighting in diff-mode would be
either --word-diff=color (and then process the output to turn the color
escape sequence into faces) or --word-diff=porcelain and then
post-process the output to hide the extra stuff.
For example, applying

   (while (re-search-forward "\n\\(?:[-+ ]\\|\\(~\\)\n\\)" nil t)
     (let ((m (if (match-end 1) 1 0)))
       (put-text-property (match-beginning 0) (match-end m) 'invisible t)))

to the body of each hunk (in porcelain format) results in acceptable
display (basically equivalent to word-diff=color).  But of course,
there's a lot more work to be done for actual support (e.g. for
diff-goto-source, diff-apply-hunk, diff-reverse-direction, ...).


reply via email to

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