From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Samuel Wales" Newsgroups: gmane.emacs.help Subject: function needed (to simplify diff output) Date: Thu, 25 Dec 2008 17:38:03 -0700 Message-ID: <20524da70812251638w2ec821ccuf8fb7efabfb44c95@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1230251922 17081 80.91.229.12 (26 Dec 2008 00:38:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Dec 2008 00:38:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 26 01:39:47 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LG0ju-0006PS-DC for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Dec 2008 01:39:43 +0100 Original-Received: from localhost ([127.0.0.1]:43315 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LG0ih-0008Og-9Z for geh-help-gnu-emacs@m.gmane.org; Thu, 25 Dec 2008 19:38:27 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LG0iN-0008Mr-Ja for help-gnu-emacs@gnu.org; Thu, 25 Dec 2008 19:38:07 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LG0iL-0008L2-Kf for help-gnu-emacs@gnu.org; Thu, 25 Dec 2008 19:38:06 -0500 Original-Received: from [199.232.76.173] (port=54573 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LG0iL-0008Kz-EF for help-gnu-emacs@gnu.org; Thu, 25 Dec 2008 19:38:05 -0500 Original-Received: from nf-out-0910.google.com ([64.233.182.190]:12484) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LG0iK-0004kM-Rw for help-gnu-emacs@gnu.org; Thu, 25 Dec 2008 19:38:05 -0500 Original-Received: by nf-out-0910.google.com with SMTP id c7so516631nfi.26 for ; Thu, 25 Dec 2008 16:38:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=C6cIJ7Z9gvPB2SznxVsmfPhPDUVhdBFNHMoR3x4Wjmg=; b=sKPXAngtTQZ4SkE7Tu3kQ9k800c8j9iih5tD623/nF9TETvmTO5a99bUzBw+175FeT 0dkeY9QuW/Qzo7EoAhk9+taXUgKdGS/zqUxbESTWXd8BCBEVgIkzsYVfMF+33rWz9xjf aKgsg/Vh76TDugPgIlAUt91J4NDQ/4cMN6HZs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=TW7VQ6W82Z8ikK70fz+aVw+ffnd1eI1+63weP4wI7u4QAMRJ1gdtX39mHxXEu5RoeR U4T9pbwNpXW4toXl0IdzhMxRy44+4WidGx0miWlleJTsxN/1q1sWQPxO8PbSqZMHBPYF MRDgUE2xI0R14D91aJE0nnRuK18sm7zSIUZvg= Original-Received: by 10.210.10.8 with SMTP id 8mr6878120ebj.186.1230251883131; Thu, 25 Dec 2008 16:38:03 -0800 (PST) Original-Received: by 10.210.66.4 with HTTP; Thu, 25 Dec 2008 16:38:03 -0800 (PST) Content-Disposition: inline X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:60929 Archived-At: 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