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 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@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="232015"; 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 Mon Sep 16 22:28:14 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 1i9xbY-000yBC-MH for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Sep 2019 22:28:12 +0200 Original-Received: from localhost ([::1]:39806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9xbW-0002we-VV for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Sep 2019 16:28:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52698) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9xbR-0002wW-1R for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2019 16:28:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9xbP-0007hx-Q4 for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2019 16:28:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42313) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i9xbO-0007gm-LV for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2019 16:28:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i9xbO-0006WV-CC for bug-gnu-emacs@gnu.org; Mon, 16 Sep 2019 16:28:02 -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: Mon, 16 Sep 2019 20:28: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.156866563125015 (code B ref 37395); Mon, 16 Sep 2019 20:28:01 +0000 Original-Received: (at 37395) by debbugs.gnu.org; 16 Sep 2019 20:27:11 +0000 Original-Received: from localhost ([127.0.0.1]:51134 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i9xaY-0006VO-9F for submit@debbugs.gnu.org; Mon, 16 Sep 2019 16:27:10 -0400 Original-Received: from forward101p.mail.yandex.net ([77.88.28.101]:60164) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1i9xaP-0006Ul-C3 for 37395@debbugs.gnu.org; Mon, 16 Sep 2019 16:27:05 -0400 Original-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@debbugs.gnu.org>; Mon, 16 Sep 2019 23:26:54 +0300 (MSK) Original-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 Original-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) 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:166581 Archived-At: * 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