GNU bug report logs - #37395
Diff-mode doesn't take into account patch-separators as produced by git-format-patch

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Konstantin Kharlamov <hi-angel@HIDDEN>; Keywords: fixed; Done: Lars Ingebrigtsen <larsi@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug marked as fixed in version 27.1, send any further explanations to 37395 <at> debbugs.gnu.org and Konstantin Kharlamov <hi-angel@HIDDEN> Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 13 Oct 2019 03:53:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Oct 12 23:53:18 2019
Received: from localhost ([127.0.0.1]:34719 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iJUwY-0001NP-43
	for submit <at> debbugs.gnu.org; Sat, 12 Oct 2019 23:53:18 -0400
Received: from quimby.gnus.org ([80.91.231.51]:48272)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1iJUwW-0001NH-4J
 for 37395 <at> debbugs.gnu.org; Sat, 12 Oct 2019 23:53:16 -0400
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie)
 by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.89) (envelope-from <larsi@HIDDEN>)
 id 1iJUwR-00049y-Rc; Sun, 13 Oct 2019 05:53:14 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Konstantin Kharlamov <Hi-Angel@HIDDEN>
Subject: Re: bug#37395: [PATCH v5] diff-mode.el: take into account patch
 separators
References: <1568323985.28657.0@HIDDEN>
 <20191009200732.197380-1-Hi-Angel@HIDDEN>
