From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#25410: 26.0.50; Refine an unified diff hunk only if adds lines Date: Fri, 13 Jan 2017 15:14:04 +0900 (JST) Message-ID: References: <8737grz0q3.fsf@gmail.com> <8737gr0zbn.fsf@users.sourceforge.net> <87fukqe2eu.fsf@gmail.com> <8760lmqak1.fsf@gmail.com> <87wpe0zz0s.fsf@users.sourceforge.net> <87inpjzhpb.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1484288128 1828 195.159.176.226 (13 Jan 2017 06:15:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 13 Jan 2017 06:15:28 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: 25410@debbugs.gnu.org, Tino Calancha To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jan 13 07:15:24 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRv8l-00075B-Lj for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Jan 2017 07:15:07 +0100 Original-Received: from localhost ([::1]:39224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRv8q-0001N9-25 for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Jan 2017 01:15:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRv8k-0001Ln-4k for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 01:15:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRv8g-0002SJ-V4 for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 01:15:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cRv8g-0002S4-QO for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 01:15:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cRv8g-0005wc-Fe for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 01:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Jan 2017 06:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25410 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 25410-submit@debbugs.gnu.org id=B25410.148428805622763 (code B ref 25410); Fri, 13 Jan 2017 06:15:02 +0000 Original-Received: (at 25410) by debbugs.gnu.org; 13 Jan 2017 06:14:16 +0000 Original-Received: from localhost ([127.0.0.1]:52005 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRv7w-0005v5-Db for submit@debbugs.gnu.org; Fri, 13 Jan 2017 01:14:16 -0500 Original-Received: from mail-pf0-f179.google.com ([209.85.192.179]:35353) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cRv7u-0005ul-7G for 25410@debbugs.gnu.org; Fri, 13 Jan 2017 01:14:14 -0500 Original-Received: by mail-pf0-f179.google.com with SMTP id f144so25956278pfa.2 for <25410@debbugs.gnu.org>; Thu, 12 Jan 2017 22:14:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=2Mg3S9zejRh/E7dAuOvM5BJCxOF0d0ytNA4qqcCBgFk=; b=ljHidW0jSMhjaVxKzaOI1RWfGbNLFnuUfgC+5ByQYH3I4J1ZYoboFz+6eMeOCPEGJ3 qCul2kbDevP1wheXz2BhBM7sQ9l0at0Fg+QQ/4vN74IVwwDULOIJzuud3n428aXUzXw6 NokGOVAwoO71KleIXaNLc6hLZbkw/xA8G632hGdj5iKM08Mga1V2qgcookULma6ewMd8 zjJp1wgPn+WfY2idIhE7h25Mqi4RCWez6xDBfVCrnG6/JNc0B8aFCw+dKc1mEQ0M9KHe jnuy/plhen+d02Fru29asLn61f9zcE9+sWcDbt4LI/hrUX78WcXhCaaqHXAsqaOuTO4N rVBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=2Mg3S9zejRh/E7dAuOvM5BJCxOF0d0ytNA4qqcCBgFk=; b=FRzFkzVmoAiBk0ZBvvTxbnWlavzBWtobiUjNDRVoJDt5vgXDvARLjkv0MbTjNqaivD qjAeBQnFTKFuqZJwX09JrmVBoYxSSVI1YwGW4/UuOdKzEu0C0IiPlM29miw0GDTLgNZm IvnslkBY9FRAdzYXLElxLvBwUiyJZvLXBXoXD6sVHORKd8SnItk92liNBQAdO+OQJiCD kgweCDptRgKHIyJTPc51rP6GS5pdvh1x3cRbspOgEbzgXWOda3IXYMCC8Q5K9F/jas6A OL7IMT1ZKPlq1fEbSmxK76ju4booO3zlPS0uDI/HjcKkO25nDfrxODDohdjTiieTdo7d Lw/g== X-Gm-Message-State: AIkVDXIlmAbMWG5k1AEwb5NO4bVfPHecAFKOUFIWOlbchF7MKt83pzFs+ruIQotim43d2w== X-Received: by 10.84.133.129 with SMTP id f1mr26930643plf.64.1484288048209; Thu, 12 Jan 2017 22:14:08 -0800 (PST) Original-Received: from calancha-pc (217.225.128.101.dy.bbexcite.jp. [101.128.225.217]) by smtp.gmail.com with ESMTPSA id x16sm25495196pfk.79.2017.01.12.22.14.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jan 2017 22:14:07 -0800 (PST) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: <87inpjzhpb.fsf@users.sourceforge.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:128054 Archived-At: On Thu, 12 Jan 2017, npostavs@users.sourceforge.net wrote: >+ (while (re-search-forward "^-" end t) >+ (let ((beg-del (progn (beginning-of-line) (point))) >+ beg-add end-add) >+ (when (and (diff--forward-while-leading-char ?- end) >+ ;; Allow for "\ No newline at end of file". >+ (progn (diff--forward-while-leading-char ?\\ end) >+ (setq beg-add (point))) >+ (diff--forward-while-leading-char ?+ end) >+ (progn (diff--forward-while-leading-char ?\\ end) >+ (setq end-add (point)))) >+ (smerge-refine-subst beg-del beg-add beg-add end-add >+ nil 'diff-refine-preproc props-r props-a))))) How about hide the complexity resulting for checking ?\\ inside the auxiliary function? diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 9dfcd944bb..e3487a722b 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2062,6 +2062,19 @@ diff-refine-preproc (declare-function smerge-refine-subst "smerge-mode" (beg1 end1 beg2 end2 props-c &optional preproc props-r props-a)) +(defun diff--forward-while-leading-char (char bound &optional ok-no-lf-eol) + "Move point until reaching a line not starting with CHAR. +Return new point, if it was moved. +If optional arg OK-NO-LF-EOL is non-nil, then allow no newline at end of line." + (let ((orig (point))) + (cl-labels ((fn (ch limit) + (while (and (< (point) limit) (eql (following-char) ch)) + (forward-line 1)))) + (progn + (fn char bound) + (when ok-no-lf-eol (fn ?\\ bound)) + (unless (= orig (point)) (point)))))) + (defun diff-refine-hunk () "Highlight changes of hunk at point at a finer granularity." (interactive) @@ -2081,16 +2094,13 @@ diff-refine-hunk (goto-char beg) (pcase style (`unified - (while (re-search-forward - (eval-when-compile - (let ((no-LF-at-eol-re "\\(?:\\\\.*\n\\)?")) - (concat "^\\(?:-.*\n\\)+" no-LF-at-eol-re - "\\(\\)" - "\\(?:\\+.*\n\\)+" no-LF-at-eol-re))) - end t) - (smerge-refine-subst (match-beginning 0) (match-end 1) - (match-end 1) (match-end 0) - nil 'diff-refine-preproc props-r props-a))) + (while (re-search-forward "^-" end t) + (let ((beg-del (progn (beginning-of-line) (point))) + (beg-add (diff--forward-while-leading-char ?- end 'no-lf-eol)) + (end-add (diff--forward-while-leading-char ?+ end 'no-lf-eol))) + (when (and beg-add end-add) + (smerge-refine-subst beg-del beg-add beg-add end-add + nil 'diff-refine-preproc props-r props-a))))) (`context (let* ((middle (save-excursion (re-search-forward "^---"))) (other middle))