From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Highlighting word diffs
Date: Sat, 18 Apr 2015 12:46:41 -0400 [thread overview]
Message-ID: <jwvpp71tnls.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: 20150418160720.GY14328@chitra.no-ip.org
> 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:
plain
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, ...).
Stefan
next prev parent reply other threads:[~2015-04-18 16:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-18 7:51 Highlighting word diffs Suvayu Ali
2015-04-18 13:25 ` Stefan Monnier
2015-04-18 16:07 ` Suvayu Ali
2015-04-18 16:46 ` Stefan Monnier [this message]
2015-04-18 16:58 ` Marcin Borkowski
2015-04-19 1:41 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvpp71tnls.fsf-monnier+gmane.emacs.help@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.