Date: Sun, 13 Oct 2019 05:53:11 +0200
In-Reply-To: <20191009200732.197380-1-Hi-Angel@HIDDEN> (Konstantin
 Kharlamov's message of "Wed, 9 Oct 2019 23:07:32 +0300")
Message-ID: <87imotcndk.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview:  Konstantin Kharlamov <Hi-Angel@HIDDEN> writes: > v5: *
 move defvar diff-buffer-type before the 1st use > * replace (previous-line)
 with (forward-line -1) and remove > (line-beginning) call, since forward-line
 sets point to > line-beginning. 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Konstantin Kharlamov <Hi-Angel@HIDDEN> writes:

> v5: * move defvar diff-buffer-type before the 1st use
>     * replace (previous-line) with (forward-line -1) and remove
>       (line-beginning) call, since forward-line sets point to
>       line-beginning.

Thanks; applied to the trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 9 Oct 2019 20:08:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Oct 09 16:08:30 2019
Received: from localhost ([127.0.0.1]:54175 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iIIG6-0000np-0s
	for submit <at> debbugs.gnu.org; Wed, 09 Oct 2019 16:08:30 -0400
Received: from forward104o.mail.yandex.net ([37.140.190.179]:52986)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hi-angel@HIDDEN>) id 1iIIG2-0000nV-1A
 for 37395 <at> debbugs.gnu.org; Wed, 09 Oct 2019 16:08:28 -0400
Received: from forward103q.mail.yandex.net (forward103q.mail.yandex.net
 [IPv6:2a02:6b8:c0e:50:0:640:b21c:d009])
 by forward104o.mail.yandex.net (Yandex) with ESMTP id 67CD994217E;
 Wed,  9 Oct 2019 23:08:18 +0300 (MSK)
Received: from mxback9q.mail.yandex.net (mxback9q.mail.yandex.net
 [IPv6:2a02:6b8:c0e:6b:0:640:b813:52e4])
 by forward103q.mail.yandex.net (Yandex) with ESMTP id 6350361E0002;
 Wed,  9 Oct 2019 23:08:18 +0300 (MSK)
Received: from vla1-a59883171b53.qloud-c.yandex.net
 (vla1-a59883171b53.qloud-c.yandex.net [2a02:6b8:c0d:1a17:0:640:a598:8317])
 by mxback9q.mail.yandex.net (nwsmtp/Yandex) with ESMTP id B6jtVNria3-8I2Su1GX; 
 Wed, 09 Oct 2019 23:08:18 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1570651698; bh=2WvYN2O9xVL8KD65kPBJn6K+4osIVFTJVidDIvZXrc0=;
 h=In-Reply-To:Cc:To:Subject:From:References:Date:Message-Id;
 b=XfMtF9zcQs48RRft7Zizdaiv6R4p37ijYf+b7YZxnwKwbv/Lfiv3uHpaTEqoUz+Gu
 sqjAY1yvmlgXMLjKWjMYuCfqQfoLupu6n/XpTDR+jda6fmzBagEsim13w4S2sbdtK2
 DiWcJ9oLsA5XTSCjLg/0CdEtJ3v11geRMt0hhmB4=
Authentication-Results: mxback9q.mail.yandex.net; dkim=pass header.i=@yandex.ru
Received: by vla1-a59883171b53.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id 47H8NqrKGA-8HruCCPu; Wed, 09 Oct 2019 23:08:17 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
Date: Wed, 09 Oct 2019 23:08:16 +0300
From: Konstantin Kharlamov <hi-angel@HIDDEN>
Subject: Re: bug#37395: [PATCH v4] diff-mode.el: take into account patch
 separators
To: Lars Ingebrigtsen <larsi@HIDDEN>
Message-Id: <1570651696.135652.4@HIDDEN>
In-Reply-To: <87mue9678m.fsf@HIDDEN>
References: <1568323985.28657.0@HIDDEN>
 <20191008193420.193239-1-Hi-Angel@HIDDEN>
 <Konstantin	Kharlamov's message of "Tue, 8 Oct 2019 22:34:20 +0300">
X-Mailer: geary/3.35.0
MIME-Version: 1.0
Content-Type: text/plain; charset=koi8-r; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Ah, sorry, I missed it. v5 sent, now should be no new warnings.

On =F3=D2, =CF=CB=D4 9, 2019 at 21:36, Lars Ingebrigtsen <larsi@HIDDEN>=20
wrote:
> Konstantin Kharlamov <Hi-Angel@HIDDEN> writes:
>=20
>>  * lisp/vc/diff-mode.el (diff-prev-line-if-patch-separator):
>>  A function to return prev. line if it has git-format-patch
>>  separator.
>>  (diff-end-of-hunk): Make use of
>>  diff-prev-line-if-patch-separator
>>  diff-buffer-type: whether a buffer is a git-diff
>>  (define-derived-mode): set diff-buffer-type to appropriate
>>  value
>=20
> Byte-compiling gives:
>=20
> In diff-prev-line-if-patch-separator:
> vc/diff-mode.el:516:10:Warning: reference to free variable=20
> `diff-buffer-type'
> vc/diff-mode.el:517:7:Warning: `previous-line' is for interactive use=20
> only;
>     use `forward-line' with negative argument instead.
>=20
> So you have to move the defvar earlier and adjust the previous-line,=20
> but
> otherwise I think it looks OK...
>=20
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no

=





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 9 Oct 2019 20:07:50 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Oct 09 16:07:49 2019
Received: from localhost ([127.0.0.1]:54171 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iIIFR-0000mP-LR
	for submit <at> debbugs.gnu.org; Wed, 09 Oct 2019 16:07:49 -0400
Received: from forward104j.mail.yandex.net ([5.45.198.247]:54746)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <Hi-Angel@HIDDEN>) id 1iIIFO-0000m7-KN
 for 37395 <at> debbugs.gnu.org; Wed, 09 Oct 2019 16:07:48 -0400
Received: from mxback12o.mail.yandex.net (mxback12o.mail.yandex.net
 [IPv6:2a02:6b8:0:1a2d::63])
 by forward104j.mail.yandex.net (Yandex) with ESMTP id 389E44A1DB9
 for <37395 <at> debbugs.gnu.org>; Wed,  9 Oct 2019 23:07:39 +0300 (MSK)
Received: from iva7-f08b2a8dca2b.qloud-c.yandex.net
 (iva7-f08b2a8dca2b.qloud-c.yandex.net [2a02:6b8:c0c:6e00:0:640:f08b:2a8d])
 by mxback12o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id bNw56gjk52-7cbSrM3p;
 Wed, 09 Oct 2019 23:07:39 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1570651659; bh=anWSaD6YT9HfGXyKIvcjd4yPkP38CiCtRnoLjONHpAQ=;
 h=Subject:To:From:Date:Message-Id;
 b=MwdgQQ1RtiLpbTUSkMnTg08psDqmna+pzNZkhPgIGAeC35zp2DrK4IHUrkMWrRW0K
 TdBVX7yKeCcuJi9GvJVHXwCmcevh9yduMrjUvxKME9pD/Kmklw6xICJkhQY+LoQgpG
 QN+z/yXvYMwCp9dFmgempUDiD/2Q9ouwuqfgHAxQ=
Authentication-Results: mxback12o.mail.yandex.net;
 dkim=pass header.i=@yandex.ru
Received: by iva7-f08b2a8dca2b.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id ZUVmtCBOHw-7cqqHYEN; Wed, 09 Oct 2019 23:07:38 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
From: Konstantin Kharlamov <Hi-Angel@HIDDEN>
To: 37395 <at> debbugs.gnu.org
Subject: [PATCH v5] diff-mode.el: take into account patch separators
Date: Wed,  9 Oct 2019 23:07:32 +0300
Message-Id: <20191009200732.197380-1-Hi-Angel@HIDDEN>
X-Mailer: git-send-email 2.23.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

* lisp/vc/diff-mode.el (diff-prev-line-if-patch-separator):
A function to return prev. line if it has git-format-patch
separator.
(diff-end-of-hunk): Make use of
diff-prev-line-if-patch-separator
diff-buffer-type: whether a buffer is a git-diff
(define-derived-mode): set diff-buffer-type to appropriate
value
---

v5: * move defvar diff-buffer-type before the 1st use
    * replace (previous-line) with (forward-line -1) and remove
      (line-beginning) call, since forward-line sets point to
      line-beginning.

 lisp/vc/diff-mode.el | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 19f9c802d4..c86f15cee0 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -504,6 +504,7 @@ diff-file-header-re
 (defconst diff-separator-re "^--+ ?$")
 
 (defvar diff-narrowed-to nil)
+(defvar diff-buffer-type nil)
 
 (defun diff-hunk-style (&optional style)
   (when (looking-at diff-hunk-header-re)
@@ -511,6 +512,18 @@ diff-hunk-style
     (goto-char (match-end 0)))
   style)
 
+(defun diff-prev-line-if-patch-separator ()
+  "Return previous line if it has patch separator as produced by git."
+  (pcase diff-buffer-type
+    ('git
+     (save-excursion
+       (let ((old-point (point)))
+         (forward-line -1)
+         (if (looking-at "^-- $")
+             (point)
+           old-point))))
+    (_ (point))))
+
 (defun diff-end-of-hunk (&optional style donttrustheader)
   "Advance to the end of the current hunk, and return its position."
   (let (end)
@@ -561,7 +574,8 @@ diff-end-of-hunk
         (goto-char (or end (point-max)))
         (while (eq ?\n (char-before (1- (point))))
           (forward-char -1)
-          (setq end (point)))))
+          (setq end (point))))
+      (setq end (diff-prev-line-if-patch-separator)))
     ;; The return value is used by easy-mmode-define-navigation.
     (goto-char (or end (point-max)))))
 
@@ -1491,7 +1505,12 @@ diff-mode
   (add-function :filter-return (local 'filter-buffer-substring-function)
                 #'diff--filter-substring)
   (unless buffer-file-name
-    (hack-dir-local-variables-non-file-buffer)))
+    (hack-dir-local-variables-non-file-buffer))
+  (save-excursion
+    (setq-local diff-buffer-type
+                (if (re-search-forward "^diff --git" nil t)
+                    'git
+                  nil))))
 
 ;;;###autoload
 (define-minor-mode diff-minor-mode
-- 
2.23.0





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 9 Oct 2019 19:37:08 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Oct 09 15:37:08 2019
Received: from localhost ([127.0.0.1]:54153 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iIHli-0008SJ-C2
	for submit <at> debbugs.gnu.org; Wed, 09 Oct 2019 15:37:08 -0400
Received: from quimby.gnus.org ([80.91.231.51]:42448)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1iIHld-0008Rl-Ei
 for 37395 <at> debbugs.gnu.org; Wed, 09 Oct 2019 15:37:02 -0400
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie)
 by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.89) (envelope-from <larsi@HIDDEN>)
 id 1iIHlZ-0003hY-OH; Wed, 09 Oct 2019 21:37:00 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Konstantin Kharlamov <Hi-Angel@HIDDEN>
Subject: Re: bug#37395: [PATCH v4] diff-mode.el: take into account patch
 separators
References: <1568323985.28657.0@HIDDEN>
 <20191008193420.193239-1-Hi-Angel@HIDDEN>
Date: Wed, 09 Oct 2019 21:36:57 +0200
In-Reply-To: <20191008193420.193239-1-Hi-Angel@HIDDEN> (Konstantin
 Kharlamov's message of "Tue, 8 Oct 2019 22:34:20 +0300")
Message-ID: <87mue9678m.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Konstantin Kharlamov <Hi-Angel@HIDDEN> writes: > *
 lisp/vc/diff-mode.el
 (diff-prev-line-if-patch-separator): > A function to return prev. line if
 it has git-format-patch > separator. > (diff-end-of-hunk): Make use of >
 diff-prev-line-if-patch-sepa [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Konstantin Kharlamov <Hi-Angel@HIDDEN> writes:

> * lisp/vc/diff-mode.el (diff-prev-line-if-patch-separator):
> A function to return prev. line if it has git-format-patch
> separator.
> (diff-end-of-hunk): Make use of
> diff-prev-line-if-patch-separator
> diff-buffer-type: whether a buffer is a git-diff
> (define-derived-mode): set diff-buffer-type to appropriate
> value

Byte-compiling gives:

In diff-prev-line-if-patch-separator:
vc/diff-mode.el:516:10:Warning: reference to free variable `diff-buffer-type'
vc/diff-mode.el:517:7:Warning: `previous-line' is for interactive use only;
    use `forward-line' with negative argument instead.

So you have to move the defvar earlier and adjust the previous-line, but
otherwise I think it looks OK...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 8 Oct 2019 20:08:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Oct 08 16:08:47 2019
Received: from localhost ([127.0.0.1]:51580 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iHvmp-0003jG-IM
	for submit <at> debbugs.gnu.org; Tue, 08 Oct 2019 16:08:47 -0400
Received: from forward100o.mail.yandex.net ([37.140.190.180]:35697)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hi-angel@HIDDEN>) id 1iHvmm-0003iw-1X
 for 37395 <at> debbugs.gnu.org; Tue, 08 Oct 2019 16:08:46 -0400
Received: from mxback17g.mail.yandex.net (mxback17g.mail.yandex.net
 [IPv6:2a02:6b8:0:1472:2741:0:8b7:317])
 by forward100o.mail.yandex.net (Yandex) with ESMTP id E19D54AC1D4D;
 Tue,  8 Oct 2019 23:08:36 +0300 (MSK)
Received: from myt1-e9eae5d2de9d.qloud-c.yandex.net
 (myt1-e9eae5d2de9d.qloud-c.yandex.net [2a02:6b8:c00:1290:0:640:e9ea:e5d2])
 by mxback17g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 0G0nUPgZ8t-8aOS34he;
 Tue, 08 Oct 2019 23:08:36 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1570565316; bh=n21RargOiBJwPxTAFLFUgnmfVXZQn/fuGDsJ+46lB3g=;
 h=In-Reply-To:Cc:To:Subject:From:References:Date:Message-Id;
 b=UtKQKf1BgwLh8fPSLtXPoCyeBNKN+HHXlBpXQzyIhh9cmFX9FwyxCvvX97+H269cR
 OGwwxn/M4mhkzryTtNzXdOt9XjoBm2eU/aX22UZq660lOA50IDJoujfTSaDpJgZPRC
 G8fmP3Y6n1+a4Sqyo1+JBdpjt3WcBHvoJhH4Xhco=
Authentication-Results: mxback17g.mail.yandex.net;
 dkim=pass header.i=@yandex.ru
Received: by myt1-e9eae5d2de9d.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id e78WpQ12bG-8Zq8tkOI; Tue, 08 Oct 2019 23:08:36 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
Date: Tue, 08 Oct 2019 23:08:32 +0300
From: Konstantin Kharlamov <hi-angel@HIDDEN>
Subject: Re: bug#37395: [PATCH v3] diff-mode.el: take into account patch
 separators
To: Lars Ingebrigtsen <larsi@HIDDEN>
Message-Id: <1570565312.135652.3@HIDDEN>
In-Reply-To: <87lftv1b4h.fsf@HIDDEN>
References: <1568323985.28657.0@HIDDEN>
 <20190916202643.27946-1-Hi-Angel@HIDDEN> <1570489462.135652.1@HIDDEN>
 <Konstantin Kharlamov's message	of "Tue, 08 Oct 2019 02:04:22 +0300">
X-Mailer: geary/3.35.0
MIME-Version: 1.0
Content-Type: text/plain; charset=koi8-r; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)



