Subject: Re: bug#61396: diff mode could distinguish changed from deleted lines

From: Juri Linkov <[email-masked]>
Date: Sun, 12 Feb 2023 19:20:53 +0200

>> You can use such a heuristics that when the region with deleted lines
>> borders the region with added lines this means that both regions show
>> the changed lines.  So adjacent regions in the hunk = changed lines,
>> disconnected regions of added or deleted lines = separate
>> additions/deletions.
>
> i'm not sure that will work with alternate presentatin f difflll.
> what woul dbe good is for the internal diffing to notate not merely
> additions and deleteions but also absence of addionts.  a marker that
> something will be deleted. no matter where.

This depends on the definition of changed lines.  And what is their
granularity.  To me and to the diff command, the changed lines form
a block, and when there are some changes (additions or deletions) on lines
inside that block, then the whole block of lines is declared as changed.

But it seems that you want to check words on every line in the block
for changes, and to categorize every line to three groups:

1. if on the line marked with the '-' indicator, all words are marked
   by refinement as deleted (ignoring whitespace), or there are no
   refinements on the standalone nonadjacent '-' line, declare
   the whole line as deleted;
2. if on the line marked with the '+' indicator, all words are marked by
   refinement as added (ignoring whitespace), or there are no refinements
   on the standalone nonadjacent '+' line, declare the whole line as added;
3. Otherwise, it's changed.

Still it's impossible to classify lines even with such elaborate definition.
For example,

@@ -1,2 +3,4 @@
   '(function-1
     function-2
-    function-3)
+    function-3
+    function-4)

You might want to consider the line with "function-4" added, but its closing paren
comes from the line with "function-3", so it's a changed line, not added.

Probably we can't do anything better than what the current word refinement does.