From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Konstantin Kharlamov Newsgroups: gmane.emacs.bugs Subject: bug#37395: [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@yandex.ru> References: <1568323985.28657.0@yandex.ru> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="108811"; mail-complaints-to="usenet@blaine.gmane.org" To: 37395@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 09 23:47:09 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iIJnY-000SBi-Ny for geb-bug-gnu-emacs@m.gmane.org; Wed, 09 Oct 2019 23:47:08 +0200 Original-Received: from localhost ([::1]:59830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIJnX-0000cc-A7 for geb-bug-gnu-emacs@m.gmane.org; Wed, 09 Oct 2019 17:47:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60086) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIIFf-0008Dj-I2 for bug-gnu-emacs@gnu.org; Wed, 09 Oct 2019 16:08:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIIFe-0002MG-Dp for bug-gnu-emacs@gnu.org; Wed, 09 Oct 2019 16:08:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45350) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iIIFd-0002Kh-So for bug-gnu-emacs@gnu.org; Wed, 09 Oct 2019 16:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iIIFd-0000mq-MK for bug-gnu-emacs@gnu.org; Wed, 09 Oct 2019 16:08:01 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <1568323985.28657.0@yandex.ru> Resent-From: Konstantin Kharlamov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Oct 2019 20:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37395 X-GNU-PR-Package: emacs Original-Received: via spool by 37395-submit@debbugs.gnu.org id=B37395.15706516703005 (code B ref 37395); Wed, 09 Oct 2019 20:08:01 +0000 Original-Received: (at 37395) by debbugs.gnu.org; 9 Oct 2019 20:07:50 +0000 Original-Received: from localhost ([127.0.0.1]:54171 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iIIFR-0000mP-LR for submit@debbugs.gnu.org; Wed, 09 Oct 2019 16:07:49 -0400 Original-Received: from forward104j.mail.yandex.net ([5.45.198.247]:54746) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iIIFO-0000m7-KN for 37395@debbugs.gnu.org; Wed, 09 Oct 2019 16:07:48 -0400 Original-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@debbugs.gnu.org>; Wed, 9 Oct 2019 23:07:39 +0300 (MSK) Original-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 Original-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) X-Mailer: git-send-email 2.23.0 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: 209.51.188.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:168799 Archived-At: * 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