On =F7=D4, =CF=CB=D4 8, 2019 at 17:59, Lars Ingebrigtsen <larsi@HIDDEN>=20
wrote:
> Konstantin Kharlamov <hi-angel@HIDDEN> writes:
>=20
>>>  And the first doc string line should be a complete sentence.
>>=20
>>  Sorry, I'm not sure I get it: do you want me to keep the
>>  "git-format-patch." text on the first line, with the rest of the
>>  sentence?
>=20
> If that doesn't make the line too long.  Otherwise you have to rewrite
> the sentence.

Thanks, comments are addressed. That one too (I forgot to mention it in=20
"v4" patch changes).

=





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 8 Oct 2019 19:34:40 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Oct 08 15:34:40 2019
Received: from localhost ([127.0.0.1]:51545 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iHvFo-0002pY-43
	for submit <at> debbugs.gnu.org; Tue, 08 Oct 2019 15:34:40 -0400
Received: from forward100j.mail.yandex.net ([5.45.198.240]:56956)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <Hi-Angel@HIDDEN>) id 1iHvFj-0002pE-8Y
 for 37395 <at> debbugs.gnu.org; Tue, 08 Oct 2019 15:34:38 -0400
Received: from forward102q.mail.yandex.net (forward102q.mail.yandex.net
 [IPv6:2a02:6b8:c0e:1ba:0:640:516:4e7d])
 by forward100j.mail.yandex.net (Yandex) with ESMTP id 9A81650E03A5
 for <37395 <at> debbugs.gnu.org>; Tue,  8 Oct 2019 22:34:27 +0300 (MSK)
Received: from mxback10q.mail.yandex.net (mxback10q.mail.yandex.net
 [IPv6:2a02:6b8:c0e:1b4:0:640:b6ef:cb3])
 by forward102q.mail.yandex.net (Yandex) with ESMTP id 947397F20017
 for <37395 <at> debbugs.gnu.org>; Tue,  8 Oct 2019 22:34:27 +0300 (MSK)
Received: from vla5-63eb7479a3c9.qloud-c.yandex.net
 (vla5-63eb7479a3c9.qloud-c.yandex.net [2a02:6b8:c18:3411:0:640:63eb:7479])
 by mxback10q.mail.yandex.net (nwsmtp/Yandex) with ESMTP id scSyZydX9a-YRIW7YeQ;
 Tue, 08 Oct 2019 22:34:27 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1570563267; bh=4Ol1viYtRtNIqN1z/FgAGmSPi0rCp84NFWO+dd2A3cY=;
 h=Subject:To:From:Date:Message-Id;
 b=IBu6V28ez8sqTdxNE5JiKWyyvwO3+cwRYri1Uh9HS69pyoUdAui8p2dz6k7hLrjec
 1Cg1lECGs3439ClzhBMgxLhPYWEg8qxNPUQAbKubhLiirgOeXc9mfEeQtzYROA5mmx
 g8JfNwz+9cIqH6k2mVwQbTok6Ps5EHXgzRBx3lRE=
Authentication-Results: mxback10q.mail.yandex.net;
 dkim=pass header.i=@yandex.ru
Received: by vla5-63eb7479a3c9.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id A2PCPZJIvS-YQrmqrBb; Tue, 08 Oct 2019 22:34:26 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
From: Konstantin Kharlamov <Hi-Angel@HIDDEN>
To: 37395 <at> debbugs.gnu.org
Subject: [PATCH v4] diff-mode.el: take into account patch separators
Date: Tue,  8 Oct 2019 22:34:20 +0300
Message-Id: <20191008193420.193239-1-Hi-Angel@HIDDEN>
X-Mailer: git-send-email 2.23.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

* lisp/vc/diff-mode.el (diff-prev-line-if-patch-separator):
A function to return prev. line if it has git-format-patch
separator.
(diff-end-of-hunk): Make use of
diff-prev-line-if-patch-separator
diff-buffer-type: whether a buffer is a git-diff
(define-derived-mode): set diff-buffer-type to appropriate
value
---

v4:
    * replace defsubst with defun
    * define diff-buffer-type with defvar and set with setq-local
    * call `setq-local` just once

 lisp/vc/diff-mode.el | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 19f9c802d4..1cc3cd3d4d 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -511,6 +511,19 @@ diff-hunk-style
     (goto-char (match-end 0)))
   style)
 
+(defun diff-prev-line-if-patch-separator ()
+  "Return previous line if it has patch separator as produced by git."
+  (pcase diff-buffer-type
+    ('git
+     (save-excursion
+       (let ((old-point (point)))
+         (previous-line)
+         (beginning-of-line)
+         (if (looking-at "^-- $")
+             (point)
+           old-point))))
+    (_ (point))))
+
 (defun diff-end-of-hunk (&optional style donttrustheader)
   "Advance to the end of the current hunk, and return its position."
   (let (end)
@@ -561,7 +574,8 @@ diff-end-of-hunk
         (goto-char (or end (point-max)))
         (while (eq ?\n (char-before (1- (point))))
           (forward-char -1)
-          (setq end (point)))))
+          (setq end (point))))
+      (setq end (diff-prev-line-if-patch-separator)))
     ;; The return value is used by easy-mmode-define-navigation.
     (goto-char (or end (point-max)))))
 
@@ -1425,6 +1439,7 @@ diff--font-lock-cleanup
 
 (defvar whitespace-style)
 (defvar whitespace-trailing-regexp)
+(defvar diff-buffer-type nil)
 
 ;;;###autoload
 (define-derived-mode diff-mode fundamental-mode "Diff"
@@ -1491,7 +1506,12 @@ diff-mode
   (add-function :filter-return (local 'filter-buffer-substring-function)
                 #'diff--filter-substring)
   (unless buffer-file-name
-    (hack-dir-local-variables-non-file-buffer)))
+    (hack-dir-local-variables-non-file-buffer))
+  (save-excursion
+    (setq-local diff-buffer-type
+                (if (re-search-forward "^diff --git" nil t)
+                    'git
+                  nil))))
 
 ;;;###autoload
 (define-minor-mode diff-minor-mode
-- 
2.23.0





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 8 Oct 2019 15:59:50 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Oct 08 11:59:50 2019
Received: from localhost ([127.0.0.1]:51291 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iHrtu-0003vQ-FR
	for submit <at> debbugs.gnu.org; Tue, 08 Oct 2019 11:59:50 -0400
Received: from quimby.gnus.org ([80.91.231.51]:38696)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1iHrtq-0003vF-97
 for 37395 <at> debbugs.gnu.org; Tue, 08 Oct 2019 11:59:48 -0400
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie)
 by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.89) (envelope-from <larsi@HIDDEN>)
 id 1iHrtm-0006zd-WC; Tue, 08 Oct 2019 17:59:45 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Konstantin Kharlamov <hi-angel@HIDDEN>
Subject: Re: bug#37395: [PATCH v3] diff-mode.el: take into account patch
 separators
References: <1568323985.28657.0@HIDDEN>
 <20190916202643.27946-1-Hi-Angel@HIDDEN>
 <1570489462.135652.1@HIDDEN>
Date: Tue, 08 Oct 2019 17:59:42 +0200
In-Reply-To: <1570489462.135652.1@HIDDEN> (Konstantin Kharlamov's message
 of "Tue, 08 Oct 2019 02:04:22 +0300")
