From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Highlighting word diffs Date: Sat, 18 Apr 2015 12:46:41 -0400 Message-ID: References: <20150418075126.GW14328@chitra.no-ip.org> <20150418160720.GY14328@chitra.no-ip.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1429375634 1398 80.91.229.3 (18 Apr 2015 16:47:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Apr 2015 16:47:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Apr 18 18:47:06 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YjVtZ-0003YX-Or for geh-help-gnu-emacs@m.gmane.org; Sat, 18 Apr 2015 18:47:05 +0200 Original-Received: from localhost ([::1]:46256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YjVtZ-0005Vl-3o for geh-help-gnu-emacs@m.gmane.org; Sat, 18 Apr 2015 12:47:05 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YjVtP-0005Uw-ES for help-gnu-emacs@gnu.org; Sat, 18 Apr 2015 12:46:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YjVtM-0002vp-9X for help-gnu-emacs@gnu.org; Sat, 18 Apr 2015 12:46:55 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:42091) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YjVtM-0002vb-2T for help-gnu-emacs@gnu.org; Sat, 18 Apr 2015 12:46:52 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1YjVtJ-0003PP-8a for help-gnu-emacs@gnu.org; Sat, 18 Apr 2015 18:46:49 +0200 Original-Received: from 108.175.234.143 ([108.175.234.143]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 18 Apr 2015 18:46:49 +0200 Original-Received: from monnier by 108.175.234.143 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 18 Apr 2015 18:46:49 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 48 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 108.175.234.143 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) Cancel-Lock: sha1:+I9viiw8RdNnk0xbGh9QEvpD4Kg= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:103830 Archived-At: > 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 [--] 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