* Highlighting word diffs
@ 2015-04-18 7:51 Suvayu Ali
2015-04-18 13:25 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Suvayu Ali @ 2015-04-18 7:51 UTC (permalink / raw)
To: Emacs help
Hi,
I wanted to use word diffs for text-modes (i.e. Org, TeX, plain text,
etc). So I change diff-switches in text-mode-hook, and the output looks
as expected. However the highlighting in diff-mode does not seem to
work. I guess there is probably a switch, or maybe I need to change a
regex; I can't seem to find it though.
Any pointers?
Cheers,
--
Suvayu
Open source is the future. It sets us free.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Highlighting word diffs
2015-04-18 7:51 Highlighting word diffs Suvayu Ali
@ 2015-04-18 13:25 ` Stefan Monnier
2015-04-18 16:07 ` Suvayu Ali
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2015-04-18 13:25 UTC (permalink / raw)
To: help-gnu-emacs
> I wanted to use word diffs for text-modes (i.e. Org, TeX, plain text,
> etc). So I change diff-switches in text-mode-hook, and the output looks
> as expected.
I don't know how you changed diff-switches, and I don't know what this
expected output looks like, nor which command you used to get it.
> However the highlighting in diff-mode does not seem to work.
I don't know how it fails to work either.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Highlighting word diffs
2015-04-18 13:25 ` Stefan Monnier
@ 2015-04-18 16:07 ` Suvayu Ali
2015-04-18 16:46 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Suvayu Ali @ 2015-04-18 16:07 UTC (permalink / raw)
To: help-gnu-emacs
Hi Stefan,
On Sat, Apr 18, 2015 at 09:25:51AM -0400, Stefan Monnier wrote:
> > I wanted to use word diffs for text-modes (i.e. Org, TeX, plain text,
> > etc). So I change diff-switches in text-mode-hook, and the output looks
> > as expected.
>
> I don't know how you changed diff-switches, and I don't know what this
> expected output looks like, nor which command you used to get it.
>
This is how I set it:
(setq vc-git-diff-switches (list "--word-diff"))
And I use vc-diff to generate the diff. Here is a sample of how it
looks:
diff --git a/time-acceptance.org b/time-acceptance.org
index 361a6ee..33fac7c 100644
--- a/time-acceptance.org
+++ b/time-acceptance.org
@@ -1,35 +1,43 @@
#+title: [-Decay time-]{+Decay-time+} dependent acceptance
#+include: options.org
#+include: macros.org
* WInP [-Decay time-]{+Decay-time+} dependent acceptance
:PROPERTIES:
:CUSTOM_ID: ch:tacc
:END:
An ideal event selection would accept all events that are true signal
events, and reject the rest. Reality is different however. Since the
flight distance and [-decay time-]{+decay-time+} are directly related{{{todo(Cite eqn
from introduction)}}}, some selection requirements related to the
flight distance of the B_{s} meson could bias the sample of accepted
events in [-decay time.-]{+decay-time[fn:: One might even think of this as a selection+}
{+efficiency function.].+} The {+most effective+} selection [-requirement responsible could be any-]{+requirements are+}
{+often designed to reject displaced vertices not associated with a+}
{+B_{s} meson. Which is inevitably at odds with an unbiased decay-time.+}
... and so on.
> > However the highlighting in diff-mode does not seem to work.
>
> I don't know how it fails to work either.
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? Is there support for this? If not, would it be a valid
feature request?
Thanks for any comments.
--
Suvayu
Open source is the future. It sets us free.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Highlighting word diffs
2015-04-18 16:07 ` Suvayu Ali
@ 2015-04-18 16:46 ` Stefan Monnier
2015-04-18 16:58 ` Marcin Borkowski
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2015-04-18 16:46 UTC (permalink / raw)
To: help-gnu-emacs
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-04-19 1:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2015-04-18 16:58 ` Marcin Borkowski
2015-04-19 1:41 ` Stefan Monnier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).