Message-ID: <87lftv1b4h.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Konstantin Kharlamov <hi-angel@HIDDEN> writes: >> And the
 first doc string line should be a complete sentence. > > Sorry, I'm not sure
 I get it: do you want me to keep the > "git-format-patch." text on the first
 line, with the rest of the > senten [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Konstantin Kharlamov <hi-angel@HIDDEN> writes:

>> And the first doc string line should be a complete sentence.
>
> Sorry, I'm not sure I get it: do you want me to keep the
> "git-format-patch." text on the first line, with the rest of the 
> sentence?

If that doesn't make the line too long.  Otherwise you have to rewrite
the sentence.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 7 Oct 2019 23:13:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Oct 07 19:13:12 2019
Received: from localhost ([127.0.0.1]:49258 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iHcBk-0002Cf-48
	for submit <at> debbugs.gnu.org; Mon, 07 Oct 2019 19:13:12 -0400
Received: from forward101o.mail.yandex.net ([37.140.190.181]:50689)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hi-angel@HIDDEN>) id 1iHcBe-0002C2-LV
 for 37395 <at> debbugs.gnu.org; Mon, 07 Oct 2019 19:13:09 -0400
Received: from mxback15j.mail.yandex.net (mxback15j.mail.yandex.net
 [IPv6:2a02:6b8:0:1619::91])
 by forward101o.mail.yandex.net (Yandex) with ESMTP id 2C0393C00F42;
 Tue,  8 Oct 2019 02:13:00 +0300 (MSK)
Received: from iva5-d6550783a3c3.qloud-c.yandex.net
 (iva5-d6550783a3c3.qloud-c.yandex.net [2a02:6b8:c0c:74a5:0:640:d655:783])
 by mxback15j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id p3q70fjJg6-Cx6SAtx1;
 Tue, 08 Oct 2019 02:13:00 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1570489980; bh=NCeaDb7Uw/uFqi3+y2htztLvTo4TCOkzuYbBwp+l5GY=;
 h=In-Reply-To:Cc:To:Subject:From:References:Date:Message-Id;
 b=wyhl1VHbZcBcnwoKUjkOTcTRXzYqgkfHmeVDrnMNivi1bLg5mi3Owyb7LB87nnzFv
 XX/SHhgBs8L9WDTx0HpvDMtE7wJqafbPVmhCwlsZ/FiUD18BVRi2kY2sowA5cIr5w7
 N/GXG65WMXuSTyV2265MdXvAi4x9dXlmzzSTZXQs=
Authentication-Results: mxback15j.mail.yandex.net;
 dkim=pass header.i=@yandex.ru
Received: by iva5-d6550783a3c3.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id zVO4upHYle-Ciq8rMtS; Tue, 08 Oct 2019 02:12:44 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
Date: Tue, 08 Oct 2019 02:12:43 +0300
From: Konstantin Kharlamov <hi-angel@HIDDEN>
Subject: Re: bug#37395: [PATCH v3] diff-mode.el: take into account patch
 separators
To: Lars Ingebrigtsen <larsi@HIDDEN>
Message-Id: <1570489963.135652.2@HIDDEN>
In-Reply-To: <1570489462.135652.1@HIDDEN>
References: <1568323985.28657.0@HIDDEN>
 <20190916202643.27946-1-Hi-Angel@HIDDEN>
 <Konstantin	Kharlamov's message of "Mon, 16 Sep 2019 23:26:43 +0300">
X-Mailer: geary/3.35.0
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1251; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)



On =C2=F2, =EE=EA=F2 8, 2019 at 02:04, Konstantin Kharlamov=20
<hi-angel@HIDDEN> wrote:
> Well, according to #git channel on Freenode and this answer=20
> https://stackoverflow.com/questions/39834729/what-does-the-diff-git-outpu=
t-in-git-diff-refer-to=20
> apparently, it's there unless someone explicitly changed config for=20
> it to not be there.
>=20
> But any other ideas to detect git format are welcome. I personally=20
> would prefer to not do detection at all, because I'm sure the case=20
> where we could misdetect text and miscalculate the diff header is too=20
> statistically insignificant.

=85as well as consequences insignificant too, in case it somehow have=20
happened, I should add.

=





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 7 Oct 2019 23:04:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Oct 07 19:04:35 2019
Received: from localhost ([127.0.0.1]:49253 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iHc3P-0001zH-4v
	for submit <at> debbugs.gnu.org; Mon, 07 Oct 2019 19:04:35 -0400
Received: from forward105p.mail.yandex.net ([77.88.28.108]:51833)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hi-angel@HIDDEN>) id 1iHc3L-0001yz-5t
 for 37395 <at> debbugs.gnu.org; Mon, 07 Oct 2019 19:04:33 -0400
Received: from mxback28o.mail.yandex.net (mxback28o.mail.yandex.net
 [IPv6:2a02:6b8:0:1a2d::79])
 by forward105p.mail.yandex.net (Yandex) with ESMTP id DF7E44D40140;
 Tue,  8 Oct 2019 02:04:23 +0300 (MSK)
Received: from iva1-dacac67eb28c.qloud-c.yandex.net
 (iva1-dacac67eb28c.qloud-c.yandex.net [2a02:6b8:c0c:789:0:640:daca:c67e])
 by mxback28o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id RFQgHEyJSO-4N9iIQiX;
 Tue, 08 Oct 2019 02:04:23 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1570489463; bh=U65q+HFVRQMBHpBIrZr8Ps4ROzEUQjExCmL4FXqruF0=;
 h=In-Reply-To:Cc:To:Subject:From:References:Date:Message-Id;
 b=gZck18BUezyoynHaK9LgVVS29AY9v0XRj4aOg2OWljICHLoCTTJra0N6h68VF89yl
 655/Gx4BmjrnvMu+zDmvo+78oR4UfofkV90Es9RvwKWmnASZfANWY8Yr5x5hRp0QDK
 IiL5cv/pF+asRQZWd8TY8huMwj9aJrhuAi/v9W2c=
Authentication-Results: mxback28o.mail.yandex.net;
 dkim=pass header.i=@yandex.ru
Received: by iva1-dacac67eb28c.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id glbeUbQbWU-4MqiAmj4; Tue, 08 Oct 2019 02:04:23 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
Date: Tue, 08 Oct 2019 02:04:22 +0300
From: Konstantin Kharlamov <hi-angel@HIDDEN>
Subject: Re: bug#37395: [PATCH v3] diff-mode.el: take into account patch
 separators
To: Lars Ingebrigtsen <larsi@HIDDEN>
Message-Id: <1570489462.135652.1@HIDDEN>
In-Reply-To: <874l0l9njn.fsf@HIDDEN>
References: <1568323985.28657.0@HIDDEN>
 <20190916202643.27946-1-Hi-Angel@HIDDEN>
 <Konstantin	Kharlamov's message of "Mon, 16 Sep 2019 23:26:43 +0300">
X-Mailer: geary/3.35.0
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1251; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)



On =CF=ED, =EE=EA=F2 7, 2019 at 06:39, Lars Ingebrigtsen <larsi@HIDDEN>=20
wrote:
> (Some minor comments.)

Thanks!

