unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* function needed (to simplify diff output)
@ 2008-12-26  0:38 Samuel Wales
  0 siblings, 0 replies; 3+ messages in thread
From: Samuel Wales @ 2008-12-26  0:38 UTC (permalink / raw)
  To: help-gnu-emacs

I need a function and hope that somebody can help implement
it.

The purpose is to simplify diff -u for human viewing by
eliminating trivial changes, including line moves.

My algorithm is very simple:

   1.  Process the text after the + or - with PROCESSOR.
       Default: no processing.
   2.  Of the + and - lines, show only those with unique
       text.
   3.  Replace lines like "@@ -1,3 +1,6 @@" with "...".

The unique lines step detects line moves.  It will also
eliminate duplicated lines, but that's OK.

The processing step lets you specify what else is trivial
besides line moves.  For example, if you don't need to see
changes that involve commenting and uncommenting, you pass a
function that deletes "^#".  This makes both sides of the
diff uncommented.

As another example, you can tell diff to ignore headline
level changes in org mode by deleting "^\*+ ".  Your diffs
will not show any changes in the headline structure, but
will show other changes.  This is particularly useful.

This command would be useful to assign to a key in a version
control interface like egg.el.

Example:

Here is a diff hunk that you can call the function on.

diff -u ?????
--- aaaaa	2008-12-25 11:06:12.000000000 -0700
+++ bbbbb	2008-12-25 11:06:11.000000000 -0700
@@ -1,3 +1,6 @@
+will be moved
+will also be moved
+this will be moved
 the same
 the same again 1
 the same again 2
@@ -5,12 +8,8 @@
 the same again 4
 the same again 5
 still the same
-only in aaaaa
-will be deleted
-will be commented
-will be moved
-will also be moved
-this will be moved
+only in bbbbb!
+#will be commented
 another identical line
 another identical line

The output will be the following if the preprocessor removes
comment-start from every line that has it.  Note that the
"will be commented" line and the moved lines are eliminated.

diff -u ?????
--- aaaaa	2008-12-25 11:06:12.000000000 -0700
+++ bbbbb	2008-12-25 11:06:11.000000000 -0700
...
 the same
 the same again 1
 the same again 2
...
 the same again 4
 the same again 5
 still the same
-only in aaaaa
-will be deleted
+only in bbbbb!
 another identical line
 another identical line

Here is what I have so far:

(defun fix-diff (&optional processor)
  "When point is near a diff -u hunk, pop up a
buffer with that hunk cleaned up for human viewing.

By default, just eliminate evidence of line moves from the
diff and replace lines like "@@ -1,3 +1,6 @@" with "...".
(This also eliminates evidence of duplicated lines.)

With PROCESSOR, first call processor on a temporary buffer
that consists of the diff hunk with the first column (the
one that has + and -) removed.

For example, if the diff is of two versions of a shell
script, and processor deletes all instances of the regexp
"^#", then the cleaned-up diff output will not have any
evidence of lines that are commented in one version and
uncommented in the other."
  (interactive)
  ;;this is the part i can't do
  )

Thanks.

-- 
Myalgic encephalomyelitis denialists are knowingly causing further
suffering and death by opposing biomedical research on this serious
infectious disease.  Do you care about the world?
http://www.meactionuk.org.uk/What_Is_ME_What_Is_CFS.htm




^ permalink raw reply	[flat|nested] 3+ messages in thread
[parent not found: <mailman.3361.1230251889.26697.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2008-12-26  4:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-26  0:38 function needed (to simplify diff output) Samuel Wales
     [not found] <mailman.3361.1230251889.26697.help-gnu-emacs@gnu.org>
2008-12-26  2:33 ` htbest2000
2008-12-26  4:27   ` Samuel Wales

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).