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 21:11:20 +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; charset=US-ASCII; format=flowed X-Trace: blaine.gmane.org 1484309538 1775 195.159.176.226 (13 Jan 2017 12:12:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 13 Jan 2017 12:12:18 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) To: 25410@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jan 13 13:12:11 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 1cS0iG-0007wv-4I for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Jan 2017 13:12:08 +0100 Original-Received: from localhost ([::1]:40557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cS0iK-0004Ez-Dq for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Jan 2017 07:12:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cS0iF-0004BW-2X for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 07:12:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cS0iA-00059M-3j for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 07:12:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36728) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cS0i9-000595-UN for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 07:12:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cS0i9-0008BK-PB for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2017 07:12:01 -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 12:12:01 +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.148430949131408 (code B ref 25410); Fri, 13 Jan 2017 12:12:01 +0000 Original-Received: (at 25410) by debbugs.gnu.org; 13 Jan 2017 12:11:31 +0000 Original-Received: from localhost ([127.0.0.1]:52127 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cS0he-0008AV-Oj for submit@debbugs.gnu.org; Fri, 13 Jan 2017 07:11:31 -0500 Original-Received: from mail-pf0-f170.google.com ([209.85.192.170]:35938) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cS0hd-0008AJ-IH for 25410@debbugs.gnu.org; Fri, 13 Jan 2017 07:11:29 -0500 Original-Received: by mail-pf0-f170.google.com with SMTP id 189so30969605pfu.3 for <25410@debbugs.gnu.org>; Fri, 13 Jan 2017 04:11:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:subject:in-reply-to:message-id:references:user-agent :mime-version; bh=Mf6zOXp1l3XOyVEXMTZ981b89FaMg2qTMSYBtYAg3q0=; b=u8o1TMXFhqkzRXcSDaCIvqSYhIXWRYvrP+7gpQAqA3TnSqAWFnYrjwYGVAJXnCJnEQ ag8zl/+2vDW4lYKGMWfJMsPJaAAkij7cixavK5k4vP47rJ1KyU1Zz5G1FZOuEr8vA0Us ICz6V5FQjjJfZIY0I+PRjckRBX6pwPmE5+XO9bJUiD7ucKm9vXjxp7ZYB4ntcIwWVBqQ kEnMkBCwyvfmvk19ujzkGCqWD38dOlO3ZB0bSUrikHocM0sRY82igqL0mR+IdjuagwPp xImOiTKhwbykopDHONSzWyXRsgNdbMFVN1T3tJY+7tRzoD5McYy/QDA8xedZ2sgDqnak GJEQ== 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:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=Mf6zOXp1l3XOyVEXMTZ981b89FaMg2qTMSYBtYAg3q0=; b=GqYWUOxcRuWJViYvNBIqL9JMMpXXm1gtav0stxHbA4IjnyGpv3n0x/c5s6FHGQqrMD y7TBT6zCdWCl1WgrA3OocDgK154330tsQCD4RGirPyh3FDD2iE7ahsCFX90roW1pAKOy SA3+7k8nZO7YG3RrNDekAwNGHwvxL6FaKslYc0FXJ4dhZllDrOIjyyEpOAgLo/j/ScFI vSYCIti07fVOgFV6pep2jWbRwAtbVQ2mVJnL9WcFuOIkrs+yzd5k9lsBTkGJyV/PE9yy gkzCMSuX5k/xZht3br2CJv7ugMkEdV5E5FlX0X7vDadzvWeCsUotQCHkqtsmKtMOMfoX QK7Q== X-Gm-Message-State: AIkVDXK5VzBTj7wMTVFiU2qLAa9t+1Te4+vkPnSpKl5nIlrtVUZYe22z46CQnPfu8kelsQ== X-Received: by 10.98.86.203 with SMTP id h72mr12833411pfj.108.1484309482992; Fri, 13 Jan 2017 04:11:22 -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 r78sm28935339pfe.55.2017.01.13.04.11.21 for <25410@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jan 2017 04:11:22 -0800 (PST) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: 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:128064 Archived-At: On Fri, 13 Jan 2017, Tino Calancha wrote: > + (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))))) This is symmetrical respect beg-add/end-add but we could save a `diff--forward-while-leading-char' call if beg-add is nil. I think the following lazy version is better: diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 9dfcd944bb..d550a59d6d 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,14 @@ 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 t)) + (end-add (and beg-add + (diff--forward-while-leading-char ?+ end t)))) + (when 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))