> Konstantin Kharlamov <Hi-Angel@HIDDEN> writes:
>=20
>>  +(defsubst diff-prev-line-if-patch-separator ()
>>  +  "Return previous line if it has patch separator produced by
>>  +git-format-patch."
>=20
> I don't think this needs to be a defsubst -- a defun is fine here.

Will do.

> And the first doc string line should be a complete sentence.

Sorry, I'm not sure I get it: do you want me to keep the=20
"git-format-patch." text on the first line, with the rest of the=20
sentence?

>>  +(setq-local diff-buffer-type nil)
>=20
> This should probably be a defvar and then a setq-local in `diff-mode'.

Will do.

>>  +  (save-excursion
>>  +    (if (re-search-forward "^diff --git" nil t)
>>  +        (setq diff-buffer-type 'git)
>>  +      (setq diff-buffer-type nil))))
>=20
> Hm...  are we really guaranteed that all git diffs have that string in
> it somewhere?

Well, according to #git channel on Freenode and this answer=20
https://stackoverflow.com/questions/39834729/what-does-the-diff-git-output-=
in-git-diff-refer-to=20
apparently, it's there unless someone explicitly changed config for it=20
to not be there.

But any other ideas to detect git format are welcome. I personally=20
would prefer to not do detection at all, because I'm sure the case=20
where we could misdetect text and miscalculate the diff header is too=20
statistically insignificant. Too many things need to happen at once =97=20
and it doesn't seem that diff-mode being used by a lot of people too,=20
since pretty major problem that I fix here went unnoticed for so long.

=





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 7 Oct 2019 04:39:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Oct 07 00:39:47 2019
Received: from localhost ([127.0.0.1]:47195 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iHKoE-0000R7-LD
	for submit <at> debbugs.gnu.org; Mon, 07 Oct 2019 00:39:46 -0400
Received: from quimby.gnus.org ([80.91.231.51]:56244)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1iHKoC-0000Qz-C9
 for 37395 <at> debbugs.gnu.org; Mon, 07 Oct 2019 00:39:44 -0400
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie)
 by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.89) (envelope-from <larsi@HIDDEN>)
 id 1iHKo8-0005pq-Tz; Mon, 07 Oct 2019 06:39:43 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Konstantin Kharlamov <Hi-Angel@HIDDEN>
Subject: Re: bug#37395: [PATCH v3] diff-mode.el: take into account patch
 separators
References: <1568323985.28657.0@HIDDEN>
 <20190916202643.27946-1-Hi-Angel@HIDDEN>
Date: Mon, 07 Oct 2019 06:39:40 +0200
In-Reply-To: <20190916202643.27946-1-Hi-Angel@HIDDEN> (Konstantin
 Kharlamov's message of "Mon, 16 Sep 2019 23:26:43 +0300")
Message-ID: <874l0l9njn.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: (Some minor comments.) Konstantin Kharlamov
 <Hi-Angel@HIDDEN>
 writes: > +(defsubst diff-prev-line-if-patch-separator () > + "Return previous
 line if it has patch separator produced by > +git-format-patch." 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

(Some minor comments.)

Konstantin Kharlamov <Hi-Angel@HIDDEN> writes:

> +(defsubst diff-prev-line-if-patch-separator ()
> +  "Return previous line if it has patch separator produced by
> +git-format-patch."

I don't think this needs to be a defsubst -- a defun is fine here.  And
the first doc string line should be a complete sentence.

> +(setq-local diff-buffer-type nil)

This should probably be a defvar and then a setq-local in `diff-mode'.

> +  (save-excursion
> +    (if (re-search-forward "^diff --git" nil t)
> +        (setq diff-buffer-type 'git)
> +      (setq diff-buffer-type nil))))

Hm...  are we really guaranteed that all git diffs have that string in
it somewhere?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 16 Sep 2019 20:31:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Sep 16 16:31:22 2019
Received: from localhost ([127.0.0.1]:51143 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1i9xeb-0007rd-L9
	for submit <at> debbugs.gnu.org; Mon, 16 Sep 2019 16:31:22 -0400
Received: from forward104o.mail.yandex.net ([37.140.190.179]:32893)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hi-angel@HIDDEN>) id 1i9xeY-0007jb-IW
 for 37395 <at> debbugs.gnu.org; Mon, 16 Sep 2019 16:31:19 -0400
Received: from mxback27o.mail.yandex.net (mxback27o.mail.yandex.net
 [IPv6:2a02:6b8:0:1a2d::78])
 by forward104o.mail.yandex.net (Yandex) with ESMTP id 0B3219406D5;
 Mon, 16 Sep 2019 23:31:12 +0300 (MSK)
Received: from iva4-994a9845f60e.qloud-c.yandex.net
 (iva4-994a9845f60e.qloud-c.yandex.net [2a02:6b8:c0c:152e:0:640:994a:9845])
 by mxback27o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id J04yHk4s5K-VBIaOfa4;
 Mon, 16 Sep 2019 23:31:12 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1568665872; bh=9LF4/XjjvmxITVruj+k16/3nvjZ17mvlm3buMYxV3vA=;
 h=In-Reply-To:Cc:To:Subject:From:References:Date:Message-Id;
 b=kHntFE9xicIOylfAPKT3nTTkGDq55bkpugi2ZivZFH6/DbVXK5sfD8CDH4Pk5jOyD
 QE3zNbBIOqPC89h+Jf3FfBGJDLIDysgp/CHyBfqN3W5feG+E3RYDc9HO0bGiTfYIlE
 92JdTynpO597jcju5XhChGMZ286Kn5CY/86tiCvw=
Authentication-Results: mxback27o.mail.yandex.net;
 dkim=pass header.i=@yandex.ru
Received: by iva4-994a9845f60e.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id HbLLW4CwpP-VAHqJnUc; Mon, 16 Sep 2019 23:31:11 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
Date: Mon, 16 Sep 2019 23:31:10 +0300
From: Konstantin Kharlamov <hi-angel@HIDDEN>
Subject: Re: bug#37395: [PATCH] diff-mode.el: take into account patch
 separators
To: Eli Zaretskii <eliz@HIDDEN>
Message-Id: <1568665870.19637.0@HIDDEN>
In-Reply-To: <1568357907.5095.0@HIDDEN>
References: <1568323985.28657.0@HIDDEN>
 <20190912213445.16304-1-Hi-Angel@HIDDEN>
 <message from	Konstantin Kharlamov on Fri, 13 Sep 2019 00:34:45 +0300>
X-Mailer: geary/3.33.90
MIME-Version: 1.0
Content-Type: text/plain; charset=koi8-r; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)



On =F0=D4, =D3=C5=CE 13, 2019 at 09:58, Konstantin Kharlamov=20
<hi-angel@HIDDEN> wrote:
>=20
>=20
> On =F0=D4, =D3=C5=CE 13, 2019 at 09:14, Eli Zaretskii <eliz@HIDDEN> wrot=
e:
>>>  From: Konstantin Kharlamov <Hi-Angel@HIDDEN>
>>>  Date: Fri, 13 Sep 2019 00:34:45 +0300
>>>=20
>>>  * lisp/vc/diff-mode.el (diff-goto-line-before-patch-separator): an
>>>  inline function to check if prev. line was git-format-patch=20
>>> =7F=7Fseparator,
>>>  in which case go there.
>>>  (diff-end-of-hunk): make use of=20
>>> =7F=7F(diff-goto-line-before-patch-separator)
>>=20
>> The descriptions of changes should start with a capital letter. =20
>> Also,
>> your lines in the commit log message are too long, they should not
>> exceed 61 characters (because in the release tarball we create a
>> ChangeLog file from them, which prepends a TAB character to each
>> line).
>>=20
>>>  +(defsubst diff-goto-line-before-patch-separator ()
>>>  +  "Go to prev. line, then if it has patch separator as produced
>>>  +by git-format-patch, stay there. Otherwise go back."
>>=20
>> The first line of a doc string should be a complete sentence.  I
>> suggest to rephrase as follows:
>>=20
>>   Return buffer position before patch separator produced by=20
>> =7Fgit-format-patch.
>=20
> Thank you, I'll address the comments a bit later this day!
>=20
>>>  +  (previous-line)
>>>  +  (when (not (looking-at "-- "))
>>>  +      (next-line))
>>>  +  (point))
>>=20
>> Btw, Diff mode is more general than just Git-produced diffs.  Is=20
>> there
>> any possibility that this change will misfire in diffs produced by
>> other tools?  If so, perhaps we should also verify the buffer is=20
>> under
>> Git control.
>=20
> Oh, while writing this, I figured I should change the regexp from `--=20
> ` to `^-- $`. Will do.
>=20
> With that addressed: very unlikely. A miscalculation could happen if=20
> all of the following holds true *simultaneously*:
>=20
> 	* The diff removes a line with the exact text `- `, i.e. two=20
> characters {dash,space}. That would result in {dash,dash,space} diff,=20
> same as patch separator.
> 	* The line was the last line removed in the hunk.
> 	* The hunk has no context after the removed line
>=20
> Note, these need to hold true simultaneously. Give the low=20
> probability of this compared to git-format-patch that is used=20
> literally everywhere (and that without this patch diff-mode can't=20
> handle it), I think this is a reasonable trade-off.

While still on it: I figured I could detect whether diff has git-diff=20
format by searching the `diff --git` text that seems to be always=20
present when starting diff-mode, and only then try to find the=20
patch-separator. Done. I'm not sure if the `setq-local foo` and then=20
modification of the `foo` in `(define-derived-mode)` is the preferred=20
way to do this, but otherwise it seems to be fine, and worked in my=20
tests.

=





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 16 Sep 2019 20:27:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Sep 16 16:27:11 2019
Received: from localhost ([127.0.0.1]:51134 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1i9xaY-0006VO-9F
	for submit <at> debbugs.gnu.org; Mon, 16 Sep 2019 16:27:10 -0400
Received: from forward101p.mail.yandex.net ([77.88.28.101]:60164)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <Hi-Angel@HIDDEN>) id 1i9xaP-0006Ul-C3
 for 37395 <at> debbugs.gnu.org; Mon, 16 Sep 2019 16:27:05 -0400
