Subject: Re: bug#1537: diff-mode for git patches trouble

From: Stefan Monnier <[email-masked]>
Date: Thu, 11 Dec 2008 14:04:58 -0500

> The last but one line is two minuses by default.  And diff-mode
> recognizes first minus as deleted string.  Therefore when we change
> some strings in patch, emacs creates malformed hunk offset.  It will
> be @@ -6,8 +6,7 @@ insead of correct @@ -6,7 +6,7 @@ after patch
> edition (if we don't delete/create strings).

> Is it possible to fix this harm or I should append whitespace before "--"
> string always?

Given the way the code is currently implemented, it's difficult to fix
this problem.  One of the problem is that we currently don't do anything
special before the user modifies the buffer.  Not even in
a before-change-function.  So by the time we try to update the hunk
header, the buffer has been modified and we don't know what it looked
like before.
I.e. to fix it we'll need to mark the end-of-hunk before the buffer is
really modified.  E.g. by automatically adding an empty line at
end-of-hunk (or a marker).

Of course, in the general case the problem is insoluble (e.g. if you
edit the line with the "--"), but clearly we can do better in the
"normal" case.

        Stefan