Received: from mxback5g.mail.yandex.net (mxback5g.mail.yandex.net
 [IPv6:2a02:6b8:0:1472:2741:0:8b7:166])
 by forward101p.mail.yandex.net (Yandex) with ESMTP id 767B73280A4A
 for <37395 <at> debbugs.gnu.org>; Mon, 16 Sep 2019 23:26:54 +0300 (MSK)
Received: from myt1-e9eae5d2de9d.qloud-c.yandex.net
 (myt1-e9eae5d2de9d.qloud-c.yandex.net [2a02:6b8:c00:1290:0:640:e9ea:e5d2])
 by mxback5g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id BaypbsY89x-QsLa2n6R; 
 Mon, 16 Sep 2019 23:26:54 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1568665614; bh=Ax0aI7bSrLyiz9v84zFvwXD8ojrgeqZfpn6RqvEGqqE=;
 h=Subject:To:From:Date:Message-Id;
 b=YWWxDmbM+XBKJdrg7uSzlY7cwNWXQXu1MPndcRZaqx9PEv3iYJmEB2kYnedKi52UG
 F58sFZyI574ULbpCDe7nw3Xv2JHWaupp+iq8rRNJGyzeBWMe0ihRf+uNlDMvxRqN9P
 p3wKKeMS5YgZtpZi5jHphjxg0uLA9klLtBN9MaUg=
Authentication-Results: mxback5g.mail.yandex.net; dkim=pass header.i=@yandex.ru
Received: by myt1-e9eae5d2de9d.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id jMZQam1zq6-QrHWgrIL; Mon, 16 Sep 2019 23:26:53 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
From: Konstantin Kharlamov <Hi-Angel@HIDDEN>
To: 37395 <at> debbugs.gnu.org
Subject: [PATCH v3] diff-mode.el: take into account patch separators
Date: Mon, 16 Sep 2019 23:26:43 +0300
Message-Id: <20190916202643.27946-1-Hi-Angel@HIDDEN>
X-Mailer: git-send-email 2.23.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

* lisp/vc/diff-mode.el (diff-prev-line-if-patch-separator):
An inline function to return prev. line if it has
git-format-patch separator.
(diff-end-of-hunk): Make use of
diff-prev-line-if-patch-separator
diff-buffer-type: whether a buffer is a git-diff
(define-derived-mode): set diff-buffer-type to appropriate
value
---

v3: detect whether buffer has git-diff format.


 lisp/vc/diff-mode.el | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 19f9c802d4..5e74dbc18c 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -511,6 +511,20 @@ diff-hunk-style
     (goto-char (match-end 0)))
   style)
 
+(defsubst diff-prev-line-if-patch-separator ()
+  "Return previous line if it has patch separator produced by
+git-format-patch."
+  (pcase diff-buffer-type
+    ('git
+     (save-excursion
+       (let ((old-point (point)))
+         (previous-line)
+         (beginning-of-line)
+         (if (looking-at "^-- $")
+             (point)
+           old-point))))
+    (_ (point))))
+
 (defun diff-end-of-hunk (&optional style donttrustheader)
   "Advance to the end of the current hunk, and return its position."
   (let (end)
@@ -561,7 +575,8 @@ diff-end-of-hunk
         (goto-char (or end (point-max)))
         (while (eq ?\n (char-before (1- (point))))
           (forward-char -1)
-          (setq end (point)))))
+          (setq end (point))))
+      (setq end (diff-prev-line-if-patch-separator)))
     ;; The return value is used by easy-mmode-define-navigation.
     (goto-char (or end (point-max)))))
 
@@ -1426,6 +1441,8 @@ diff--font-lock-cleanup
 (defvar whitespace-style)
 (defvar whitespace-trailing-regexp)
 
+(setq-local diff-buffer-type nil)
+
 ;;;###autoload
 (define-derived-mode diff-mode fundamental-mode "Diff"
   "Major mode for viewing/editing context diffs.
@@ -1491,7 +1508,11 @@ diff-mode
   (add-function :filter-return (local 'filter-buffer-substring-function)
                 #'diff--filter-substring)
   (unless buffer-file-name
-    (hack-dir-local-variables-non-file-buffer)))
+    (hack-dir-local-variables-non-file-buffer))
+  (save-excursion
+    (if (re-search-forward "^diff --git" nil t)
+        (setq diff-buffer-type 'git)
+      (setq diff-buffer-type nil))))
 
 ;;;###autoload
 (define-minor-mode diff-minor-mode
-- 
2.23.0





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 13 Sep 2019 09:19:40 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Sep 13 05:19:40 2019
Received: from localhost ([127.0.0.1]:44369 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1i8hjw-0006E6-3F
	for submit <at> debbugs.gnu.org; Fri, 13 Sep 2019 05:19:40 -0400
Received: from forward100j.mail.yandex.net ([5.45.198.240]:48669)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <Hi-Angel@HIDDEN>) id 1i8hjt-0006Dq-5u
 for 37395 <at> debbugs.gnu.org; Fri, 13 Sep 2019 05:19:38 -0400
Received: from mxback3j.mail.yandex.net (mxback3j.mail.yandex.net
 [IPv6:2a02:6b8:0:1619::10c])
 by forward100j.mail.yandex.net (Yandex) with ESMTP id E75B950E07F5
 for <37395 <at> debbugs.gnu.org>; Fri, 13 Sep 2019 12:19:29 +0300 (MSK)
Received: from sas1-8413c76d2429.qloud-c.yandex.net
 (sas1-8413c76d2429.qloud-c.yandex.net [2a02:6b8:c08:2206:0:640:8413:c76d])
 by mxback3j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id C91Dewgosj-JTYSOMr5; 
 Fri, 13 Sep 2019 12:19:29 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1568366369; bh=BKNJXxJGBfAMLpiDE6PaVllP3qL2D2FhHhmqIw7ObmE=;
 h=In-Reply-To:Subject:To:From:References:Date:Message-Id;
 b=PGeaHvKf1k43+jxACjl3jxrdNxhPgxzd4bD0hSzQKeCwNbEjzlaXMEbi1lmSp9KdJ
 yBNvViGgcCkpaP04Sf0t0DHE3sYOqGMaDRYl2xKcLhR2vm9ZiOQ6P1DC8MHmhcpamH
 ppH6g9LAMVdZrKOmWOS8xES4+PtPkp+VHXiFG6lU=
Authentication-Results: mxback3j.mail.yandex.net; dkim=pass header.i=@yandex.ru
Received: by sas1-8413c76d2429.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id E6Ujd12ZdY-JTEe4m0j; Fri, 13 Sep 2019 12:19:29 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
From: Konstantin Kharlamov <Hi-Angel@HIDDEN>
To: 37395 <at> debbugs.gnu.org
Subject: [PATCH v2] diff-mode.el: take into account patch separators
Date: Fri, 13 Sep 2019 12:19:21 +0300
Message-Id: <20190913091921.23441-1-Hi-Angel@HIDDEN>
X-Mailer: git-send-email 2.23.0
In-Reply-To: <838sqs205w.fsf@HIDDEN>
References: <838sqs205w.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

* lisp/vc/diff-mode.el (diff-prev-line-if-patch-separator):
An inline function to return prev. line if it has
git-format-patch separator.
(diff-end-of-hunk): Make use of
diff-prev-line-if-patch-separator
---

v2:
* Start commit description with capital letter
* Limit commit description to 61 character line length
* Rename diff-goto-line-before-patch-separator, to
  diff-prev-line-if-patch-separator and rephrase the doc-string.
* diff-prev-line-if-patch-separator now does not mutate point.
* Make sure we're at line beginning before (looking-at …)

 lisp/vc/diff-mode.el | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 19f9c802d4..6702614472 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -511,6 +511,17 @@ diff-hunk-style
     (goto-char (match-end 0)))
   style)
 
+(defsubst diff-prev-line-if-patch-separator ()
+  "Return previous line if it has patch separator produced by
+git-format-patch."
+  (save-excursion
+    (let ((old-point (point)))
+      (previous-line)
+      (beginning-of-line)
+      (if (looking-at "^-- $")
+          (point)
+        old-point))))
+
 (defun diff-end-of-hunk (&optional style donttrustheader)
   "Advance to the end of the current hunk, and return its position."
   (let (end)
@@ -561,7 +572,8 @@ diff-end-of-hunk
         (goto-char (or end (point-max)))
         (while (eq ?\n (char-before (1- (point))))
           (forward-char -1)
-          (setq end (point)))))
+          (setq end (point))))
+      (setq end (diff-prev-line-if-patch-separator)))
     ;; The return value is used by easy-mmode-define-navigation.
     (goto-char (or end (point-max)))))
 
-- 
2.23.0





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 13 Sep 2019 06:58:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Sep 13 02:58:42 2019
Received: from localhost ([127.0.0.1]:44274 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1i8fXW-0000Zd-DO
	for submit <at> debbugs.gnu.org; Fri, 13 Sep 2019 02:58:42 -0400
Received: from forward104j.mail.yandex.net ([5.45.198.247]:48166)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hi-angel@HIDDEN>) id 1i8fXT-0000ZM-GL
 for 37395 <at> debbugs.gnu.org; Fri, 13 Sep 2019 02:58:41 -0400
Received: from mxback21j.mail.yandex.net (mxback21j.mail.yandex.net
 [IPv6:2a02:6b8:0:1619::221])
 by forward104j.mail.yandex.net (Yandex) with ESMTP id 99DF04A0CB4;
 Fri, 13 Sep 2019 09:58:32 +0300 (MSK)
Received: from myt4-6a59ac13d093.qloud-c.yandex.net
 (myt4-6a59ac13d093.qloud-c.yandex.net [2a02:6b8:c12:88f:0:640:6a59:ac13])
 by mxback21j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id dDkbhkWb8d-wWSm3tjk;
 Fri, 13 Sep 2019 09:58:32 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1568357912; bh=tqvDt4kPHXj7+o7D5PXngEZvRSYdUGj8GwSHrMM+k+o=;
 h=In-Reply-To:Cc:To:Subject:From:References:Date:Message-Id;
 b=VB7sO+yaZf3nviRzSaBu+CAN3qrnMZJDkwbFR31JiddP0ALKmzlxQnJ5hD9j6vV6h
 BiMug7AYd2Ri25XkInTlMT/wxH+Mfj9B2j1euKSMur1N5Kt1lxBEd5+7F98jqGVymw
 UTnO2prex1OHjFeIo17nxXXTA5aqVpFzzu0WK3EQ=
Authentication-Results: mxback21j.mail.yandex.net;
 dkim=pass header.i=@yandex.ru
Received: by myt4-6a59ac13d093.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id hmr2fpHNN7-wVF49NjO; Fri, 13 Sep 2019 09:58:31 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
Date: Fri, 13 Sep 2019 09:58:27 +0300
From: Konstantin Kharlamov <hi-angel@HIDDEN>
Subject: Re: bug#37395: [PATCH] diff-mode.el: take into account patch
 separators
To: Eli Zaretskii <eliz@HIDDEN>
Message-Id: <1568357907.5095.0@HIDDEN>
In-Reply-To: <838sqs205w.fsf@HIDDEN>
References: <1568323985.28657.0@HIDDEN>
 <20190912213445.16304-1-Hi-Angel@HIDDEN>
 <message from	Konstantin Kharlamov on Fri, 13 Sep 2019 00:34:45 +0300>
X-Mailer: geary/3.33.90
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-5; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)



On =BF=E2, =E1=D5=DD 13, 2019 at 09:14, Eli Zaretskii <eliz@HIDDEN> wrote:
>>  From: Konstantin Kharlamov <Hi-Angel@HIDDEN>
>>  Date: Fri, 13 Sep 2019 00:34:45 +0300
>>=20
>>  * lisp/vc/diff-mode.el (diff-goto-line-before-patch-separator): an
>>  inline function to check if prev. line was git-format-patch=20
>> separator,
>>  in which case go there.
>>  (diff-end-of-hunk): make use of=20
>> (diff-goto-line-before-patch-separator)
>=20
> The descriptions of changes should start with a capital letter.  Also,
> your lines in the commit log message are too long, they should not
> exceed 61 characters (because in the release tarball we create a
> ChangeLog file from them, which prepends a TAB character to each
> line).
>=20
>>  +(defsubst diff-goto-line-before-patch-separator ()
>>  +  "Go to prev. line, then if it has patch separator as produced
>>  +by git-format-patch, stay there. Otherwise go back."
>=20
> The first line of a doc string should be a complete sentence.  I
> suggest to rephrase as follows:
>=20
>   Return buffer position before patch separator produced by=20
> git-format-patch.

Thank you, I'll address the comments a bit later this day!

>>  +  (previous-line)
>>  +  (when (not (looking-at "-- "))
>>  +      (next-line))
>>  +  (point))
>=20
> Btw, Diff mode is more general than just Git-produced diffs.  Is there
> any possibility that this change will misfire in diffs produced by
> other tools?  If so, perhaps we should also verify the buffer is under
> Git control.

Oh, while writing this, I figured I should change the regexp from `-- `=20
to `^-- $`. Will do.

With that addressed: very unlikely. A miscalculation could happen if=20
all of the following holds true *simultaneously*:

	* The diff removes a line with the exact text `- `, i.e. two=20
characters {dash,space}. That would result in {dash,dash,space} diff,=20
same as patch separator.
	* The line was the last line removed in the hunk.
	* The hunk has no context after the removed line

Note, these need to hold true simultaneously. Give the low probability=20
of this compared to git-format-patch that is used literally everywhere=20
(and that without this patch diff-mode can't handle it), I think this=20
is a reasonable trade-off.

=





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 13 Sep 2019 06:13:59 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Sep 13 02:13:59 2019
Received: from localhost ([127.0.0.1]:44268 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1i8eqE-0007y6-OS
	for submit <at> debbugs.gnu.org; Fri, 13 Sep 2019 02:13:58 -0400
Received: from eggs.gnu.org ([209.51.188.92]:43948)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1i8eqC-0007xs-KC
 for 37395 <at> debbugs.gnu.org; Fri, 13 Sep 2019 02:13:57 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:48282)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <eliz@HIDDEN>)
 id 1i8eq7-0002u4-6L; Fri, 13 Sep 2019 02:13:51 -0400
Received: from [176.228.60.248] (port=1647 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1i8eq6-00056K-FZ; Fri, 13 Sep 2019 02:13:50 -0400
Date: Fri, 13 Sep 2019 09:14:03 +0300
Message-Id: <838sqs205w.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Konstantin Kharlamov <Hi-Angel@HIDDEN>
In-reply-to: <20190912213445.16304-1-Hi-Angel@HIDDEN> (message from
 Konstantin Kharlamov on Fri, 13 Sep 2019 00:34:45 +0300)
Subject: Re: bug#37395: [PATCH] diff-mode.el: take into account patch
 separators
References: <1568323985.28657.0@HIDDEN>
 <20190912213445.16304-1-Hi-Angel@HIDDEN>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 37395
Cc: 37395 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Konstantin Kharlamov <Hi-Angel@HIDDEN>
> Date: Fri, 13 Sep 2019 00:34:45 +0300
> 
> * lisp/vc/diff-mode.el (diff-goto-line-before-patch-separator): an
> inline function to check if prev. line was git-format-patch separator,
> in which case go there.
> (diff-end-of-hunk): make use of (diff-goto-line-before-patch-separator)

The descriptions of changes should start with a capital letter.  Also,
your lines in the commit log message are too long, they should not
exceed 61 characters (because in the release tarball we create a
ChangeLog file from them, which prepends a TAB character to each
line).

> +(defsubst diff-goto-line-before-patch-separator ()
> +  "Go to prev. line, then if it has patch separator as produced
> +by git-format-patch, stay there. Otherwise go back."

The first line of a doc string should be a complete sentence.  I
suggest to rephrase as follows:

  Return buffer position before patch separator produced by git-format-patch.

> +  (previous-line)
> +  (when (not (looking-at "-- "))
> +      (next-line))
> +  (point))

Btw, Diff mode is more general than just Git-produced diffs.  Is there
any possibility that this change will misfire in diffs produced by
other tools?  If so, perhaps we should also verify the buffer is under
Git control.

Thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at 37395 <at> debbugs.gnu.org:


Received: (at 37395) by debbugs.gnu.org; 12 Sep 2019 21:35:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Sep 12 17:35:07 2019
Received: from localhost ([127.0.0.1]:44164 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1i8Wk7-0008Ga-47
	for submit <at> debbugs.gnu.org; Thu, 12 Sep 2019 17:35:07 -0400
Received: from forward103o.mail.yandex.net ([37.140.190.177]:40361)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <Hi-Angel@HIDDEN>) id 1i8Wk4-0008Fo-ES
 for 37395 <at> debbugs.gnu.org; Thu, 12 Sep 2019 17:35:06 -0400
Received: from mxback12g.mail.yandex.net (mxback12g.mail.yandex.net
 [IPv6:2a02:6b8:0:1472:2741:0:8b7:91])
 by forward103o.mail.yandex.net (Yandex) with ESMTP id B60535F80328
 for <37395 <at> debbugs.gnu.org>; Fri, 13 Sep 2019 00:34:56 +0300 (MSK)
Received: from sas8-b94264ec42f5.qloud-c.yandex.net
 (sas8-b94264ec42f5.qloud-c.yandex.net [2a02:6b8:c1b:2a1f:0:640:b942:64ec])
 by mxback12g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Ght53kdkbd-Yu2Of1fV;
 Fri, 13 Sep 2019 00:34:56 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1568324096; bh=RirpcKE9vFeFFy7WOMFvsAzQ7ZjgkwSuajtPlOb08bg=;
 h=Subject:To:From:Date:Message-Id;
 b=TgN5kCxJyESscOughTD2x2bPxtM1uy4bub2hc202WwHTdskmQZYnwTrxFN9T7/ODh
 kgc2qBs/CnoHZeZaoG5AhHsJjP0pxTsN21gRSkOK16bx8G1VXSJIVUgUTurUkv6G10
 O51CaitexXAaoT37G8zfsoIfBkBl2lOl9J+TFmjY=
Authentication-Results: mxback12g.mail.yandex.net;
 dkim=pass header.i=@yandex.ru
Received: by sas8-b94264ec42f5.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id ZbSwCbAh8H-YuEeXpBs; Fri, 13 Sep 2019 00:34:56 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
From: Konstantin Kharlamov <Hi-Angel@HIDDEN>
To: 37395 <at> debbugs.gnu.org
Subject: [PATCH] diff-mode.el: take into account patch separators
Date: Fri, 13 Sep 2019 00:34:45 +0300
Message-Id: <20190912213445.16304-1-Hi-Angel@HIDDEN>
X-Mailer: git-send-email 2.23.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 37395
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

* lisp/vc/diff-mode.el (diff-goto-line-before-patch-separator): an
inline function to check if prev. line was git-format-patch separator,
in which case go there.
(diff-end-of-hunk): make use of (diff-goto-line-before-patch-separator)
---
 lisp/vc/diff-mode.el | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 19f9c802d4..a3e4923fb4 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -511,6 +511,14 @@ diff-hunk-style
     (goto-char (match-end 0)))
   style)
 
+(defsubst diff-goto-line-before-patch-separator ()
+  "Go to prev. line, then if it has patch separator as produced
+by git-format-patch, stay there. Otherwise go back."
+  (previous-line)
+  (when (not (looking-at "-- "))
+      (next-line))
+  (point))
+
 (defun diff-end-of-hunk (&optional style donttrustheader)
   "Advance to the end of the current hunk, and return its position."
   (let (end)
@@ -561,7 +569,8 @@ diff-end-of-hunk
         (goto-char (or end (point-max)))
         (while (eq ?\n (char-before (1- (point))))
           (forward-char -1)
-          (setq end (point)))))
+          (setq end (point))))
+      (setq end (diff-goto-line-before-patch-separator)))
     ;; The return value is used by easy-mmode-define-navigation.
     (goto-char (or end (point-max)))))
 
-- 
2.23.0





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Sep 2019 21:33:19 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Sep 12 17:33:19 2019
Received: from localhost ([127.0.0.1]:44159 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1i8WiM-0008D1-Lh
	for submit <at> debbugs.gnu.org; Thu, 12 Sep 2019 17:33:18 -0400
Received: from lists.gnu.org ([209.51.188.17]:38192)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hi-angel@HIDDEN>) id 1i8WiL-0008Ct-5S
 for submit <at> debbugs.gnu.org; Thu, 12 Sep 2019 17:33:17 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:60488)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <hi-angel@HIDDEN>) id 1i8WiJ-0008V4-NA
 for bug-gnu-emacs@HIDDEN; Thu, 12 Sep 2019 17:33:16 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: **
X-Spam-Status: No, score=2.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM,
 SPOOFED_FREEMAIL,URIBL_BLOCKED autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <hi-angel@HIDDEN>) id 1i8WiH-0001jp-V5
 for bug-gnu-emacs@HIDDEN; Thu, 12 Sep 2019 17:33:14 -0400
Received: from forward105o.mail.yandex.net ([2a02:6b8:0:1a2d::608]:49288)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <hi-angel@HIDDEN>) id 1i8WiH-0001i2-Cw
 for bug-gnu-emacs@HIDDEN; Thu, 12 Sep 2019 17:33:13 -0400
Received: from mxback5j.mail.yandex.net (mxback5j.mail.yandex.net
 [IPv6:2a02:6b8:0:1619::10e])
 by forward105o.mail.yandex.net (Yandex) with ESMTP id BF6F44200A8D
 for <bug-gnu-emacs@HIDDEN>; Fri, 13 Sep 2019 00:33:06 +0300 (MSK)
Received: from sas2-69645cccb3fe.qloud-c.yandex.net
 (sas2-69645cccb3fe.qloud-c.yandex.net [2a02:6b8:c08:bd8e:0:640:6964:5ccc])
 by mxback5j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id OKJzOl3gzm-X6ZGZipi; 
 Fri, 13 Sep 2019 00:33:06 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1568323986; bh=k6mLAK66dNdOlx/TDFfi9LrWSioc7TSNaE189RF+guw=;
 h=To:Subject:From:Date:Message-Id;
 b=kvSWIoV6OubWI4IhyeJlhyBs06mxQvjof2qdHsQKXTKMH76P4XNooQBxZKQrMkOjg
 VTWKLE5tsL3zaV5nUQHK2iYWUz6cAtLv07pGAH/FK1ZvInIANRlS3/wD/P0ZlTIzRE
 RR17ALun3/g9/rjMsxMlCGZaJuS3zFmNCKd2foCI=
Authentication-Results: mxback5j.mail.yandex.net; dkim=pass header.i=@yandex.ru
Received: by sas2-69645cccb3fe.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA
 id s33Rxrqxom-X5HmaYK9; Fri, 13 Sep 2019 00:33:06 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
Date: Fri, 13 Sep 2019 00:33:05 +0300
From: Konstantin Kharlamov <hi-angel@HIDDEN>
Subject: Diff-mode doesn't take into account patch-separators as produced by
 git-format-patch
To: bug-gnu-emacs@HIDDEN
Message-Id: <1568323985.28657.0@HIDDEN>
X-Mailer: geary/3.33.90
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 2a02:6b8:0:1a2d::608
X-Spam-Score: 0.7 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.3 (/)

As title says. As a follow-up to this report I'm gonna send a fix to 
this problem.

Observable result of the problem is that Emacs thinks `-- ` patch line 
is a "deleted line", whereas it actually is end of the patch.

The follow-up patch I successfully used to edit patch-series of 12 
patches to libinput 
https://gitlab.freedesktop.org/libinput/libinput/merge_requests/288#note_223871

# Steps to reproduce

1. In terminal, go to Emacs git repository
2. Execute `git format-patch -1 --stdout > 1.patch`
3. Open 1.patch in Emacs (diff-mode should automatically get enabled)
4. Replace at the beginning of a "deleted line" the `-` with space ` `.

## Expected

The 4-digit header (which looks like `@@ -561,7 +569,8`) should have 
first 2 digits (561 and 7 in example) unchanged.

## Actual

The 4-digit header increases count of 2nd digit (7 in example) by one.






Acknowledgement sent to Konstantin Kharlamov <hi-angel@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#37395; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 13 Oct 2019 04:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.